node-autotask 0.8.0 → 0.8.1
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/ARCHITECTURE.md +54 -12
- package/N8N_MCP_MANIFEST.json +2 -2
- package/N8N_MCP_MANIFEST.md +3 -3
- package/README.md +9 -3
- package/dist/{chunk-C7U3ZRRK.js → chunk-2QLOK7PX.js} +27 -31
- package/dist/{chunk-C7U3ZRRK.js.map → chunk-2QLOK7PX.js.map} +1 -1
- package/dist/{chunk-LDKIIVFV.cjs → chunk-CQIZDSBE.cjs} +272 -276
- package/dist/chunk-CQIZDSBE.cjs.map +1 -0
- package/dist/{chunk-QUFEIJEB.cjs → chunk-DA73ALND.cjs} +136 -138
- package/dist/chunk-DA73ALND.cjs.map +1 -0
- package/dist/{chunk-GNS47RBV.js → chunk-IUJJPWUX.js} +612 -18
- package/dist/chunk-IUJJPWUX.js.map +1 -0
- package/dist/{chunk-RFXGG37L.cjs → chunk-IV2Z3JLR.cjs} +680 -86
- package/dist/chunk-IV2Z3JLR.cjs.map +1 -0
- package/dist/{chunk-ONPT4PIV.js → chunk-PAQXQFGG.js} +4 -6
- package/dist/{chunk-ONPT4PIV.js.map → chunk-PAQXQFGG.js.map} +1 -1
- package/dist/index.cjs +120 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +129 -3
- package/dist/index.d.ts +129 -3
- package/dist/index.js +156 -63
- package/dist/index.js.map +1 -1
- package/dist/operations/index.cjs +113 -116
- package/dist/operations/index.cjs.map +1 -1
- package/dist/operations/index.js +9 -12
- package/dist/operations/index.js.map +1 -1
- package/dist/pool.cjs +8 -11
- package/dist/pool.cjs.map +1 -1
- package/dist/pool.js +4 -7
- package/dist/pool.js.map +1 -1
- package/dist/resources/index.cjs +3 -5
- package/dist/resources/index.cjs.map +1 -1
- package/dist/resources/index.js +2 -4
- package/package.json +9 -3
- package/dist/chunk-5QVXRT3A.cjs +0 -580
- package/dist/chunk-5QVXRT3A.cjs.map +0 -1
- package/dist/chunk-FE225M76.js +0 -580
- package/dist/chunk-FE225M76.js.map +0 -1
- package/dist/chunk-GNS47RBV.js.map +0 -1
- package/dist/chunk-IFXFOYDU.cjs +0 -32
- package/dist/chunk-IFXFOYDU.cjs.map +0 -1
- package/dist/chunk-LDKIIVFV.cjs.map +0 -1
- package/dist/chunk-OOEVTGP4.js +0 -121
- package/dist/chunk-OOEVTGP4.js.map +0 -1
- package/dist/chunk-PBBFMRI5.cjs +0 -121
- package/dist/chunk-PBBFMRI5.cjs.map +0 -1
- package/dist/chunk-QF4K3XTK.js +0 -32
- package/dist/chunk-QF4K3XTK.js.map +0 -1
- package/dist/chunk-QUFEIJEB.cjs.map +0 -1
- package/dist/chunk-RFXGG37L.cjs.map +0 -1
- package/dist/credential-shape.cjs +0 -15
- package/dist/credential-shape.cjs.map +0 -1
- package/dist/credential-shape.d.cts +0 -52
- package/dist/credential-shape.d.ts +0 -52
- package/dist/credential-shape.js +0 -15
- package/dist/credential-shape.js.map +0 -1
- package/dist/credentials.cjs +0 -17
- package/dist/credentials.cjs.map +0 -1
- package/dist/credentials.d.cts +0 -78
- package/dist/credentials.d.ts +0 -78
- package/dist/credentials.js +0 -17
- package/dist/credentials.js.map +0 -1
|
@@ -24,11 +24,8 @@
|
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
|
|
27
|
-
var _chunkRFXGG37Lcjs = require('./chunk-RFXGG37L.cjs');
|
|
28
27
|
|
|
29
28
|
|
|
30
|
-
var _chunkU2PEBFPUcjs = require('./chunk-U2PEBFPU.cjs');
|
|
31
|
-
|
|
32
29
|
|
|
33
30
|
|
|
34
31
|
|
|
@@ -52,11 +49,10 @@ var _chunkU2PEBFPUcjs = require('./chunk-U2PEBFPU.cjs');
|
|
|
52
49
|
|
|
53
50
|
|
|
54
51
|
|
|
55
|
-
var
|
|
52
|
+
var _chunkIV2Z3JLRcjs = require('./chunk-IV2Z3JLR.cjs');
|
|
56
53
|
|
|
57
54
|
|
|
58
|
-
|
|
59
|
-
var _chunkIFXFOYDUcjs = require('./chunk-IFXFOYDU.cjs');
|
|
55
|
+
var _chunkU2PEBFPUcjs = require('./chunk-U2PEBFPU.cjs');
|
|
60
56
|
|
|
61
57
|
// src/auth.ts
|
|
62
58
|
var AUTH_HEADERS = {
|
|
@@ -114,40 +110,40 @@ function isFilterOperator(op) {
|
|
|
114
110
|
return typeof op === "string" && FILTER_OPERATORS.includes(op);
|
|
115
111
|
}
|
|
116
112
|
function validateCondition(cond, path) {
|
|
117
|
-
if (!
|
|
118
|
-
throw new (0,
|
|
113
|
+
if (!_chunkIV2Z3JLRcjs.isRecord.call(void 0, cond)) {
|
|
114
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`Filter condition at ${path} must be an object`);
|
|
119
115
|
}
|
|
120
116
|
const op = cond.op;
|
|
121
117
|
if (!isFilterOperator(op)) {
|
|
122
|
-
throw new (0,
|
|
118
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(
|
|
123
119
|
`Unknown filter operator "${String(op)}" at ${path}; expected one of: ${FILTER_OPERATORS.join(", ")}`
|
|
124
120
|
);
|
|
125
121
|
}
|
|
126
122
|
if (op === "and" || op === "or") {
|
|
127
123
|
if (!Array.isArray(cond.items) || cond.items.length === 0) {
|
|
128
|
-
throw new (0,
|
|
124
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`Grouping operator "${op}" requires a non-empty "items" array at ${path}`);
|
|
129
125
|
}
|
|
130
126
|
cond.items.forEach((item, i) => validateCondition(item, `${path}.items[${i}]`));
|
|
131
127
|
return;
|
|
132
128
|
}
|
|
133
129
|
if (typeof cond.field !== "string" || cond.field.trim().length === 0) {
|
|
134
|
-
throw new (0,
|
|
130
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`Filter condition at ${path} requires a non-empty "field"`);
|
|
135
131
|
}
|
|
136
132
|
if (cond.field.length > MAX_FIELD_LENGTH) {
|
|
137
|
-
throw new (0,
|
|
133
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(
|
|
138
134
|
`Filter field name at ${path} is ${cond.field.length} chars; the cap is ${MAX_FIELD_LENGTH}`
|
|
139
135
|
);
|
|
140
136
|
}
|
|
141
137
|
if (op === "in" || op === "notIn") {
|
|
142
138
|
if (!Array.isArray(cond.value)) {
|
|
143
|
-
throw new (0,
|
|
139
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`Operator "${op}" requires an array "value" at ${path}`);
|
|
144
140
|
}
|
|
145
141
|
}
|
|
146
142
|
if (cond.value !== void 0) {
|
|
147
143
|
const values = Array.isArray(cond.value) ? cond.value : [cond.value];
|
|
148
144
|
for (const value of values) {
|
|
149
145
|
if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") {
|
|
150
|
-
throw new (0,
|
|
146
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`Filter value at ${path} must be a string, number or boolean`);
|
|
151
147
|
}
|
|
152
148
|
}
|
|
153
149
|
}
|
|
@@ -155,7 +151,7 @@ function validateCondition(cond, path) {
|
|
|
155
151
|
function countOrConditions(conditions) {
|
|
156
152
|
let n = 0;
|
|
157
153
|
for (const cond of conditions) {
|
|
158
|
-
if (!
|
|
154
|
+
if (!_chunkIV2Z3JLRcjs.isRecord.call(void 0, cond)) continue;
|
|
159
155
|
if (cond.op === "or" && Array.isArray(cond.items)) n += cond.items.length;
|
|
160
156
|
if (Array.isArray(cond.items)) n += countOrConditions(cond.items);
|
|
161
157
|
}
|
|
@@ -164,7 +160,7 @@ function countOrConditions(conditions) {
|
|
|
164
160
|
function countUdfConditions(conditions) {
|
|
165
161
|
let n = 0;
|
|
166
162
|
for (const cond of conditions) {
|
|
167
|
-
if (!
|
|
163
|
+
if (!_chunkIV2Z3JLRcjs.isRecord.call(void 0, cond)) continue;
|
|
168
164
|
if (cond.udf === true) n += 1;
|
|
169
165
|
if (Array.isArray(cond.items)) n += countUdfConditions(cond.items);
|
|
170
166
|
}
|
|
@@ -174,25 +170,25 @@ function serializeFilter(filter) {
|
|
|
174
170
|
return JSON.stringify(filter);
|
|
175
171
|
}
|
|
176
172
|
function validateFilter(filter) {
|
|
177
|
-
if (!
|
|
178
|
-
throw new (0,
|
|
173
|
+
if (!_chunkIV2Z3JLRcjs.isRecord.call(void 0, filter) || !Array.isArray(filter.filter)) {
|
|
174
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)("Filter must be the shape { filter: FilterCondition[] }");
|
|
179
175
|
}
|
|
180
176
|
filter.filter.forEach((condition, i) => validateCondition(condition, `filter[${i}]`));
|
|
181
177
|
const orCount = countOrConditions(filter.filter);
|
|
182
178
|
if (orCount > MAX_OR_CONDITIONS) {
|
|
183
|
-
throw new (0,
|
|
179
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(
|
|
184
180
|
`Query has ${orCount} OR-conditions; the vendor cap is ${MAX_OR_CONDITIONS} \u2014 split the query`
|
|
185
181
|
);
|
|
186
182
|
}
|
|
187
183
|
const udfCount = countUdfConditions(filter.filter);
|
|
188
184
|
if (udfCount > MAX_UDF_PER_QUERY) {
|
|
189
|
-
throw new (0,
|
|
185
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(
|
|
190
186
|
`Query has ${udfCount} UDF conditions (udf: true); the vendor allows at most ${MAX_UDF_PER_QUERY} per query`
|
|
191
187
|
);
|
|
192
188
|
}
|
|
193
189
|
const length = serializeFilter(filter).length;
|
|
194
190
|
if (length > MAX_QUERY_LENGTH) {
|
|
195
|
-
throw new (0,
|
|
191
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(
|
|
196
192
|
`Serialised filter is ${length} chars; the vendor cap is ${MAX_QUERY_LENGTH} \u2014 narrow the query`
|
|
197
193
|
);
|
|
198
194
|
}
|
|
@@ -200,7 +196,7 @@ function validateFilter(filter) {
|
|
|
200
196
|
function buildFilter(conditions) {
|
|
201
197
|
const list = Array.isArray(conditions) ? conditions : [conditions];
|
|
202
198
|
if (list.length === 0) {
|
|
203
|
-
throw new (0,
|
|
199
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)("buildFilter requires at least one condition");
|
|
204
200
|
}
|
|
205
201
|
const root = list.length === 1 ? list[0] : { op: "and", items: list };
|
|
206
202
|
const filter = { filter: [root] };
|
|
@@ -256,7 +252,7 @@ function buildQueryRequest(baseUrl, resourcePath, params) {
|
|
|
256
252
|
};
|
|
257
253
|
const url = buildUrl(baseUrl, queryPath, req.query);
|
|
258
254
|
if (url.length > MAX_GET_LENGTH) {
|
|
259
|
-
throw new (0,
|
|
255
|
+
throw new (0, _chunkIV2Z3JLRcjs.QueryTooLongError)(
|
|
260
256
|
`GET query URL is ${url.length} chars; the vendor GET cap is ${MAX_GET_LENGTH}`
|
|
261
257
|
);
|
|
262
258
|
}
|
|
@@ -287,7 +283,7 @@ function sleep(ms, signal) {
|
|
|
287
283
|
});
|
|
288
284
|
}
|
|
289
285
|
async function readBodyText(res, max, what, ctx) {
|
|
290
|
-
const tooLarge = () => new (0,
|
|
286
|
+
const tooLarge = () => new (0, _chunkIV2Z3JLRcjs.ResponseRejectedError)(`Response for ${what} exceeds maxResponseBytes (${max})`, {
|
|
291
287
|
...ctx,
|
|
292
288
|
code: "RESPONSE_TOO_LARGE",
|
|
293
289
|
suggestedAction: "Narrow the query (filter/includeFields) or raise maxResponseBytes."
|
|
@@ -339,7 +335,7 @@ function isJsonMediaType(header) {
|
|
|
339
335
|
}
|
|
340
336
|
function bodySnippet(text, redactPersonalData) {
|
|
341
337
|
const bytes = Buffer.from(text, "utf8").subarray(0, 256).toString("utf8");
|
|
342
|
-
return
|
|
338
|
+
return _chunkIV2Z3JLRcjs.redactResponseBody.call(void 0, bytes, { redactPersonalData });
|
|
343
339
|
}
|
|
344
340
|
var CREDENTIAL_HEADER_NAMES = /* @__PURE__ */ new Set([
|
|
345
341
|
"ApiIntegrationCode",
|
|
@@ -353,10 +349,10 @@ function assertCredentialShape(headers, auth) {
|
|
|
353
349
|
for (const name of Object.keys(headers)) {
|
|
354
350
|
if (!owned.has(name)) continue;
|
|
355
351
|
const value = headers[name];
|
|
356
|
-
const shape =
|
|
352
|
+
const shape = _chunkIV2Z3JLRcjs.credentialShapeProblem.call(void 0, value.trim(), { skipEdgeWhitespace: true });
|
|
357
353
|
if (shape === void 0) continue;
|
|
358
|
-
throw new (0,
|
|
359
|
-
`${name} ${
|
|
354
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(
|
|
355
|
+
`${name} ${_chunkIV2Z3JLRcjs.CREDENTIAL_ENV_LOAD_ACTION} (${shape})`,
|
|
360
356
|
{
|
|
361
357
|
code: "INVALID_CREDENTIAL_SHAPE",
|
|
362
358
|
suggestedAction: "Load the credential with the shell (`set -a; . ./.env; set +a`) or with loadAutotaskCredentialsFromEnv() from node-autotask; single-quoted values must be shell-sourced, not parsed by a quote-preserving loader. No request was sent."
|
|
@@ -372,7 +368,7 @@ function credentialShapeExpectation(headers, auth) {
|
|
|
372
368
|
let problem;
|
|
373
369
|
for (const name of names) {
|
|
374
370
|
const value = headers[name];
|
|
375
|
-
problem =
|
|
371
|
+
problem = _chunkIV2Z3JLRcjs.credentialShapeProblem.call(void 0, value.trim(), { skipEdgeWhitespace: true });
|
|
376
372
|
if (problem !== void 0) break;
|
|
377
373
|
}
|
|
378
374
|
return {
|
|
@@ -477,19 +473,19 @@ var HttpClient = (_class = class {
|
|
|
477
473
|
this.maxRetries = config.maxRetries;
|
|
478
474
|
this.maxResponseBytes = config.maxResponseBytes;
|
|
479
475
|
this.perHour = _optionalChain([config, 'access', _13 => _13.rateLimit, 'optionalAccess', _14 => _14.perHour]);
|
|
480
|
-
this.tenantKey =
|
|
481
|
-
this.cooldownStore = config.cooldown.enabled ? _nullishCoalesce(config.cooldown.store, () => (
|
|
476
|
+
this.tenantKey = _chunkIV2Z3JLRcjs.buildTenantKey.call(void 0, config.userName, config.baseUrl);
|
|
477
|
+
this.cooldownStore = config.cooldown.enabled ? _nullishCoalesce(config.cooldown.store, () => ( _chunkIV2Z3JLRcjs.defaultCooldownStore.call(void 0, ))) : void 0;
|
|
482
478
|
this.cooldownMaxMs = config.cooldown.maxMs;
|
|
483
479
|
this.cooldownDefaultMs = config.cooldown.defaultMs;
|
|
484
|
-
this.breakerKey =
|
|
480
|
+
this.breakerKey = _chunkIV2Z3JLRcjs.buildBreakerKey.call(void 0, config.baseUrl);
|
|
485
481
|
this.breaker = config.circuitBreaker.enabled ? {
|
|
486
482
|
failureWindowMs: config.circuitBreaker.failureWindowMs,
|
|
487
483
|
failureThreshold: config.circuitBreaker.failureThreshold,
|
|
488
484
|
openTimeoutMs: config.circuitBreaker.openTimeoutMs,
|
|
489
485
|
successesToClose: config.circuitBreaker.successesToClose,
|
|
490
486
|
halfOpenProbes: config.circuitBreaker.halfOpenProbes,
|
|
491
|
-
store: _nullishCoalesce(config.circuitBreaker.store, () => (
|
|
492
|
-
isFailure: _nullishCoalesce(config.circuitBreaker.isFailure, () => (
|
|
487
|
+
store: _nullishCoalesce(config.circuitBreaker.store, () => ( _chunkIV2Z3JLRcjs.defaultCircuitBreakerStore.call(void 0, ))),
|
|
488
|
+
isFailure: _nullishCoalesce(config.circuitBreaker.isFailure, () => ( _chunkIV2Z3JLRcjs.isBreakerFailure))
|
|
493
489
|
} : void 0;
|
|
494
490
|
this.profile = config.profile;
|
|
495
491
|
this.maxConcurrent = config.maxConcurrent;
|
|
@@ -629,7 +625,7 @@ var HttpClient = (_class = class {
|
|
|
629
625
|
}
|
|
630
626
|
const waitMs = this.hourStamps[0] + HOUR_MS - now;
|
|
631
627
|
if (waitMs >= deadlineAt - now) {
|
|
632
|
-
const err = new (0,
|
|
628
|
+
const err = new (0, _chunkIV2Z3JLRcjs.RateLimitError)(`Client-side rateLimit.perHour (${this.perHour}) exhausted; next slot in ${Math.ceil(waitMs / 1e3)}s`, {
|
|
633
629
|
...ctx,
|
|
634
630
|
suggestedAction: this.profile === "agent" ? "Stop or narrow the query \u2014 the LOCAL hourly budget is exhausted (per-process: it cannot see other instances or integrations on the tenant). Do NOT raise rateLimit.perHour; the window frees in about an hour." : "Back off until the hourly window frees a slot, or raise rateLimit.perHour."
|
|
635
631
|
});
|
|
@@ -697,7 +693,7 @@ var HttpClient = (_class = class {
|
|
|
697
693
|
} catch (e6) {
|
|
698
694
|
return void 0;
|
|
699
695
|
}
|
|
700
|
-
if (!
|
|
696
|
+
if (!_chunkIV2Z3JLRcjs.isRecord.call(void 0, body) || typeof body.url !== "string" || body.url.trim().length === 0) {
|
|
701
697
|
return void 0;
|
|
702
698
|
}
|
|
703
699
|
return normalizeZoneBase(body.url);
|
|
@@ -716,8 +712,8 @@ var HttpClient = (_class = class {
|
|
|
716
712
|
repointZoneBase(to) {
|
|
717
713
|
const from = this.liveBaseUrl;
|
|
718
714
|
this.liveBaseUrl = to;
|
|
719
|
-
this.tenantKey =
|
|
720
|
-
this.breakerKey =
|
|
715
|
+
this.tenantKey = _chunkIV2Z3JLRcjs.buildTenantKey.call(void 0, this.auth.userName, to);
|
|
716
|
+
this.breakerKey = _chunkIV2Z3JLRcjs.buildBreakerKey.call(void 0, to);
|
|
721
717
|
_optionalChain([this, 'access', _26 => _26.logger, 'access', _27 => _27.warn, 'optionalCall', _28 => _28(
|
|
722
718
|
`[autotask] zone re-point ${from} -> ${to} (a 401 on the stale zone base; the vendor's unauthenticated zone discovery named the tenant's current zone) \u2014 retrying the request once against the new base`,
|
|
723
719
|
void 0
|
|
@@ -731,7 +727,7 @@ var HttpClient = (_class = class {
|
|
|
731
727
|
assertCredentialShape(headers, this.auth);
|
|
732
728
|
if (opts.body !== void 0) headers["Content-Type"] = "application/json";
|
|
733
729
|
const bodyText = opts.body !== void 0 ? JSON.stringify(opts.body) : void 0;
|
|
734
|
-
const correlationId =
|
|
730
|
+
const correlationId = _chunkIV2Z3JLRcjs.newCorrelationId.call(void 0, );
|
|
735
731
|
const timeoutMs = _nullishCoalesce(opts.timeoutMs, () => ( this.timeoutMs));
|
|
736
732
|
const maxRetries = _nullishCoalesce(opts.maxRetries, () => ( this.maxRetries));
|
|
737
733
|
const started = Date.now();
|
|
@@ -740,12 +736,12 @@ var HttpClient = (_class = class {
|
|
|
740
736
|
const signal = AbortSignal.any(
|
|
741
737
|
callerSignal === void 0 ? [AbortSignal.timeout(timeoutMs)] : [AbortSignal.timeout(timeoutMs), callerSignal]
|
|
742
738
|
);
|
|
743
|
-
const auditBody = opts.body !== void 0 ?
|
|
739
|
+
const auditBody = opts.body !== void 0 ? _chunkIV2Z3JLRcjs.redactAuditBody.call(void 0, opts.body) : void 0;
|
|
744
740
|
const retriable = _nullishCoalesce(opts.idempotent, () => ( IDEMPOTENT_METHODS.includes(method)));
|
|
745
741
|
const expectBody = _nullishCoalesce(opts.expectBody, () => ( method !== "DELETE"));
|
|
746
742
|
const ctx = { operation: opts.operation, url, correlationId };
|
|
747
743
|
let lastStatus;
|
|
748
|
-
const interrupted = () => _optionalChain([callerSignal, 'optionalAccess', _29 => _29.aborted]) ? new (0,
|
|
744
|
+
const interrupted = () => _optionalChain([callerSignal, 'optionalAccess', _29 => _29.aborted]) ? new (0, _chunkIV2Z3JLRcjs.AutotaskAbortError)(`Request aborted: ${method} ${opts.path}`, { ...ctx, suggestedAction: "The caller aborted; re-issue the call if still needed." }) : new (0, _chunkIV2Z3JLRcjs.AutotaskTimeoutError)(`Request timed out after ${timeoutMs}ms: ${method} ${opts.path}`, ctx);
|
|
749
745
|
const canWait = (delay) => delay <= MAX_RETRY_DELAY_MS && delay < deadlineAt - Date.now();
|
|
750
746
|
const pause = async (delay) => {
|
|
751
747
|
try {
|
|
@@ -761,7 +757,7 @@ var HttpClient = (_class = class {
|
|
|
761
757
|
if (remainingMs > 0) {
|
|
762
758
|
if (_optionalChain([callerSignal, 'optionalAccess', _30 => _30.aborted])) throw interrupted();
|
|
763
759
|
const seconds = Math.ceil(remainingMs / 1e3);
|
|
764
|
-
const err = new (0,
|
|
760
|
+
const err = new (0, _chunkIV2Z3JLRcjs.RateLimitError)(
|
|
765
761
|
`Tenant is in a rate-limit cooldown; the call was NOT sent. ${seconds}s remain \u2014 do not retry before then, and narrow the query (filter/includeFields) before retrying.`,
|
|
766
762
|
{
|
|
767
763
|
...ctx,
|
|
@@ -798,7 +794,7 @@ var HttpClient = (_class = class {
|
|
|
798
794
|
if (now < openUntil) {
|
|
799
795
|
const remainingMs = openUntil - now;
|
|
800
796
|
const seconds = Math.ceil(remainingMs / 1e3);
|
|
801
|
-
const err = new (0,
|
|
797
|
+
const err = new (0, _chunkIV2Z3JLRcjs.CircuitBreakerError)(
|
|
802
798
|
`The circuit breaker for ${this.breakerKey} is open; the call was NOT sent. ${seconds}s remain \u2014 retry the same call after the wait (a host-scoped vendor fault, not the request).`,
|
|
803
799
|
{
|
|
804
800
|
...ctx,
|
|
@@ -821,7 +817,7 @@ var HttpClient = (_class = class {
|
|
|
821
817
|
throw err;
|
|
822
818
|
}
|
|
823
819
|
if (st.probes >= this.breaker.halfOpenProbes) {
|
|
824
|
-
const err = new (0,
|
|
820
|
+
const err = new (0, _chunkIV2Z3JLRcjs.CircuitBreakerError)(
|
|
825
821
|
`The circuit breaker for ${this.breakerKey} is half-open and its probes are in flight; the call was NOT sent \u2014 retry once a probe settles.`,
|
|
826
822
|
{
|
|
827
823
|
...ctx,
|
|
@@ -876,7 +872,7 @@ var HttpClient = (_class = class {
|
|
|
876
872
|
await pause(delay);
|
|
877
873
|
continue;
|
|
878
874
|
}
|
|
879
|
-
throw new (0,
|
|
875
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskNetworkError)(
|
|
880
876
|
`Network error during ${method} ${opts.path}: ${err2 instanceof Error ? err2.message : String(err2)}`,
|
|
881
877
|
ctx
|
|
882
878
|
);
|
|
@@ -887,7 +883,7 @@ var HttpClient = (_class = class {
|
|
|
887
883
|
status = res.status;
|
|
888
884
|
if (status >= 300 && status < 400) {
|
|
889
885
|
await _optionalChain([res, 'access', _38 => _38.body, 'optionalAccess', _39 => _39.cancel, 'call', _40 => _40(), 'access', _41 => _41.catch, 'call', _42 => _42(() => void 0)]);
|
|
890
|
-
throw new (0,
|
|
886
|
+
throw new (0, _chunkIV2Z3JLRcjs.ResponseRejectedError)(
|
|
891
887
|
`Refused to follow a ${status} redirect for ${method} ${opts.path}`,
|
|
892
888
|
{ ...ctx, code: "REDIRECT_BLOCKED", httpStatus: status, suggestedAction: "Check the configured zone/baseUrl; the API does not redirect." }
|
|
893
889
|
);
|
|
@@ -895,9 +891,9 @@ var HttpClient = (_class = class {
|
|
|
895
891
|
text = await readBodyText(res, this.maxResponseBytes, `${method} ${opts.path}`, { ...ctx, httpStatus: status });
|
|
896
892
|
} catch (err2) {
|
|
897
893
|
this.release();
|
|
898
|
-
if (err2 instanceof
|
|
894
|
+
if (err2 instanceof _chunkIV2Z3JLRcjs.AutotaskError) throw err2;
|
|
899
895
|
if (signal.aborted || isAbortLike(err2)) throw interrupted();
|
|
900
|
-
throw new (0,
|
|
896
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskNetworkError)(
|
|
901
897
|
`Network error reading the response of ${method} ${opts.path}: ${err2 instanceof Error ? err2.message : String(err2)}`,
|
|
902
898
|
ctx
|
|
903
899
|
);
|
|
@@ -908,7 +904,7 @@ var HttpClient = (_class = class {
|
|
|
908
904
|
if (this.cooldownStore !== void 0) this.cooldownStore.delete(this.tenantKey);
|
|
909
905
|
if (text.length === 0) {
|
|
910
906
|
if (expectBody) {
|
|
911
|
-
const err2 = new (0,
|
|
907
|
+
const err2 = new (0, _chunkIV2Z3JLRcjs.EmptyResponseError)(`Empty ${status} response for ${method} ${opts.path}`, {
|
|
912
908
|
...ctx,
|
|
913
909
|
httpStatus: status,
|
|
914
910
|
retryable: method !== "DELETE",
|
|
@@ -925,7 +921,7 @@ var HttpClient = (_class = class {
|
|
|
925
921
|
parsed = JSON.parse(text);
|
|
926
922
|
} catch (e8) {
|
|
927
923
|
const contentType = res.headers.get("Content-Type");
|
|
928
|
-
const err2 = contentType !== null && contentType !== "" && !isJsonMediaType(contentType) ? new (0,
|
|
924
|
+
const err2 = contentType !== null && contentType !== "" && !isJsonMediaType(contentType) ? new (0, _chunkIV2Z3JLRcjs.UnexpectedContentTypeError)(
|
|
929
925
|
`Non-JSON response body for ${method} ${opts.path} (HTTP ${status})`,
|
|
930
926
|
{
|
|
931
927
|
...ctx,
|
|
@@ -940,7 +936,7 @@ var HttpClient = (_class = class {
|
|
|
940
936
|
// the raw snippet rides details only.
|
|
941
937
|
suggestedAction: retriable ? `The zone answered with a non-JSON body (content-type: ${contentType.slice(0, 100)}); the zone is likely in a maintenance window \u2014 retry after the window, or verify baseUrl points at the REST API.` : `The zone answered a write with a non-JSON body (content-type: ${contentType.slice(0, 100)}); the request may have taken effect \u2014 verify the record before re-issuing (writes are never auto-retried).`
|
|
942
938
|
}
|
|
943
|
-
) : new (0,
|
|
939
|
+
) : new (0, _chunkIV2Z3JLRcjs.AutotaskError)(`Invalid JSON response body for ${method} ${opts.path}`, {
|
|
944
940
|
...ctx,
|
|
945
941
|
code: "INVALID_RESPONSE",
|
|
946
942
|
category: "server",
|
|
@@ -964,7 +960,7 @@ var HttpClient = (_class = class {
|
|
|
964
960
|
throw err2;
|
|
965
961
|
}
|
|
966
962
|
outcome = {
|
|
967
|
-
value: opts.skipResponseRedaction ? parsed :
|
|
963
|
+
value: opts.skipResponseRedaction ? parsed : _chunkIV2Z3JLRcjs.redactResponseBody.call(void 0, parsed, { redactPersonalData: this.redactPersonalData }),
|
|
968
964
|
status
|
|
969
965
|
};
|
|
970
966
|
break;
|
|
@@ -977,7 +973,7 @@ var HttpClient = (_class = class {
|
|
|
977
973
|
body = text;
|
|
978
974
|
}
|
|
979
975
|
}
|
|
980
|
-
const deterministic500 = status >= 500 &&
|
|
976
|
+
const deterministic500 = status >= 500 && _chunkIV2Z3JLRcjs.isDeterministicVendor500.call(void 0, _chunkIV2Z3JLRcjs.parseVendorErrors.call(void 0, body));
|
|
981
977
|
const retryableStatus = status === 429 || status >= 500;
|
|
982
978
|
if (retryableStatus && !deterministic500 && attempt < maxRetries && retriable) {
|
|
983
979
|
const retryAfter = parseRetryAfter(res.headers.get("Retry-After"));
|
|
@@ -994,7 +990,7 @@ var HttpClient = (_class = class {
|
|
|
994
990
|
}
|
|
995
991
|
if (status === 401 && zoneRetry === void 0 && this.canReResolveZone(opts)) {
|
|
996
992
|
const target = await this.discoverZoneBase(signal, ctx);
|
|
997
|
-
const targetViolation = target === void 0 || this.hostPolicy === void 0 ? null :
|
|
993
|
+
const targetViolation = target === void 0 || this.hostPolicy === void 0 ? null : _chunkIV2Z3JLRcjs.decideHostPolicy.call(void 0, target, this.hostPolicy);
|
|
998
994
|
if (targetViolation !== null) {
|
|
999
995
|
_optionalChain([this, 'access', _49 => _49.logger, 'access', _50 => _50.warn, 'optionalCall', _51 => _51(
|
|
1000
996
|
`[autotask] zone re-point refused by hostPolicy (${targetViolation.bound}): ${targetViolation.origin} \u2014 the original 401 propagates, zero wire to the refused host`,
|
|
@@ -1009,7 +1005,7 @@ var HttpClient = (_class = class {
|
|
|
1009
1005
|
}
|
|
1010
1006
|
}
|
|
1011
1007
|
const retryAfterSecs = parseRetryAfter(res.headers.get("Retry-After"));
|
|
1012
|
-
const err =
|
|
1008
|
+
const err = _chunkIV2Z3JLRcjs.errorFromStatus.call(void 0,
|
|
1013
1009
|
status,
|
|
1014
1010
|
body,
|
|
1015
1011
|
url,
|
|
@@ -1025,10 +1021,10 @@ var HttpClient = (_class = class {
|
|
|
1025
1021
|
};
|
|
1026
1022
|
}
|
|
1027
1023
|
attachEmptyReasonDetails(err);
|
|
1028
|
-
if (err instanceof
|
|
1024
|
+
if (err instanceof _chunkIV2Z3JLRcjs.RateLimitError && retryAfterSecs !== void 0) err.retryAfter = retryAfterSecs;
|
|
1029
1025
|
if (status === 429 && this.cooldownStore !== void 0) {
|
|
1030
1026
|
const threadThreshold = err.code.toLowerCase() === "itgenatr005";
|
|
1031
|
-
const durationMs =
|
|
1027
|
+
const durationMs = _chunkIV2Z3JLRcjs.cooldownDurationMs.call(void 0, retryAfterSecs, {
|
|
1032
1028
|
maxMs: this.cooldownMaxMs,
|
|
1033
1029
|
defaultMs: this.cooldownDefaultMs,
|
|
1034
1030
|
threadThreshold
|
|
@@ -1060,7 +1056,7 @@ var HttpClient = (_class = class {
|
|
|
1060
1056
|
return outcome.value;
|
|
1061
1057
|
}
|
|
1062
1058
|
} catch (err) {
|
|
1063
|
-
if (this.breaker !== void 0 && err instanceof
|
|
1059
|
+
if (this.breaker !== void 0 && err instanceof _chunkIV2Z3JLRcjs.AutotaskError && err.notSent !== true) {
|
|
1064
1060
|
try {
|
|
1065
1061
|
if (this.breaker.isFailure(err)) this.recordBreakerFailure(breakerProbe, breakerProbeKey, correlationId);
|
|
1066
1062
|
} catch (e11) {
|
|
@@ -1074,9 +1070,9 @@ var HttpClient = (_class = class {
|
|
|
1074
1070
|
status: lastStatus,
|
|
1075
1071
|
durationMs: Date.now() - started,
|
|
1076
1072
|
body: auditBody,
|
|
1077
|
-
errorCode: err instanceof
|
|
1073
|
+
errorCode: err instanceof _chunkIV2Z3JLRcjs.AutotaskError ? err.code : "NETWORK_ERROR"
|
|
1078
1074
|
});
|
|
1079
|
-
if (this.fieldCache !== void 0 && err instanceof
|
|
1075
|
+
if (this.fieldCache !== void 0 && err instanceof _chunkIV2Z3JLRcjs.AutotaskError) {
|
|
1080
1076
|
const op = typeof opts.operation === "string" ? opts.operation : void 0;
|
|
1081
1077
|
const verb = op !== void 0 ? op.slice(op.lastIndexOf(".") + 1) : "";
|
|
1082
1078
|
const drift = _optionalChain([err, 'access', _55 => _55.details, 'optionalAccess', _56 => _56.deterministic]) === true || err.code === "INVALID_RESPONSE" && META_TRIO_VERBS.has(verb);
|
|
@@ -1089,7 +1085,7 @@ var HttpClient = (_class = class {
|
|
|
1089
1085
|
} finally {
|
|
1090
1086
|
if (!(method === "GET" || opts.idempotent === true)) _optionalChain([this, 'access', _57 => _57.readCache, 'optionalAccess', _58 => _58.clear, 'call', _59 => _59()]);
|
|
1091
1087
|
}
|
|
1092
|
-
throw new (0,
|
|
1088
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskError)("unreachable: the request loop ended without an outcome");
|
|
1093
1089
|
}
|
|
1094
1090
|
}, _class);
|
|
1095
1091
|
var INVALID_SHAPE_ACTION = "Report the unexpected response shape; verify baseUrl points at the REST API.";
|
|
@@ -1101,15 +1097,15 @@ function attachEmptyReasonDetails(err) {
|
|
|
1101
1097
|
const resource = err.operation.slice(0, dot);
|
|
1102
1098
|
const op = err.operation.slice(dot + 1);
|
|
1103
1099
|
const surface = err.operation;
|
|
1104
|
-
const stamp = _optionalChain([
|
|
1105
|
-
const pointer =
|
|
1106
|
-
const isGetMiss = err instanceof
|
|
1100
|
+
const stamp = _optionalChain([_chunkIV2Z3JLRcjs.EMPTY_REASON_STAMPS, 'access', _60 => _60[resource], 'optionalAccess', _61 => _61[op]]);
|
|
1101
|
+
const pointer = _chunkIV2Z3JLRcjs.POINTER_NOTES[surface];
|
|
1102
|
+
const isGetMiss = err instanceof _chunkIV2Z3JLRcjs.NotFoundError && op === "get";
|
|
1107
1103
|
if (stamp === void 0 && pointer === void 0 && !isGetMiss) return;
|
|
1108
1104
|
err.details = { ..._nullishCoalesce(err.details, () => ( {})) };
|
|
1109
1105
|
if (stamp !== void 0) {
|
|
1110
1106
|
err.details.emptyReason = stamp;
|
|
1111
1107
|
} else if (isGetMiss) {
|
|
1112
|
-
const blindOps =
|
|
1108
|
+
const blindOps = _chunkIV2Z3JLRcjs.BLIND_SURFACE_STAMPS[resource];
|
|
1113
1109
|
const blind = blindOps !== void 0 ? Object.values(blindOps).find((v) => v !== void 0) : void 0;
|
|
1114
1110
|
err.details.emptyReason = blind !== void 0 ? {
|
|
1115
1111
|
surface,
|
|
@@ -1128,8 +1124,8 @@ function attachEmptyReasonDetails(err) {
|
|
|
1128
1124
|
if (pointer !== void 0) err.details.pointerNote = pointer;
|
|
1129
1125
|
}
|
|
1130
1126
|
function unwrapItems(body, operation) {
|
|
1131
|
-
if (!
|
|
1132
|
-
const err = new (0,
|
|
1127
|
+
if (!_chunkIV2Z3JLRcjs.isRecord.call(void 0, body) || !Array.isArray(body.items) || !_chunkIV2Z3JLRcjs.isRecord.call(void 0, body.pageDetails)) {
|
|
1128
|
+
const err = new (0, _chunkIV2Z3JLRcjs.AutotaskError)("Expected the query envelope { items, pageDetails }; got a different shape", {
|
|
1133
1129
|
code: "INVALID_RESPONSE",
|
|
1134
1130
|
category: "server",
|
|
1135
1131
|
operation,
|
|
@@ -1141,8 +1137,8 @@ function unwrapItems(body, operation) {
|
|
|
1141
1137
|
return { items: body.items, pageDetails: body.pageDetails };
|
|
1142
1138
|
}
|
|
1143
1139
|
function unwrapItem(body, id, operation) {
|
|
1144
|
-
if (!
|
|
1145
|
-
throw new (0,
|
|
1140
|
+
if (!_chunkIV2Z3JLRcjs.isRecord.call(void 0, body) || !("item" in body)) {
|
|
1141
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskError)("Expected the item envelope { item }; got a different shape", {
|
|
1146
1142
|
code: "INVALID_RESPONSE",
|
|
1147
1143
|
category: "server",
|
|
1148
1144
|
operation,
|
|
@@ -1151,7 +1147,7 @@ function unwrapItem(body, id, operation) {
|
|
|
1151
1147
|
}
|
|
1152
1148
|
const item = body.item;
|
|
1153
1149
|
if (item === null) {
|
|
1154
|
-
const err = new (0,
|
|
1150
|
+
const err = new (0, _chunkIV2Z3JLRcjs.NotFoundError)(
|
|
1155
1151
|
id !== void 0 ? `The record with ID ${id} was not found` : "The record was not found",
|
|
1156
1152
|
{
|
|
1157
1153
|
httpStatus: 200,
|
|
@@ -1166,8 +1162,8 @@ function unwrapItem(body, id, operation) {
|
|
|
1166
1162
|
return item;
|
|
1167
1163
|
}
|
|
1168
1164
|
function unwrapQueryCount(body, operation) {
|
|
1169
|
-
if (!
|
|
1170
|
-
const err = new (0,
|
|
1165
|
+
if (!_chunkIV2Z3JLRcjs.isRecord.call(void 0, body) || typeof body.queryCount !== "number") {
|
|
1166
|
+
const err = new (0, _chunkIV2Z3JLRcjs.AutotaskError)("Expected the count envelope { queryCount: number }; got a different shape", {
|
|
1171
1167
|
code: "INVALID_RESPONSE",
|
|
1172
1168
|
category: "server",
|
|
1173
1169
|
operation,
|
|
@@ -1179,10 +1175,10 @@ function unwrapQueryCount(body, operation) {
|
|
|
1179
1175
|
return body.queryCount;
|
|
1180
1176
|
}
|
|
1181
1177
|
function unwrapOperation(body, operation) {
|
|
1182
|
-
const value =
|
|
1178
|
+
const value = _chunkIV2Z3JLRcjs.isRecord.call(void 0, body) ? body.itemId !== void 0 ? body.itemId : body.id : void 0;
|
|
1183
1179
|
const numeric = toNumericId(value);
|
|
1184
1180
|
if (numeric === void 0) {
|
|
1185
|
-
const err = new (0,
|
|
1181
|
+
const err = new (0, _chunkIV2Z3JLRcjs.AutotaskError)(
|
|
1186
1182
|
"Expected OperationResultModel { itemId } (or { id }); got a different shape",
|
|
1187
1183
|
{ code: "INVALID_RESPONSE", category: "server", operation, suggestedAction: INVALID_SHAPE_ACTION }
|
|
1188
1184
|
);
|
|
@@ -1363,24 +1359,24 @@ function blindEmptyReason(stamp) {
|
|
|
1363
1359
|
};
|
|
1364
1360
|
}
|
|
1365
1361
|
function attachUpdateTargetMissReason(err, key) {
|
|
1366
|
-
const pinned = _optionalChain([
|
|
1362
|
+
const pinned = _optionalChain([_chunkIV2Z3JLRcjs.EMPTY_REASON_STAMPS, 'access', _62 => _62[key], 'optionalAccess', _63 => _63.update]);
|
|
1367
1363
|
if (pinned === void 0) return;
|
|
1368
1364
|
err.details = { ..._nullishCoalesce(err.details, () => ( {})), emptyReason: pinned };
|
|
1369
1365
|
}
|
|
1370
1366
|
function buildDryRunResult(spec, policy = { redactPersonalData: true }) {
|
|
1371
1367
|
if (spec.operation === "") {
|
|
1372
|
-
throw new (0,
|
|
1368
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)("dry-run: the operation name is required");
|
|
1373
1369
|
}
|
|
1374
1370
|
const wouldApply = spec.checks.every((check) => check.ok);
|
|
1375
1371
|
const resource = _nullishCoalesce(spec.operation.split(".")[0], () => ( spec.operation));
|
|
1376
1372
|
const diffPart = spec.diff !== void 0 ? {
|
|
1377
1373
|
diff: spec.diff.map((entry) => {
|
|
1378
1374
|
if (entry.to === void 0) return entry;
|
|
1379
|
-
const to =
|
|
1375
|
+
const to = _chunkIV2Z3JLRcjs.isRedactedFieldName.call(void 0, entry.field, policy) ? _chunkIV2Z3JLRcjs.REDACTED : _chunkIV2Z3JLRcjs.redactResponseBody.call(void 0, entry.to, policy);
|
|
1380
1376
|
return { ...entry, to };
|
|
1381
1377
|
})
|
|
1382
1378
|
} : {};
|
|
1383
|
-
const dataPart = spec.data !== void 0 ? { data:
|
|
1379
|
+
const dataPart = spec.data !== void 0 ? { data: _chunkIV2Z3JLRcjs.redactResponseBody.call(void 0, spec.data, policy) } : {};
|
|
1384
1380
|
return {
|
|
1385
1381
|
operation: spec.operation,
|
|
1386
1382
|
wouldApply,
|
|
@@ -1416,16 +1412,16 @@ function mergePartialBody(current, data) {
|
|
|
1416
1412
|
function normalizeUdfInput(value) {
|
|
1417
1413
|
if (Array.isArray(value)) {
|
|
1418
1414
|
return value.map((entry) => {
|
|
1419
|
-
if (!
|
|
1420
|
-
throw new (0,
|
|
1415
|
+
if (!_chunkIV2Z3JLRcjs.isRecord.call(void 0, entry) || typeof entry.name !== "string" || entry.name === "") {
|
|
1416
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)("userDefinedFields array entries must be { name, value } objects");
|
|
1421
1417
|
}
|
|
1422
1418
|
return { name: entry.name, value: entry.value };
|
|
1423
1419
|
});
|
|
1424
1420
|
}
|
|
1425
|
-
if (
|
|
1421
|
+
if (_chunkIV2Z3JLRcjs.isRecord.call(void 0, value)) {
|
|
1426
1422
|
return Object.entries(value).map(([name, entryValue]) => ({ name, value: entryValue }));
|
|
1427
1423
|
}
|
|
1428
|
-
throw new (0,
|
|
1424
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)("userDefinedFields must be an array of { name, value } entries or a name-to-value map");
|
|
1429
1425
|
}
|
|
1430
1426
|
function normalizedConditions(filter) {
|
|
1431
1427
|
if (filter === void 0) return void 0;
|
|
@@ -1438,7 +1434,7 @@ function blindStampFor(stamp, filter) {
|
|
|
1438
1434
|
return conditions === void 0 || conditions.length === 0 ? stamp : void 0;
|
|
1439
1435
|
}
|
|
1440
1436
|
function decodeFileData(body) {
|
|
1441
|
-
if (
|
|
1437
|
+
if (_chunkIV2Z3JLRcjs.isRecord.call(void 0, body)) {
|
|
1442
1438
|
const data = body.data;
|
|
1443
1439
|
if (typeof data === "string") return Buffer.from(data, "base64");
|
|
1444
1440
|
if (Array.isArray(data) && data.every((b) => typeof b === "number")) {
|
|
@@ -1446,7 +1442,7 @@ function decodeFileData(body) {
|
|
|
1446
1442
|
}
|
|
1447
1443
|
}
|
|
1448
1444
|
if (typeof body === "string") return Buffer.from(body, "base64");
|
|
1449
|
-
throw new (0,
|
|
1445
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskError)(
|
|
1450
1446
|
"Expected the file envelope FileQueryResultModel { data } (or a base64 string); got a different shape",
|
|
1451
1447
|
{ code: "INVALID_RESPONSE", category: "server" }
|
|
1452
1448
|
);
|
|
@@ -1474,11 +1470,11 @@ var BaseResource = class {
|
|
|
1474
1470
|
}
|
|
1475
1471
|
constructor(http, config, pageSize) {
|
|
1476
1472
|
if (config.key === "" || config.resourcePath === "") {
|
|
1477
|
-
throw new (0,
|
|
1473
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)("BaseResource requires a non-empty key and resourcePath");
|
|
1478
1474
|
}
|
|
1479
1475
|
this.http = http;
|
|
1480
1476
|
this.config = config;
|
|
1481
|
-
this.defaultPageSize =
|
|
1477
|
+
this.defaultPageSize = _chunkIV2Z3JLRcjs.clampPageSize.call(void 0, _nullishCoalesce(pageSize, () => ( _chunkIV2Z3JLRcjs.DEFAULT_PAGE_SIZE)));
|
|
1482
1478
|
}
|
|
1483
1479
|
// ------------------------------------------------------------------
|
|
1484
1480
|
// Query walk (wired to the G3 walker; cursor-follow per the pinned wire)
|
|
@@ -1493,7 +1489,7 @@ var BaseResource = class {
|
|
|
1493
1489
|
}
|
|
1494
1490
|
const cursor = state.cursor;
|
|
1495
1491
|
if (cursor === null) {
|
|
1496
|
-
throw new (0,
|
|
1492
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskError)(`No pagination cursor available for page ${page} of ${operation}`, {
|
|
1497
1493
|
code: "INVALID_RESPONSE",
|
|
1498
1494
|
category: "server",
|
|
1499
1495
|
operation
|
|
@@ -1524,7 +1520,7 @@ var BaseResource = class {
|
|
|
1524
1520
|
readPage(body, page, pageSize, state) {
|
|
1525
1521
|
const { items, pageDetails } = unwrapItems(body, `${this.config.key}.query`);
|
|
1526
1522
|
state.cursor = pageDetails.nextPageUrl;
|
|
1527
|
-
const totalPages =
|
|
1523
|
+
const totalPages = _chunkIV2Z3JLRcjs.totalPagesFor.call(void 0, pageDetails.requestCount, pageSize);
|
|
1528
1524
|
return {
|
|
1529
1525
|
items,
|
|
1530
1526
|
page,
|
|
@@ -1543,19 +1539,19 @@ var BaseResource = class {
|
|
|
1543
1539
|
return (page, pageSize) => this.fetchPage(p, page, pageSize, state);
|
|
1544
1540
|
}
|
|
1545
1541
|
walkPageSize(params) {
|
|
1546
|
-
return
|
|
1542
|
+
return _chunkIV2Z3JLRcjs.clampPageSize.call(void 0, _nullishCoalesce(_optionalChain([params, 'optionalAccess', _64 => _64.maxRecords]), () => ( this.defaultPageSize)));
|
|
1547
1543
|
}
|
|
1548
1544
|
/** Stream items across pages (the resource `query` surface). */
|
|
1549
1545
|
queryItems(params) {
|
|
1550
|
-
return
|
|
1546
|
+
return _chunkIV2Z3JLRcjs.paginateItems.call(void 0, this.pageFetcher(params), { pageSize: this.walkPageSize(params) });
|
|
1551
1547
|
}
|
|
1552
1548
|
/** Stream page objects (the resource `queryPages` surface). */
|
|
1553
1549
|
queryPageIter(params) {
|
|
1554
|
-
return
|
|
1550
|
+
return _chunkIV2Z3JLRcjs.paginate.call(void 0, this.pageFetcher(params), { pageSize: this.walkPageSize(params) });
|
|
1555
1551
|
}
|
|
1556
1552
|
/** Collect every item across all pages (the resource `queryAll` surface; 1000-page guarded). */
|
|
1557
1553
|
async queryAllItems(params) {
|
|
1558
|
-
return
|
|
1554
|
+
return _chunkIV2Z3JLRcjs.collectAll.call(void 0, this.pageFetcher(params), { pageSize: this.walkPageSize(params), maxRecords: _optionalChain([params, 'optionalAccess', _65 => _65.maxTotalRecords]) });
|
|
1559
1555
|
}
|
|
1560
1556
|
/**
|
|
1561
1557
|
* `queryBounded` — server-side pagination (the MCP query surface): ONE call
|
|
@@ -1583,13 +1579,13 @@ var BaseResource = class {
|
|
|
1583
1579
|
*/
|
|
1584
1580
|
async queryBounded(params) {
|
|
1585
1581
|
if (Array.isArray(params)) {
|
|
1586
|
-
throw new (0,
|
|
1582
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(
|
|
1587
1583
|
"queryBounded: params must be an object { filter?, limit?, includeFields? } \u2014 a bare conditions array is not accepted (wrap it: { filter: [...] })"
|
|
1588
1584
|
);
|
|
1589
1585
|
}
|
|
1590
1586
|
const limit = _nullishCoalesce(_optionalChain([params, 'optionalAccess', _66 => _66.limit]), () => ( BOUNDED_QUERY_DEFAULT_LIMIT));
|
|
1591
1587
|
if (!Number.isInteger(limit) || limit < 1 || limit > BOUNDED_QUERY_MAX_LIMIT) {
|
|
1592
|
-
throw new (0,
|
|
1588
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(
|
|
1593
1589
|
`queryBounded: limit must be an integer 1..${BOUNDED_QUERY_MAX_LIMIT} (got ${String(limit)}) \u2014 it is the TOTAL record cap, not a page size`
|
|
1594
1590
|
);
|
|
1595
1591
|
}
|
|
@@ -1599,9 +1595,9 @@ var BaseResource = class {
|
|
|
1599
1595
|
let pages = 0;
|
|
1600
1596
|
let sliced = 0;
|
|
1601
1597
|
let guard = false;
|
|
1602
|
-
const pageSize = Math.min(
|
|
1598
|
+
const pageSize = Math.min(_chunkIV2Z3JLRcjs.MAX_PAGE_SIZE, limit);
|
|
1603
1599
|
for (; ; ) {
|
|
1604
|
-
if (pages >=
|
|
1600
|
+
if (pages >= _chunkIV2Z3JLRcjs.MAX_PAGES) {
|
|
1605
1601
|
guard = true;
|
|
1606
1602
|
break;
|
|
1607
1603
|
}
|
|
@@ -1617,8 +1613,8 @@ var BaseResource = class {
|
|
|
1617
1613
|
const hasMore = (items.length >= limit || guard) && (sliced > 0 || state.cursor !== null);
|
|
1618
1614
|
const result = { items, fetched: items.length, hasMore, pagesWalked: pages };
|
|
1619
1615
|
if (items.length === 0) {
|
|
1620
|
-
result.blindSurface = blindStampFor(_optionalChain([
|
|
1621
|
-
const pinnedReason = normalizedConditions(_optionalChain([params, 'optionalAccess', _70 => _70.filter])) === void 0 ? _optionalChain([
|
|
1616
|
+
result.blindSurface = blindStampFor(_optionalChain([_chunkIV2Z3JLRcjs.BLIND_SURFACE_STAMPS, 'access', _67 => _67[this.config.key], 'optionalAccess', _68 => _68.query]), _optionalChain([params, 'optionalAccess', _69 => _69.filter]));
|
|
1617
|
+
const pinnedReason = normalizedConditions(_optionalChain([params, 'optionalAccess', _70 => _70.filter])) === void 0 ? _optionalChain([_chunkIV2Z3JLRcjs.EMPTY_REASON_STAMPS, 'access', _71 => _71[this.config.key], 'optionalAccess', _72 => _72.query]) : void 0;
|
|
1622
1618
|
if (result.blindSurface !== void 0 || pinnedReason !== void 0) {
|
|
1623
1619
|
result.emptyReason = result.blindSurface !== void 0 ? blindEmptyReason(result.blindSurface) : pinnedReason;
|
|
1624
1620
|
}
|
|
@@ -1643,9 +1639,9 @@ var BaseResource = class {
|
|
|
1643
1639
|
idempotent: true
|
|
1644
1640
|
});
|
|
1645
1641
|
const count = unwrapQueryCount(res, `${this.config.key}.count`);
|
|
1646
|
-
const stamp = blindStampFor(_optionalChain([
|
|
1642
|
+
const stamp = blindStampFor(_optionalChain([_chunkIV2Z3JLRcjs.BLIND_SURFACE_STAMPS, 'access', _74 => _74[this.config.key], 'optionalAccess', _75 => _75.count]), _optionalChain([params, 'optionalAccess', _76 => _76.filter]));
|
|
1647
1643
|
if (count === 0) {
|
|
1648
|
-
const pinnedReason = conditions === void 0 ? _optionalChain([
|
|
1644
|
+
const pinnedReason = conditions === void 0 ? _optionalChain([_chunkIV2Z3JLRcjs.EMPTY_REASON_STAMPS, 'access', _77 => _77[this.config.key], 'optionalAccess', _78 => _78.count]) : void 0;
|
|
1649
1645
|
if (stamp !== void 0 || pinnedReason !== void 0) {
|
|
1650
1646
|
return {
|
|
1651
1647
|
count,
|
|
@@ -1715,7 +1711,7 @@ var BaseResource = class {
|
|
|
1715
1711
|
return value;
|
|
1716
1712
|
});
|
|
1717
1713
|
work.catch((err) => {
|
|
1718
|
-
if (err instanceof
|
|
1714
|
+
if (err instanceof _chunkIV2Z3JLRcjs.AutotaskError && (err.code === "INVALID_RESPONSE" || _optionalChain([err, 'access', _81 => _81.details, 'optionalAccess', _82 => _82.deterministic]) === true)) {
|
|
1719
1715
|
cache.invalidate(key);
|
|
1720
1716
|
}
|
|
1721
1717
|
});
|
|
@@ -1723,7 +1719,7 @@ var BaseResource = class {
|
|
|
1723
1719
|
}
|
|
1724
1720
|
/** `GET /V1.0/<E>/{id}` → `{ item }` unwrapped (`item: null` → NotFoundError). */
|
|
1725
1721
|
async getGlobal(id, fresh = false) {
|
|
1726
|
-
const numeric =
|
|
1722
|
+
const numeric = _chunkIV2Z3JLRcjs.parseIdentifier.call(void 0, id, "id");
|
|
1727
1723
|
const res = await this.cachedGet(`${this.resourcePath}/${numeric}`, `${this.config.key}.get`, fresh, this.config.key);
|
|
1728
1724
|
return unwrapItem(res, numeric, `${this.config.key}.get`);
|
|
1729
1725
|
}
|
|
@@ -1739,7 +1735,7 @@ var BaseResource = class {
|
|
|
1739
1735
|
* (redacted-view) read cache.
|
|
1740
1736
|
*/
|
|
1741
1737
|
async getGlobalUnredacted(id) {
|
|
1742
|
-
const numeric =
|
|
1738
|
+
const numeric = _chunkIV2Z3JLRcjs.parseIdentifier.call(void 0, id, "id");
|
|
1743
1739
|
const res = await this.http.request({
|
|
1744
1740
|
method: "GET",
|
|
1745
1741
|
path: `${this.resourcePath}/${numeric}`,
|
|
@@ -1757,7 +1753,7 @@ var BaseResource = class {
|
|
|
1757
1753
|
* '[REDACTED]' markers into the fallback PUT (corruption on live records).
|
|
1758
1754
|
*/
|
|
1759
1755
|
async getScopedUnredacted(parentId, id) {
|
|
1760
|
-
const numeric =
|
|
1756
|
+
const numeric = _chunkIV2Z3JLRcjs.parseIdentifier.call(void 0, id, "id");
|
|
1761
1757
|
const res = await this.http.request({
|
|
1762
1758
|
method: "GET",
|
|
1763
1759
|
path: this.scopedItemPath(parentId, numeric),
|
|
@@ -1768,7 +1764,7 @@ var BaseResource = class {
|
|
|
1768
1764
|
}
|
|
1769
1765
|
/** Parent-scoped `GET .../{parentId}/<Child>/{id}` → `{ item }` unwrapped. */
|
|
1770
1766
|
async getScopedRaw(parentId, id, fresh = false) {
|
|
1771
|
-
const numeric =
|
|
1767
|
+
const numeric = _chunkIV2Z3JLRcjs.parseIdentifier.call(void 0, id, "id");
|
|
1772
1768
|
const res = await this.cachedGet(this.scopedItemPath(parentId, id), `${this.config.key}.get`, fresh, this.config.key);
|
|
1773
1769
|
return unwrapItem(res, numeric, `${this.config.key}.get`);
|
|
1774
1770
|
}
|
|
@@ -1778,25 +1774,25 @@ var BaseResource = class {
|
|
|
1778
1774
|
* accept all three shapes; empty/null → NotFoundError.
|
|
1779
1775
|
*/
|
|
1780
1776
|
async getScopedModel(parentId, id, fresh = false) {
|
|
1781
|
-
const numeric =
|
|
1777
|
+
const numeric = _chunkIV2Z3JLRcjs.parseIdentifier.call(void 0, id, "id");
|
|
1782
1778
|
const res = await this.cachedGet(this.scopedItemPath(parentId, id), `${this.config.key}.get`, fresh, this.config.key);
|
|
1783
1779
|
return this.unwrapModelLike(res, numeric);
|
|
1784
1780
|
}
|
|
1785
1781
|
unwrapModelLike(body, id) {
|
|
1786
|
-
if (!
|
|
1787
|
-
throw new (0,
|
|
1782
|
+
if (!_chunkIV2Z3JLRcjs.isRecord.call(void 0, body)) {
|
|
1783
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskError)(
|
|
1788
1784
|
`Expected an attachment model (or { item } / { items }) envelope for ID ${id}; got a different shape`,
|
|
1789
1785
|
{ code: "INVALID_RESPONSE", category: "server", resourceIds: [id] }
|
|
1790
1786
|
);
|
|
1791
1787
|
}
|
|
1792
1788
|
if (Object.keys(body).length === 0) {
|
|
1793
|
-
throw new (0,
|
|
1789
|
+
throw new (0, _chunkIV2Z3JLRcjs.NotFoundError)(`The record with ID ${id} was not found`, { httpStatus: 200, resourceIds: [id] });
|
|
1794
1790
|
}
|
|
1795
1791
|
if ("item" in body) return unwrapItem(body, id);
|
|
1796
1792
|
if (Array.isArray(body.items)) {
|
|
1797
1793
|
const first = body.items[0];
|
|
1798
1794
|
if (first === null || first === void 0) {
|
|
1799
|
-
throw new (0,
|
|
1795
|
+
throw new (0, _chunkIV2Z3JLRcjs.NotFoundError)(`The record with ID ${id} was not found`, { httpStatus: 200, resourceIds: [id] });
|
|
1800
1796
|
}
|
|
1801
1797
|
return first;
|
|
1802
1798
|
}
|
|
@@ -1844,8 +1840,8 @@ var BaseResource = class {
|
|
|
1844
1840
|
try {
|
|
1845
1841
|
return unwrapOperation(body, operation);
|
|
1846
1842
|
} catch (err) {
|
|
1847
|
-
if (!
|
|
1848
|
-
const pin =
|
|
1843
|
+
if (!_chunkIV2Z3JLRcjs.isAutotaskError.call(void 0, err) || err.code !== "INVALID_RESPONSE") throw err;
|
|
1844
|
+
const pin = _chunkIV2Z3JLRcjs.RESPONSE_DRIFT_MARKERS[this.config.key];
|
|
1849
1845
|
if (pin === void 0 || opts.recoverIdFromMarker === false) throw err;
|
|
1850
1846
|
return this.recoverCreatedIdByMarker(err, body, wireBody, opts, pin);
|
|
1851
1847
|
}
|
|
@@ -1938,7 +1934,7 @@ var BaseResource = class {
|
|
|
1938
1934
|
* never a 2xx shape fault (those keep today's typed error byte-identical).
|
|
1939
1935
|
*/
|
|
1940
1936
|
putFallbackEligible(err) {
|
|
1941
|
-
return this.http.update.putFallback === true && err instanceof
|
|
1937
|
+
return this.http.update.putFallback === true && err instanceof _chunkIV2Z3JLRcjs.NotFoundError && err.httpStatus === 404;
|
|
1942
1938
|
}
|
|
1943
1939
|
/**
|
|
1944
1940
|
* Issue #34: the fallback retry body — the caller's (normalised) fields
|
|
@@ -1953,7 +1949,7 @@ var BaseResource = class {
|
|
|
1953
1949
|
try {
|
|
1954
1950
|
current = await read();
|
|
1955
1951
|
} catch (err) {
|
|
1956
|
-
if (err instanceof
|
|
1952
|
+
if (err instanceof _chunkIV2Z3JLRcjs.NotFoundError) attachUpdateTargetMissReason(err, this.config.key);
|
|
1957
1953
|
throw err;
|
|
1958
1954
|
}
|
|
1959
1955
|
const merged = mergePartialBody(current, callerBody);
|
|
@@ -1974,7 +1970,7 @@ var BaseResource = class {
|
|
|
1974
1970
|
return err;
|
|
1975
1971
|
}
|
|
1976
1972
|
async updateGlobal(id, data, opts = {}) {
|
|
1977
|
-
const numeric =
|
|
1973
|
+
const numeric = _chunkIV2Z3JLRcjs.parseIdentifier.call(void 0, id, "id");
|
|
1978
1974
|
const operation = `${this.config.key}.update`;
|
|
1979
1975
|
let body = this.normalizeMutationBody(data);
|
|
1980
1976
|
const collectionUpdate = this.config.collectionUpdate === true;
|
|
@@ -1984,7 +1980,7 @@ var BaseResource = class {
|
|
|
1984
1980
|
try {
|
|
1985
1981
|
current = await this.getGlobalUnredacted(numeric);
|
|
1986
1982
|
} catch (err) {
|
|
1987
|
-
if (err instanceof
|
|
1983
|
+
if (err instanceof _chunkIV2Z3JLRcjs.NotFoundError) attachUpdateTargetMissReason(err, this.config.key);
|
|
1988
1984
|
throw err;
|
|
1989
1985
|
}
|
|
1990
1986
|
this.staleObjectCheck(current, opts, operation);
|
|
@@ -2034,7 +2030,7 @@ var BaseResource = class {
|
|
|
2034
2030
|
* result from the path id (issue #25: the transport returns undefined
|
|
2035
2031
|
* for it; a non-blank wrong shape still throws via unwrapOperation). */
|
|
2036
2032
|
async deleteGlobal(id) {
|
|
2037
|
-
const numeric =
|
|
2033
|
+
const numeric = _chunkIV2Z3JLRcjs.parseIdentifier.call(void 0, id, "id");
|
|
2038
2034
|
const res = await this.http.request({
|
|
2039
2035
|
method: "DELETE",
|
|
2040
2036
|
path: `${this.resourcePath}/${numeric}`,
|
|
@@ -2044,13 +2040,13 @@ var BaseResource = class {
|
|
|
2044
2040
|
}
|
|
2045
2041
|
scopedCollectionPath(parentId) {
|
|
2046
2042
|
if (this.config.parentScopedPath === void 0) {
|
|
2047
|
-
throw new (0,
|
|
2043
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`Resource ${this.config.key} is not parent-scoped; there is no parent-scoped path`);
|
|
2048
2044
|
}
|
|
2049
|
-
const p =
|
|
2045
|
+
const p = _chunkIV2Z3JLRcjs.parseIdentifier.call(void 0, parentId, "parentId");
|
|
2050
2046
|
return this.config.parentScopedPath.replace("{parentId}", String(p));
|
|
2051
2047
|
}
|
|
2052
2048
|
scopedItemPath(parentId, id) {
|
|
2053
|
-
return `${this.scopedCollectionPath(parentId)}/${
|
|
2049
|
+
return `${this.scopedCollectionPath(parentId)}/${_chunkIV2Z3JLRcjs.parseIdentifier.call(void 0, id, "id")}`;
|
|
2054
2050
|
}
|
|
2055
2051
|
/** Parent-scoped create: `POST .../{parentId}/<Child>` (issue #13: a drifted 2xx runs the bounded marker recovery where the plan pins a marker field). */
|
|
2056
2052
|
async createScopedRaw(parentId, data, opts = {}) {
|
|
@@ -2068,7 +2064,7 @@ var BaseResource = class {
|
|
|
2068
2064
|
* the item path anywhere in the spec; the node strips the id from the path and
|
|
2069
2065
|
* PATCHes the collection, and the vendor keys the record by the id in the body. */
|
|
2070
2066
|
async updateScopedRaw(parentId, id, data) {
|
|
2071
|
-
const numeric =
|
|
2067
|
+
const numeric = _chunkIV2Z3JLRcjs.parseIdentifier.call(void 0, id, "id");
|
|
2072
2068
|
const body = this.normalizeMutationBody(data);
|
|
2073
2069
|
body.id = numeric;
|
|
2074
2070
|
const path = this.scopedCollectionPath(parentId);
|
|
@@ -2107,7 +2103,7 @@ var BaseResource = class {
|
|
|
2107
2103
|
/** Parent-scoped delete: `DELETE .../{parentId}/<Child>/{id}` → `{ id }`
|
|
2108
2104
|
* (a blank 2xx synthesizes `{ id }` from the path id — issue #25). */
|
|
2109
2105
|
async deleteScopedRaw(parentId, id) {
|
|
2110
|
-
const numeric =
|
|
2106
|
+
const numeric = _chunkIV2Z3JLRcjs.parseIdentifier.call(void 0, id, "id");
|
|
2111
2107
|
const res = await this.http.request({
|
|
2112
2108
|
method: "DELETE",
|
|
2113
2109
|
path: this.scopedItemPath(parentId, id),
|
|
@@ -2120,15 +2116,15 @@ var BaseResource = class {
|
|
|
2120
2116
|
* OperationResultModel (G1 envelope.md) — pass it through typed.
|
|
2121
2117
|
*/
|
|
2122
2118
|
async deleteScopedModel(parentId, id) {
|
|
2123
|
-
const numeric =
|
|
2119
|
+
const numeric = _chunkIV2Z3JLRcjs.parseIdentifier.call(void 0, id, "id");
|
|
2124
2120
|
const res = await this.http.request({
|
|
2125
2121
|
method: "DELETE",
|
|
2126
2122
|
path: this.scopedItemPath(parentId, id),
|
|
2127
2123
|
operation: `${this.config.key}.delete`
|
|
2128
2124
|
});
|
|
2129
2125
|
if (res === void 0) return {};
|
|
2130
|
-
if (!
|
|
2131
|
-
throw new (0,
|
|
2126
|
+
if (!_chunkIV2Z3JLRcjs.isRecord.call(void 0, res)) {
|
|
2127
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskError)(
|
|
2132
2128
|
`Expected the deleted attachment model for ID ${numeric}; got a different shape`,
|
|
2133
2129
|
{ code: "INVALID_RESPONSE", category: "server", resourceIds: [numeric] }
|
|
2134
2130
|
);
|
|
@@ -2150,9 +2146,9 @@ var BaseResource = class {
|
|
|
2150
2146
|
`${this.resourcePath}/entityInformation`,
|
|
2151
2147
|
`${this.config.key}.getEntityInfo`,
|
|
2152
2148
|
(res) => {
|
|
2153
|
-
const body =
|
|
2154
|
-
if (body === void 0 || !
|
|
2155
|
-
throw new (0,
|
|
2149
|
+
const body = _chunkIV2Z3JLRcjs.isRecord.call(void 0, res) ? res : void 0;
|
|
2150
|
+
if (body === void 0 || !_chunkIV2Z3JLRcjs.isRecord.call(void 0, body.info)) {
|
|
2151
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskError)("Expected the entityInformation envelope { info }; got a different shape", {
|
|
2156
2152
|
code: "INVALID_RESPONSE",
|
|
2157
2153
|
category: "server"
|
|
2158
2154
|
});
|
|
@@ -2190,8 +2186,8 @@ var BaseResource = class {
|
|
|
2190
2186
|
);
|
|
2191
2187
|
}
|
|
2192
2188
|
unwrapFields(body, envelopeName) {
|
|
2193
|
-
if (!
|
|
2194
|
-
throw new (0,
|
|
2189
|
+
if (!_chunkIV2Z3JLRcjs.isRecord.call(void 0, body) || !Array.isArray(body.fields)) {
|
|
2190
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskError)(`Expected the ${envelopeName} envelope { fields: [] }; got a different shape`, {
|
|
2195
2191
|
code: "INVALID_RESPONSE",
|
|
2196
2192
|
category: "server"
|
|
2197
2193
|
});
|
|
@@ -2207,7 +2203,7 @@ var BaseResource = class {
|
|
|
2207
2203
|
*/
|
|
2208
2204
|
async queryEntity(entityPath, conditions, opts = {}) {
|
|
2209
2205
|
const body = { filter: buildFilter(conditions).filter };
|
|
2210
|
-
if (opts.maxRecords !== void 0) body.MaxRecords =
|
|
2206
|
+
if (opts.maxRecords !== void 0) body.MaxRecords = _chunkIV2Z3JLRcjs.clampPageSize.call(void 0, opts.maxRecords);
|
|
2211
2207
|
if (opts.includeFields !== void 0) body.IncludeFields = opts.includeFields;
|
|
2212
2208
|
const res = await this.http.request({
|
|
2213
2209
|
method: "POST",
|
|
@@ -2219,7 +2215,7 @@ var BaseResource = class {
|
|
|
2219
2215
|
return unwrapItems(res, `${this.config.key}.cross-query`).items;
|
|
2220
2216
|
}
|
|
2221
2217
|
async createIfNotExists(dataOrParentId, dataOrOpts, opts = {}) {
|
|
2222
|
-
const isObject = (v) =>
|
|
2218
|
+
const isObject = (v) => _chunkIV2Z3JLRcjs.isRecord.call(void 0, v) && !Array.isArray(v);
|
|
2223
2219
|
const scoped = this.config.parentScopedPath !== void 0;
|
|
2224
2220
|
let parentId;
|
|
2225
2221
|
let data;
|
|
@@ -2227,23 +2223,23 @@ var BaseResource = class {
|
|
|
2227
2223
|
if (scoped) {
|
|
2228
2224
|
const dataIsOptsBag = isObject(dataOrOpts) && ("dedupFields" in dataOrOpts || "dryRun" in dataOrOpts);
|
|
2229
2225
|
if (typeof dataOrParentId !== "number" || !isObject(dataOrOpts) || dataIsOptsBag) {
|
|
2230
|
-
throw new (0,
|
|
2226
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(
|
|
2231
2227
|
`createIfNotExists for parent-scoped resource ${this.config.key} requires (parentId, data[, opts]) \u2014 the global collection has no create; a missing parentId would be a wrong-path request`
|
|
2232
2228
|
);
|
|
2233
2229
|
}
|
|
2234
|
-
parentId =
|
|
2230
|
+
parentId = _chunkIV2Z3JLRcjs.parseIdentifier.call(void 0, dataOrParentId, "parentId");
|
|
2235
2231
|
data = dataOrOpts;
|
|
2236
2232
|
cinOpts = opts;
|
|
2237
2233
|
} else {
|
|
2238
2234
|
if (!isObject(dataOrParentId)) {
|
|
2239
|
-
throw new (0,
|
|
2235
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(
|
|
2240
2236
|
`createIfNotExists for top-level resource ${this.config.key} takes (data[, opts]) \u2014 got a non-record first argument`
|
|
2241
2237
|
);
|
|
2242
2238
|
}
|
|
2243
2239
|
data = dataOrParentId;
|
|
2244
2240
|
cinOpts = isObject(dataOrOpts) ? dataOrOpts : {};
|
|
2245
2241
|
}
|
|
2246
|
-
const record =
|
|
2242
|
+
const record = _chunkIV2Z3JLRcjs.isRecord.call(void 0, data) ? data : {};
|
|
2247
2243
|
const dedupFields = (_nullishCoalesce(cinOpts.dedupFields, () => ( []))).filter((field) => field in record);
|
|
2248
2244
|
let existing;
|
|
2249
2245
|
let existingId;
|
|
@@ -2268,7 +2264,7 @@ var BaseResource = class {
|
|
|
2268
2264
|
}
|
|
2269
2265
|
if (cinOpts.dryRun === true) {
|
|
2270
2266
|
const checks = [
|
|
2271
|
-
{ name: "input-validation", ok:
|
|
2267
|
+
{ name: "input-validation", ok: _chunkIV2Z3JLRcjs.isRecord.call(void 0, data) && Object.keys(data).length > 0 }
|
|
2272
2268
|
];
|
|
2273
2269
|
if (dedupFields.length > 0) {
|
|
2274
2270
|
checks.push({ name: "duplicate-detection", ok: existingId === void 0 });
|
|
@@ -2308,7 +2304,7 @@ var BaseResource = class {
|
|
|
2308
2304
|
const actual = current[field];
|
|
2309
2305
|
if (typeof actual !== "string") return false;
|
|
2310
2306
|
if (actual !== expected) {
|
|
2311
|
-
throw new (0,
|
|
2307
|
+
throw new (0, _chunkIV2Z3JLRcjs.StaleObjectError)(
|
|
2312
2308
|
`stale object: ${this.config.key} ${field} changed since the caller read it (expected ${expected}, current ${actual})`,
|
|
2313
2309
|
{
|
|
2314
2310
|
code: "STALE_OBJECT",
|
|
@@ -2331,7 +2327,7 @@ var BaseResource = class {
|
|
|
2331
2327
|
try {
|
|
2332
2328
|
current = parentId === void 0 ? await this.getGlobal(id, true) : this.config.attachmentGet ? await this.getScopedModel(parentId, id, true) : await this.getScopedRaw(parentId, id, true);
|
|
2333
2329
|
} catch (err) {
|
|
2334
|
-
if (err instanceof
|
|
2330
|
+
if (err instanceof _chunkIV2Z3JLRcjs.NotFoundError) attachUpdateTargetMissReason(err, this.config.key);
|
|
2335
2331
|
throw err;
|
|
2336
2332
|
}
|
|
2337
2333
|
this.staleObjectCheck(current, opts, operation);
|
|
@@ -2345,8 +2341,8 @@ var BaseResource = class {
|
|
|
2345
2341
|
async runCreateDryRun(data, parentId) {
|
|
2346
2342
|
const checks = [];
|
|
2347
2343
|
const warnings = [];
|
|
2348
|
-
checks.push({ name: "input-validation", ok:
|
|
2349
|
-
const deleteBoundaryNote =
|
|
2344
|
+
checks.push({ name: "input-validation", ok: _chunkIV2Z3JLRcjs.isRecord.call(void 0, data) && Object.keys(data).length > 0 });
|
|
2345
|
+
const deleteBoundaryNote = _chunkIV2Z3JLRcjs.DELETE_BOUNDARY_NOTES[this.config.key];
|
|
2350
2346
|
if (deleteBoundaryNote !== void 0) {
|
|
2351
2347
|
checks.push({ name: "delete-boundary", ok: true });
|
|
2352
2348
|
warnings.push(deleteBoundaryNote);
|
|
@@ -2356,7 +2352,7 @@ var BaseResource = class {
|
|
|
2356
2352
|
path = this.scopedCollectionPath(parentId);
|
|
2357
2353
|
const parentPath = this.config.parentPath;
|
|
2358
2354
|
if (parentPath === void 0) {
|
|
2359
|
-
throw new (0,
|
|
2355
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(
|
|
2360
2356
|
`dry-run: ${this.config.key} is parent-scoped but has no parentPath configured`
|
|
2361
2357
|
);
|
|
2362
2358
|
}
|
|
@@ -2387,7 +2383,7 @@ var BaseResource = class {
|
|
|
2387
2383
|
const operation = `${this.config.key}.update`;
|
|
2388
2384
|
const checks = [];
|
|
2389
2385
|
const warnings = [];
|
|
2390
|
-
checks.push({ name: "input-validation", ok:
|
|
2386
|
+
checks.push({ name: "input-validation", ok: _chunkIV2Z3JLRcjs.isRecord.call(void 0, data) && Object.keys(data).length > 0 });
|
|
2391
2387
|
const scopedUpdate = parentId !== void 0 && this.config.parentScopedPath !== void 0;
|
|
2392
2388
|
const collectionUpdate = scopedUpdate || this.config.collectionUpdate === true;
|
|
2393
2389
|
const path = scopedUpdate ? this.scopedCollectionPath(parentId) : collectionUpdate ? this.resourcePath : `${this.resourcePath}/${id}`;
|
|
@@ -2396,8 +2392,8 @@ var BaseResource = class {
|
|
|
2396
2392
|
try {
|
|
2397
2393
|
current = parentId === void 0 ? await this.getGlobal(id, true) : this.config.attachmentGet ? await this.getScopedModel(parentId, id, true) : await this.getScopedRaw(parentId, id, true);
|
|
2398
2394
|
} catch (err) {
|
|
2399
|
-
if (err instanceof
|
|
2400
|
-
const updateReason = _optionalChain([
|
|
2395
|
+
if (err instanceof _chunkIV2Z3JLRcjs.NotFoundError) {
|
|
2396
|
+
const updateReason = _optionalChain([_chunkIV2Z3JLRcjs.EMPTY_REASON_STAMPS, 'access', _83 => _83[this.config.key], 'optionalAccess', _84 => _84.update]);
|
|
2401
2397
|
checks.push({
|
|
2402
2398
|
name: "current-record-exists",
|
|
2403
2399
|
ok: false,
|
|
@@ -2455,7 +2451,7 @@ var BaseResource = class {
|
|
|
2455
2451
|
try {
|
|
2456
2452
|
current = parentId === void 0 ? await this.getGlobal(id, true) : this.config.attachmentGet ? await this.getScopedModel(parentId, id, true) : await this.getScopedRaw(parentId, id, true);
|
|
2457
2453
|
} catch (err) {
|
|
2458
|
-
if (err instanceof
|
|
2454
|
+
if (err instanceof _chunkIV2Z3JLRcjs.NotFoundError) {
|
|
2459
2455
|
checks.push({ name: "current-record-exists", ok: false });
|
|
2460
2456
|
warnings.push(`record ${id} not fetchable; the vendor would reject the delete`);
|
|
2461
2457
|
return buildDryRunResult({
|
|
@@ -2507,7 +2503,7 @@ var BaseResource = class {
|
|
|
2507
2503
|
* the composite ROOT of a hot resource (issue #36) must see the live
|
|
2508
2504
|
* record, never a snapshot. */
|
|
2509
2505
|
async fetchRecordRaw(entityPath, id, fresh = false) {
|
|
2510
|
-
const numeric =
|
|
2506
|
+
const numeric = _chunkIV2Z3JLRcjs.parseIdentifier.call(void 0, id, "id");
|
|
2511
2507
|
const resource = RESOURCE_KEY_BY_PATH[entityPath];
|
|
2512
2508
|
const res = await this.cachedGet(`${entityPath}/${numeric}`, `${this.config.key}.fetchRecord`, fresh, resource);
|
|
2513
2509
|
if (this.config.attachmentGet) {
|
|
@@ -2558,7 +2554,7 @@ var BaseResource = class {
|
|
|
2558
2554
|
try {
|
|
2559
2555
|
return await this.fetchRecordRaw(entityPath, referenceId);
|
|
2560
2556
|
} catch (err) {
|
|
2561
|
-
if (err instanceof
|
|
2557
|
+
if (err instanceof _chunkIV2Z3JLRcjs.NotFoundError) {
|
|
2562
2558
|
_optionalChain([cache, 'optionalAccess', _85 => _85.set, 'call', _86 => _86(absentKey, CONTEXT_ABSENT_MARKER, RESOURCE_KEY_BY_PATH[entityPath])]);
|
|
2563
2559
|
return null;
|
|
2564
2560
|
}
|
|
@@ -2589,7 +2585,7 @@ var BaseResource = class {
|
|
|
2589
2585
|
let numeric = null;
|
|
2590
2586
|
if (typeof identifier === "number") {
|
|
2591
2587
|
if (!Number.isInteger(identifier) || identifier < 0) {
|
|
2592
|
-
throw new (0,
|
|
2588
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)("resolve: numeric id must be a non-negative integer");
|
|
2593
2589
|
}
|
|
2594
2590
|
numeric = identifier;
|
|
2595
2591
|
} else if (/^\d+$/.test(identifier.trim())) {
|
|
@@ -2600,12 +2596,12 @@ var BaseResource = class {
|
|
|
2600
2596
|
return { value: record, resolutionCost: "direct", scanned: 0, scanTruncated: false };
|
|
2601
2597
|
}
|
|
2602
2598
|
if (typeof identifier !== "string" || identifier.trim() === "") {
|
|
2603
|
-
throw new (0,
|
|
2599
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)("resolve: identifier must be a numeric id or a non-empty value");
|
|
2604
2600
|
}
|
|
2605
2601
|
const value = identifier.trim();
|
|
2606
2602
|
const fields = _nullishCoalesce(this.config.searchFields, () => ( []));
|
|
2607
2603
|
if (fields.length === 0) {
|
|
2608
|
-
throw new (0,
|
|
2604
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(
|
|
2609
2605
|
`resolve: ${this.config.key} has no primary text field (ids only)`
|
|
2610
2606
|
);
|
|
2611
2607
|
}
|
|
@@ -2617,7 +2613,7 @@ var BaseResource = class {
|
|
|
2617
2613
|
}
|
|
2618
2614
|
if (items.length >= 2) {
|
|
2619
2615
|
const ids = items.map((m) => m.id).filter((id) => typeof id === "number");
|
|
2620
|
-
throw new (0,
|
|
2616
|
+
throw new (0, _chunkIV2Z3JLRcjs.ResolutionError)(
|
|
2621
2617
|
`resolve: "${value}" is ambiguous on ${this.config.key} (matched ${items.length} records)`,
|
|
2622
2618
|
{ code: "RESOLUTION_AMBIGUOUS", resourceIds: ids }
|
|
2623
2619
|
);
|
|
@@ -2635,7 +2631,7 @@ var BaseResource = class {
|
|
|
2635
2631
|
};
|
|
2636
2632
|
}
|
|
2637
2633
|
if (scan.truncated) {
|
|
2638
|
-
throw new (0,
|
|
2634
|
+
throw new (0, _chunkIV2Z3JLRcjs.ResolutionError)(
|
|
2639
2635
|
`resolve: "${value}" is unverified on ${this.config.key} \u2014 the bounded client scan read ${scan.scanned} records (cap) without completing; a complete non-match cannot be proven`,
|
|
2640
2636
|
{
|
|
2641
2637
|
code: "RESOLUTION_TRUNCATED",
|
|
@@ -2705,7 +2701,7 @@ var BaseResource = class {
|
|
|
2705
2701
|
* candidate ids.
|
|
2706
2702
|
*/
|
|
2707
2703
|
async findByField(field, value) {
|
|
2708
|
-
if (value.trim() === "") throw new (0,
|
|
2704
|
+
if (value.trim() === "") throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`findBy${field}: empty value`);
|
|
2709
2705
|
const matches = await this.queryEntity(
|
|
2710
2706
|
`${this.resourcePath}/query`,
|
|
2711
2707
|
[{ field, op: "eq", value: value.trim() }],
|
|
@@ -2714,7 +2710,7 @@ var BaseResource = class {
|
|
|
2714
2710
|
if (matches.length === 0) return null;
|
|
2715
2711
|
if (matches.length > 1) {
|
|
2716
2712
|
const ids = matches.map((m) => m.id).filter((id) => typeof id === "number");
|
|
2717
|
-
throw new (0,
|
|
2713
|
+
throw new (0, _chunkIV2Z3JLRcjs.ResolutionError)(
|
|
2718
2714
|
`findBy${field}: "${value}" is ambiguous on ${this.config.key} (matched ${matches.length} records)`,
|
|
2719
2715
|
{ code: "RESOLUTION_AMBIGUOUS", resourceIds: ids }
|
|
2720
2716
|
);
|
|
@@ -2728,12 +2724,12 @@ var BaseResource = class {
|
|
|
2728
2724
|
*/
|
|
2729
2725
|
async searchBase(query, opts = {}) {
|
|
2730
2726
|
const text = query.trim();
|
|
2731
|
-
if (text === "") throw new (0,
|
|
2727
|
+
if (text === "") throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)("search: empty query");
|
|
2732
2728
|
const fields = _nullishCoalesce(this.config.searchFields, () => ( []));
|
|
2733
2729
|
if (fields.length === 0) {
|
|
2734
|
-
throw new (0,
|
|
2730
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`search: ${this.config.key} has no searchable field`);
|
|
2735
2731
|
}
|
|
2736
|
-
const limit = opts.limit === void 0 ? 25 :
|
|
2732
|
+
const limit = opts.limit === void 0 ? 25 : _chunkIV2Z3JLRcjs.clampPageSize.call(void 0, opts.limit);
|
|
2737
2733
|
const leaf = fields.map((field) => ({ field, op: "contains", value: text }));
|
|
2738
2734
|
const root = leaf.length === 1 ? leaf[0] : { op: "or", items: leaf };
|
|
2739
2735
|
return this.queryEntity(`${this.resourcePath}/query`, [root], { maxRecords: limit });
|
|
@@ -3166,7 +3162,7 @@ var DEFAULT_LIMIT = 25;
|
|
|
3166
3162
|
var MAX_LIMIT = 500;
|
|
3167
3163
|
function clampLimit(limit) {
|
|
3168
3164
|
const n = limit === void 0 ? DEFAULT_LIMIT : Math.trunc(limit);
|
|
3169
|
-
if (!Number.isInteger(n) || n < 1) throw new (0,
|
|
3165
|
+
if (!Number.isInteger(n) || n < 1) throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`limit must be an integer >= 1 (got ${String(limit)})`);
|
|
3170
3166
|
return Math.min(n, MAX_LIMIT);
|
|
3171
3167
|
}
|
|
3172
3168
|
async function queryCompanies(http, filter, limit) {
|
|
@@ -3202,7 +3198,7 @@ async function fetchCompanies(http, ids, limit) {
|
|
|
3202
3198
|
const item = body && "item" in body ? body.item : null;
|
|
3203
3199
|
if (item) out.push(item);
|
|
3204
3200
|
} catch (err) {
|
|
3205
|
-
if (err instanceof
|
|
3201
|
+
if (err instanceof _chunkIV2Z3JLRcjs.NotFoundError) continue;
|
|
3206
3202
|
throw err;
|
|
3207
3203
|
}
|
|
3208
3204
|
}
|
|
@@ -3210,7 +3206,7 @@ async function fetchCompanies(http, ids, limit) {
|
|
|
3210
3206
|
}
|
|
3211
3207
|
async function searchByDomain(_resource, domain, opts = {}, http) {
|
|
3212
3208
|
const text = domain.trim();
|
|
3213
|
-
if (text === "") throw new (0,
|
|
3209
|
+
if (text === "") throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)("searchByDomain: empty domain");
|
|
3214
3210
|
const limit = clampLimit(opts.limit);
|
|
3215
3211
|
const filter = [{ field: "webAddress", op: "contains", value: text }];
|
|
3216
3212
|
const direct = await queryCompanies(http, filter, limit);
|
|
@@ -3224,7 +3220,7 @@ async function searchByIdentity(_resource, identity, opts = {}, http) {
|
|
|
3224
3220
|
const email = _nullishCoalesce(_optionalChain([identity, 'access', _90 => _90.email, 'optionalAccess', _91 => _91.trim, 'call', _92 => _92()]), () => ( ""));
|
|
3225
3221
|
const website = _nullishCoalesce(_optionalChain([identity, 'access', _93 => _93.website, 'optionalAccess', _94 => _94.trim, 'call', _95 => _95()]), () => ( ""));
|
|
3226
3222
|
if (name === "" && email === "" && website === "") {
|
|
3227
|
-
throw new (0,
|
|
3223
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)("searchByIdentity: at least one of companyName / email / website is required");
|
|
3228
3224
|
}
|
|
3229
3225
|
const limit = clampLimit(opts.limit);
|
|
3230
3226
|
const found = /* @__PURE__ */ new Map();
|
|
@@ -3247,7 +3243,7 @@ var DEFAULT_COMPANY_TYPE = 1;
|
|
|
3247
3243
|
var DEDUP_NAME_LIMIT = 10;
|
|
3248
3244
|
var BLIND_SURFACE_CAVEAT = "dedup only covers companies this API user can enumerate (the unowned surface is blind); a same-name company outside that scope is not detected";
|
|
3249
3245
|
var SAFE_COMPANY_CREATE_DEFAULTS = {};
|
|
3250
|
-
var OwnerResourceRequiredError = class extends
|
|
3246
|
+
var OwnerResourceRequiredError = class extends _chunkIV2Z3JLRcjs.AutotaskError {
|
|
3251
3247
|
constructor(message, options = {}) {
|
|
3252
3248
|
super(message, {
|
|
3253
3249
|
code: "OWNER_RESOURCE_REQUIRED",
|
|
@@ -3258,13 +3254,13 @@ var OwnerResourceRequiredError = class extends _chunk5QVXRT3Acjs.AutotaskError {
|
|
|
3258
3254
|
this.name = "OwnerResourceRequiredError";
|
|
3259
3255
|
}
|
|
3260
3256
|
};
|
|
3261
|
-
var CompanyResourceInvalidError = class extends
|
|
3257
|
+
var CompanyResourceInvalidError = class extends _chunkIV2Z3JLRcjs.AutotaskError {
|
|
3262
3258
|
constructor(message, options = {}) {
|
|
3263
3259
|
super(message, { code: "RESOURCE_INVALID", category: "validation", ...options });
|
|
3264
3260
|
this.name = "CompanyResourceInvalidError";
|
|
3265
3261
|
}
|
|
3266
3262
|
};
|
|
3267
|
-
var CompanyCreateFailedError = class extends
|
|
3263
|
+
var CompanyCreateFailedError = class extends _chunkIV2Z3JLRcjs.AutotaskError {
|
|
3268
3264
|
/** The vendor-named fields (empty when the 500 body named nothing parseable). */
|
|
3269
3265
|
|
|
3270
3266
|
constructor(message, vendorFields, options = {}) {
|
|
@@ -3275,18 +3271,18 @@ var CompanyCreateFailedError = class extends _chunk5QVXRT3Acjs.AutotaskError {
|
|
|
3275
3271
|
};
|
|
3276
3272
|
async function upsertByName(resource, companyName, params, opts, http) {
|
|
3277
3273
|
if (typeof companyName !== "string" || companyName.trim() === "") {
|
|
3278
|
-
throw new (0,
|
|
3274
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)("upsertByName: companyName is required (a non-empty string)", { operation: OP_UPSERT_NAME });
|
|
3279
3275
|
}
|
|
3280
3276
|
if (typeof _optionalChain([params, 'optionalAccess', _96 => _96.phone]) !== "string" || params.phone.trim() === "") {
|
|
3281
|
-
throw new (0,
|
|
3277
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)("upsertByName: params.phone is required (a non-empty string \u2014 the ww29 live-required set is { companyName, companyType, phone, ownerResourceID })", { operation: OP_UPSERT_NAME });
|
|
3282
3278
|
}
|
|
3283
3279
|
const companyType = _nullishCoalesce(params.companyType, () => ( DEFAULT_COMPANY_TYPE));
|
|
3284
3280
|
if (typeof companyType !== "number" || !Number.isInteger(companyType) || companyType < 1) {
|
|
3285
|
-
throw new (0,
|
|
3281
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`upsertByName: params.companyType must be a positive integer picklist value (got ${String(params.companyType)}; default 1 \u2014 the ww29-proven value)`, { operation: OP_UPSERT_NAME });
|
|
3286
3282
|
}
|
|
3287
3283
|
const owner = params.ownerResourceID;
|
|
3288
3284
|
if (owner !== void 0 && (typeof owner !== "number" || !Number.isInteger(owner) || owner < 1)) {
|
|
3289
|
-
throw new (0,
|
|
3285
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`upsertByName: params.ownerResourceID must be a positive integer (got ${String(owner)})`, { operation: OP_UPSERT_NAME });
|
|
3290
3286
|
}
|
|
3291
3287
|
const q = await resource.queryBounded({ filter: [{ field: "companyName", op: "eq", value: companyName }], limit: DEDUP_NAME_LIMIT });
|
|
3292
3288
|
const caveat = {
|
|
@@ -3380,8 +3376,8 @@ async function upsertByName(resource, companyName, params, opts, http) {
|
|
|
3380
3376
|
sideEffects: ['vendor auto-creates a "Primary Address" location under the new company (UI-only cleanup \u2014 the delete 405 gap, \xA711.5)']
|
|
3381
3377
|
};
|
|
3382
3378
|
} catch (err) {
|
|
3383
|
-
if (!
|
|
3384
|
-
const named = (_nullishCoalesce(
|
|
3379
|
+
if (!_chunkIV2Z3JLRcjs.isAutotaskError.call(void 0, err) || err.vendorError === void 0) throw err;
|
|
3380
|
+
const named = (_nullishCoalesce(_chunkIV2Z3JLRcjs.parseVendorErrors.call(void 0, err.vendorError), () => ( []))).map((e) => e.field).filter((f) => f !== void 0);
|
|
3385
3381
|
const seen = /* @__PURE__ */ new Set();
|
|
3386
3382
|
const unique = [...named].filter((f) => seen.has(f) ? false : (seen.add(f), true));
|
|
3387
3383
|
const hasDefault = unique.some((f) => SAFE_COMPANY_CREATE_DEFAULTS[f] !== void 0);
|
|
@@ -3395,7 +3391,7 @@ async function upsertByName(resource, companyName, params, opts, http) {
|
|
|
3395
3391
|
}
|
|
3396
3392
|
continue;
|
|
3397
3393
|
}
|
|
3398
|
-
const detail =
|
|
3394
|
+
const detail = _chunkIV2Z3JLRcjs.formatVendorDetail.call(void 0, err.vendorError);
|
|
3399
3395
|
throw new CompanyCreateFailedError(
|
|
3400
3396
|
`upsertByName: the vendor rejected the company create${unique.length > 0 ? ` naming field(s) ${unique.join(", ")}` : ""} (no proven-safe default \u2014 the ww29 required set is fully filled by the node)${detail ? ` \u2014 ${detail}` : ""}`,
|
|
3401
3397
|
unique,
|
|
@@ -3414,7 +3410,7 @@ var PROFILE_PART_LIMIT = 50;
|
|
|
3414
3410
|
function profilePartLimit(value, name) {
|
|
3415
3411
|
const n = value === void 0 ? PROFILE_PART_LIMIT : Math.trunc(value);
|
|
3416
3412
|
if (!Number.isInteger(n) || n < 1) {
|
|
3417
|
-
throw new (0,
|
|
3413
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`fullProfile: ${name} must be an integer >= 1 (got ${String(value)})`);
|
|
3418
3414
|
}
|
|
3419
3415
|
return n;
|
|
3420
3416
|
}
|
|
@@ -3458,7 +3454,7 @@ async function fullProfile(resource, id, opts = {}, http) {
|
|
|
3458
3454
|
note: OPEN_TICKETS_NOTE
|
|
3459
3455
|
};
|
|
3460
3456
|
if (openRows.length === 0) {
|
|
3461
|
-
const stamp = blindStampFor(_optionalChain([
|
|
3457
|
+
const stamp = blindStampFor(_optionalChain([_chunkIV2Z3JLRcjs.BLIND_SURFACE_STAMPS, 'access', _97 => _97["tickets"], 'optionalAccess', _98 => _98.query]), [
|
|
3462
3458
|
{ field: "companyID", op: "eq", value: id },
|
|
3463
3459
|
{ field: "status", op: "noteq", value: 5 }
|
|
3464
3460
|
]);
|
|
@@ -4280,16 +4276,16 @@ async function fetchRecord(http, path, label) {
|
|
|
4280
4276
|
const res = await http.request({ method: "GET", path, operation: "configuration_items.moveConfigurationItem" });
|
|
4281
4277
|
const body = res;
|
|
4282
4278
|
if (body === null || !("item" in body) || body.item === null || body.item === void 0) {
|
|
4283
|
-
throw new (0,
|
|
4279
|
+
throw new (0, _chunkIV2Z3JLRcjs.NotFoundError)(`${label} not found`, { code: "NOT_FOUND", category: "not_found" });
|
|
4284
4280
|
}
|
|
4285
4281
|
return body.item;
|
|
4286
4282
|
}
|
|
4287
4283
|
async function moveConfigurationItem(_resource, sourceId, opts, http) {
|
|
4288
|
-
const numericSource =
|
|
4284
|
+
const numericSource = _chunkIV2Z3JLRcjs.parseIdentifier.call(void 0, sourceId, "sourceId");
|
|
4289
4285
|
if (_optionalChain([opts, 'optionalAccess', _99 => _99.destinationCompanyId]) === void 0) {
|
|
4290
|
-
throw new (0,
|
|
4286
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)("moveConfigurationItem: destinationCompanyId is required");
|
|
4291
4287
|
}
|
|
4292
|
-
const destId =
|
|
4288
|
+
const destId = _chunkIV2Z3JLRcjs.parseIdentifier.call(void 0, opts.destinationCompanyId, "destinationCompanyId");
|
|
4293
4289
|
const source = await fetchRecord(http, `/V1.0/ConfigurationItems/${numericSource}`, `Configuration item ${numericSource}`);
|
|
4294
4290
|
await fetchRecord(http, `/V1.0/Companies/${destId}`, `Company ${destId}`);
|
|
4295
4291
|
const body = { ...source };
|
|
@@ -4299,13 +4295,13 @@ async function moveConfigurationItem(_resource, sourceId, opts, http) {
|
|
|
4299
4295
|
body.companyID = destId;
|
|
4300
4296
|
body.isActive = true;
|
|
4301
4297
|
if (opts.newReferenceTitle !== void 0) {
|
|
4302
|
-
if (opts.newReferenceTitle.trim() === "") throw new (0,
|
|
4298
|
+
if (opts.newReferenceTitle.trim() === "") throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)("moveConfigurationItem: newReferenceTitle must be non-empty");
|
|
4303
4299
|
body.referenceTitle = opts.newReferenceTitle.trim();
|
|
4304
4300
|
}
|
|
4305
4301
|
if (opts.lastModifiedDate !== void 0) {
|
|
4306
4302
|
const current = source.lastModifiedDate;
|
|
4307
4303
|
if (current !== opts.lastModifiedDate) {
|
|
4308
|
-
throw new (0,
|
|
4304
|
+
throw new (0, _chunkIV2Z3JLRcjs.StaleObjectError)(
|
|
4309
4305
|
`moveConfigurationItem: source item ${numericSource} was modified since the snapshot (expected lastModifiedDate ${opts.lastModifiedDate}, current ${_nullishCoalesce(current, () => ( "unknown"))})`,
|
|
4310
4306
|
{ operation: "configuration_items.moveConfigurationItem", resourceIds: [numericSource] }
|
|
4311
4307
|
);
|
|
@@ -4336,7 +4332,7 @@ async function moveConfigurationItem(_resource, sourceId, opts, http) {
|
|
|
4336
4332
|
const createdBody = created;
|
|
4337
4333
|
const newId = createdBody !== null ? _nullishCoalesce(createdBody.itemId, () => ( createdBody.id)) : void 0;
|
|
4338
4334
|
if (typeof newId !== "number") {
|
|
4339
|
-
throw new (0,
|
|
4335
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)("moveConfigurationItem: vendor create response has no itemId");
|
|
4340
4336
|
}
|
|
4341
4337
|
let sourceDeactivated = false;
|
|
4342
4338
|
if (opts.deactivateSource !== false) {
|
|
@@ -4354,7 +4350,7 @@ var PROFILE_PART_LIMIT2 = 50;
|
|
|
4354
4350
|
function profilePartLimit2(value, name) {
|
|
4355
4351
|
const n = value === void 0 ? PROFILE_PART_LIMIT2 : Math.trunc(value);
|
|
4356
4352
|
if (!Number.isInteger(n) || n < 1) {
|
|
4357
|
-
throw new (0,
|
|
4353
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`profile: ${name} must be an integer >= 1 (got ${String(value)})`);
|
|
4358
4354
|
}
|
|
4359
4355
|
return n;
|
|
4360
4356
|
}
|
|
@@ -4370,14 +4366,14 @@ async function contextFetchPart(http, entityPath, referenceId) {
|
|
|
4370
4366
|
});
|
|
4371
4367
|
const body = res;
|
|
4372
4368
|
if (body === null || !("item" in body)) {
|
|
4373
|
-
throw new (0,
|
|
4369
|
+
throw new (0, _chunkIV2Z3JLRcjs.NotFoundError)(`context part not found (unexpected envelope shape)`, { resourceIds: [referenceId] });
|
|
4374
4370
|
}
|
|
4375
4371
|
if (body.item === null || body.item === void 0) {
|
|
4376
|
-
throw new (0,
|
|
4372
|
+
throw new (0, _chunkIV2Z3JLRcjs.NotFoundError)("context part not found", { resourceIds: [referenceId] });
|
|
4377
4373
|
}
|
|
4378
4374
|
return body.item;
|
|
4379
4375
|
} catch (err) {
|
|
4380
|
-
if (err instanceof
|
|
4376
|
+
if (err instanceof _chunkIV2Z3JLRcjs.NotFoundError) return null;
|
|
4381
4377
|
throw err;
|
|
4382
4378
|
}
|
|
4383
4379
|
}
|
|
@@ -4401,7 +4397,7 @@ async function profile(resource, id, opts = {}, http) {
|
|
|
4401
4397
|
const notes = await ciScopedQuery(http, "/V1.0/ConfigurationItemNotes/query", id, noteLimit);
|
|
4402
4398
|
const relatedItems = await ciScopedQuery(http, "/V1.0/ConfigurationItemRelatedItems/query", id, relatedLimit);
|
|
4403
4399
|
const associations = await ciScopedQuery(http, "/V1.0/ConfigurationItemBillingProductAssociations/query", id, PROFILE_PART_LIMIT2);
|
|
4404
|
-
const wallQuirk = _optionalChain([
|
|
4400
|
+
const wallQuirk = _optionalChain([_chunkIV2Z3JLRcjs.RELATIONSHIP_MAP, 'access', _100 => _100["configuration_items"], 'optionalAccess', _101 => _101.zoneFacts, 'optionalAccess', _102 => _102.quirks, 'optionalAccess', _103 => _103.find, 'call', _104 => _104((q) => q.startsWith("product wall"))]);
|
|
4405
4401
|
const productAssociations = {
|
|
4406
4402
|
items: associations,
|
|
4407
4403
|
capped: associations.length >= PROFILE_PART_LIMIT2,
|
|
@@ -4861,22 +4857,22 @@ async function fetchRecord2(http, path, label) {
|
|
|
4861
4857
|
const res = await http.request({ method: "GET", path, operation: "contacts.moveToCompany" });
|
|
4862
4858
|
const body = res;
|
|
4863
4859
|
if (body === null || !("item" in body) || body.item === null || body.item === void 0) {
|
|
4864
|
-
throw new (0,
|
|
4860
|
+
throw new (0, _chunkIV2Z3JLRcjs.NotFoundError)(`${label} not found`, { code: "NOT_FOUND", category: "not_found" });
|
|
4865
4861
|
}
|
|
4866
4862
|
return body.item;
|
|
4867
4863
|
}
|
|
4868
4864
|
async function moveToCompany(_resource, sourceContactId, destinationCompanyId, opts = {}, http) {
|
|
4869
|
-
const sourceId =
|
|
4870
|
-
const destId =
|
|
4865
|
+
const sourceId = _chunkIV2Z3JLRcjs.parseIdentifier.call(void 0, sourceContactId, "sourceContactId");
|
|
4866
|
+
const destId = _chunkIV2Z3JLRcjs.parseIdentifier.call(void 0, destinationCompanyId, "destinationCompanyId");
|
|
4871
4867
|
const source = await fetchRecord2(http, `/V1.0/Contacts/${sourceId}`, `Contact ${sourceId}`);
|
|
4872
4868
|
const companyID = source.companyID;
|
|
4873
4869
|
if (typeof companyID !== "number" || companyID < 0) {
|
|
4874
|
-
throw new (0,
|
|
4870
|
+
throw new (0, _chunkIV2Z3JLRcjs.NotFoundError)(`Contact ${sourceId} has no companyID (cannot scope the source delete)`);
|
|
4875
4871
|
}
|
|
4876
4872
|
if (opts.lastModifiedDate !== void 0) {
|
|
4877
4873
|
const current = source.lastModifiedDate;
|
|
4878
4874
|
if (current !== opts.lastModifiedDate) {
|
|
4879
|
-
throw new (0,
|
|
4875
|
+
throw new (0, _chunkIV2Z3JLRcjs.StaleObjectError)(
|
|
4880
4876
|
`moveToCompany: source contact ${sourceId} was modified since the snapshot (expected lastModifiedDate ${opts.lastModifiedDate}, current ${typeof current === "string" ? current : "unknown"})`,
|
|
4881
4877
|
{ operation: "contacts.moveToCompany", resourceIds: [sourceId, destId] }
|
|
4882
4878
|
);
|
|
@@ -4901,7 +4897,7 @@ async function moveToCompany(_resource, sourceContactId, destinationCompanyId, o
|
|
|
4901
4897
|
const items = unwrapItems(res).items;
|
|
4902
4898
|
const clash = items.find((c) => Number(c.id) !== sourceId);
|
|
4903
4899
|
if (clash !== void 0) {
|
|
4904
|
-
throw new (0,
|
|
4900
|
+
throw new (0, _chunkIV2Z3JLRcjs.ConflictError)(
|
|
4905
4901
|
`Contact email "${email}" already exists under company ${destId} (contact ${String(clash.id)}); aborting the move`,
|
|
4906
4902
|
{ resourceIds: [sourceId, destId] }
|
|
4907
4903
|
);
|
|
@@ -4940,7 +4936,7 @@ async function moveToCompany(_resource, sourceContactId, destinationCompanyId, o
|
|
|
4940
4936
|
const createdBody = created;
|
|
4941
4937
|
const newId = createdBody !== null ? _nullishCoalesce(createdBody.itemId, () => ( createdBody.id)) : void 0;
|
|
4942
4938
|
if (typeof newId !== "number") {
|
|
4943
|
-
throw new (0,
|
|
4939
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)("contacts.moveToCompany: vendor create response has no itemId");
|
|
4944
4940
|
}
|
|
4945
4941
|
let sourceDeleted = false;
|
|
4946
4942
|
if (opts.deleteSource === true) {
|
|
@@ -4958,7 +4954,7 @@ var UPSERT_MAX_DISCOVERY_MERGES = 3;
|
|
|
4958
4954
|
var EMAIL_SHAPE = /^.+@.+/;
|
|
4959
4955
|
var SAFE_CONTACT_CREATE_DEFAULTS = {};
|
|
4960
4956
|
var DEDUP_LIMIT = 10;
|
|
4961
|
-
var CompanyNotFoundError = class extends
|
|
4957
|
+
var CompanyNotFoundError = class extends _chunkIV2Z3JLRcjs.AutotaskError {
|
|
4962
4958
|
constructor(message, options = {}) {
|
|
4963
4959
|
super(message, {
|
|
4964
4960
|
code: "COMPANY_NOT_FOUND",
|
|
@@ -4969,7 +4965,7 @@ var CompanyNotFoundError = class extends _chunk5QVXRT3Acjs.AutotaskError {
|
|
|
4969
4965
|
this.name = "CompanyNotFoundError";
|
|
4970
4966
|
}
|
|
4971
4967
|
};
|
|
4972
|
-
var ContactCreateFailedError = class extends
|
|
4968
|
+
var ContactCreateFailedError = class extends _chunkIV2Z3JLRcjs.AutotaskError {
|
|
4973
4969
|
/** The vendor-named fields (empty when the 500 body named nothing parseable). */
|
|
4974
4970
|
|
|
4975
4971
|
constructor(message, vendorFields, options = {}) {
|
|
@@ -4979,25 +4975,25 @@ var ContactCreateFailedError = class extends _chunk5QVXRT3Acjs.AutotaskError {
|
|
|
4979
4975
|
}
|
|
4980
4976
|
};
|
|
4981
4977
|
async function upsertByEmail(resource, companyID, email, extra, opts, http) {
|
|
4982
|
-
const cid =
|
|
4978
|
+
const cid = _chunkIV2Z3JLRcjs.parseIdentifier.call(void 0, companyID, "companyID");
|
|
4983
4979
|
if (typeof email !== "string" || !EMAIL_SHAPE.test(email)) {
|
|
4984
|
-
throw new (0,
|
|
4980
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(
|
|
4985
4981
|
`upsertByEmail: email must be a non-empty string with the @ shape (a non-empty local part + a non-empty domain; got ${JSON.stringify(email)})`,
|
|
4986
4982
|
{ operation: OP_UPSERT_EMAIL }
|
|
4987
4983
|
);
|
|
4988
4984
|
}
|
|
4989
4985
|
if (extra !== void 0) {
|
|
4990
4986
|
if (extra.isActive !== void 0 && typeof extra.isActive !== "boolean" && extra.isActive !== 0 && extra.isActive !== 1) {
|
|
4991
|
-
throw new (0,
|
|
4987
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(
|
|
4992
4988
|
`upsertByEmail: extra.isActive must be a boolean (mapped to the zone-correct number 1/0) or a raw 0/1 number (got ${String(extra.isActive)})`,
|
|
4993
4989
|
{ operation: OP_UPSERT_EMAIL }
|
|
4994
4990
|
);
|
|
4995
4991
|
}
|
|
4996
4992
|
if (extra.firstName !== void 0 && (typeof extra.firstName !== "string" || extra.firstName === "")) {
|
|
4997
|
-
throw new (0,
|
|
4993
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)("upsertByEmail: extra.firstName must be a non-empty string (or omitted \u2014 the node defaults it to the email local-part)", { operation: OP_UPSERT_EMAIL });
|
|
4998
4994
|
}
|
|
4999
4995
|
if (extra.lastName !== void 0 && typeof extra.lastName !== "string") {
|
|
5000
|
-
throw new (0,
|
|
4996
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)("upsertByEmail: extra.lastName must be a string (or omitted \u2014 the node defaults it to the non-empty neutral value Unknown)", { operation: OP_UPSERT_EMAIL });
|
|
5001
4997
|
}
|
|
5002
4998
|
}
|
|
5003
4999
|
const parentRes = await http.request({ method: "GET", path: `/V1.0/Companies/${cid}`, operation: OP_UPSERT_EMAIL });
|
|
@@ -5071,8 +5067,8 @@ async function upsertByEmail(resource, companyID, email, extra, opts, http) {
|
|
|
5071
5067
|
const created = await resource.create(cid, body, {});
|
|
5072
5068
|
return { id: created.id, created: true };
|
|
5073
5069
|
} catch (err) {
|
|
5074
|
-
if (!
|
|
5075
|
-
const named = (_nullishCoalesce(
|
|
5070
|
+
if (!_chunkIV2Z3JLRcjs.isAutotaskError.call(void 0, err) || err.vendorError === void 0) throw err;
|
|
5071
|
+
const named = (_nullishCoalesce(_chunkIV2Z3JLRcjs.parseVendorErrors.call(void 0, err.vendorError), () => ( []))).map((e) => e.field).filter((f) => f !== void 0);
|
|
5076
5072
|
const seen = /* @__PURE__ */ new Set();
|
|
5077
5073
|
const unique = [...named].filter((f) => seen.has(f) ? false : (seen.add(f), true));
|
|
5078
5074
|
const hasDefault = unique.some((f) => SAFE_CONTACT_CREATE_DEFAULTS[f] !== void 0);
|
|
@@ -5086,7 +5082,7 @@ async function upsertByEmail(resource, companyID, email, extra, opts, http) {
|
|
|
5086
5082
|
}
|
|
5087
5083
|
continue;
|
|
5088
5084
|
}
|
|
5089
|
-
const detail =
|
|
5085
|
+
const detail = _chunkIV2Z3JLRcjs.formatVendorDetail.call(void 0, err.vendorError);
|
|
5090
5086
|
throw new ContactCreateFailedError(
|
|
5091
5087
|
`upsertByEmail: the vendor rejected the contact create${unique.length > 0 ? ` naming field(s) ${unique.join(", ")}` : ""} (no proven-safe default \u2014 the required set is fully filled by the node)${detail ? ` \u2014 ${detail}` : ""}`,
|
|
5092
5088
|
unique,
|
|
@@ -7168,7 +7164,7 @@ async function markup(_resource, id, format, http) {
|
|
|
7168
7164
|
});
|
|
7169
7165
|
const body = res;
|
|
7170
7166
|
if (body === null || typeof body !== "object" || typeof body.invoiceMarkup !== "string") {
|
|
7171
|
-
throw new (0,
|
|
7167
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskError)(
|
|
7172
7168
|
`Expected the InvoiceMarkupResultModel envelope { invoiceMarkup: string } for invoice ${id}; got a different shape`,
|
|
7173
7169
|
{ code: "INVALID_RESPONSE", category: "server", resourceIds: [id] }
|
|
7174
7170
|
);
|
|
@@ -8508,21 +8504,21 @@ var ResourceSkillsResource = class extends BaseResource {
|
|
|
8508
8504
|
var MAX_TRANSFER_IDS = 500;
|
|
8509
8505
|
function requirePositiveIds(ids, label) {
|
|
8510
8506
|
if (!Array.isArray(ids) || ids.length === 0) {
|
|
8511
|
-
throw new (0,
|
|
8507
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`${label}: at least one positive integer id is required`);
|
|
8512
8508
|
}
|
|
8513
8509
|
if (ids.length > MAX_TRANSFER_IDS) {
|
|
8514
|
-
throw new (0,
|
|
8510
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`${label}: at most ${MAX_TRANSFER_IDS} ids are accepted (bounded fan-out)`);
|
|
8515
8511
|
}
|
|
8516
8512
|
for (const id of ids) {
|
|
8517
8513
|
if (!Number.isInteger(id) || id < 1) {
|
|
8518
|
-
throw new (0,
|
|
8514
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`${label}: every id must be a positive integer (got ${String(id)})`);
|
|
8519
8515
|
}
|
|
8520
8516
|
}
|
|
8521
8517
|
return ids;
|
|
8522
8518
|
}
|
|
8523
8519
|
async function whoAmI(_resource, userName, http) {
|
|
8524
8520
|
const user = userName.trim();
|
|
8525
|
-
if (user === "") throw new (0,
|
|
8521
|
+
if (user === "") throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)("whoAmI: the configured UserName is empty");
|
|
8526
8522
|
const value = user.includes("@") ? _nullishCoalesce(user.split("@")[0], () => ( "")) : user;
|
|
8527
8523
|
const res = await http.request({
|
|
8528
8524
|
method: "POST",
|
|
@@ -8535,7 +8531,7 @@ async function whoAmI(_resource, userName, http) {
|
|
|
8535
8531
|
if (matches.length === 0) return null;
|
|
8536
8532
|
if (matches.length > 1) {
|
|
8537
8533
|
const ids = matches.map((m) => m.id).filter((id) => typeof id === "number");
|
|
8538
|
-
throw new (0,
|
|
8534
|
+
throw new (0, _chunkIV2Z3JLRcjs.ResolutionError)(
|
|
8539
8535
|
`whoAmI: "${value}" is ambiguous (matched ${matches.length} resources)`,
|
|
8540
8536
|
{ code: "RESOLUTION_AMBIGUOUS", resourceIds: ids }
|
|
8541
8537
|
);
|
|
@@ -8545,7 +8541,7 @@ async function whoAmI(_resource, userName, http) {
|
|
|
8545
8541
|
async function transferOwnership(_resource, companyIds, destinationResourceId, http, opts) {
|
|
8546
8542
|
const ids = requirePositiveIds(companyIds, "transferOwnership");
|
|
8547
8543
|
if (!Number.isInteger(destinationResourceId) || destinationResourceId < 1) {
|
|
8548
|
-
throw new (0,
|
|
8544
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)("transferOwnership: destinationResourceId must be a positive integer");
|
|
8549
8545
|
}
|
|
8550
8546
|
const dryRun = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _108 => _108.dryRun]), () => ( true));
|
|
8551
8547
|
const changes = [];
|
|
@@ -8571,7 +8567,7 @@ async function transferOwnership(_resource, companyIds, destinationResourceId, h
|
|
|
8571
8567
|
applied.push(id);
|
|
8572
8568
|
}
|
|
8573
8569
|
} catch (err) {
|
|
8574
|
-
if (!dryRun && err instanceof
|
|
8570
|
+
if (!dryRun && err instanceof _chunkIV2Z3JLRcjs.AutotaskError) {
|
|
8575
8571
|
err.resourceIds = [id];
|
|
8576
8572
|
err.suggestedAction = `Partial transfer: ${applied.length} of ${ids.length} companies were re-owned (ids: ${applied.join(", ") || "none"}); id ${id} failed. Re-run transferOwnership for the remaining ids (from ${id} on).`;
|
|
8577
8573
|
}
|
|
@@ -8775,7 +8771,7 @@ async function getByResource2(_resource, resourceId, http) {
|
|
|
8775
8771
|
}
|
|
8776
8772
|
async function getByYear(_resource, resourceId, year, http) {
|
|
8777
8773
|
if (!Number.isInteger(year) || year < 1) {
|
|
8778
|
-
throw new (0,
|
|
8774
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)("getByYear: year must be a positive integer");
|
|
8779
8775
|
}
|
|
8780
8776
|
const res = await http.request({
|
|
8781
8777
|
method: "GET",
|
|
@@ -10703,9 +10699,9 @@ async function fetchTicket(http, id, operation) {
|
|
|
10703
10699
|
});
|
|
10704
10700
|
const body = res;
|
|
10705
10701
|
if (body === null || !("item" in body)) {
|
|
10706
|
-
throw new (0,
|
|
10702
|
+
throw new (0, _chunkIV2Z3JLRcjs.NotFoundError)(`Ticket ${id} not found (unexpected envelope shape)`, { resourceIds: [id] });
|
|
10707
10703
|
}
|
|
10708
|
-
if (body.item === null || body.item === void 0) throw new (0,
|
|
10704
|
+
if (body.item === null || body.item === void 0) throw new (0, _chunkIV2Z3JLRcjs.NotFoundError)(`Ticket ${id} not found`, { resourceIds: [id] });
|
|
10709
10705
|
return body.item;
|
|
10710
10706
|
}
|
|
10711
10707
|
async function ticketQueryItems(http, path, filter, maxRecords, operation) {
|
|
@@ -10719,13 +10715,13 @@ async function ticketQueryItems(http, path, filter, maxRecords, operation) {
|
|
|
10719
10715
|
return unwrapItems(res).items;
|
|
10720
10716
|
}
|
|
10721
10717
|
function isRouteUnavailable(err) {
|
|
10722
|
-
return
|
|
10718
|
+
return _chunkIV2Z3JLRcjs.isAutotaskError.call(void 0, err) && (err.httpStatus === 404 || err.httpStatus === 500);
|
|
10723
10719
|
}
|
|
10724
10720
|
function routeFact(route, path, err) {
|
|
10725
10721
|
return {
|
|
10726
10722
|
route,
|
|
10727
10723
|
path,
|
|
10728
|
-
httpStatus:
|
|
10724
|
+
httpStatus: _chunkIV2Z3JLRcjs.isAutotaskError.call(void 0, err) && typeof err.httpStatus === "number" ? err.httpStatus : null
|
|
10729
10725
|
};
|
|
10730
10726
|
}
|
|
10731
10727
|
function childDeclaresQuery(resourceKey) {
|
|
@@ -10735,10 +10731,10 @@ function childDeclaresQuery(resourceKey) {
|
|
|
10735
10731
|
}
|
|
10736
10732
|
function planScopedPath(resourceKey, ticketId) {
|
|
10737
10733
|
if (!childDeclaresQuery(resourceKey)) return null;
|
|
10738
|
-
const entry =
|
|
10734
|
+
const entry = _chunkIV2Z3JLRcjs.RELATIONSHIP_MAP[resourceKey];
|
|
10739
10735
|
const parent = entry === void 0 ? null : entry.parent;
|
|
10740
10736
|
if (parent === null || parent.resource !== "tickets" || parent.segment === null || parent.field === null) return null;
|
|
10741
|
-
const parentPath = _optionalChain([
|
|
10737
|
+
const parentPath = _optionalChain([_chunkIV2Z3JLRcjs.RELATIONSHIP_MAP, 'access', _109 => _109[parent.resource], 'optionalAccess', _110 => _110.path]);
|
|
10742
10738
|
if (parentPath === null || parentPath === void 0) return null;
|
|
10743
10739
|
return `/V1.0/${parentPath}/${ticketId}/${parent.segment}`;
|
|
10744
10740
|
}
|
|
@@ -10851,7 +10847,7 @@ async function slaHealthCheck(_resource, id, opts = {}, http) {
|
|
|
10851
10847
|
async function summary(_resource, id, opts = {}, http) {
|
|
10852
10848
|
const limit = opts.summaryTextLimit === void 0 ? 500 : Math.trunc(opts.summaryTextLimit);
|
|
10853
10849
|
if (!Number.isInteger(limit) || limit < 1) {
|
|
10854
|
-
throw new (0,
|
|
10850
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`summaryTextLimit must be an integer >= 1 (got ${String(opts.summaryTextLimit)})`);
|
|
10855
10851
|
}
|
|
10856
10852
|
const ticket = await fetchTicket(http, id, "tickets.summary");
|
|
10857
10853
|
const desc = truncate(ticket.description, limit);
|
|
@@ -10879,11 +10875,11 @@ async function summary(_resource, id, opts = {}, http) {
|
|
|
10879
10875
|
}
|
|
10880
10876
|
async function timeline(_resource, id, opts = {}, http) {
|
|
10881
10877
|
const limit = opts.limit === void 0 ? 100 : Math.trunc(opts.limit);
|
|
10882
|
-
if (!Number.isInteger(limit) || limit < 1) throw new (0,
|
|
10878
|
+
if (!Number.isInteger(limit) || limit < 1) throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`limit must be an integer >= 1 (got ${String(opts.limit)})`);
|
|
10883
10879
|
const bounded = Math.min(limit, 500);
|
|
10884
10880
|
const textLimit = opts.textLimit === void 0 ? 500 : Math.trunc(opts.textLimit);
|
|
10885
10881
|
if (!Number.isInteger(textLimit) || textLimit < 1) {
|
|
10886
|
-
throw new (0,
|
|
10882
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`textLimit must be an integer >= 1 (got ${String(opts.textLimit)})`);
|
|
10887
10883
|
}
|
|
10888
10884
|
await fetchTicket(http, id, "tickets.timeline");
|
|
10889
10885
|
const dateFilters = (field) => {
|
|
@@ -10971,14 +10967,14 @@ function isPositiveInt(v) {
|
|
|
10971
10967
|
return typeof v === "number" && Number.isInteger(v) && v > 0;
|
|
10972
10968
|
}
|
|
10973
10969
|
function namedVendorFields(err) {
|
|
10974
|
-
if (!
|
|
10975
|
-
const entries = _nullishCoalesce(
|
|
10970
|
+
if (!_chunkIV2Z3JLRcjs.isAutotaskError.call(void 0, err) || err.vendorError === void 0) return [];
|
|
10971
|
+
const entries = _nullishCoalesce(_chunkIV2Z3JLRcjs.parseVendorErrors.call(void 0, err.vendorError), () => ( []));
|
|
10976
10972
|
const out = /* @__PURE__ */ new Set();
|
|
10977
10973
|
for (const e of entries) if (e.field !== void 0) out.add(e.field);
|
|
10978
10974
|
return [...out];
|
|
10979
10975
|
}
|
|
10980
10976
|
function vendorDetailOf(err) {
|
|
10981
|
-
return
|
|
10977
|
+
return _chunkIV2Z3JLRcjs.isAutotaskError.call(void 0, err) ? _chunkIV2Z3JLRcjs.formatVendorDetail.call(void 0, err.vendorError) : void 0;
|
|
10982
10978
|
}
|
|
10983
10979
|
async function fetchItem(http, path, operation) {
|
|
10984
10980
|
const res = await http.request({ method: "GET", path, operation });
|
|
@@ -10999,8 +10995,8 @@ function operationId(res) {
|
|
|
10999
10995
|
return typeof body.itemId === "number" ? body.itemId : typeof body.id === "number" ? body.id : void 0;
|
|
11000
10996
|
}
|
|
11001
10997
|
function discoveryMerge(err, body, defaults) {
|
|
11002
|
-
if (!
|
|
11003
|
-
const entries =
|
|
10998
|
+
if (!_chunkIV2Z3JLRcjs.isAutotaskError.call(void 0, err) || err.vendorError === void 0) return null;
|
|
10999
|
+
const entries = _chunkIV2Z3JLRcjs.parseVendorErrors.call(void 0, err.vendorError);
|
|
11004
11000
|
if (entries === void 0) return null;
|
|
11005
11001
|
for (const entry of entries) {
|
|
11006
11002
|
const field = entry.field;
|
|
@@ -11012,7 +11008,7 @@ function discoveryMerge(err, body, defaults) {
|
|
|
11012
11008
|
}
|
|
11013
11009
|
function stepErrorText(code, err) {
|
|
11014
11010
|
const detail = vendorDetailOf(err);
|
|
11015
|
-
const base =
|
|
11011
|
+
const base = _chunkIV2Z3JLRcjs.isAutotaskError.call(void 0, err) ? err.message : String(err);
|
|
11016
11012
|
return detail ? `${code}: ${detail}` : `${code}: ${base}`;
|
|
11017
11013
|
}
|
|
11018
11014
|
var DEFAULT_TICKET_PRIORITY = 3;
|
|
@@ -11021,7 +11017,7 @@ var DEFAULT_NOTE_TYPE = 1;
|
|
|
11021
11017
|
var DEFAULT_PUBLISH = 1;
|
|
11022
11018
|
var PUBLISH_VALUES = /* @__PURE__ */ new Set([1, 2, 4]);
|
|
11023
11019
|
var SAFE_TICKET_CREATE_DEFAULTS = {};
|
|
11024
|
-
var QueueRequiredError = class extends
|
|
11020
|
+
var QueueRequiredError = class extends _chunkIV2Z3JLRcjs.AutotaskError {
|
|
11025
11021
|
constructor(message, options = {}) {
|
|
11026
11022
|
super(message, {
|
|
11027
11023
|
code: "QUEUE_REQUIRED",
|
|
@@ -11032,13 +11028,13 @@ var QueueRequiredError = class extends _chunk5QVXRT3Acjs.AutotaskError {
|
|
|
11032
11028
|
this.name = "QueueRequiredError";
|
|
11033
11029
|
}
|
|
11034
11030
|
};
|
|
11035
|
-
var TicketResourceInvalidError = class extends
|
|
11031
|
+
var TicketResourceInvalidError = class extends _chunkIV2Z3JLRcjs.AutotaskError {
|
|
11036
11032
|
constructor(message, options = {}) {
|
|
11037
11033
|
super(message, { code: "RESOURCE_INVALID", category: "validation", ...options });
|
|
11038
11034
|
this.name = "TicketResourceInvalidError";
|
|
11039
11035
|
}
|
|
11040
11036
|
};
|
|
11041
|
-
var TicketCreateValidationFailedError = class extends
|
|
11037
|
+
var TicketCreateValidationFailedError = class extends _chunkIV2Z3JLRcjs.AutotaskError {
|
|
11042
11038
|
/** The vendor-named fields (empty when the 500 body named nothing parseable). */
|
|
11043
11039
|
|
|
11044
11040
|
constructor(message, vendorFields, options = {}) {
|
|
@@ -11048,43 +11044,43 @@ var TicketCreateValidationFailedError = class extends _chunk5QVXRT3Acjs.Autotask
|
|
|
11048
11044
|
}
|
|
11049
11045
|
};
|
|
11050
11046
|
async function openWithNoteAndAssign(resource, params, note, assign, opts, http) {
|
|
11051
|
-
const companyID =
|
|
11047
|
+
const companyID = _chunkIV2Z3JLRcjs.parseIdentifier.call(void 0, _optionalChain([params, 'optionalAccess', _111 => _111.companyID]), "params.companyID");
|
|
11052
11048
|
const title = _optionalChain([params, 'optionalAccess', _112 => _112.title]);
|
|
11053
11049
|
if (typeof title !== "string" || title.trim() === "") {
|
|
11054
|
-
throw new (0,
|
|
11050
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)("openWithNoteAndAssign: params.title is required (a non-empty string)", { operation: OP_OPEN });
|
|
11055
11051
|
}
|
|
11056
11052
|
const priority = _nullishCoalesce(params.priority, () => ( DEFAULT_TICKET_PRIORITY));
|
|
11057
11053
|
const status = _nullishCoalesce(params.status, () => ( DEFAULT_TICKET_STATUS));
|
|
11058
11054
|
if (!isPositiveInt(priority)) {
|
|
11059
|
-
throw new (0,
|
|
11055
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`openWithNoteAndAssign: params.priority must be a positive integer (got ${String(params.priority)})`, { operation: OP_OPEN });
|
|
11060
11056
|
}
|
|
11061
11057
|
if (!isPositiveInt(status)) {
|
|
11062
|
-
throw new (0,
|
|
11058
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`openWithNoteAndAssign: params.status must be a positive integer (got ${String(params.status)})`, { operation: OP_OPEN });
|
|
11063
11059
|
}
|
|
11064
11060
|
if (params.queueID !== void 0 && !isPositiveInt(params.queueID)) {
|
|
11065
|
-
throw new (0,
|
|
11061
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`openWithNoteAndAssign: params.queueID must be a positive integer (got ${String(params.queueID)})`, { operation: OP_OPEN });
|
|
11066
11062
|
}
|
|
11067
11063
|
if (note !== void 0) {
|
|
11068
11064
|
if (typeof note.description !== "string" || note.description.trim() === "") {
|
|
11069
|
-
throw new (0,
|
|
11065
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)("openWithNoteAndAssign: note.description is required (a non-empty string)", { operation: OP_OPEN });
|
|
11070
11066
|
}
|
|
11071
11067
|
if (typeof note.title !== "string" || note.title.trim() === "") {
|
|
11072
|
-
throw new (0,
|
|
11068
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)("openWithNoteAndAssign: note.title is required (a non-empty string) \u2014 the ww29 scoped note create 500s without it (S12-A live-verified: Missing Required Field: title; the S11-B proven note body is { title, description, noteType: 1, publish: 1 })", { operation: OP_OPEN });
|
|
11073
11069
|
}
|
|
11074
11070
|
if (note.noteType !== void 0 && !isPositiveInt(note.noteType)) {
|
|
11075
|
-
throw new (0,
|
|
11071
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`openWithNoteAndAssign: note.noteType must be a positive integer (got ${String(note.noteType)})`, { operation: OP_OPEN });
|
|
11076
11072
|
}
|
|
11077
11073
|
if (note.publish !== void 0 && !PUBLISH_VALUES.has(note.publish)) {
|
|
11078
|
-
throw new (0,
|
|
11074
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`openWithNoteAndAssign: note.publish must be an integer picklist value 1/2/4 (got ${String(note.publish)} \u2014 NOT a boolean)`, { operation: OP_OPEN });
|
|
11079
11075
|
}
|
|
11080
11076
|
}
|
|
11081
11077
|
const assignee = _optionalChain([assign, 'optionalAccess', _113 => _113.resourceID]);
|
|
11082
11078
|
if (assign !== void 0 && !isPositiveInt(assignee)) {
|
|
11083
|
-
throw new (0,
|
|
11079
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`openWithNoteAndAssign: assign.resourceID must be a positive integer (got ${String(assignee)})`, { operation: OP_OPEN });
|
|
11084
11080
|
}
|
|
11085
11081
|
const roleID = _optionalChain([assign, 'optionalAccess', _114 => _114.roleID]);
|
|
11086
11082
|
if (assign !== void 0 && !isPositiveInt(roleID)) {
|
|
11087
|
-
throw new (0,
|
|
11083
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)("openWithNoteAndAssign: assign.roleID is required (a positive integer) \u2014 the ww29 vendor requires BOTH assignedResourceID and assignedResourceRoleID when assigning a resource (S12-A live-verified: Data violation: When assigning a Resource, you must assign both a assignedResourceID and assignedResourceRoleID)", { operation: OP_OPEN });
|
|
11088
11084
|
}
|
|
11089
11085
|
if (assign !== void 0 && assignee !== void 0) {
|
|
11090
11086
|
const rid = assignee;
|
|
@@ -11161,8 +11157,8 @@ async function openWithNoteAndAssign(resource, params, note, assign, opts, http)
|
|
|
11161
11157
|
`openWithNoteAndAssign: the vendor rejected the ticket create naming 'queueID' (the ww29 live-required set is { title, status, priority, companyID, queueID }) and the node never guesses a queue${detail ? ` \u2014 ${detail}` : ""}`,
|
|
11162
11158
|
{
|
|
11163
11159
|
operation: OP_OPEN,
|
|
11164
|
-
httpStatus:
|
|
11165
|
-
vendorError:
|
|
11160
|
+
httpStatus: _chunkIV2Z3JLRcjs.isAutotaskError.call(void 0, err) ? err.httpStatus : void 0,
|
|
11161
|
+
vendorError: _chunkIV2Z3JLRcjs.isAutotaskError.call(void 0, err) ? err.vendorError : void 0
|
|
11166
11162
|
}
|
|
11167
11163
|
);
|
|
11168
11164
|
}
|
|
@@ -11177,8 +11173,8 @@ async function openWithNoteAndAssign(resource, params, note, assign, opts, http)
|
|
|
11177
11173
|
named,
|
|
11178
11174
|
{
|
|
11179
11175
|
operation: OP_OPEN,
|
|
11180
|
-
httpStatus:
|
|
11181
|
-
vendorError:
|
|
11176
|
+
httpStatus: _chunkIV2Z3JLRcjs.isAutotaskError.call(void 0, err) ? err.httpStatus : void 0,
|
|
11177
|
+
vendorError: _chunkIV2Z3JLRcjs.isAutotaskError.call(void 0, err) ? err.vendorError : void 0,
|
|
11182
11178
|
resourceIds: [companyID]
|
|
11183
11179
|
}
|
|
11184
11180
|
);
|
|
@@ -11200,7 +11196,7 @@ async function openWithNoteAndAssign(resource, params, note, assign, opts, http)
|
|
|
11200
11196
|
try {
|
|
11201
11197
|
const current = await fetchItemUnredacted(http, `/V1.0/Tickets/${ticketId}`, OP_OPEN);
|
|
11202
11198
|
if (current === null) {
|
|
11203
|
-
throw new (0,
|
|
11199
|
+
throw new (0, _chunkIV2Z3JLRcjs.NotFoundError)(`openWithNoteAndAssign: ticket ${ticketId} vanished between the create and the assign merge read`, { operation: OP_OPEN, resourceIds: [ticketId] });
|
|
11204
11200
|
}
|
|
11205
11201
|
ticketNumber = typeof current.ticketNumber === "string" ? current.ticketNumber : null;
|
|
11206
11202
|
const merged = mergePartialBody(current, { id: ticketId, assignedResourceID: assignee, assignedResourceRoleID: roleID });
|
|
@@ -11258,7 +11254,7 @@ var STATUS_PICKLIST_SET = new Set(STATUS_PICKLIST.map((v) => v.id));
|
|
|
11258
11254
|
var STATUS_REQUIRED_FIELDS = {
|
|
11259
11255
|
// <discovery output lands here — e.g. 8: { requiredFields: ['dueDateTime'], safeDefaults: { dueDateTime: '<now>' } }>
|
|
11260
11256
|
};
|
|
11261
|
-
var StatusUnknownError = class extends
|
|
11257
|
+
var StatusUnknownError = class extends _chunkIV2Z3JLRcjs.AutotaskError {
|
|
11262
11258
|
/** The pinned picklist size (the message names it; the labels are via autotask_describe(tickets.describeFields)). */
|
|
11263
11259
|
|
|
11264
11260
|
constructor(message, options = {}) {
|
|
@@ -11272,7 +11268,7 @@ var StatusUnknownError = class extends _chunk5QVXRT3Acjs.AutotaskError {
|
|
|
11272
11268
|
this.picklistCount = STATUS_PICKLIST.length;
|
|
11273
11269
|
}
|
|
11274
11270
|
};
|
|
11275
|
-
var StatusFieldsRequiredError = class extends
|
|
11271
|
+
var StatusFieldsRequiredError = class extends _chunkIV2Z3JLRcjs.AutotaskError {
|
|
11276
11272
|
|
|
11277
11273
|
|
|
11278
11274
|
|
|
@@ -11287,9 +11283,9 @@ var StatusFieldsRequiredError = class extends _chunk5QVXRT3Acjs.AutotaskError {
|
|
|
11287
11283
|
}
|
|
11288
11284
|
};
|
|
11289
11285
|
async function changeStatus(_resource, id, targetStatus, fields, opts, http) {
|
|
11290
|
-
const ticketId =
|
|
11286
|
+
const ticketId = _chunkIV2Z3JLRcjs.parseIdentifier.call(void 0, id, "id");
|
|
11291
11287
|
if (!isPositiveInt(targetStatus)) {
|
|
11292
|
-
throw new (0,
|
|
11288
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`changeStatus: targetStatus must be a positive integer (got ${String(targetStatus)})`, { operation: OP_STATUS });
|
|
11293
11289
|
}
|
|
11294
11290
|
if (!STATUS_PICKLIST_SET.has(targetStatus)) {
|
|
11295
11291
|
throw new StatusUnknownError(
|
|
@@ -11298,11 +11294,11 @@ async function changeStatus(_resource, id, targetStatus, fields, opts, http) {
|
|
|
11298
11294
|
);
|
|
11299
11295
|
}
|
|
11300
11296
|
if (fields !== void 0 && (typeof fields !== "object" || fields === null || Array.isArray(fields))) {
|
|
11301
|
-
throw new (0,
|
|
11297
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)("changeStatus: fields must be a plain object of ticket fields (or omitted)", { operation: OP_STATUS });
|
|
11302
11298
|
}
|
|
11303
11299
|
const current = await fetchItemUnredacted(http, `/V1.0/Tickets/${ticketId}`, OP_STATUS);
|
|
11304
11300
|
if (current === null) {
|
|
11305
|
-
throw new (0,
|
|
11301
|
+
throw new (0, _chunkIV2Z3JLRcjs.NotFoundError)(`changeStatus: ticket ${ticketId} was not found (tickets.get returned item: null)`, { operation: OP_STATUS, resourceIds: [ticketId] });
|
|
11306
11302
|
}
|
|
11307
11303
|
const previousStatus = typeof current.status === "number" ? current.status : null;
|
|
11308
11304
|
if (previousStatus === targetStatus) {
|
|
@@ -11400,8 +11396,8 @@ async function changeStatus(_resource, id, targetStatus, fields, opts, http) {
|
|
|
11400
11396
|
{ vendorFields: named, currentStatus: previousStatus, targetStatus, currentValues },
|
|
11401
11397
|
{
|
|
11402
11398
|
operation: OP_STATUS,
|
|
11403
|
-
httpStatus:
|
|
11404
|
-
vendorError:
|
|
11399
|
+
httpStatus: _chunkIV2Z3JLRcjs.isAutotaskError.call(void 0, err) ? err.httpStatus : void 0,
|
|
11400
|
+
vendorError: _chunkIV2Z3JLRcjs.isAutotaskError.call(void 0, err) ? err.vendorError : void 0,
|
|
11405
11401
|
resourceIds: [ticketId]
|
|
11406
11402
|
}
|
|
11407
11403
|
);
|
|
@@ -11411,7 +11407,7 @@ async function changeStatus(_resource, id, targetStatus, fields, opts, http) {
|
|
|
11411
11407
|
}
|
|
11412
11408
|
const verify = await fetchItem(http, `/V1.0/Tickets/${ticketId}`, OP_STATUS);
|
|
11413
11409
|
if (verify === null) {
|
|
11414
|
-
throw new (0,
|
|
11410
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskError)(`changeStatus: the post-PUT read-back found no ticket ${ticketId} (the PUT 200ed but the record is gone)`, {
|
|
11415
11411
|
code: "INVALID_RESPONSE",
|
|
11416
11412
|
category: "server",
|
|
11417
11413
|
operation: OP_STATUS,
|
|
@@ -11420,7 +11416,7 @@ async function changeStatus(_resource, id, targetStatus, fields, opts, http) {
|
|
|
11420
11416
|
}
|
|
11421
11417
|
const finalStatus = typeof verify.status === "number" ? verify.status : null;
|
|
11422
11418
|
if (finalStatus !== targetStatus) {
|
|
11423
|
-
throw new (0,
|
|
11419
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskError)(
|
|
11424
11420
|
`changeStatus: the post-PUT read-back shows status ${_nullishCoalesce(finalStatus, () => ( "unknown"))} (the vendor 200ed the PUT but did not apply ${targetStatus} \u2014 the F-A1 lesson: the 200 proves nothing)`,
|
|
11425
11421
|
{
|
|
11426
11422
|
code: "INVALID_RESPONSE",
|
|
@@ -11438,7 +11434,7 @@ var DEFAULT_PART_LIMIT = 50;
|
|
|
11438
11434
|
function partLimit(value, name) {
|
|
11439
11435
|
const n = value === void 0 ? DEFAULT_PART_LIMIT : Math.trunc(value);
|
|
11440
11436
|
if (!Number.isInteger(n) || n < 1) {
|
|
11441
|
-
throw new (0,
|
|
11437
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`fullContext: ${name} must be an integer >= 1 (got ${String(value)})`);
|
|
11442
11438
|
}
|
|
11443
11439
|
return n;
|
|
11444
11440
|
}
|
|
@@ -11698,7 +11694,7 @@ var MAX_LIMIT2 = 500;
|
|
|
11698
11694
|
function clampLimit2(limit) {
|
|
11699
11695
|
const n = limit === void 0 ? DEFAULT_LIMIT2 : Math.trunc(limit);
|
|
11700
11696
|
if (!Number.isInteger(n) || n < 1) {
|
|
11701
|
-
throw new (0,
|
|
11697
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`limit must be an integer >= 1 (got ${String(limit)})`);
|
|
11702
11698
|
}
|
|
11703
11699
|
return Math.min(n, MAX_LIMIT2);
|
|
11704
11700
|
}
|
|
@@ -11790,7 +11786,7 @@ async function windowQuery(_resource, kind, http, opts) {
|
|
|
11790
11786
|
async function customRange(_resource, from, to, http, opts) {
|
|
11791
11787
|
const parseDay = (value, label) => {
|
|
11792
11788
|
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value.trim());
|
|
11793
|
-
if (!m) throw new (0,
|
|
11789
|
+
if (!m) throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`customRange: ${label} must be a UTC 'YYYY-MM-DD' date`);
|
|
11794
11790
|
return Date.UTC(Number(m[1]), Number(m[2]) - 1, Number(m[3]));
|
|
11795
11791
|
};
|
|
11796
11792
|
const fromMs = parseDay(from, "from");
|
|
@@ -11814,21 +11810,21 @@ async function postedWithin(_resource, from, to, http, opts) {
|
|
|
11814
11810
|
const parseBound = (value, label) => {
|
|
11815
11811
|
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value.trim());
|
|
11816
11812
|
if (!m) {
|
|
11817
|
-
throw new (0,
|
|
11813
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(
|
|
11818
11814
|
`postedWithin: ${label} must be a UTC 'YYYY-MM-DD' date string (got ${JSON.stringify(value)})`,
|
|
11819
11815
|
{ operation: OP2 }
|
|
11820
11816
|
);
|
|
11821
11817
|
}
|
|
11822
11818
|
const ms = Date.UTC(Number(m[1]), Number(m[2]) - 1, Number(m[3]));
|
|
11823
11819
|
if (!Number.isFinite(ms)) {
|
|
11824
|
-
throw new (0,
|
|
11820
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`postedWithin: ${label} is not a valid UTC date (${JSON.stringify(value)})`, { operation: OP2 });
|
|
11825
11821
|
}
|
|
11826
11822
|
return ms;
|
|
11827
11823
|
};
|
|
11828
11824
|
const fromMs = parseBound(from, "from");
|
|
11829
11825
|
const toMs = parseBound(to, "to");
|
|
11830
11826
|
if (fromMs > toMs) {
|
|
11831
|
-
throw new (0,
|
|
11827
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(`postedWithin: from (${iso(fromMs)}) must not be after to (${iso(toMs)})`, { operation: OP2 });
|
|
11832
11828
|
}
|
|
11833
11829
|
const windowToMs = toMs + DAY_MS - 1;
|
|
11834
11830
|
const filter = [
|
|
@@ -11889,13 +11885,13 @@ var LINKAGE_OWNED_FIELDS = /* @__PURE__ */ new Set([
|
|
|
11889
11885
|
"roleID"
|
|
11890
11886
|
]);
|
|
11891
11887
|
var TIME_WINDOW_FIELDS = /* @__PURE__ */ new Set(["dateWorked", "startDateTime", "endDateTime", "hoursWorked"]);
|
|
11892
|
-
var ResourceInvalidError = class extends
|
|
11888
|
+
var ResourceInvalidError = class extends _chunkIV2Z3JLRcjs.AutotaskError {
|
|
11893
11889
|
constructor(message, options = {}) {
|
|
11894
11890
|
super(message, { code: "RESOURCE_INVALID", category: "validation", ...options });
|
|
11895
11891
|
this.name = "ResourceInvalidError";
|
|
11896
11892
|
}
|
|
11897
11893
|
};
|
|
11898
|
-
var AllocationCodeError = class extends
|
|
11894
|
+
var AllocationCodeError = class extends _chunkIV2Z3JLRcjs.AutotaskError {
|
|
11899
11895
|
/** The failure kind (the machine code is `ALLOCATION_CODE_<KIND>`). */
|
|
11900
11896
|
|
|
11901
11897
|
constructor(kind, message, options = {}) {
|
|
@@ -11904,7 +11900,7 @@ var AllocationCodeError = class extends _chunk5QVXRT3Acjs.AutotaskError {
|
|
|
11904
11900
|
this.kind = kind;
|
|
11905
11901
|
}
|
|
11906
11902
|
};
|
|
11907
|
-
var NoApplicableAllocationCodeError = class extends
|
|
11903
|
+
var NoApplicableAllocationCodeError = class extends _chunkIV2Z3JLRcjs.AutotaskError {
|
|
11908
11904
|
/** The structured blocker details (filters tried + department sets). */
|
|
11909
11905
|
|
|
11910
11906
|
constructor(details, options = {}) {
|
|
@@ -11940,7 +11936,7 @@ async function boundedQuery(http, path, filter, totalCap, operation) {
|
|
|
11940
11936
|
let pages = 0;
|
|
11941
11937
|
for (; ; ) {
|
|
11942
11938
|
if (pages >= PAGE_GUARD) {
|
|
11943
|
-
throw new (0,
|
|
11939
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskError)(`createForResource: the ${path} walk hit the ${PAGE_GUARD}-page guard`, {
|
|
11944
11940
|
code: "RESOLUTION_TRUNCATED",
|
|
11945
11941
|
category: "resolution",
|
|
11946
11942
|
operation,
|
|
@@ -12068,7 +12064,7 @@ function windowDefaults(params) {
|
|
|
12068
12064
|
};
|
|
12069
12065
|
}
|
|
12070
12066
|
async function createForResource(resource, resourceID, params, opts = {}, http) {
|
|
12071
|
-
const rid =
|
|
12067
|
+
const rid = _chunkIV2Z3JLRcjs.parseIdentifier.call(void 0, resourceID, "resourceID");
|
|
12072
12068
|
const pins = {
|
|
12073
12069
|
code: typeof params.internallAllocationCodeID === "number" ? params.internallAllocationCodeID : void 0,
|
|
12074
12070
|
ticket: typeof params.ticketID === "number" ? params.ticketID : void 0,
|
|
@@ -12077,19 +12073,19 @@ async function createForResource(resource, resourceID, params, opts = {}, http)
|
|
|
12077
12073
|
};
|
|
12078
12074
|
const pinCount = [pins.code, pins.ticket, pins.task].filter((v) => v !== void 0).length;
|
|
12079
12075
|
if (pinCount > 1) {
|
|
12080
|
-
throw new (0,
|
|
12076
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(
|
|
12081
12077
|
"createForResource: exactly one linkage pin is honoured (internallAllocationCodeID | ticketID | taskID) \u2014 the vendor gate requires exactly one; pass one pin (or none for the default internal linkage)",
|
|
12082
12078
|
{ operation: OP }
|
|
12083
12079
|
);
|
|
12084
12080
|
}
|
|
12085
12081
|
if (pins.role !== void 0 && pins.code !== void 0) {
|
|
12086
|
-
throw new (0,
|
|
12082
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(
|
|
12087
12083
|
"createForResource: a pinned roleID is only meaningful with the task/ticket linkage (internallAllocationCodeID pins the internal linkage and owns the code) \u2014 drop one",
|
|
12088
12084
|
{ operation: OP }
|
|
12089
12085
|
);
|
|
12090
12086
|
}
|
|
12091
12087
|
if (params.hoursWorked !== void 0 && (typeof params.hoursWorked !== "number" || !Number.isFinite(params.hoursWorked) || params.hoursWorked <= 0)) {
|
|
12092
|
-
throw new (0,
|
|
12088
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)(
|
|
12093
12089
|
`createForResource: hoursWorked must be a positive finite number (got ${String(params.hoursWorked)})`,
|
|
12094
12090
|
{ operation: OP }
|
|
12095
12091
|
);
|
|
@@ -12205,7 +12201,7 @@ async function createForResource(resource, resourceID, params, opts = {}, http)
|
|
|
12205
12201
|
};
|
|
12206
12202
|
} catch (err) {
|
|
12207
12203
|
lastError = err;
|
|
12208
|
-
const text =
|
|
12204
|
+
const text = _chunkIV2Z3JLRcjs.isAutotaskError.call(void 0, err) ? `${_nullishCoalesce(_chunkIV2Z3JLRcjs.formatVendorDetail.call(void 0, err.vendorError), () => ( ""))} ${err.message}` : "";
|
|
12209
12205
|
const gate3 = ROLE_REJECTION_PATTERN.test(text);
|
|
12210
12206
|
if (usedLinkage !== "internal" && gate3) {
|
|
12211
12207
|
if (!taskRoleFetched && usedLinkage === "task" && pins.task !== void 0) {
|
|
@@ -12225,14 +12221,14 @@ async function createForResource(resource, resourceID, params, opts = {}, http)
|
|
|
12225
12221
|
throw err;
|
|
12226
12222
|
}
|
|
12227
12223
|
}
|
|
12228
|
-
if (
|
|
12224
|
+
if (_chunkIV2Z3JLRcjs.isAutotaskError.call(void 0, lastError)) {
|
|
12229
12225
|
lastError.suggestedAction = (lastError.suggestedAction ? `${lastError.suggestedAction} ` : "") + `The createForResource attempt budget (${MAX_CREATE_ATTEMPTS} attempts: the role ladder + ${MAX_DISCOVERY_MERGES2} discovery merges) was exhausted \u2014 the vendor oracle rejected every candidate. Re-read the record/fields (time_entries.getFieldInfo, billing_codes.query with a filter) and retry with an explicit pin.`;
|
|
12230
12226
|
}
|
|
12231
12227
|
throw lastError;
|
|
12232
12228
|
}
|
|
12233
12229
|
function discoveryField(err, body, defaults) {
|
|
12234
|
-
if (!
|
|
12235
|
-
const entries =
|
|
12230
|
+
if (!_chunkIV2Z3JLRcjs.isAutotaskError.call(void 0, err) || err.vendorError === void 0) return null;
|
|
12231
|
+
const entries = _chunkIV2Z3JLRcjs.parseVendorErrors.call(void 0, err.vendorError);
|
|
12236
12232
|
if (entries === void 0) return null;
|
|
12237
12233
|
for (const entry of entries) {
|
|
12238
12234
|
const field = entry.field;
|
|
@@ -12462,7 +12458,7 @@ async function approve(_resource, id, opts = {}, http) {
|
|
|
12462
12458
|
async function reject(_resource, id, reason, opts = {}, http) {
|
|
12463
12459
|
const text = reason.trim();
|
|
12464
12460
|
if (text === "") {
|
|
12465
|
-
throw new (0,
|
|
12461
|
+
throw new (0, _chunkIV2Z3JLRcjs.AutotaskConfigError)("reject: a non-empty reason is required (vendor TimeOffRequestRejectModel)");
|
|
12466
12462
|
}
|
|
12467
12463
|
if (opts.dryRun === true) {
|
|
12468
12464
|
return buildDryRunResult({
|
|
@@ -12746,4 +12742,4 @@ var ZoneInformationResource = class {
|
|
|
12746
12742
|
|
|
12747
12743
|
|
|
12748
12744
|
exports.AUTH_HEADERS = AUTH_HEADERS; exports.buildAuthHeaders = buildAuthHeaders; exports.withAuthHeaders = withAuthHeaders; exports.FILTER_OPERATORS = FILTER_OPERATORS; exports.GROUPING_OPERATORS = GROUPING_OPERATORS; exports.MAX_OR_CONDITIONS = MAX_OR_CONDITIONS; exports.MAX_UDF_PER_QUERY = MAX_UDF_PER_QUERY; exports.MAX_QUERY_LENGTH = MAX_QUERY_LENGTH; exports.MAX_GET_LENGTH = MAX_GET_LENGTH; exports.MAX_FIELD_LENGTH = MAX_FIELD_LENGTH; exports.isFilterOperator = isFilterOperator; exports.serializeFilter = serializeFilter; exports.validateFilter = validateFilter; exports.buildFilter = buildFilter; exports.IDEMPOTENT_METHODS = IDEMPOTENT_METHODS; exports.buildUrl = buildUrl; exports.buildQueryRequest = buildQueryRequest; exports.runWithSignal = runWithSignal; exports.HttpClient = HttpClient; exports.unwrapItems = unwrapItems; exports.unwrapItem = unwrapItem; exports.unwrapQueryCount = unwrapQueryCount; exports.unwrapOperation = unwrapOperation; exports.passthrough = passthrough; exports.AppointmentsResource = AppointmentsResource; exports.AuthenticateResource = AuthenticateResource; exports.BillingCodesResource = BillingCodesResource; exports.BillingItemsResource = BillingItemsResource; exports.ChangeRequestLinksResource = ChangeRequestLinksResource; exports.ChecklistLibrariesResource = ChecklistLibrariesResource; exports.ChecklistLibraryChecklistItemsResource = ChecklistLibraryChecklistItemsResource; exports.ClassificationIconsResource = ClassificationIconsResource; exports.CompaniesResource = CompaniesResource; exports.CompanyAlertsResource = CompanyAlertsResource; exports.CompanyLocationsResource = CompanyLocationsResource; exports.CompanyNotesResource = CompanyNotesResource; exports.CompanySiteConfigurationsResource = CompanySiteConfigurationsResource; exports.CompanyWebhooksResource = CompanyWebhooksResource; exports.ConfigurationItemBillingProductAssociationsResource = ConfigurationItemBillingProductAssociationsResource; exports.ConfigurationItemCategoriesResource = ConfigurationItemCategoriesResource; exports.ConfigurationItemCategoryUdfAssociationsResource = ConfigurationItemCategoryUdfAssociationsResource; exports.ConfigurationItemDnsRecordsResource = ConfigurationItemDnsRecordsResource; exports.ConfigurationItemNotesResource = ConfigurationItemNotesResource; exports.ConfigurationItemRelatedItemsResource = ConfigurationItemRelatedItemsResource; exports.ConfigurationItemsResource = ConfigurationItemsResource; exports.ConfigurationItemSslSubjectAlternativeNamesResource = ConfigurationItemSslSubjectAlternativeNamesResource; exports.ConfigurationItemTypesResource = ConfigurationItemTypesResource; exports.ConfigurationItemWebhooksResource = ConfigurationItemWebhooksResource; exports.ContactGroupContactsResource = ContactGroupContactsResource; exports.ContactGroupsResource = ContactGroupsResource; exports.ContactsResource = ContactsResource; exports.ContactWebhooksResource = ContactWebhooksResource; exports.ContractBillingRulesResource = ContractBillingRulesResource; exports.ContractBlockHourFactorsResource = ContractBlockHourFactorsResource; exports.ContractBlocksResource = ContractBlocksResource; exports.ContractChargesResource = ContractChargesResource; exports.ContractExclusionBillingCodesResource = ContractExclusionBillingCodesResource; exports.ContractExclusionRolesResource = ContractExclusionRolesResource; exports.ContractExclusionSetExcludedRolesResource = ContractExclusionSetExcludedRolesResource; exports.ContractExclusionSetExcludedWorkTypesResource = ContractExclusionSetExcludedWorkTypesResource; exports.ContractExclusionSetsResource = ContractExclusionSetsResource; exports.ContractMilestonesResource = ContractMilestonesResource; exports.ContractNotesResource = ContractNotesResource; exports.ContractRatesResource = ContractRatesResource; exports.ContractRetainersResource = ContractRetainersResource; exports.ContractRoleCostsResource = ContractRoleCostsResource; exports.ContractServiceAdjustmentsResource = ContractServiceAdjustmentsResource; exports.ContractServiceBundleAdjustmentsResource = ContractServiceBundleAdjustmentsResource; exports.ContractServiceBundlesResource = ContractServiceBundlesResource; exports.ContractServiceBundleUnitsResource = ContractServiceBundleUnitsResource; exports.ContractServicesResource = ContractServicesResource; exports.ContractServiceUnitsResource = ContractServiceUnitsResource; exports.ContractsResource = ContractsResource; exports.ContractTicketPurchasesResource = ContractTicketPurchasesResource; exports.CountriesResource = CountriesResource; exports.DepartmentsResource = DepartmentsResource; exports.DomainRegistrarsResource = DomainRegistrarsResource; exports.EntityInformationResource = EntityInformationResource; exports.ExpenseItemAttachmentsResource = ExpenseItemAttachmentsResource; exports.ExpenseItemsResource = ExpenseItemsResource; exports.ExpenseReportsResource = ExpenseReportsResource; exports.HolidaySetsResource = HolidaySetsResource; exports.HolidaysResource = HolidaysResource; exports.InventoryProductsResource = InventoryProductsResource; exports.InvoicesResource = InvoicesResource; exports.ModulesResource = ModulesResource; exports.NotificationHistoryResource = NotificationHistoryResource; exports.OpportunitiesResource = OpportunitiesResource; exports.OpportunityAttachmentsResource = OpportunityAttachmentsResource; exports.OpportunityCategoriesResource = OpportunityCategoriesResource; exports.PhasesResource = PhasesResource; exports.ProductsResource = ProductsResource; exports.ProductVendorsResource = ProductVendorsResource; exports.ProjectChargesResource = ProjectChargesResource; exports.ProjectNotesResource = ProjectNotesResource; exports.ProjectsResource = ProjectsResource; exports.PurchaseApprovalsResource = PurchaseApprovalsResource; exports.PurchaseOrderItemReceivingResource = PurchaseOrderItemReceivingResource; exports.PurchaseOrderItemsResource = PurchaseOrderItemsResource; exports.PurchaseOrdersResource = PurchaseOrdersResource; exports.QuoteItemsResource = QuoteItemsResource; exports.QuoteLocationsResource = QuoteLocationsResource; exports.QuotesResource = QuotesResource; exports.QuoteTemplatesResource = QuoteTemplatesResource; exports.ResourceRoleQueuesResource = ResourceRoleQueuesResource; exports.ResourceRolesResource = ResourceRolesResource; exports.ResourceSkillsResource = ResourceSkillsResource; exports.ResourcesResource = ResourcesResource; exports.ResourceTimeOffAdditionalResource = ResourceTimeOffAdditionalResource; exports.ResourceTimeOffApproversResource = ResourceTimeOffApproversResource; exports.ResourceTimeOffBalancesResource = ResourceTimeOffBalancesResource; exports.RolesResource = RolesResource; exports.ServiceCallsResource = ServiceCallsResource; exports.ServiceCallTaskResourcesResource = ServiceCallTaskResourcesResource; exports.ServiceCallTasksResource = ServiceCallTasksResource; exports.ServiceCallTicketResourcesResource = ServiceCallTicketResourcesResource; exports.ServiceCallTicketsResource = ServiceCallTicketsResource; exports.ServiceLevelAgreementResultsResource = ServiceLevelAgreementResultsResource; exports.ServicesResource = ServicesResource; exports.SkillsResource = SkillsResource; exports.SubscriptionPeriodsResource = SubscriptionPeriodsResource; exports.SubscriptionsResource = SubscriptionsResource; exports.SurveyResultsResource = SurveyResultsResource; exports.SurveysResource = SurveysResource; exports.TagAliasesResource = TagAliasesResource; exports.TagGroupsResource = TagGroupsResource; exports.TagsResource = TagsResource; exports.TaskSecondaryResourcesResource = TaskSecondaryResourcesResource; exports.TasksResource = TasksResource; exports.ThresholdInformationResource = ThresholdInformationResource; exports.TicketAdditionalConfigurationItemsResource = TicketAdditionalConfigurationItemsResource; exports.TicketAdditionalContactsResource = TicketAdditionalContactsResource; exports.TicketAttachmentsResource = TicketAttachmentsResource; exports.TicketCategoriesResource = TicketCategoriesResource; exports.TicketCategoryFieldDefaultsResource = TicketCategoryFieldDefaultsResource; exports.TicketChangeRequestApprovalsResource = TicketChangeRequestApprovalsResource; exports.TicketChargesResource = TicketChargesResource; exports.TicketChecklistItemsResource = TicketChecklistItemsResource; exports.TicketChecklistLibrariesResource = TicketChecklistLibrariesResource; exports.TicketHistoryResource = TicketHistoryResource; exports.TicketNoteAttachmentsResource = TicketNoteAttachmentsResource; exports.TicketNotesResource = TicketNotesResource; exports.TicketNoteWebhooksResource = TicketNoteWebhooksResource; exports.TicketSecondaryResourcesResource = TicketSecondaryResourcesResource; exports.TicketsResource = TicketsResource; exports.TicketWebhooksResource = TicketWebhooksResource; exports.TimeEntriesResource = TimeEntriesResource; exports.TimeEntryAttachmentsResource = TimeEntryAttachmentsResource; exports.TimeOffRequestsResource = TimeOffRequestsResource; exports.VersionInformationResource = VersionInformationResource; exports.VersionResource = VersionResource; exports.ZoneInformationResource = ZoneInformationResource;
|
|
12749
|
-
//# sourceMappingURL=chunk-
|
|
12745
|
+
//# sourceMappingURL=chunk-CQIZDSBE.cjs.map
|