node-autotask 0.71.0 → 0.73.0
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/CHANGELOG.md +24 -0
- package/MCP_TOOL_CATALOG.json +196 -9
- package/README.md +1 -1
- package/capabilities.json +651 -9
- package/dist/capabilities-data.js +650 -8
- package/dist/capabilities.cjs +4 -4
- package/dist/capabilities.js +1 -1
- package/dist/{chunk-4DSLRDIF.cjs → chunk-CKIKNZEB.cjs} +31 -30
- package/dist/{chunk-QQFF7X67.cjs → chunk-CWSXFVF2.cjs} +229 -16
- package/dist/{chunk-YKQ2KNQO.js → chunk-L4J5EDCU.js} +3 -2
- package/dist/{chunk-LKJA57CH.js → chunk-PNMEXWYR.js} +3 -3
- package/dist/{chunk-5COLIVBE.js → chunk-RFH4VBMX.js} +126 -2
- package/dist/{chunk-QJ327YI6.cjs → chunk-STUQU7AX.cjs} +301 -177
- package/dist/{chunk-4OR3XBIP.js → chunk-VHN5B7OQ.js} +223 -12
- package/dist/{chunk-JLCHKCEB.cjs → chunk-VHNWLON6.cjs} +3 -3
- package/dist/{index-CM_SRgtH.d.cts → index-CGp16Cdm.d.cts} +49 -21
- package/dist/{index-CM_SRgtH.d.ts → index-CGp16Cdm.d.ts} +49 -21
- package/dist/{index-lGpxr4gY.d.ts → index-Dv8d9p_J.d.ts} +165 -4
- package/dist/{index-CAXT5ZKT.d.cts → index-MUM-uBX1.d.cts} +165 -4
- package/dist/index.cjs +84 -84
- package/dist/index.d.cts +3 -5
- package/dist/index.d.ts +3 -5
- package/dist/index.js +5 -5
- package/dist/operations/index.cjs +51 -51
- package/dist/operations/index.d.cts +5 -6
- package/dist/operations/index.d.ts +5 -6
- package/dist/operations/index.js +2 -2
- package/dist/pool.cjs +12 -12
- package/dist/pool.d.cts +1 -1
- package/dist/pool.d.ts +1 -1
- package/dist/pool.js +4 -4
- package/dist/resources/index.cjs +27 -27
- package/dist/resources/index.d.cts +2 -2
- package/dist/resources/index.d.ts +2 -2
- package/dist/resources/index.js +3 -3
- package/dist/types/index.d.cts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/docs/API.md +26 -7
- package/docs/N8N-ADAPTER.md +1 -1
- package/package.json +1 -1
- package/dist/base-CHMATPq0.d.cts +0 -145
- package/dist/base-CHMATPq0.d.ts +0 -145
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkCWSXFVF2_cjs = require('./chunk-CWSXFVF2.cjs');
|
|
4
|
+
var chunkVHNWLON6_cjs = require('./chunk-VHNWLON6.cjs');
|
|
5
5
|
|
|
6
6
|
// src/resources/special/configuration_items.ts
|
|
7
7
|
async function fetchRecord(http, path, label, readOpts) {
|
|
8
8
|
const res = await http.request({ method: "GET", path, operation: "configuration_items.moveConfigurationItem", maxRetries: readOpts?.maxRetries });
|
|
9
9
|
const body = res;
|
|
10
10
|
if (body === null || !("item" in body) || body.item === null || body.item === void 0) {
|
|
11
|
-
throw new
|
|
11
|
+
throw new chunkCWSXFVF2_cjs.NotFoundError(`${label} not found`, { code: "NOT_FOUND", category: "not_found" });
|
|
12
12
|
}
|
|
13
13
|
return body.item;
|
|
14
14
|
}
|
|
15
15
|
async function moveConfigurationItem(_resource, sourceId, opts) {
|
|
16
16
|
const http = _resource.http;
|
|
17
|
-
const numericSource =
|
|
17
|
+
const numericSource = chunkCWSXFVF2_cjs.parseIdentifier(sourceId, "sourceId");
|
|
18
18
|
if (opts?.destinationCompanyId === void 0) {
|
|
19
|
-
throw new
|
|
19
|
+
throw new chunkCWSXFVF2_cjs.AutotaskConfigError("moveConfigurationItem: destinationCompanyId is required");
|
|
20
20
|
}
|
|
21
|
-
const destId =
|
|
21
|
+
const destId = chunkCWSXFVF2_cjs.parseIdentifier(opts.destinationCompanyId, "destinationCompanyId");
|
|
22
22
|
const source = await fetchRecord(http, `/V1.0/ConfigurationItems/${numericSource}`, `Configuration item ${numericSource}`, { maxRetries: opts.maxRetries });
|
|
23
23
|
await fetchRecord(http, `/V1.0/Companies/${destId}`, `Company ${destId}`, { maxRetries: opts.maxRetries });
|
|
24
24
|
const body = { ...source };
|
|
@@ -28,20 +28,20 @@ async function moveConfigurationItem(_resource, sourceId, opts) {
|
|
|
28
28
|
body.companyID = destId;
|
|
29
29
|
body.isActive = true;
|
|
30
30
|
if (opts.newReferenceTitle !== void 0) {
|
|
31
|
-
if (opts.newReferenceTitle.trim() === "") throw new
|
|
31
|
+
if (opts.newReferenceTitle.trim() === "") throw new chunkCWSXFVF2_cjs.AutotaskConfigError("moveConfigurationItem: newReferenceTitle must be non-empty");
|
|
32
32
|
body.referenceTitle = opts.newReferenceTitle.trim();
|
|
33
33
|
}
|
|
34
34
|
if (opts.lastModifiedDate !== void 0) {
|
|
35
35
|
const current = source.lastModifiedDate;
|
|
36
36
|
if (current !== opts.lastModifiedDate) {
|
|
37
|
-
throw new
|
|
37
|
+
throw new chunkCWSXFVF2_cjs.StaleObjectError(
|
|
38
38
|
`moveConfigurationItem: source item ${numericSource} was modified since the snapshot (expected lastModifiedDate ${opts.lastModifiedDate}, current ${current ?? "unknown"})`,
|
|
39
39
|
{ operation: "configuration_items.moveConfigurationItem", resourceIds: [numericSource], details: { idRefs: [{ entity: "configuration_item", id: numericSource }] } }
|
|
40
40
|
);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
if (opts.dryRun === true) {
|
|
44
|
-
return
|
|
44
|
+
return chunkCWSXFVF2_cjs.buildDryRunResult({
|
|
45
45
|
operation: "configuration_items.moveConfigurationItem",
|
|
46
46
|
method: "POST",
|
|
47
47
|
path: "/V1.0/ConfigurationItems",
|
|
@@ -66,7 +66,7 @@ async function moveConfigurationItem(_resource, sourceId, opts) {
|
|
|
66
66
|
const createdBody = created;
|
|
67
67
|
const newId = createdBody !== null ? createdBody.itemId ?? createdBody.id : void 0;
|
|
68
68
|
if (typeof newId !== "number") {
|
|
69
|
-
throw new
|
|
69
|
+
throw new chunkCWSXFVF2_cjs.AutotaskConfigError("moveConfigurationItem: vendor create response has no itemId");
|
|
70
70
|
}
|
|
71
71
|
let sourceDeactivated = false;
|
|
72
72
|
if (opts.deactivateSource !== false) {
|
|
@@ -85,7 +85,7 @@ var PROFILE_PART_LIMIT = 50;
|
|
|
85
85
|
function profilePartLimit(value, name) {
|
|
86
86
|
const n = value === void 0 ? PROFILE_PART_LIMIT : Math.trunc(value);
|
|
87
87
|
if (!Number.isInteger(n) || n < 1) {
|
|
88
|
-
throw new
|
|
88
|
+
throw new chunkCWSXFVF2_cjs.AutotaskConfigError(`profile: ${name} must be an integer >= 1 (got ${String(value)})`);
|
|
89
89
|
}
|
|
90
90
|
return n;
|
|
91
91
|
}
|
|
@@ -94,17 +94,17 @@ async function contextFetchPart(http, entityPath, referenceId, entity) {
|
|
|
94
94
|
return null;
|
|
95
95
|
}
|
|
96
96
|
try {
|
|
97
|
-
const res = await
|
|
97
|
+
const res = await chunkCWSXFVF2_cjs.cachedRecordGet(http, `${entityPath}/${referenceId}`, "configuration_items.profile");
|
|
98
98
|
const body = res;
|
|
99
99
|
if (body === null || !("item" in body)) {
|
|
100
|
-
throw new
|
|
100
|
+
throw new chunkCWSXFVF2_cjs.NotFoundError(`context part not found (unexpected envelope shape)`, { resourceIds: [referenceId], details: { idRefs: [{ entity, id: referenceId }] } });
|
|
101
101
|
}
|
|
102
102
|
if (body.item === null || body.item === void 0) {
|
|
103
|
-
throw new
|
|
103
|
+
throw new chunkCWSXFVF2_cjs.NotFoundError("context part not found", { resourceIds: [referenceId], details: { idRefs: [{ entity, id: referenceId }] } });
|
|
104
104
|
}
|
|
105
105
|
return body.item;
|
|
106
106
|
} catch (err) {
|
|
107
|
-
if (err instanceof
|
|
107
|
+
if (err instanceof chunkCWSXFVF2_cjs.NotFoundError) return null;
|
|
108
108
|
throw err;
|
|
109
109
|
}
|
|
110
110
|
}
|
|
@@ -116,7 +116,7 @@ async function ciScopedQuery(http, path, itemID, limit) {
|
|
|
116
116
|
body: { MaxRecords: limit, filter: [{ field: "configurationItemID", op: "eq", value: itemID }] },
|
|
117
117
|
operation: "configuration_items.profile"
|
|
118
118
|
});
|
|
119
|
-
return
|
|
119
|
+
return chunkCWSXFVF2_cjs.unwrapItems(res).items;
|
|
120
120
|
}
|
|
121
121
|
async function profile(resource, id, opts = {}) {
|
|
122
122
|
const http = resource.http;
|
|
@@ -124,7 +124,7 @@ async function profile(resource, id, opts = {}) {
|
|
|
124
124
|
const relatedLimit = profilePartLimit(opts.relatedLimit, "relatedLimit");
|
|
125
125
|
const ci = await resource.get(id);
|
|
126
126
|
const root = ci;
|
|
127
|
-
const [type, category, notes, relatedItems, associations] = await
|
|
127
|
+
const [type, category, notes, relatedItems, associations] = await chunkCWSXFVF2_cjs.readTasks(http, [
|
|
128
128
|
() => contextFetchPart(http, "/V1.0/ConfigurationItemTypes", root["configurationItemType"], "configuration_item_type"),
|
|
129
129
|
() => contextFetchPart(http, "/V1.0/ConfigurationItemCategories", root["configurationItemCategoryID"], "configuration_item_category"),
|
|
130
130
|
() => ciScopedQuery(http, "/V1.0/ConfigurationItemNotes/query", id, noteLimit),
|
|
@@ -153,11 +153,11 @@ async function profile(resource, id, opts = {}) {
|
|
|
153
153
|
}
|
|
154
154
|
};
|
|
155
155
|
if (opts.names === true) {
|
|
156
|
-
const builder =
|
|
156
|
+
const builder = chunkCWSXFVF2_cjs.createNamePlan();
|
|
157
157
|
builder.addFk("contract", root["contractID"]);
|
|
158
|
-
const names = await
|
|
158
|
+
const names = await chunkCWSXFVF2_cjs.resolveCompositeNames(http, builder.plan(), { maxNameReads: opts.maxNameReads });
|
|
159
159
|
const ciRow = { ...ci };
|
|
160
|
-
|
|
160
|
+
chunkCWSXFVF2_cjs.addNameSibling(ciRow, "contractID", (v) => names.recordName("contract", v));
|
|
161
161
|
result.ci = ciRow;
|
|
162
162
|
result.names = names.section;
|
|
163
163
|
}
|
|
@@ -165,7 +165,7 @@ async function profile(resource, id, opts = {}) {
|
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
// src/resources/configuration_items.ts
|
|
168
|
-
var ConfigurationItemsResource = class extends
|
|
168
|
+
var ConfigurationItemsResource = class extends chunkCWSXFVF2_cjs.GenericResource {
|
|
169
169
|
constructor(http, pageSize) {
|
|
170
170
|
super(http, {
|
|
171
171
|
key: "configuration_items",
|
|
@@ -191,7 +191,7 @@ var ConfigurationItemsResource = class extends chunkQQFF7X67_cjs.GenericResource
|
|
|
191
191
|
async getContext(id) {
|
|
192
192
|
const configurationItem = await this.fetchRecordRaw("/V1.0/ConfigurationItems", id);
|
|
193
193
|
const root = configurationItem;
|
|
194
|
-
const [company, contact, contract] = await
|
|
194
|
+
const [company, contact, contract] = await chunkCWSXFVF2_cjs.readTasks(this.http, [
|
|
195
195
|
() => this.contextFetch("/V1.0/Companies", root["companyID"]),
|
|
196
196
|
() => this.contextFetch("/V1.0/Contacts", root["contactID"]),
|
|
197
197
|
() => this.contextFetch("/V1.0/Contracts", root["contractID"])
|
|
@@ -213,23 +213,23 @@ async function fetchRecord2(http, path, label, readOpts) {
|
|
|
213
213
|
const res = await http.request({ method: "GET", path, operation: "contacts.moveToCompany", maxRetries: readOpts?.maxRetries });
|
|
214
214
|
const body = res;
|
|
215
215
|
if (body === null || !("item" in body) || body.item === null || body.item === void 0) {
|
|
216
|
-
throw new
|
|
216
|
+
throw new chunkCWSXFVF2_cjs.NotFoundError(`${label} not found`, { code: "NOT_FOUND", category: "not_found" });
|
|
217
217
|
}
|
|
218
218
|
return body.item;
|
|
219
219
|
}
|
|
220
220
|
async function moveToCompany(_resource, sourceContactId, destinationCompanyId, opts = {}) {
|
|
221
221
|
const http = _resource.http;
|
|
222
|
-
const sourceId =
|
|
223
|
-
const destId =
|
|
222
|
+
const sourceId = chunkCWSXFVF2_cjs.parseIdentifier(sourceContactId, "sourceContactId");
|
|
223
|
+
const destId = chunkCWSXFVF2_cjs.parseIdentifier(destinationCompanyId, "destinationCompanyId");
|
|
224
224
|
const source = await fetchRecord2(http, `/V1.0/Contacts/${sourceId}`, `Contact ${sourceId}`, { maxRetries: opts.maxRetries });
|
|
225
225
|
const companyID = source.companyID;
|
|
226
226
|
if (typeof companyID !== "number" || companyID < 0) {
|
|
227
|
-
throw new
|
|
227
|
+
throw new chunkCWSXFVF2_cjs.NotFoundError(`Contact ${sourceId} has no companyID (cannot scope the source delete)`);
|
|
228
228
|
}
|
|
229
229
|
if (opts.lastModifiedDate !== void 0) {
|
|
230
230
|
const current = source.lastModifiedDate;
|
|
231
231
|
if (current !== opts.lastModifiedDate) {
|
|
232
|
-
throw new
|
|
232
|
+
throw new chunkCWSXFVF2_cjs.StaleObjectError(
|
|
233
233
|
`moveToCompany: source contact ${sourceId} was modified since the snapshot (expected lastModifiedDate ${opts.lastModifiedDate}, current ${typeof current === "string" ? current : "unknown"})`,
|
|
234
234
|
{ operation: "contacts.moveToCompany", resourceIds: [sourceId, destId], details: { idRefs: [{ entity: "contact", id: sourceId }, { entity: "company", id: destId }] } }
|
|
235
235
|
);
|
|
@@ -251,10 +251,10 @@ async function moveToCompany(_resource, sourceContactId, destinationCompanyId, o
|
|
|
251
251
|
},
|
|
252
252
|
operation: "contacts.moveToCompany"
|
|
253
253
|
});
|
|
254
|
-
const items =
|
|
254
|
+
const items = chunkCWSXFVF2_cjs.unwrapItems(res).items;
|
|
255
255
|
const clash = items.find((c) => String(c.id) !== String(sourceId));
|
|
256
256
|
if (clash !== void 0) {
|
|
257
|
-
throw new
|
|
257
|
+
throw new chunkCWSXFVF2_cjs.ConflictError(
|
|
258
258
|
`Contact email "${email}" already exists under company ${destId} (contact ${String(clash.id)}); aborting the move`,
|
|
259
259
|
{ resourceIds: [sourceId, destId], details: { idRefs: [{ entity: "contact", id: sourceId }, { entity: "company", id: destId }] } }
|
|
260
260
|
);
|
|
@@ -268,7 +268,7 @@ async function moveToCompany(_resource, sourceContactId, destinationCompanyId, o
|
|
|
268
268
|
if (opts.dryRun === true) {
|
|
269
269
|
const warnings = [];
|
|
270
270
|
if (opts.deleteSource === true) warnings.push("the source contact will be deleted after the move");
|
|
271
|
-
return
|
|
271
|
+
return chunkCWSXFVF2_cjs.buildDryRunResult({
|
|
272
272
|
operation: "contacts.moveToCompany",
|
|
273
273
|
method: "POST",
|
|
274
274
|
path: `/V1.0/Companies/${destId}/Contacts`,
|
|
@@ -294,7 +294,7 @@ async function moveToCompany(_resource, sourceContactId, destinationCompanyId, o
|
|
|
294
294
|
const createdBody = created;
|
|
295
295
|
const newId = createdBody !== null ? createdBody.itemId ?? createdBody.id : void 0;
|
|
296
296
|
if (typeof newId !== "number") {
|
|
297
|
-
throw new
|
|
297
|
+
throw new chunkCWSXFVF2_cjs.AutotaskConfigError("contacts.moveToCompany: vendor create response has no itemId");
|
|
298
298
|
}
|
|
299
299
|
let sourceDeleted = false;
|
|
300
300
|
if (opts.deleteSource === true) {
|
|
@@ -310,27 +310,27 @@ async function moveToCompany(_resource, sourceContactId, destinationCompanyId, o
|
|
|
310
310
|
}
|
|
311
311
|
var FULL_PROFILE_OP = "contacts.fullProfile";
|
|
312
312
|
async function fullProfile(resource, id, opts = {}) {
|
|
313
|
-
const client =
|
|
314
|
-
const ticketLimit =
|
|
315
|
-
const contactId =
|
|
316
|
-
const envelope = await
|
|
313
|
+
const client = chunkCWSXFVF2_cjs.clientOf(resource, FULL_PROFILE_OP);
|
|
314
|
+
const ticketLimit = chunkCWSXFVF2_cjs.compositePartLimit(opts.ticketLimit, "ticketLimit", FULL_PROFILE_OP);
|
|
315
|
+
const contactId = chunkCWSXFVF2_cjs.parseIdentifier(id, "id");
|
|
316
|
+
const envelope = await chunkCWSXFVF2_cjs.invokeRead(client, "contacts.query", [
|
|
317
317
|
{ filter: [{ field: "id", op: "eq", value: contactId }], limit: 1 }
|
|
318
318
|
]);
|
|
319
319
|
const row = (envelope.items ?? [])[0];
|
|
320
320
|
if (row === void 0) {
|
|
321
|
-
throw new
|
|
321
|
+
throw new chunkCWSXFVF2_cjs.NotFoundError(`Contact ${contactId} not found`, { operation: "contacts.get", httpStatus: 404 });
|
|
322
322
|
}
|
|
323
323
|
const fk = typeof row.companyID === "number" && row.companyID > 0 ? row.companyID : null;
|
|
324
|
-
const root = fk === null ? row : await
|
|
325
|
-
const [company, openTickets] = await
|
|
326
|
-
async () => fk === null ? { value: null, absent: "NO_FK" } : await
|
|
327
|
-
async () => await
|
|
324
|
+
const root = fk === null ? row : await chunkCWSXFVF2_cjs.invokeRead(client, "contacts.get", [fk, contactId]);
|
|
325
|
+
const [company, openTickets] = await chunkCWSXFVF2_cjs.readTasks(resource.http, [
|
|
326
|
+
async () => fk === null ? { value: null, absent: "NO_FK" } : await chunkCWSXFVF2_cjs.compositePart(client, "companies.get", [fk]),
|
|
327
|
+
async () => await chunkCWSXFVF2_cjs.openTicketsOfPart(client, "contactID", contactId, ticketLimit)
|
|
328
328
|
]);
|
|
329
329
|
return { root, parts: { company, open_tickets: openTickets } };
|
|
330
330
|
}
|
|
331
331
|
|
|
332
332
|
// src/resources/contacts.ts
|
|
333
|
-
var ContactsResource = class extends
|
|
333
|
+
var ContactsResource = class extends chunkCWSXFVF2_cjs.GenericResource {
|
|
334
334
|
constructor(http, pageSize) {
|
|
335
335
|
super(http, {
|
|
336
336
|
key: "contacts",
|
|
@@ -379,10 +379,10 @@ var PATH_SUFFIX = {
|
|
|
379
379
|
};
|
|
380
380
|
async function stockedItems(_resource, kind, parentId, data, opts = {}) {
|
|
381
381
|
const http = _resource.http;
|
|
382
|
-
const numericParent =
|
|
382
|
+
const numericParent = chunkCWSXFVF2_cjs.parseIdentifier(parentId, "parentId");
|
|
383
383
|
const suffix = PATH_SUFFIX[kind];
|
|
384
384
|
if (opts.dryRun === true) {
|
|
385
|
-
return
|
|
385
|
+
return chunkCWSXFVF2_cjs.buildDryRunResult({
|
|
386
386
|
operation: `inventory_products.stockedItems${suffix.slice("StockedItems".length)}`,
|
|
387
387
|
method: "POST",
|
|
388
388
|
path: `/V1.0/InventoryProducts/${numericParent}/${suffix}`,
|
|
@@ -399,11 +399,11 @@ async function stockedItems(_resource, kind, parentId, data, opts = {}) {
|
|
|
399
399
|
operation: `inventory_products.stockedItems${suffix.slice("StockedItems".length)}`,
|
|
400
400
|
maxRetries: opts.maxRetries
|
|
401
401
|
});
|
|
402
|
-
return
|
|
402
|
+
return chunkCWSXFVF2_cjs.unwrapOperation(res);
|
|
403
403
|
}
|
|
404
404
|
|
|
405
405
|
// src/resources/inventory_products.ts
|
|
406
|
-
var InventoryProductsResource = class extends
|
|
406
|
+
var InventoryProductsResource = class extends chunkCWSXFVF2_cjs.GenericResource {
|
|
407
407
|
constructor(http, pageSize) {
|
|
408
408
|
super(http, {
|
|
409
409
|
key: "inventory_products",
|
|
@@ -431,18 +431,18 @@ var InventoryProductsResource = class extends chunkQQFF7X67_cjs.GenericResource
|
|
|
431
431
|
// src/resources/special/quotes.ts
|
|
432
432
|
var OP = "quotes.withItems";
|
|
433
433
|
async function withItems(resource, id, opts = {}) {
|
|
434
|
-
const client =
|
|
435
|
-
const itemLimit =
|
|
436
|
-
const quoteId =
|
|
437
|
-
const root = await
|
|
438
|
-
const items = await
|
|
434
|
+
const client = chunkCWSXFVF2_cjs.clientOf(resource, OP);
|
|
435
|
+
const itemLimit = chunkCWSXFVF2_cjs.compositePartLimit(opts.itemLimit, "itemLimit", OP);
|
|
436
|
+
const quoteId = chunkCWSXFVF2_cjs.parseIdentifier(id, "id");
|
|
437
|
+
const root = await chunkCWSXFVF2_cjs.invokeRead(client, "quotes.get", [quoteId]);
|
|
438
|
+
const items = await chunkCWSXFVF2_cjs.compositePart(client, "quote_items.query", [
|
|
439
439
|
{ filter: [{ field: "quoteID", op: "eq", value: quoteId }], limit: itemLimit }
|
|
440
440
|
]);
|
|
441
441
|
return { root, parts: { items } };
|
|
442
442
|
}
|
|
443
443
|
|
|
444
444
|
// src/resources/quotes.ts
|
|
445
|
-
var QuotesResource = class extends
|
|
445
|
+
var QuotesResource = class extends chunkCWSXFVF2_cjs.GenericResource {
|
|
446
446
|
constructor(http, pageSize) {
|
|
447
447
|
super(http, {
|
|
448
448
|
key: "quotes",
|
|
@@ -468,7 +468,7 @@ var QuotesResource = class extends chunkQQFF7X67_cjs.GenericResource {
|
|
|
468
468
|
// src/resources/special/resource_time_off_additional.ts
|
|
469
469
|
async function getByResource(_resource, resourceId) {
|
|
470
470
|
const http = _resource.http;
|
|
471
|
-
const numericResource =
|
|
471
|
+
const numericResource = chunkCWSXFVF2_cjs.parseIdentifier(resourceId, "resourceId");
|
|
472
472
|
const res = await http.request({
|
|
473
473
|
method: "GET",
|
|
474
474
|
path: `/V1.0/Resources/${numericResource}/TimeOffAdditional`,
|
|
@@ -482,11 +482,11 @@ async function getByResource(_resource, resourceId) {
|
|
|
482
482
|
if (typeof item === "object" && !Array.isArray(item)) return [item];
|
|
483
483
|
}
|
|
484
484
|
}
|
|
485
|
-
return
|
|
485
|
+
return chunkCWSXFVF2_cjs.unwrapItems(res, "resource_time_off_additional.getByResource").items;
|
|
486
486
|
}
|
|
487
487
|
|
|
488
488
|
// src/resources/resource_time_off_additional.ts
|
|
489
|
-
var ResourceTimeOffAdditionalResource = class extends
|
|
489
|
+
var ResourceTimeOffAdditionalResource = class extends chunkCWSXFVF2_cjs.GenericResource {
|
|
490
490
|
constructor(http, pageSize) {
|
|
491
491
|
super(http, {
|
|
492
492
|
key: "resource_time_off_additional",
|
|
@@ -507,30 +507,30 @@ var ResourceTimeOffAdditionalResource = class extends chunkQQFF7X67_cjs.GenericR
|
|
|
507
507
|
// src/resources/special/resource_time_off_balances.ts
|
|
508
508
|
async function getByResource2(_resource, resourceId) {
|
|
509
509
|
const http = _resource.http;
|
|
510
|
-
const numericResource =
|
|
510
|
+
const numericResource = chunkCWSXFVF2_cjs.parseIdentifier(resourceId, "resourceId");
|
|
511
511
|
const res = await http.request({
|
|
512
512
|
method: "GET",
|
|
513
513
|
path: `/V1.0/Resources/${numericResource}/TimeOffBalances`,
|
|
514
514
|
operation: "resource_time_off_balances.getByResource"
|
|
515
515
|
});
|
|
516
|
-
return
|
|
516
|
+
return chunkCWSXFVF2_cjs.unwrapItems(res, "resource_time_off_balances.getByResource").items;
|
|
517
517
|
}
|
|
518
518
|
async function getByYear(_resource, resourceId, year) {
|
|
519
519
|
const http = _resource.http;
|
|
520
|
-
const numericResource =
|
|
520
|
+
const numericResource = chunkCWSXFVF2_cjs.parseIdentifier(resourceId, "resourceId");
|
|
521
521
|
if (!Number.isSafeInteger(year) || year < 1) {
|
|
522
|
-
throw new
|
|
522
|
+
throw new chunkCWSXFVF2_cjs.AutotaskConfigError("getByYear: year must be a positive integer");
|
|
523
523
|
}
|
|
524
524
|
const res = await http.request({
|
|
525
525
|
method: "GET",
|
|
526
526
|
path: `/V1.0/Resources/${numericResource}/TimeOffBalances/${year}`,
|
|
527
527
|
operation: "resource_time_off_balances.getByYear"
|
|
528
528
|
});
|
|
529
|
-
return
|
|
529
|
+
return chunkCWSXFVF2_cjs.unwrapItem(res, year, "resource_time_off_balances.getByYear", "resource_time_off_balance");
|
|
530
530
|
}
|
|
531
531
|
|
|
532
532
|
// src/resources/resource_time_off_balances.ts
|
|
533
|
-
var ResourceTimeOffBalancesResource = class extends
|
|
533
|
+
var ResourceTimeOffBalancesResource = class extends chunkCWSXFVF2_cjs.GenericResource {
|
|
534
534
|
constructor(http, pageSize) {
|
|
535
535
|
super(http, {
|
|
536
536
|
key: "resource_time_off_balances",
|
|
@@ -556,7 +556,7 @@ var ResourceTimeOffBalancesResource = class extends chunkQQFF7X67_cjs.GenericRes
|
|
|
556
556
|
async function whoAmI(_resource, userName) {
|
|
557
557
|
const http = _resource.http;
|
|
558
558
|
const user = userName.trim();
|
|
559
|
-
if (user === "") throw new
|
|
559
|
+
if (user === "") throw new chunkCWSXFVF2_cjs.AutotaskConfigError("whoAmI: the configured UserName is empty");
|
|
560
560
|
const value = user.includes("@") ? user.split("@")[0] ?? "" : user;
|
|
561
561
|
const res = await http.request({
|
|
562
562
|
method: "POST",
|
|
@@ -565,11 +565,11 @@ async function whoAmI(_resource, userName) {
|
|
|
565
565
|
body: { MaxRecords: 2, filter: [{ field: "userName", op: "eq", value }] },
|
|
566
566
|
operation: "resources.whoAmI"
|
|
567
567
|
});
|
|
568
|
-
const matches =
|
|
568
|
+
const matches = chunkCWSXFVF2_cjs.unwrapItems(res).items;
|
|
569
569
|
if (matches.length === 0) return null;
|
|
570
570
|
if (matches.length > 1) {
|
|
571
571
|
const ids = matches.map((m) => m.id).filter((id) => typeof id === "number");
|
|
572
|
-
throw new
|
|
572
|
+
throw new chunkCWSXFVF2_cjs.ResolutionError(
|
|
573
573
|
`whoAmI: "${value}" is ambiguous (matched ${matches.length} resources)`,
|
|
574
574
|
{ code: "RESOLUTION_AMBIGUOUS", resourceIds: ids, details: { idRefs: ids.map((cid) => ({ entity: "resource", id: cid })) } }
|
|
575
575
|
);
|
|
@@ -578,28 +578,28 @@ async function whoAmI(_resource, userName) {
|
|
|
578
578
|
}
|
|
579
579
|
var WORKLOAD_OP = "resources.workload";
|
|
580
580
|
async function workload(resource, id, opts = {}) {
|
|
581
|
-
const client =
|
|
582
|
-
const ticketLimit =
|
|
583
|
-
const taskLimit =
|
|
584
|
-
const timeOffLimit =
|
|
585
|
-
const resourceId =
|
|
586
|
-
const root = await
|
|
581
|
+
const client = chunkCWSXFVF2_cjs.clientOf(resource, WORKLOAD_OP);
|
|
582
|
+
const ticketLimit = chunkCWSXFVF2_cjs.compositePartLimit(opts.ticketLimit, "ticketLimit", WORKLOAD_OP);
|
|
583
|
+
const taskLimit = chunkCWSXFVF2_cjs.compositePartLimit(opts.taskLimit, "taskLimit", WORKLOAD_OP);
|
|
584
|
+
const timeOffLimit = chunkCWSXFVF2_cjs.compositePartLimit(opts.timeOffLimit, "timeOffLimit", WORKLOAD_OP);
|
|
585
|
+
const resourceId = chunkCWSXFVF2_cjs.parseIdentifier(id, "id");
|
|
586
|
+
const root = await chunkCWSXFVF2_cjs.invokeRead(client, "resources.get", [resourceId]);
|
|
587
587
|
const strict = { allowAssumed: false };
|
|
588
|
-
const [joined, counted, assignmentBranch, balances, timeOff] = await
|
|
589
|
-
() =>
|
|
588
|
+
const [joined, counted, assignmentBranch, balances, timeOff] = await chunkCWSXFVF2_cjs.readTasks(resource.http, [
|
|
589
|
+
() => chunkCWSXFVF2_cjs.compositePart(client, "tickets.forResource", [
|
|
590
590
|
resourceId,
|
|
591
591
|
{ openOnly: true, limit: Math.min(ticketLimit, 500), ...strict }
|
|
592
592
|
]),
|
|
593
|
-
() =>
|
|
593
|
+
() => chunkCWSXFVF2_cjs.compositePart(client, "tickets.forResource", [resourceId, { countOnly: true, ...strict }]),
|
|
594
594
|
async () => {
|
|
595
|
-
const assignments2 = await
|
|
595
|
+
const assignments2 = await chunkCWSXFVF2_cjs.compositePart(client, "service_call_task_resources.query", [
|
|
596
596
|
{ filter: [{ field: "resourceID", op: "eq", value: resourceId }], limit: taskLimit }
|
|
597
597
|
]);
|
|
598
|
-
const taskDetails2 = await
|
|
598
|
+
const taskDetails2 = await chunkCWSXFVF2_cjs.joinedCompositePart(client, assignments2, "serviceCallTaskID", "service_call_tasks.query", "id", taskLimit, "NO_ASSIGNMENTS");
|
|
599
599
|
return { assignments: assignments2, taskDetails: taskDetails2 };
|
|
600
600
|
},
|
|
601
|
-
() =>
|
|
602
|
-
() =>
|
|
601
|
+
() => chunkCWSXFVF2_cjs.compositePart(client, "resource_time_off_balances.getByResource", [resourceId]),
|
|
602
|
+
() => chunkCWSXFVF2_cjs.compositePart(client, "time_off_requests.query", [
|
|
603
603
|
{ filter: [{ field: "resourceID", op: "eq", value: resourceId }], limit: timeOffLimit }
|
|
604
604
|
])
|
|
605
605
|
]);
|
|
@@ -627,7 +627,7 @@ async function workload(resource, id, opts = {}) {
|
|
|
627
627
|
}
|
|
628
628
|
|
|
629
629
|
// src/resources/resources.ts
|
|
630
|
-
var ResourcesResource = class extends
|
|
630
|
+
var ResourcesResource = class extends chunkCWSXFVF2_cjs.GenericResource {
|
|
631
631
|
clientConfig;
|
|
632
632
|
constructor(http, clientConfig, pageSize) {
|
|
633
633
|
super(http, {
|
|
@@ -659,20 +659,20 @@ var ResourcesResource = class extends chunkQQFF7X67_cjs.GenericResource {
|
|
|
659
659
|
// src/resources/special/service_calls.ts
|
|
660
660
|
var OP2 = "service_calls.fullProfile";
|
|
661
661
|
async function fullProfile2(resource, id, opts = {}) {
|
|
662
|
-
const client =
|
|
663
|
-
const ticketLimit =
|
|
664
|
-
const taskLimit =
|
|
665
|
-
const callId =
|
|
666
|
-
const root = await
|
|
667
|
-
const [tickets, taskBranch] = await
|
|
668
|
-
() =>
|
|
662
|
+
const client = chunkCWSXFVF2_cjs.clientOf(resource, OP2);
|
|
663
|
+
const ticketLimit = chunkCWSXFVF2_cjs.compositePartLimit(opts.ticketLimit, "ticketLimit", OP2);
|
|
664
|
+
const taskLimit = chunkCWSXFVF2_cjs.compositePartLimit(opts.taskLimit, "taskLimit", OP2);
|
|
665
|
+
const callId = chunkCWSXFVF2_cjs.parseIdentifier(id, "id");
|
|
666
|
+
const root = await chunkCWSXFVF2_cjs.invokeRead(client, "service_calls.get", [callId]);
|
|
667
|
+
const [tickets, taskBranch] = await chunkCWSXFVF2_cjs.readTasks(resource.http, [
|
|
668
|
+
() => chunkCWSXFVF2_cjs.compositePart(client, "service_call_tickets.query", [
|
|
669
669
|
{ filter: [{ field: "serviceCallID", op: "eq", value: callId }], limit: ticketLimit }
|
|
670
670
|
]),
|
|
671
671
|
async () => {
|
|
672
|
-
const tasks2 = await
|
|
672
|
+
const tasks2 = await chunkCWSXFVF2_cjs.compositePart(client, "service_call_tasks.query", [
|
|
673
673
|
{ filter: [{ field: "serviceCallID", op: "eq", value: callId }], limit: taskLimit }
|
|
674
674
|
]);
|
|
675
|
-
const resourceAssignments2 = await
|
|
675
|
+
const resourceAssignments2 = await chunkCWSXFVF2_cjs.joinedCompositePart(client, tasks2, "id", "service_call_task_resources.query", "serviceCallTaskID", taskLimit, "NO_TASKS");
|
|
676
676
|
return { tasks: tasks2, resourceAssignments: resourceAssignments2 };
|
|
677
677
|
}
|
|
678
678
|
]);
|
|
@@ -688,7 +688,7 @@ async function fullProfile2(resource, id, opts = {}) {
|
|
|
688
688
|
}
|
|
689
689
|
|
|
690
690
|
// src/resources/service_calls.ts
|
|
691
|
-
var ServiceCallsResource = class extends
|
|
691
|
+
var ServiceCallsResource = class extends chunkCWSXFVF2_cjs.GenericResource {
|
|
692
692
|
constructor(http, pageSize) {
|
|
693
693
|
super(http, {
|
|
694
694
|
key: "service_calls",
|
|
@@ -710,13 +710,13 @@ var OP3 = "ticket_charges.moveToTicket";
|
|
|
710
710
|
var COPY = ["name", "description", "chargeType", "billingCodeID", "productID", "unitQuantity", "unitCost", "unitPrice", "datePurchased", "isBillableToCompany", "notes", "purchaseOrderNumber", "internalPurchaseOrderNumber"];
|
|
711
711
|
var CONTRACT_SCOPED = ["contractServiceID", "contractServiceBundleID"];
|
|
712
712
|
async function readCharge(http, id, retries) {
|
|
713
|
-
const rows = await
|
|
713
|
+
const rows = await chunkCWSXFVF2_cjs.queryRows(http, "TicketCharges", [{ field: "id", op: "eq", value: id }], OP3, retries);
|
|
714
714
|
return rows[0] ?? null;
|
|
715
715
|
}
|
|
716
716
|
async function checkSource({ http, source, sourceId, sourceTicketId, toTicketId }) {
|
|
717
717
|
if (source.isBilled === true) {
|
|
718
|
-
throw
|
|
719
|
-
manualAction: { action: "delete_source", uiLink:
|
|
718
|
+
throw chunkCWSXFVF2_cjs.refuse("MOVE_BLOCKED_BILLED", `${OP3}: ticket charge ${sourceId} is billed \u2014 move it in the Autotask UI`, { sourceId, toTicketId }, OP3, {
|
|
719
|
+
manualAction: { action: "delete_source", uiLink: chunkCWSXFVF2_cjs.uiLinkFor(http, "tickets", sourceTicketId), reason: "billed charges are not moved by the API (the ticket link opens its charges)" }
|
|
720
720
|
});
|
|
721
721
|
}
|
|
722
722
|
}
|
|
@@ -750,14 +750,14 @@ var SPEC = {
|
|
|
750
750
|
]
|
|
751
751
|
}),
|
|
752
752
|
// charges have no ExecuteCommand code: the parent ticket is the closest clickable target
|
|
753
|
-
manualLink: (http, source) => typeof source.ticketID === "number" ?
|
|
753
|
+
manualLink: (http, source) => typeof source.ticketID === "number" ? chunkCWSXFVF2_cjs.uiLinkFor(http, "tickets", source.ticketID) : null
|
|
754
754
|
};
|
|
755
755
|
function moveToTicket(resource, sourceId, toTicketId, opts) {
|
|
756
|
-
return
|
|
756
|
+
return chunkCWSXFVF2_cjs.runMove(resource.http, SPEC, sourceId, toTicketId, opts);
|
|
757
757
|
}
|
|
758
758
|
|
|
759
759
|
// src/resources/ticket_charges.ts
|
|
760
|
-
var TicketChargesResource = class extends
|
|
760
|
+
var TicketChargesResource = class extends chunkCWSXFVF2_cjs.GenericResource {
|
|
761
761
|
constructor(http, pageSize) {
|
|
762
762
|
super(http, {
|
|
763
763
|
key: "ticket_charges",
|
|
@@ -782,7 +782,7 @@ var TicketChargesResource = class extends chunkQQFF7X67_cjs.GenericResource {
|
|
|
782
782
|
};
|
|
783
783
|
|
|
784
784
|
// src/resources/special/tickets/errors.ts
|
|
785
|
-
var StatusUnknownError = class extends
|
|
785
|
+
var StatusUnknownError = class extends chunkCWSXFVF2_cjs.AutotaskError {
|
|
786
786
|
/** The live picklist size (the message names it; the values + labels are via operations.fieldCatalog with labels: true). */
|
|
787
787
|
picklistCount;
|
|
788
788
|
constructor(message, options = {}) {
|
|
@@ -796,7 +796,7 @@ var StatusUnknownError = class extends chunkQQFF7X67_cjs.AutotaskError {
|
|
|
796
796
|
this.picklistCount = options.picklistCount ?? 0;
|
|
797
797
|
}
|
|
798
798
|
};
|
|
799
|
-
var StatusFieldsRequiredError = class extends
|
|
799
|
+
var StatusFieldsRequiredError = class extends chunkCWSXFVF2_cjs.AutotaskError {
|
|
800
800
|
vendorFields;
|
|
801
801
|
currentStatus;
|
|
802
802
|
targetStatus;
|
|
@@ -818,8 +818,8 @@ function isPositiveInt(v) {
|
|
|
818
818
|
return typeof v === "number" && Number.isInteger(v) && v > 0;
|
|
819
819
|
}
|
|
820
820
|
function namedVendorFields(err) {
|
|
821
|
-
if (!
|
|
822
|
-
const entries =
|
|
821
|
+
if (!chunkCWSXFVF2_cjs.isAutotaskError(err) || err.vendorError === void 0) return [];
|
|
822
|
+
const entries = chunkCWSXFVF2_cjs.parseVendorErrors(err.vendorError) ?? [];
|
|
823
823
|
const out = /* @__PURE__ */ new Set();
|
|
824
824
|
for (const e of entries) if (e.field !== void 0) out.add(e.field);
|
|
825
825
|
return [...out];
|
|
@@ -838,8 +838,8 @@ function unwrapItemOrNull(res) {
|
|
|
838
838
|
return body.item;
|
|
839
839
|
}
|
|
840
840
|
function discoveryMerge(err, body, defaults) {
|
|
841
|
-
if (!
|
|
842
|
-
const entries =
|
|
841
|
+
if (!chunkCWSXFVF2_cjs.isAutotaskError(err) || err.vendorError === void 0) return null;
|
|
842
|
+
const entries = chunkCWSXFVF2_cjs.parseVendorErrors(err.vendorError);
|
|
843
843
|
if (entries === void 0) return null;
|
|
844
844
|
for (const entry of entries) {
|
|
845
845
|
const field = entry.field;
|
|
@@ -874,7 +874,7 @@ async function guardTargetStatus(resource, http, targetStatus) {
|
|
|
874
874
|
const ids = await readLiveStatusSet(resource);
|
|
875
875
|
if (ids.size > 0) liveStatus = ids;
|
|
876
876
|
} catch (err) {
|
|
877
|
-
if (!
|
|
877
|
+
if (!chunkCWSXFVF2_cjs.isAutotaskError(err) || err.code === "ABORTED") throw err;
|
|
878
878
|
}
|
|
879
879
|
if (liveStatus !== null && !liveStatus.has(targetStatus)) {
|
|
880
880
|
http.fieldCache?.invalidate("tickets:");
|
|
@@ -884,7 +884,7 @@ async function guardTargetStatus(resource, http, targetStatus) {
|
|
|
884
884
|
const freshIds = await readLiveStatusSet(resource);
|
|
885
885
|
if (freshIds.size > 0) freshStatus = freshIds;
|
|
886
886
|
} catch (err) {
|
|
887
|
-
if (!
|
|
887
|
+
if (!chunkCWSXFVF2_cjs.isAutotaskError(err) || err.code === "ABORTED") throw err;
|
|
888
888
|
freshStatus = null;
|
|
889
889
|
reReadFailed = true;
|
|
890
890
|
}
|
|
@@ -902,7 +902,7 @@ async function guardTargetStatus(resource, http, targetStatus) {
|
|
|
902
902
|
return { guardDegraded: liveStatus === null };
|
|
903
903
|
}
|
|
904
904
|
function noChangeDryRun(http, ticketId, targetStatus, guardDegraded) {
|
|
905
|
-
return
|
|
905
|
+
return chunkCWSXFVF2_cjs.buildDryRunResult(
|
|
906
906
|
{
|
|
907
907
|
operation: OP_STATUS,
|
|
908
908
|
method: "PUT",
|
|
@@ -956,7 +956,7 @@ function mergeDryRun(http, ticketId, targetStatus, guardDegraded, filled, mapEnt
|
|
|
956
956
|
if (mapEntry === void 0) {
|
|
957
957
|
warnings.push(`status ${targetStatus} has no entry in the live-discovered required-field map yet \u2014 if the vendor 500 names a required field without a safe default, the apply throws the typed STATUS_FIELDS_REQUIRED (the caller supplies the value; never a blind retry).`);
|
|
958
958
|
}
|
|
959
|
-
return
|
|
959
|
+
return chunkCWSXFVF2_cjs.buildDryRunResult(
|
|
960
960
|
{
|
|
961
961
|
operation: OP_STATUS,
|
|
962
962
|
method: "PUT",
|
|
@@ -976,7 +976,7 @@ function mergeDryRun(http, ticketId, targetStatus, guardDegraded, filled, mapEnt
|
|
|
976
976
|
}
|
|
977
977
|
async function putStatusWithDiscovery(http, ticketId, targetStatus, previousStatus, current, mergeData, mapEntry, filled, opts) {
|
|
978
978
|
const safeDefaults = mapEntry?.safeDefaults ?? {};
|
|
979
|
-
const body =
|
|
979
|
+
const body = chunkCWSXFVF2_cjs.mergePartialBody(current, mergeData);
|
|
980
980
|
body.id = ticketId;
|
|
981
981
|
let merges = 0;
|
|
982
982
|
for (; ; ) {
|
|
@@ -1000,8 +1000,8 @@ async function putStatusWithDiscovery(http, ticketId, targetStatus, previousStat
|
|
|
1000
1000
|
{ vendorFields: named, currentStatus: previousStatus, targetStatus, currentValues },
|
|
1001
1001
|
{
|
|
1002
1002
|
operation: OP_STATUS,
|
|
1003
|
-
httpStatus:
|
|
1004
|
-
vendorError:
|
|
1003
|
+
httpStatus: chunkCWSXFVF2_cjs.isAutotaskError(err) ? err.httpStatus : void 0,
|
|
1004
|
+
vendorError: chunkCWSXFVF2_cjs.isAutotaskError(err) ? err.vendorError : void 0,
|
|
1005
1005
|
resourceIds: [ticketId],
|
|
1006
1006
|
details: { idRefs: [{ entity: "ticket", id: ticketId }] }
|
|
1007
1007
|
}
|
|
@@ -1014,7 +1014,7 @@ async function putStatusWithDiscovery(http, ticketId, targetStatus, previousStat
|
|
|
1014
1014
|
async function verifyStatusApplied(http, ticketId, targetStatus, opts) {
|
|
1015
1015
|
const verify = await fetchItem(http, `/V1.0/Tickets/${ticketId}`, OP_STATUS, { maxRetries: opts.maxRetries });
|
|
1016
1016
|
if (verify === null) {
|
|
1017
|
-
throw new
|
|
1017
|
+
throw new chunkCWSXFVF2_cjs.AutotaskError(`changeStatus: the post-PUT read-back found no ticket ${ticketId} (the PUT 200ed but the record is gone)`, {
|
|
1018
1018
|
code: "INVALID_RESPONSE",
|
|
1019
1019
|
category: "server",
|
|
1020
1020
|
operation: OP_STATUS,
|
|
@@ -1024,7 +1024,7 @@ async function verifyStatusApplied(http, ticketId, targetStatus, opts) {
|
|
|
1024
1024
|
}
|
|
1025
1025
|
const finalStatus = typeof verify.status === "number" ? verify.status : null;
|
|
1026
1026
|
if (finalStatus !== targetStatus) {
|
|
1027
|
-
throw new
|
|
1027
|
+
throw new chunkCWSXFVF2_cjs.AutotaskError(
|
|
1028
1028
|
`changeStatus: the post-PUT read-back shows status ${finalStatus ?? "unknown"} (the vendor 200ed the PUT but did not apply ${targetStatus} \u2014 the F-A1 lesson: the 200 proves nothing)`,
|
|
1029
1029
|
{
|
|
1030
1030
|
code: "INVALID_RESPONSE",
|
|
@@ -1040,17 +1040,17 @@ async function verifyStatusApplied(http, ticketId, targetStatus, opts) {
|
|
|
1040
1040
|
}
|
|
1041
1041
|
async function changeStatus(resource, id, targetStatus, fields, opts) {
|
|
1042
1042
|
const http = resource.http;
|
|
1043
|
-
const ticketId =
|
|
1043
|
+
const ticketId = chunkCWSXFVF2_cjs.parseIdentifier(id, "id");
|
|
1044
1044
|
if (!isPositiveInt(targetStatus)) {
|
|
1045
|
-
throw new
|
|
1045
|
+
throw new chunkCWSXFVF2_cjs.AutotaskConfigError(`changeStatus: targetStatus must be a positive integer (got ${String(targetStatus)})`, { operation: OP_STATUS });
|
|
1046
1046
|
}
|
|
1047
1047
|
const { guardDegraded } = await guardTargetStatus(resource, http, targetStatus);
|
|
1048
1048
|
if (fields !== void 0 && (typeof fields !== "object" || fields === null || Array.isArray(fields))) {
|
|
1049
|
-
throw new
|
|
1049
|
+
throw new chunkCWSXFVF2_cjs.AutotaskConfigError("changeStatus: fields must be a plain object of ticket fields (or omitted)", { operation: OP_STATUS });
|
|
1050
1050
|
}
|
|
1051
1051
|
const current = await fetchItemUnredacted(http, `/V1.0/Tickets/${ticketId}`, OP_STATUS, { maxRetries: opts.maxRetries });
|
|
1052
1052
|
if (current === null) {
|
|
1053
|
-
throw new
|
|
1053
|
+
throw new chunkCWSXFVF2_cjs.NotFoundError(`changeStatus: ticket ${ticketId} was not found (tickets.get returned item: null)`, { operation: OP_STATUS, resourceIds: [ticketId], details: { idRefs: [{ entity: "ticket", id: ticketId }] } });
|
|
1054
1054
|
}
|
|
1055
1055
|
const previousStatus = typeof current.status === "number" ? current.status : null;
|
|
1056
1056
|
if (previousStatus === targetStatus) {
|
|
@@ -1076,7 +1076,7 @@ var TICKET_FIELDS = ["id", "ticketNumber", "title", "status", "assignedResourceI
|
|
|
1076
1076
|
function positiveId(value, name) {
|
|
1077
1077
|
const n = typeof value === "string" && /^\d+$/.test(value.trim()) ? Number(value) : value;
|
|
1078
1078
|
if (typeof n !== "number" || !Number.isSafeInteger(n) || n < 1) {
|
|
1079
|
-
throw new
|
|
1079
|
+
throw new chunkCWSXFVF2_cjs.AutotaskConfigError(`${OP4}: ${name} must be a positive integer id (got ${String(value)})`, { operation: OP4 });
|
|
1080
1080
|
}
|
|
1081
1081
|
return n;
|
|
1082
1082
|
}
|
|
@@ -1088,7 +1088,7 @@ async function ticketPage(http, filter, maxRecords, fields) {
|
|
|
1088
1088
|
body: { MaxRecords: maxRecords, filter, IncludeFields: fields },
|
|
1089
1089
|
operation: OP4
|
|
1090
1090
|
});
|
|
1091
|
-
const page =
|
|
1091
|
+
const page = chunkCWSXFVF2_cjs.unwrapItems(res, OP4);
|
|
1092
1092
|
return { rows: page.items, more: page.pageDetails.nextPageUrl !== null };
|
|
1093
1093
|
}
|
|
1094
1094
|
async function readLinkIds(http, resourceID, maxPages = 1) {
|
|
@@ -1098,11 +1098,11 @@ async function readLinkIds(http, resourceID, maxPages = 1) {
|
|
|
1098
1098
|
const res = await http.request({
|
|
1099
1099
|
method: "POST",
|
|
1100
1100
|
idempotent: true,
|
|
1101
|
-
path: cursor === null ? "/V1.0/TicketSecondaryResources/query" :
|
|
1101
|
+
path: cursor === null ? "/V1.0/TicketSecondaryResources/query" : chunkCWSXFVF2_cjs.cursorToPath(http.baseUrl, cursor),
|
|
1102
1102
|
body: { MaxRecords: LINK_READ_CAP, filter: [{ field: "resourceID", op: "eq", value: resourceID }], IncludeFields: ["ticketID"] },
|
|
1103
1103
|
operation: OP4
|
|
1104
1104
|
});
|
|
1105
|
-
const page =
|
|
1105
|
+
const page = chunkCWSXFVF2_cjs.unwrapItems(res, OP4);
|
|
1106
1106
|
for (const row of page.items) if (typeof row.ticketID === "number") ids.add(row.ticketID);
|
|
1107
1107
|
cursor = page.pageDetails.nextPageUrl;
|
|
1108
1108
|
if (cursor === null || page.items.length === 0) return { ids: [...ids], capped: false };
|
|
@@ -1111,35 +1111,35 @@ async function readLinkIds(http, resourceID, maxPages = 1) {
|
|
|
1111
1111
|
}
|
|
1112
1112
|
async function forResource(_resource, resourceIDIn, opts = {}) {
|
|
1113
1113
|
const http = _resource.http;
|
|
1114
|
-
if (opts === null || typeof opts !== "object") throw new
|
|
1114
|
+
if (opts === null || typeof opts !== "object") throw new chunkCWSXFVF2_cjs.AutotaskConfigError(`${OP4}: opts must be an object`, { operation: OP4 });
|
|
1115
1115
|
const resourceID = positiveId(resourceIDIn, "resourceID");
|
|
1116
1116
|
const scope = opts.scope ?? "both";
|
|
1117
1117
|
if (scope !== "primary" && scope !== "secondary" && scope !== "both") {
|
|
1118
|
-
throw new
|
|
1118
|
+
throw new chunkCWSXFVF2_cjs.AutotaskConfigError(`${OP4}: scope must be 'primary', 'secondary' or 'both' (got ${JSON.stringify(opts.scope)})`, { operation: OP4 });
|
|
1119
1119
|
}
|
|
1120
1120
|
if (opts.openOnly !== void 0 && typeof opts.openOnly !== "boolean") {
|
|
1121
|
-
throw new
|
|
1121
|
+
throw new chunkCWSXFVF2_cjs.AutotaskConfigError(`${OP4}: openOnly must be a boolean`, { operation: OP4 });
|
|
1122
1122
|
}
|
|
1123
1123
|
const limit = opts.limit === void 0 ? LIMIT_DEFAULT : opts.limit;
|
|
1124
1124
|
if (opts.countOnly !== true && (!Number.isInteger(limit) || limit < 1 || limit > LIMIT_MAX)) {
|
|
1125
|
-
throw new
|
|
1125
|
+
throw new chunkCWSXFVF2_cjs.AutotaskConfigError(`${OP4}: limit must be an integer 1-${LIMIT_MAX} (got ${String(opts.limit)})`, { operation: OP4 });
|
|
1126
1126
|
}
|
|
1127
1127
|
const includeFields = opts.includeFields ?? [];
|
|
1128
1128
|
if (!Array.isArray(includeFields) || includeFields.some((f) => typeof f !== "string" || f.length === 0)) {
|
|
1129
|
-
throw new
|
|
1129
|
+
throw new chunkCWSXFVF2_cjs.AutotaskConfigError(`${OP4}: includeFields must be a list of field names`, { operation: OP4 });
|
|
1130
1130
|
}
|
|
1131
1131
|
const openOnly = opts.openOnly === true;
|
|
1132
1132
|
const fields = [.../* @__PURE__ */ new Set([...TICKET_FIELDS, ...includeFields])];
|
|
1133
1133
|
if (opts.countOnly !== void 0 && typeof opts.countOnly !== "boolean") {
|
|
1134
|
-
throw new
|
|
1134
|
+
throw new chunkCWSXFVF2_cjs.AutotaskConfigError(`${OP4}: countOnly must be a boolean`, { operation: OP4 });
|
|
1135
1135
|
}
|
|
1136
|
-
const closed = await
|
|
1136
|
+
const closed = await chunkCWSXFVF2_cjs.resolveTicketStatusSemantics(
|
|
1137
1137
|
http,
|
|
1138
1138
|
{ ...opts.excludeStatusIds === void 0 ? {} : { excludeStatusIds: opts.excludeStatusIds }, ...opts.allowAssumed === void 0 ? {} : { allowAssumed: opts.allowAssumed } },
|
|
1139
1139
|
OP4
|
|
1140
1140
|
);
|
|
1141
1141
|
const closedStatus = { closedIds: closed.closedIds, source: closed.source, note: closed.note };
|
|
1142
|
-
const openLeaf = openOnly || opts.countOnly === true ? [
|
|
1142
|
+
const openLeaf = openOnly || opts.countOnly === true ? [chunkCWSXFVF2_cjs.openStatusFilter(closed.closedIds)] : [];
|
|
1143
1143
|
if (opts.countOnly === true) {
|
|
1144
1144
|
const primaryCount = scope === "secondary" ? 0 : await _resource.count({ filter: [{ field: "assignedResourceID", op: "eq", value: resourceID }, ...openLeaf] });
|
|
1145
1145
|
let secondaryCount = 0;
|
|
@@ -1153,7 +1153,7 @@ async function forResource(_resource, resourceIDIn, opts = {}) {
|
|
|
1153
1153
|
const page = await ticketPage(http, [{ field: "id", op: "in", value: chunk }, ...openLeaf], chunk.length, ["id", "status", "assignedResourceID"]);
|
|
1154
1154
|
const seen = /* @__PURE__ */ new Set();
|
|
1155
1155
|
for (const t of page.rows) {
|
|
1156
|
-
if (typeof t.id !== "number" || seen.has(t.id) ||
|
|
1156
|
+
if (typeof t.id !== "number" || seen.has(t.id) || chunkCWSXFVF2_cjs.isClosedStatus(t.status, closed.closedIds)) continue;
|
|
1157
1157
|
seen.add(t.id);
|
|
1158
1158
|
if (scope === "both" && t.assignedResourceID === resourceID) bothCount++;
|
|
1159
1159
|
}
|
|
@@ -1199,13 +1199,13 @@ async function forResource(_resource, resourceIDIn, opts = {}) {
|
|
|
1199
1199
|
for (const [id, t] of primary) merged.set(id, t);
|
|
1200
1200
|
for (const [id, t] of secondary) if (!merged.has(id)) merged.set(id, t);
|
|
1201
1201
|
let tickets = [...merged.values()];
|
|
1202
|
-
if (openOnly) tickets = tickets.filter((t) => !
|
|
1202
|
+
if (openOnly) tickets = tickets.filter((t) => !chunkCWSXFVF2_cjs.isClosedStatus(t.status, closed.closedIds));
|
|
1203
1203
|
tickets.sort((a, b) => Number(a.id) - Number(b.id));
|
|
1204
1204
|
if (tickets.length > limit) {
|
|
1205
1205
|
tickets = tickets.slice(0, limit);
|
|
1206
1206
|
capped = true;
|
|
1207
1207
|
}
|
|
1208
|
-
const openCount = tickets.filter((t) => !
|
|
1208
|
+
const openCount = tickets.filter((t) => !chunkCWSXFVF2_cjs.isClosedStatus(t.status, closed.closedIds)).length;
|
|
1209
1209
|
const primaryIds = [...primary.keys()].sort((a, b) => a - b);
|
|
1210
1210
|
const secondaryIds = [...secondary.keys()].sort((a, b) => a - b);
|
|
1211
1211
|
const both = primaryIds.filter((id) => secondary.has(id));
|
|
@@ -1239,9 +1239,9 @@ async function fetchTicket(http, id, operation) {
|
|
|
1239
1239
|
});
|
|
1240
1240
|
const body = res;
|
|
1241
1241
|
if (body === null || !("item" in body)) {
|
|
1242
|
-
throw new
|
|
1242
|
+
throw new chunkCWSXFVF2_cjs.NotFoundError(`Ticket ${id} not found (unexpected envelope shape)`, { resourceIds: [id], details: { idRefs: [{ entity: "ticket", id }] } });
|
|
1243
1243
|
}
|
|
1244
|
-
if (body.item === null || body.item === void 0) throw new
|
|
1244
|
+
if (body.item === null || body.item === void 0) throw new chunkCWSXFVF2_cjs.NotFoundError(`Ticket ${id} not found`, { resourceIds: [id], details: { idRefs: [{ entity: "ticket", id }] } });
|
|
1245
1245
|
return body.item;
|
|
1246
1246
|
}
|
|
1247
1247
|
async function ticketQueryItems(http, path, filter, maxRecords, operation) {
|
|
@@ -1252,7 +1252,7 @@ async function ticketQueryItems(http, path, filter, maxRecords, operation) {
|
|
|
1252
1252
|
body: { MaxRecords: maxRecords, filter },
|
|
1253
1253
|
operation
|
|
1254
1254
|
});
|
|
1255
|
-
return
|
|
1255
|
+
return chunkCWSXFVF2_cjs.unwrapItems(res).items;
|
|
1256
1256
|
}
|
|
1257
1257
|
function truncate(text, limit) {
|
|
1258
1258
|
const full = text ?? "";
|
|
@@ -1262,27 +1262,27 @@ function truncate(text, limit) {
|
|
|
1262
1262
|
|
|
1263
1263
|
// src/resources/special/tickets/childRead.ts
|
|
1264
1264
|
function isRouteUnavailable(err) {
|
|
1265
|
-
return
|
|
1265
|
+
return chunkCWSXFVF2_cjs.isAutotaskError(err) && (err.httpStatus === 404 || err.httpStatus === 500);
|
|
1266
1266
|
}
|
|
1267
1267
|
function routeFact(route, path, err) {
|
|
1268
1268
|
return {
|
|
1269
1269
|
route,
|
|
1270
1270
|
path,
|
|
1271
|
-
httpStatus:
|
|
1271
|
+
httpStatus: chunkCWSXFVF2_cjs.isAutotaskError(err) && typeof err.httpStatus === "number" ? err.httpStatus : null
|
|
1272
1272
|
};
|
|
1273
1273
|
}
|
|
1274
1274
|
async function childDeclaresQuery(resourceKey) {
|
|
1275
|
-
const records = await
|
|
1275
|
+
const records = await chunkVHNWLON6_cjs.loadCapabilityRecords();
|
|
1276
1276
|
return records.some(
|
|
1277
1277
|
(c) => c.id === `${resourceKey}.query` && (c.status === "implemented" || c.status === "tested")
|
|
1278
1278
|
);
|
|
1279
1279
|
}
|
|
1280
1280
|
async function planScopedPath(resourceKey, ticketId) {
|
|
1281
1281
|
if (!await childDeclaresQuery(resourceKey)) return null;
|
|
1282
|
-
const entry =
|
|
1282
|
+
const entry = chunkCWSXFVF2_cjs.RELATIONSHIP_MAP[resourceKey];
|
|
1283
1283
|
const parent = entry === void 0 ? null : entry.parent;
|
|
1284
1284
|
if (parent === null || parent.resource !== "tickets" || parent.segment === null || parent.field === null) return null;
|
|
1285
|
-
const parentPath =
|
|
1285
|
+
const parentPath = chunkCWSXFVF2_cjs.RELATIONSHIP_MAP[parent.resource]?.path;
|
|
1286
1286
|
if (parentPath === null || parentPath === void 0) return null;
|
|
1287
1287
|
return `/V1.0/${parentPath}/${ticketId}/${parent.segment}`;
|
|
1288
1288
|
}
|
|
@@ -1321,14 +1321,14 @@ async function scopedCollectionRead(http, startPath, limit, operation, accept) {
|
|
|
1321
1321
|
break;
|
|
1322
1322
|
}
|
|
1323
1323
|
const body = await http.request({ method: "GET", path: target, operation });
|
|
1324
|
-
const { items: pageItems, pageDetails } =
|
|
1324
|
+
const { items: pageItems, pageDetails } = chunkCWSXFVF2_cjs.unwrapItems(body, operation);
|
|
1325
1325
|
nextCursor = pageDetails.nextPageUrl;
|
|
1326
1326
|
pages += 1;
|
|
1327
1327
|
const window = pageItems.slice(0, Math.max(0, limit - items.length));
|
|
1328
1328
|
for (const row of window) if (accept(row)) items.push(row);
|
|
1329
1329
|
if (items.length >= limit) break;
|
|
1330
1330
|
if (nextCursor === null || pageItems.length === 0) break;
|
|
1331
|
-
target =
|
|
1331
|
+
target = chunkCWSXFVF2_cjs.cursorToPath(http.baseUrl, nextCursor);
|
|
1332
1332
|
}
|
|
1333
1333
|
const capped = items.length >= limit || guard && nextCursor !== null;
|
|
1334
1334
|
return { items, capped };
|
|
@@ -1361,7 +1361,7 @@ var DEFAULT_PART_LIMIT = 50;
|
|
|
1361
1361
|
function partLimit(value, name) {
|
|
1362
1362
|
const n = value === void 0 ? DEFAULT_PART_LIMIT : Math.trunc(value);
|
|
1363
1363
|
if (!Number.isInteger(n) || n < 1) {
|
|
1364
|
-
throw new
|
|
1364
|
+
throw new chunkCWSXFVF2_cjs.AutotaskConfigError(`fullContext: ${name} must be an integer >= 1 (got ${String(value)})`);
|
|
1365
1365
|
}
|
|
1366
1366
|
return n;
|
|
1367
1367
|
}
|
|
@@ -1374,13 +1374,13 @@ function servedTextRecord(row, textField, limit) {
|
|
|
1374
1374
|
return out;
|
|
1375
1375
|
}
|
|
1376
1376
|
async function addCompositeNames(http, ctx, entriesPart, result, opts) {
|
|
1377
|
-
const builder =
|
|
1377
|
+
const builder = chunkCWSXFVF2_cjs.createNamePlan(chunkCWSXFVF2_cjs.TICKET_LABEL_FIELDS);
|
|
1378
1378
|
const t = ctx.ticket;
|
|
1379
1379
|
builder.addResource(t["creatorResourceID"]);
|
|
1380
1380
|
builder.addFk("contract", t["contractID"]);
|
|
1381
1381
|
builder.addFk("billingCode", t["billingCodeID"]);
|
|
1382
1382
|
builder.addFk("role", t["assignedResourceRoleID"]);
|
|
1383
|
-
const ticketLobPointer =
|
|
1383
|
+
const ticketLobPointer = chunkCWSXFVF2_cjs.vendorId(t["organizationalLevelAssociationID"]);
|
|
1384
1384
|
if (ticketLobPointer !== void 0) {
|
|
1385
1385
|
builder.addLineOfBusiness(ticketLobPointer, { source: "ticket" });
|
|
1386
1386
|
} else {
|
|
@@ -1392,20 +1392,20 @@ async function addCompositeNames(http, ctx, entriesPart, result, opts) {
|
|
|
1392
1392
|
builder.addFk("billingCode", e["billingCodeID"]);
|
|
1393
1393
|
builder.addFk("contract", e["contractID"]);
|
|
1394
1394
|
}
|
|
1395
|
-
const names = await
|
|
1395
|
+
const names = await chunkCWSXFVF2_cjs.resolveCompositeNames(http, builder.plan(), { maxNameReads: opts.maxNameReads });
|
|
1396
1396
|
const ticketRow = { ...ctx.ticket };
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
for (const f of
|
|
1397
|
+
chunkCWSXFVF2_cjs.addNameSibling(ticketRow, "creatorResourceID", (v) => names.resourceName(v));
|
|
1398
|
+
chunkCWSXFVF2_cjs.addNameSibling(ticketRow, "contractID", (v) => names.recordName("contract", v));
|
|
1399
|
+
chunkCWSXFVF2_cjs.addNameSibling(ticketRow, "billingCodeID", (v) => names.recordName("billingCode", v));
|
|
1400
|
+
chunkCWSXFVF2_cjs.addNameSibling(ticketRow, "assignedResourceRoleID", (v) => names.recordName("role", v));
|
|
1401
|
+
for (const f of chunkCWSXFVF2_cjs.TICKET_LABEL_FIELDS) chunkCWSXFVF2_cjs.addLabelSibling(ticketRow, f, names);
|
|
1402
1402
|
result.ticket = ticketRow;
|
|
1403
1403
|
result.timeEntries.items = entriesPart.items.map((e) => {
|
|
1404
1404
|
const row = { ...e };
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1405
|
+
chunkCWSXFVF2_cjs.addNameSibling(row, "resourceID", (v) => names.resourceName(v));
|
|
1406
|
+
chunkCWSXFVF2_cjs.addNameSibling(row, "roleID", (v) => names.recordName("role", v));
|
|
1407
|
+
chunkCWSXFVF2_cjs.addNameSibling(row, "billingCodeID", (v) => names.recordName("billingCode", v));
|
|
1408
|
+
chunkCWSXFVF2_cjs.addNameSibling(row, "contractID", (v) => names.recordName("contract", v));
|
|
1409
1409
|
return row;
|
|
1410
1410
|
});
|
|
1411
1411
|
result.names = names.section;
|
|
@@ -1422,11 +1422,11 @@ async function fullContext(resource, id, opts = {}, loadContext) {
|
|
|
1422
1422
|
const noteLimit = partLimit(opts.noteLimit, "noteLimit");
|
|
1423
1423
|
const timeEntryLimit = partLimit(opts.timeEntryLimit, "timeEntryLimit");
|
|
1424
1424
|
const textLimit = partLimit(opts.textLimit, "textLimit");
|
|
1425
|
-
const ticketId =
|
|
1425
|
+
const ticketId = chunkCWSXFVF2_cjs.parseIdentifier(id, "id");
|
|
1426
1426
|
const { ticket, tasks: contextTasks } = await loadContext();
|
|
1427
1427
|
const op = "tickets.fullContext";
|
|
1428
1428
|
const ticketFilter = [{ field: "ticketID", op: "eq", value: ticketId }];
|
|
1429
|
-
const [company, contact, assignedResource, project, notes, entries, attachmentsRead, historiesRead] = await
|
|
1429
|
+
const [company, contact, assignedResource, project, notes, entries, attachmentsRead, historiesRead] = await chunkCWSXFVF2_cjs.readTasks(http, [
|
|
1430
1430
|
...contextTasks,
|
|
1431
1431
|
() => ticketChildRead(http, { globalPath: "/V1.0/TicketNotes/query", resourceKey: "ticket_notes", filter: ticketFilter, limit: noteLimit, operation: op }, ticketId),
|
|
1432
1432
|
() => ticketChildRead(http, { globalPath: "/V1.0/TimeEntries/query", resourceKey: "time_entries", filter: ticketFilter, limit: timeEntryLimit, operation: op }, ticketId),
|
|
@@ -1489,7 +1489,7 @@ var OP5 = "tickets.lineOfBusiness";
|
|
|
1489
1489
|
function positiveId2(value, name) {
|
|
1490
1490
|
const n = typeof value === "string" && /^[0-9]+$/.test(value.trim()) ? Number(value) : value;
|
|
1491
1491
|
if (typeof n !== "number" || !Number.isSafeInteger(n) || n < 1) {
|
|
1492
|
-
throw new
|
|
1492
|
+
throw new chunkCWSXFVF2_cjs.AutotaskConfigError(OP5 + ": " + name + " must be a positive integer id (got " + String(value) + ")", { operation: OP5 });
|
|
1493
1493
|
}
|
|
1494
1494
|
return n;
|
|
1495
1495
|
}
|
|
@@ -1505,25 +1505,25 @@ async function lineOfBusiness(resource, ticketIdIn, associationIdIn) {
|
|
|
1505
1505
|
associationSource = "argument";
|
|
1506
1506
|
} else {
|
|
1507
1507
|
const ticket = await resource.get(ticketId);
|
|
1508
|
-
associationId =
|
|
1508
|
+
associationId = chunkCWSXFVF2_cjs.vendorId(ticket.organizationalLevelAssociationID);
|
|
1509
1509
|
if (associationId !== void 0) {
|
|
1510
1510
|
associationSource = "ticket";
|
|
1511
1511
|
} else {
|
|
1512
|
-
const contractRef =
|
|
1512
|
+
const contractRef = chunkCWSXFVF2_cjs.vendorId(ticket.contractID);
|
|
1513
1513
|
if (contractRef !== void 0) {
|
|
1514
1514
|
const client = http.client;
|
|
1515
1515
|
if (client === void 0) {
|
|
1516
|
-
throw new
|
|
1516
|
+
throw new chunkCWSXFVF2_cjs.AutotaskConfigError(OP5 + ": the transport is not wired to an AutotaskClient (the composite must run through the client)", { operation: OP5 });
|
|
1517
1517
|
}
|
|
1518
1518
|
try {
|
|
1519
1519
|
const contract = await client.contracts.get(contractRef);
|
|
1520
1520
|
contractId = contractRef;
|
|
1521
|
-
associationId =
|
|
1521
|
+
associationId = chunkCWSXFVF2_cjs.vendorId(contract.organizationalLevelAssociationID);
|
|
1522
1522
|
if (associationId !== void 0) associationSource = "contract";
|
|
1523
1523
|
} catch (e) {
|
|
1524
|
-
if (e instanceof
|
|
1524
|
+
if (e instanceof chunkCWSXFVF2_cjs.NotFoundError) {
|
|
1525
1525
|
contractId = contractRef;
|
|
1526
|
-
} else if (
|
|
1526
|
+
} else if (chunkCWSXFVF2_cjs.isAutotaskError(e) && e.code !== "ABORTED") {
|
|
1527
1527
|
contractId = contractRef;
|
|
1528
1528
|
contractUnread = true;
|
|
1529
1529
|
} else {
|
|
@@ -1544,7 +1544,7 @@ async function lineOfBusiness(resource, ticketIdIn, associationIdIn) {
|
|
|
1544
1544
|
markers: { association: contractUnread ? "unresolved" : "missing", organizationalLevel2: "missing", organizationalLevel1: "missing" }
|
|
1545
1545
|
};
|
|
1546
1546
|
}
|
|
1547
|
-
const chain = await
|
|
1547
|
+
const chain = await chunkCWSXFVF2_cjs.resolveLineOfBusinessChain(http, associationId, { budget: 3, operation: OP5, onError: "propagate" });
|
|
1548
1548
|
const { association, organizationalLevel2, organizationalLevel1, markers } = chain.lineOfBusiness;
|
|
1549
1549
|
return { ticketId, associationSource, contractId, association, organizationalLevel2, organizationalLevel1, markers };
|
|
1550
1550
|
}
|
|
@@ -1554,7 +1554,7 @@ var MS = 864e5;
|
|
|
1554
1554
|
var SLA_PAGE = 100;
|
|
1555
1555
|
async function slaHealthCheck(_resource, id, opts = {}) {
|
|
1556
1556
|
const http = _resource.http;
|
|
1557
|
-
const ticketId =
|
|
1557
|
+
const ticketId = chunkCWSXFVF2_cjs.parseIdentifier(id, "id");
|
|
1558
1558
|
await fetchTicket(http, ticketId, "tickets.slaHealthCheck");
|
|
1559
1559
|
const rows = await ticketQueryItems(
|
|
1560
1560
|
http,
|
|
@@ -1580,9 +1580,9 @@ async function summary(_resource, id, opts = {}) {
|
|
|
1580
1580
|
const http = _resource.http;
|
|
1581
1581
|
const limit = opts.summaryTextLimit === void 0 ? 500 : Math.trunc(opts.summaryTextLimit);
|
|
1582
1582
|
if (!Number.isInteger(limit) || limit < 1) {
|
|
1583
|
-
throw new
|
|
1583
|
+
throw new chunkCWSXFVF2_cjs.AutotaskConfigError(`summaryTextLimit must be an integer >= 1 (got ${String(opts.summaryTextLimit)})`);
|
|
1584
1584
|
}
|
|
1585
|
-
const ticketId =
|
|
1585
|
+
const ticketId = chunkCWSXFVF2_cjs.parseIdentifier(id, "id");
|
|
1586
1586
|
const ticket = await fetchTicket(http, ticketId, "tickets.summary");
|
|
1587
1587
|
const desc = truncate(ticket.description, limit);
|
|
1588
1588
|
const now = opts.now ?? /* @__PURE__ */ new Date();
|
|
@@ -1611,17 +1611,17 @@ async function summary(_resource, id, opts = {}) {
|
|
|
1611
1611
|
// src/resources/special/tickets/statusSemantics.ts
|
|
1612
1612
|
async function statusSemantics(_resource, opts = {}) {
|
|
1613
1613
|
const http = _resource.http;
|
|
1614
|
-
return
|
|
1614
|
+
return chunkCWSXFVF2_cjs.resolveTicketStatusSemantics(http, opts);
|
|
1615
1615
|
}
|
|
1616
1616
|
|
|
1617
1617
|
// src/resources/special/tickets/timeline.ts
|
|
1618
1618
|
function validateTimelineLimits(opts) {
|
|
1619
1619
|
const limit = opts.limit === void 0 ? 100 : Math.trunc(opts.limit);
|
|
1620
|
-
if (!Number.isInteger(limit) || limit < 1) throw new
|
|
1620
|
+
if (!Number.isInteger(limit) || limit < 1) throw new chunkCWSXFVF2_cjs.AutotaskConfigError(`limit must be an integer >= 1 (got ${String(opts.limit)})`);
|
|
1621
1621
|
const bounded = Math.min(limit, 500);
|
|
1622
1622
|
const textLimit = opts.textLimit === void 0 ? 500 : Math.trunc(opts.textLimit);
|
|
1623
1623
|
if (!Number.isInteger(textLimit) || textLimit < 1) {
|
|
1624
|
-
throw new
|
|
1624
|
+
throw new chunkCWSXFVF2_cjs.AutotaskConfigError(`textLimit must be an integer >= 1 (got ${String(opts.textLimit)})`);
|
|
1625
1625
|
}
|
|
1626
1626
|
return { bounded, textLimit };
|
|
1627
1627
|
}
|
|
@@ -1674,7 +1674,7 @@ function compareEventDates(a, b) {
|
|
|
1674
1674
|
async function timeline(_resource, id, opts = {}) {
|
|
1675
1675
|
const http = _resource.http;
|
|
1676
1676
|
const { bounded, textLimit } = validateTimelineLimits(opts);
|
|
1677
|
-
const ticketId =
|
|
1677
|
+
const ticketId = chunkCWSXFVF2_cjs.parseIdentifier(id, "id");
|
|
1678
1678
|
await fetchTicket(http, ticketId, "tickets.timeline");
|
|
1679
1679
|
const dateFilters = (field) => {
|
|
1680
1680
|
const f = [{ field: "ticketID", op: "eq", value: ticketId }];
|
|
@@ -1714,7 +1714,7 @@ async function timeline(_resource, id, opts = {}) {
|
|
|
1714
1714
|
}
|
|
1715
1715
|
|
|
1716
1716
|
// src/resources/tickets.ts
|
|
1717
|
-
var TicketsResource = class extends
|
|
1717
|
+
var TicketsResource = class extends chunkCWSXFVF2_cjs.GenericResource {
|
|
1718
1718
|
constructor(http, pageSize) {
|
|
1719
1719
|
super(http, {
|
|
1720
1720
|
key: "tickets",
|
|
@@ -1740,7 +1740,7 @@ var TicketsResource = class extends chunkQQFF7X67_cjs.GenericResource {
|
|
|
1740
1740
|
* fetch; no sub-lists; absent/dangling references come back null). */
|
|
1741
1741
|
async getContext(id) {
|
|
1742
1742
|
const { ticket, tasks } = await this.readTicketContext(id);
|
|
1743
|
-
return ticketContextValue(ticket, await
|
|
1743
|
+
return ticketContextValue(ticket, await chunkCWSXFVF2_cjs.readTasks(this.http, tasks));
|
|
1744
1744
|
}
|
|
1745
1745
|
/** Root authority and reusable lazy FK tasks shared by both ticket composites. */
|
|
1746
1746
|
async readTicketContext(id) {
|
|
@@ -1789,9 +1789,9 @@ var TicketsResource = class extends chunkQQFF7X67_cjs.GenericResource {
|
|
|
1789
1789
|
// src/resources/special/time_off_requests.ts
|
|
1790
1790
|
async function approve(_resource, id, opts = {}) {
|
|
1791
1791
|
const http = _resource.http;
|
|
1792
|
-
const numericId =
|
|
1792
|
+
const numericId = chunkCWSXFVF2_cjs.parseIdentifier(id, "id");
|
|
1793
1793
|
if (opts.dryRun === true) {
|
|
1794
|
-
return
|
|
1794
|
+
return chunkCWSXFVF2_cjs.buildDryRunResult({
|
|
1795
1795
|
operation: "time_off_requests.approve",
|
|
1796
1796
|
method: "GET",
|
|
1797
1797
|
path: `/V1.0/TimeOffRequests/${numericId}/Approve`,
|
|
@@ -1807,17 +1807,17 @@ async function approve(_resource, id, opts = {}) {
|
|
|
1807
1807
|
operation: "time_off_requests.approve",
|
|
1808
1808
|
maxRetries: opts.maxRetries
|
|
1809
1809
|
});
|
|
1810
|
-
return
|
|
1810
|
+
return chunkCWSXFVF2_cjs.unwrapOperation(res);
|
|
1811
1811
|
}
|
|
1812
1812
|
async function reject(_resource, id, reason, opts = {}) {
|
|
1813
1813
|
const http = _resource.http;
|
|
1814
|
-
const numericId =
|
|
1814
|
+
const numericId = chunkCWSXFVF2_cjs.parseIdentifier(id, "id");
|
|
1815
1815
|
const text = reason.trim();
|
|
1816
1816
|
if (text === "") {
|
|
1817
|
-
throw new
|
|
1817
|
+
throw new chunkCWSXFVF2_cjs.AutotaskConfigError("reject: a non-empty reason is required (vendor TimeOffRequestRejectModel)");
|
|
1818
1818
|
}
|
|
1819
1819
|
if (opts.dryRun === true) {
|
|
1820
|
-
return
|
|
1820
|
+
return chunkCWSXFVF2_cjs.buildDryRunResult({
|
|
1821
1821
|
operation: "time_off_requests.reject",
|
|
1822
1822
|
method: "POST",
|
|
1823
1823
|
path: `/V1.0/TimeOffRequests/${numericId}/Reject`,
|
|
@@ -1835,19 +1835,143 @@ async function reject(_resource, id, reason, opts = {}) {
|
|
|
1835
1835
|
operation: "time_off_requests.reject",
|
|
1836
1836
|
maxRetries: opts.maxRetries
|
|
1837
1837
|
});
|
|
1838
|
-
return
|
|
1838
|
+
return chunkCWSXFVF2_cjs.unwrapOperation(res);
|
|
1839
1839
|
}
|
|
1840
1840
|
|
|
1841
1841
|
// src/resources/time_off_requests.ts
|
|
1842
|
-
var TimeOffRequestsResource = class extends
|
|
1842
|
+
var TimeOffRequestsResource = class extends chunkCWSXFVF2_cjs.GenericResource {
|
|
1843
1843
|
constructor(http, pageSize) {
|
|
1844
1844
|
super(http, {
|
|
1845
1845
|
key: "time_off_requests",
|
|
1846
1846
|
resourcePath: "/V1.0/TimeOffRequests",
|
|
1847
|
+
parentScopedPath: "/V1.0/Resources/{parentId}/TimeOffRequests",
|
|
1848
|
+
parentPath: "/V1.0/Resources",
|
|
1849
|
+
parentField: "resourceID",
|
|
1850
|
+
staleField: "lastModifiedDateTime",
|
|
1851
|
+
ops: { query: true, queryAll: false, count: true, get: true, create: true, update: true, delete: false, getEntityInfo: true, getFieldInfo: true, getUdfInfo: true },
|
|
1852
|
+
helpers: { search: false, resolve: true, getContext: false, createIfNotExists: false, attachToDocument: false, findBy: [] },
|
|
1847
1853
|
deletable: false,
|
|
1848
1854
|
udfCapable: false
|
|
1849
1855
|
}, pageSize);
|
|
1850
1856
|
}
|
|
1857
|
+
async get(id, opts) {
|
|
1858
|
+
if (typeof opts === "number" || typeof opts === "string") {
|
|
1859
|
+
throw new chunkCWSXFVF2_cjs.OperationNotSupportedError("time_off_requests", "get");
|
|
1860
|
+
}
|
|
1861
|
+
return super.get(id, opts);
|
|
1862
|
+
}
|
|
1863
|
+
async create(a, b, c = {}) {
|
|
1864
|
+
if (typeof a !== "number" && typeof a !== "string") throw new chunkCWSXFVF2_cjs.OperationNotSupportedError("time_off_requests", "create");
|
|
1865
|
+
const parentId = chunkCWSXFVF2_cjs.parseIdentifier(a, "parentId");
|
|
1866
|
+
if (typeof parentId !== "number") throw this.writeError("create", "parentId cannot be represented safely in the numeric resourceID create body; this is an SDK create-body limit, not a vendor record-id maximum");
|
|
1867
|
+
const data = this.writePayload(b, "create");
|
|
1868
|
+
if (data.resourceID !== void 0 && data.resourceID !== parentId) throw this.writeError("create", "resourceID must equal parentId");
|
|
1869
|
+
const fields = await this.guardWriteStatus(data.status, "Submitted", "create");
|
|
1870
|
+
this.guardChoice(fields, "timeOffRequestType", data.timeOffRequestType, "create");
|
|
1871
|
+
return super.create(parentId, { ...data, resourceID: parentId }, c);
|
|
1872
|
+
}
|
|
1873
|
+
async update(a, b, c, d = {}) {
|
|
1874
|
+
if (typeof b !== "number" && typeof b !== "string") throw new chunkCWSXFVF2_cjs.OperationNotSupportedError("time_off_requests", "update");
|
|
1875
|
+
const parentId = chunkCWSXFVF2_cjs.parseIdentifier(a, "parentId");
|
|
1876
|
+
const id = chunkCWSXFVF2_cjs.parseIdentifier(b, "id");
|
|
1877
|
+
const data = this.writePayload(c, "update");
|
|
1878
|
+
await this.guardWriteStatus(data.status, "Canceled", "update");
|
|
1879
|
+
if (d.dryRun === true) {
|
|
1880
|
+
const preview = await this.runUpdateDryRun(id, data, d, parentId);
|
|
1881
|
+
if (!preview.wouldApply) return preview;
|
|
1882
|
+
return {
|
|
1883
|
+
...preview,
|
|
1884
|
+
impact: { ...preview.impact, reversible: false },
|
|
1885
|
+
warnings: [...preview.warnings, "A canceled time-off request cannot be restored through the public API."]
|
|
1886
|
+
};
|
|
1887
|
+
}
|
|
1888
|
+
const current = await this.getScopedRaw(parentId, id, true);
|
|
1889
|
+
this.staleObjectCheck(current, d, "time_off_requests.update");
|
|
1890
|
+
return this.updateScopedRaw(parentId, id, data, d);
|
|
1891
|
+
}
|
|
1892
|
+
async getScopedRaw(parentId, id, fresh = false) {
|
|
1893
|
+
const current = await super.getScopedRaw(parentId, id, fresh);
|
|
1894
|
+
if (current.resourceID === void 0 || chunkCWSXFVF2_cjs.parseIdentifier(current.resourceID, "resourceID") !== parentId) {
|
|
1895
|
+
throw this.writeError("update", "the current request resourceID must match parentId");
|
|
1896
|
+
}
|
|
1897
|
+
if (chunkCWSXFVF2_cjs.parseIdentifier(current.id, "id") !== id) {
|
|
1898
|
+
throw this.writeError("update", "the current request id must match the requested id");
|
|
1899
|
+
}
|
|
1900
|
+
return current;
|
|
1901
|
+
}
|
|
1902
|
+
async createIfNotExists(..._args) {
|
|
1903
|
+
throw new chunkCWSXFVF2_cjs.OperationNotSupportedError("time_off_requests", "createIfNotExists");
|
|
1904
|
+
}
|
|
1905
|
+
// Cancellation permits status only; never replace a full model through PUT fallback.
|
|
1906
|
+
putFallbackEligible(_err) {
|
|
1907
|
+
return false;
|
|
1908
|
+
}
|
|
1909
|
+
writeError(operation, detail) {
|
|
1910
|
+
return new chunkCWSXFVF2_cjs.AutotaskConfigError(`time_off_requests.${operation}: ${detail}`, { operation: `time_off_requests.${operation}` });
|
|
1911
|
+
}
|
|
1912
|
+
writePayload(value, operation) {
|
|
1913
|
+
if (!chunkCWSXFVF2_cjs.isRecord(value) || ![Object.prototype, null].includes(Object.getPrototypeOf(value))) throw this.writeError(operation, "supply a plain object");
|
|
1914
|
+
const allowed = operation === "create" ? ["hours", "requestDate", "resourceID", "status", "timeOffRequestType"] : ["status"];
|
|
1915
|
+
for (const key of Object.keys(value)) if (!allowed.includes(key)) throw this.writeError(operation, operation === "update" ? "cancellation accepts status only" : `${key} is not a supported create field`);
|
|
1916
|
+
if (typeof value.status !== "number" || !Number.isSafeInteger(value.status)) throw this.writeError(operation, "status must be a numeric picklist id");
|
|
1917
|
+
if (operation === "create") {
|
|
1918
|
+
if (typeof value.hours !== "number" || !Number.isFinite(value.hours) || value.hours < -24 || value.hours > 24) throw this.writeError(operation, "hours must be a finite decimal in the documented range -24 to 24");
|
|
1919
|
+
const date = value.requestDate;
|
|
1920
|
+
if (typeof date !== "string" || !chunkCWSXFVF2_cjs.isDateYMD(date.slice(0, 10)) || date.length !== 10 && (!/^T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/.test(date.slice(10)) || !Number.isFinite(Date.parse(date)))) {
|
|
1921
|
+
throw this.writeError(operation, "requestDate must be an ISO calendar date or timestamp for the single requested day");
|
|
1922
|
+
}
|
|
1923
|
+
if (typeof value.timeOffRequestType !== "number" || !Number.isSafeInteger(value.timeOffRequestType)) throw this.writeError(operation, "timeOffRequestType must be a numeric picklist id");
|
|
1924
|
+
if (value.resourceID !== void 0) {
|
|
1925
|
+
if (typeof value.resourceID !== "number") throw this.writeError(operation, "resourceID must be a numeric identifier");
|
|
1926
|
+
chunkCWSXFVF2_cjs.parseIdentifier(value.resourceID, "resourceID");
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
return { ...value, status: value.status };
|
|
1930
|
+
}
|
|
1931
|
+
async guardWriteStatus(status, label, operation) {
|
|
1932
|
+
let fields;
|
|
1933
|
+
try {
|
|
1934
|
+
fields = await this.cachedMeta("fields", `${this.resourcePath}/entityInformation/fields`, "time_off_requests.getFieldInfo", (body) => this.unwrapFields(body, "FieldInformationResultModel"), true);
|
|
1935
|
+
} catch (error) {
|
|
1936
|
+
if (chunkCWSXFVF2_cjs.isAutotaskError(error) && error.code === "ABORTED") throw error;
|
|
1937
|
+
if ((error instanceof chunkCWSXFVF2_cjs.RateLimitError || error instanceof chunkCWSXFVF2_cjs.MaintenanceError) && error.notSent === true) throw error;
|
|
1938
|
+
const detail = `status requires readable current field metadata for ${label}`;
|
|
1939
|
+
if (!chunkCWSXFVF2_cjs.isAutotaskError(error)) throw this.writeError(operation, detail);
|
|
1940
|
+
const safe = new chunkCWSXFVF2_cjs.AutotaskError(`time_off_requests.${operation}: ${detail}`, {
|
|
1941
|
+
code: error.code,
|
|
1942
|
+
category: error.category,
|
|
1943
|
+
correlationId: error.correlationId,
|
|
1944
|
+
httpStatus: error.httpStatus,
|
|
1945
|
+
nextAction: error.nextAction,
|
|
1946
|
+
operation: error.operation,
|
|
1947
|
+
retryable: error.retryable,
|
|
1948
|
+
suggestedAction: error.suggestedAction,
|
|
1949
|
+
url: error.url,
|
|
1950
|
+
...error instanceof chunkCWSXFVF2_cjs.MaintenanceError ? { details: {
|
|
1951
|
+
since: error.details?.since,
|
|
1952
|
+
retryAfterMs: error.details?.retryAfterMs
|
|
1953
|
+
} } : {}
|
|
1954
|
+
});
|
|
1955
|
+
Object.setPrototypeOf(safe, Object.getPrototypeOf(error));
|
|
1956
|
+
safe.name = error.name;
|
|
1957
|
+
if (error instanceof chunkCWSXFVF2_cjs.RateLimitError || error instanceof chunkCWSXFVF2_cjs.MaintenanceError) {
|
|
1958
|
+
Object.assign(safe, { retryAfter: error.retryAfter, notSent: error.notSent });
|
|
1959
|
+
}
|
|
1960
|
+
throw safe;
|
|
1961
|
+
}
|
|
1962
|
+
this.guardChoice(fields, "status", status, operation, label);
|
|
1963
|
+
return fields;
|
|
1964
|
+
}
|
|
1965
|
+
guardChoice(fields, name, id, operation, label) {
|
|
1966
|
+
const unavailable = () => this.writeError(operation, `${name} requires an unambiguous active exposed ${label ?? "request-type"} picklist value; inspect time_off_requests.getFieldInfo`);
|
|
1967
|
+
const rows = fields.filter((field) => chunkCWSXFVF2_cjs.isRecord(field) && field.name === name);
|
|
1968
|
+
if (rows.length !== 1 || rows[0].isPickList !== true || !Array.isArray(rows[0].picklistValues)) throw unavailable();
|
|
1969
|
+
const values = rows[0].picklistValues;
|
|
1970
|
+
const numeric = (value) => chunkCWSXFVF2_cjs.isRecord(value) && typeof value.value === "string" && /^-?\d+$/.test(value.value) && Number.isSafeInteger(Number(value.value));
|
|
1971
|
+
const named = label === void 0 ? values.filter((value) => numeric(value) && Number(value.value) === id) : values.filter((value) => chunkCWSXFVF2_cjs.isRecord(value) && typeof value.label === "string" && value.label.trim().toLowerCase() === label.toLowerCase());
|
|
1972
|
+
if (named.length !== 1 || !numeric(named[0]) || named[0].isActive !== true || Number(named[0].value) !== id) throw unavailable();
|
|
1973
|
+
if (values.filter((value) => numeric(value) && Number(value.value) === id).length !== 1) throw unavailable();
|
|
1974
|
+
}
|
|
1851
1975
|
/** Node-parity special op (hand-written in src/resources/special/time_off_requests.ts). */
|
|
1852
1976
|
approve(id, opts = {}) {
|
|
1853
1977
|
return approve(this, id, opts);
|