iit-mcp-autotask 0.64.2 → 0.65.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/capabilities.json +2 -2
- package/dist/tools/catalog-data.d.ts +4 -3
- package/dist/tools/catalog-data.js +9 -4
- package/dist/tools/context/client.js +11 -5
- package/dist/tools/context/derive.d.ts +7 -3
- package/dist/tools/context/derive.js +50 -7
- package/dist/tools/context/types.d.ts +3 -1
- package/dist/tools/dispatch.d.ts +2 -0
- package/dist/tools/dispatch.js +6 -4
- package/dist/tools/lists.js +7 -5
- package/dist/tools/meta.js +3 -0
- package/dist/tools/reasons.js +4 -4
- package/dist/tools/results/errors.js +14 -12
- package/dist/tools/write/apply.js +128 -56
- package/dist/tools/write/impersonation.js +7 -13
- package/dist/tools/write/outcome.js +31 -4
- package/dist/tools/write/preview.js +8 -9
- package/dist/tools/write/snapshot.d.ts +9 -2
- package/dist/tools/write/snapshot.js +159 -12
- package/package.json +2 -2
- package/server.json +2 -2
package/capabilities.json
CHANGED
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
},
|
|
75
75
|
{
|
|
76
76
|
"id": "autotask.platform.catalog",
|
|
77
|
-
"description": "Find the exact operation key for anything without a dedicated tool: ranked search (q) over the 1,
|
|
77
|
+
"description": "Find the exact operation key for anything without a dedicated tool: ranked search (q) over the 1,444 registry operations, with effect and whether this deployment serves it. No vendor call.",
|
|
78
78
|
"mcpPrimitive": "tool",
|
|
79
79
|
"toolName": "autotask_catalog",
|
|
80
80
|
"type": "read",
|
|
@@ -480,7 +480,7 @@
|
|
|
480
480
|
"autotask_describe",
|
|
481
481
|
"autotask_read"
|
|
482
482
|
],
|
|
483
|
-
"backingRegistryOperations":
|
|
483
|
+
"backingRegistryOperations": 1444,
|
|
484
484
|
"note": "autotask_catalog finds the exact operation key (ranked search), autotask_describe serves its contract, autotask_read runs any effect=read key. Writes go through the operator profile (autotask_write then autotask_apply); authenticate.* is never served."
|
|
485
485
|
},
|
|
486
486
|
"schemas": {}
|
|
@@ -71,12 +71,13 @@ export declare function staffReadParentFilter(resource: string): string | undefi
|
|
|
71
71
|
export declare function isStaffReadOperation(operation: unknown): operation is string;
|
|
72
72
|
/** Exact registered metadata reads can settle on a shared wire request. */
|
|
73
73
|
export declare function isRegisteredMetadataRead(operation: unknown): operation is string;
|
|
74
|
-
/**
|
|
75
|
-
export declare function
|
|
74
|
+
/** A direct HTTP 403 on these reads can be an entity permission refusal. */
|
|
75
|
+
export declare function isEntityReadPermissionRefusal(error: {
|
|
76
76
|
operation?: unknown;
|
|
77
77
|
httpStatus?: unknown;
|
|
78
78
|
category?: unknown;
|
|
79
79
|
}): boolean;
|
|
80
|
+
export declare function isDocumentCategoryReadOperation(operation: unknown): boolean;
|
|
80
81
|
/** The served tool for this row's operation in a deployment serving `served`, or `null`. */
|
|
81
82
|
export declare function servedToolName(row: CatalogRow, served: ReadonlySet<string>): string | null;
|
|
82
83
|
/** The registry keys projected onto an MCP tool name (the reverse of {@link TOOL_NAME_BY_OP}); empty when none. */
|
|
@@ -121,7 +122,7 @@ export declare function sdkCacheOptions(cache: 'on' | 'off'): Pick<AutotaskConfi
|
|
|
121
122
|
* fails the boot (or the CI test) instead of quietly shipping a tool surface that no longer
|
|
122
123
|
* describes the SDK behind it.
|
|
123
124
|
*/
|
|
124
|
-
export declare const BUILT_AGAINST_PLAN_HASH = "
|
|
125
|
+
export declare const BUILT_AGAINST_PLAN_HASH = "86416d6a76ecf010aa7956b6910b253de22ddabec45711f79dd4aeaa38c0466e";
|
|
125
126
|
/**
|
|
126
127
|
* Fail fast when the installed SDK's plan has moved out from under this surface.
|
|
127
128
|
* Called at boot (main.ts) and safe to call repeatedly (pure comparison).
|
|
@@ -121,9 +121,14 @@ export function isRegisteredMetadataRead(operation) {
|
|
|
121
121
|
const record = typeof operation === 'string' ? recordById(operation) : undefined;
|
|
122
122
|
return record?.effect === 'read' && /^(getEntityInfo|getFieldInfo|getUdfInfo)$/.test(record.operation);
|
|
123
123
|
}
|
|
124
|
-
/**
|
|
125
|
-
export function
|
|
126
|
-
return error.httpStatus === 403 && error.category === 'auth'
|
|
124
|
+
/** A direct HTTP 403 on these reads can be an entity permission refusal. */
|
|
125
|
+
export function isEntityReadPermissionRefusal(error) {
|
|
126
|
+
return error.httpStatus === 403 && error.category === 'auth'
|
|
127
|
+
&& (isStaffReadOperation(error.operation) || isDocumentCategoryReadOperation(error.operation));
|
|
128
|
+
}
|
|
129
|
+
export function isDocumentCategoryReadOperation(operation) {
|
|
130
|
+
const record = typeof operation === 'string' ? recordById(operation) : undefined;
|
|
131
|
+
return record?.effect === 'read' && record.resource === 'document_categories';
|
|
127
132
|
}
|
|
128
133
|
/** The served tool for this row's operation in a deployment serving `served`, or `null`. */
|
|
129
134
|
export function servedToolName(row, served) {
|
|
@@ -222,7 +227,7 @@ export function sdkCacheOptions(cache) {
|
|
|
222
227
|
* fails the boot (or the CI test) instead of quietly shipping a tool surface that no longer
|
|
223
228
|
* describes the SDK behind it.
|
|
224
229
|
*/
|
|
225
|
-
export const BUILT_AGAINST_PLAN_HASH = '
|
|
230
|
+
export const BUILT_AGAINST_PLAN_HASH = '86416d6a76ecf010aa7956b6910b253de22ddabec45711f79dd4aeaa38c0466e';
|
|
226
231
|
/**
|
|
227
232
|
* Fail fast when the installed SDK's plan has moved out from under this surface.
|
|
228
233
|
* Called at boot (main.ts) and safe to call repeatedly (pure comparison).
|
|
@@ -4,7 +4,7 @@ import { AutotaskClient, errorFromStatus } from 'node-autotask';
|
|
|
4
4
|
import { invokeDelete, invokeRead, invokeReadPages, invokeWrite, relationshipMap, resolveAny, searchAcrossResources } from 'node-autotask/operations';
|
|
5
5
|
import { serverCredentialDefaults } from '../../config/load.js';
|
|
6
6
|
import { normalizeBaseUrl } from '../../base-hosts.js';
|
|
7
|
-
import { isRegisteredMetadataRead, sdkCacheOptions } from '../catalog-data.js';
|
|
7
|
+
import { isDocumentCategoryReadOperation, isRegisteredMetadataRead, sdkCacheOptions } from '../catalog-data.js';
|
|
8
8
|
import { captureReadRuntime } from '../read-runtime.js';
|
|
9
9
|
// ---------------------------------------------------------------------------
|
|
10
10
|
// SDK client construction
|
|
@@ -15,7 +15,7 @@ export const PLACEHOLDER_BASE_URL = `${PLACEHOLDER_ORIGIN}/atservicesrest`;
|
|
|
15
15
|
/** Sentinel credential values a placeholder client is constructed with (never real, never dialled). */
|
|
16
16
|
export const SENTINEL_CREDENTIAL = 'unresolved-request-scope';
|
|
17
17
|
// SDK classifications here are fixed tokens. A vendor-origin SDK code must contain a digit.
|
|
18
|
-
const
|
|
18
|
+
const READ_AUDIT_CODES = new Set([
|
|
19
19
|
'ABORTED', 'HOST_POLICY_DENIED', 'MAINTENANCE', 'REDIRECT_BLOCKED', 'RESPONSE_REJECTED', 'RESPONSE_TOO_LARGE',
|
|
20
20
|
'RATE_LIMITED', 'RATE_LIMITED_COOLDOWN', 'CIRCUIT_BREAKER_OPEN',
|
|
21
21
|
'TIMEOUT', 'NETWORK_ERROR', 'INVALID_RESPONSE', 'UNEXPECTED_CONTENT_TYPE', 'EMPTY_RESPONSE',
|
|
@@ -23,9 +23,9 @@ const METADATA_AUDIT_CODES = new Set([
|
|
|
23
23
|
function auditErrorCode(code, operation, status) {
|
|
24
24
|
if (typeof code !== 'string')
|
|
25
25
|
return undefined;
|
|
26
|
-
if (isRegisteredMetadataRead(operation)) {
|
|
26
|
+
if (isRegisteredMetadataRead(operation) || isDocumentCategoryReadOperation(operation)) {
|
|
27
27
|
// A terminal SDK failure can carry the status from an earlier retry.
|
|
28
|
-
if (
|
|
28
|
+
if (READ_AUDIT_CODES.has(code))
|
|
29
29
|
return code;
|
|
30
30
|
return status !== undefined && status >= 300 ? errorFromStatus(status, undefined).code : 'UPSTREAM_ERROR';
|
|
31
31
|
}
|
|
@@ -139,7 +139,13 @@ export function buildStdioClient(config, log) {
|
|
|
139
139
|
* `invokeRead` and its governor; `authenticate.*` is refused by the deployment policy before it.)
|
|
140
140
|
*/
|
|
141
141
|
export const defaultToolOps = {
|
|
142
|
-
invokeRead: (client, operation, args, opts, signal) => withSignal(client, signal, () =>
|
|
142
|
+
invokeRead: (client, operation, args, { freshMetadata, ...opts } = {}, signal) => withSignal(client, signal, () => {
|
|
143
|
+
const sdk = client;
|
|
144
|
+
// The SDK documents invalidation as the way to refresh a raw, no-argument metadata read.
|
|
145
|
+
if (freshMetadata === true)
|
|
146
|
+
sdk.http.fieldCache?.invalidate(`${operation.split('.')[0]}:fields`);
|
|
147
|
+
return invokeRead(sdk, operation, args, opts);
|
|
148
|
+
}),
|
|
143
149
|
invokeReadPages: (client, operation, args, onPage, opts, signal) => withSignal(client, signal, () => invokeReadPages(client, operation, args, onPage, opts ?? {})),
|
|
144
150
|
invokeWrite: (client, operation, args, opts, signal) => withSignal(client, signal, () => invokeWrite(client, operation, args, opts ?? {})),
|
|
145
151
|
invokeDelete: (client, operation, args, opts, signal) => withSignal(client, signal, () => invokeDelete(client, operation, args, opts ?? {})),
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
import { AutotaskClient, type AutotaskConfig } from 'node-autotask';
|
|
1
|
+
import { AutotaskClient, type AutotaskConfig, type AutotaskError } from 'node-autotask';
|
|
3
2
|
import type { ClientPool } from 'node-autotask/pool';
|
|
4
3
|
import type { Logger } from '../../logger.js';
|
|
5
4
|
import type { ToolDeps, ToolContext } from './types.js';
|
|
5
|
+
export declare function isImpersonationValidationDenial(error: unknown): error is AutotaskError & {
|
|
6
|
+
httpStatus: 401 | 403;
|
|
7
|
+
};
|
|
8
|
+
/** Scope the wire hook to the validation call, since resources.get also serves ordinary reads. */
|
|
9
|
+
export declare function withImpersonationValidation<T>(ctx: ToolContext, read: () => Promise<T>): Promise<T>;
|
|
6
10
|
/** Resolve the SDK client and bind invalidation to its exact pool key. */
|
|
7
11
|
export declare function getPooledClient(pool: ClientPool, config: AutotaskConfig, log: Logger): AutotaskClient;
|
|
8
12
|
/** Derive the context the registrations share. */
|
|
9
13
|
export declare function deriveToolContext(deps: ToolDeps, served?: ReadonlySet<string>): ToolContext;
|
|
10
|
-
/**
|
|
14
|
+
/** An entity permission refusal applies only to a resolved direct identity. */
|
|
11
15
|
export declare function isDirectIdentity(deps: Pick<ToolDeps, 'poolConfig'>): boolean;
|
|
12
16
|
/**
|
|
13
17
|
* A vendor 401 (or impersonation-scope 401/403) deletes the pooled entry so a stale identity is
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
/** Deriving a tool context from the deps, and releasing a client on error (issue #91). */
|
|
2
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
3
|
import { AutotaskClient, isAutotaskError } from 'node-autotask';
|
|
3
4
|
import { isAuthFailure } from '../results/errors.js';
|
|
4
|
-
import { isRegisteredMetadataRead, isStaffReadOperation, recordById, toolDescription, untrustedFieldsOf } from '../catalog-data.js';
|
|
5
|
+
import { isDocumentCategoryReadOperation, isRegisteredMetadataRead, isStaffReadOperation, recordById, toolDescription, untrustedFieldsOf } from '../catalog-data.js';
|
|
5
6
|
// A real client with this hook handles eviction once per wire refusal, even if multiple readers share the result.
|
|
6
7
|
const auditInvalidatesCredentialReads = new WeakSet();
|
|
8
|
+
const impersonationValidation = new AsyncLocalStorage();
|
|
9
|
+
const invalidatedValidationErrors = new WeakSet();
|
|
7
10
|
function isCredentialReadDenial(operation, status, impersonated) {
|
|
8
11
|
return (status === 401 || (status === 403 && impersonated)) &&
|
|
9
|
-
(isStaffReadOperation(operation) || isRegisteredMetadataRead(operation));
|
|
12
|
+
(isStaffReadOperation(operation) || isRegisteredMetadataRead(operation) || isDocumentCategoryReadOperation(operation));
|
|
13
|
+
}
|
|
14
|
+
function isCategoryMutation(operation, method) {
|
|
15
|
+
return (operation === 'document_categories.create' && method === 'POST')
|
|
16
|
+
|| (operation === 'document_categories.update' && method === 'PUT')
|
|
17
|
+
|| (operation === 'document_categories.delete' && method === 'DELETE');
|
|
10
18
|
}
|
|
11
19
|
function invalidateCredentialReads(pool, config, client, log) {
|
|
12
20
|
// A pinned stdio or in-flight client can outlive its pool entry. Clear its stores if the pool did not.
|
|
@@ -22,19 +30,52 @@ function invalidateCredentialReads(pool, config, client, log) {
|
|
|
22
30
|
if (removed)
|
|
23
31
|
log.info('deleted pooled client after credential refusal', { removed, poolSize: pool.size });
|
|
24
32
|
}
|
|
33
|
+
export function isImpersonationValidationDenial(error) {
|
|
34
|
+
return isAutotaskError(error) && error.operation === 'resources.get' && error.category === 'auth'
|
|
35
|
+
&& (error.httpStatus === 401 || error.httpStatus === 403);
|
|
36
|
+
}
|
|
37
|
+
/** Scope the wire hook to the validation call, since resources.get also serves ordinary reads. */
|
|
38
|
+
export async function withImpersonationValidation(ctx, read) {
|
|
39
|
+
const scope = { client: ctx.client, invalidated: false };
|
|
40
|
+
try {
|
|
41
|
+
return await impersonationValidation.run(scope, read);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
const { pool, poolConfig, client, log } = ctx;
|
|
45
|
+
if (pool !== undefined && poolConfig?.impersonationResourceId !== undefined && isImpersonationValidationDenial(error)) {
|
|
46
|
+
if (!scope.invalidated)
|
|
47
|
+
invalidateCredentialReads(pool, poolConfig, client instanceof AutotaskClient ? client : undefined, log);
|
|
48
|
+
invalidatedValidationErrors.add(error);
|
|
49
|
+
}
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
25
53
|
/** Resolve the SDK client and bind invalidation to its exact pool key. */
|
|
26
54
|
export function getPooledClient(pool, config, log) {
|
|
27
55
|
const client = pool.get({
|
|
28
56
|
...config,
|
|
29
57
|
onAudit(event) {
|
|
30
|
-
const { status, operation, errorCode, notSent } = event;
|
|
58
|
+
const { status, operation, method, errorCode, notSent } = event;
|
|
31
59
|
// The SDK can retain a machine code containing digits for a real status error.
|
|
32
60
|
// Its own abort, maintenance and response-policy codes do not describe an auth denial.
|
|
33
61
|
const authCode = errorCode === (status === 401 ? 'UNAUTHORIZED' : 'FORBIDDEN') ||
|
|
34
62
|
(errorCode !== undefined && /^[a-z0-9][a-z0-9_-]{2,}$/i.test(errorCode) && /\d/.test(errorCode));
|
|
35
|
-
if (notSent !== true && authCode
|
|
36
|
-
|
|
37
|
-
|
|
63
|
+
if (notSent !== true && authCode) {
|
|
64
|
+
const readDenial = isCredentialReadDenial(operation, status, config.impersonationResourceId !== undefined);
|
|
65
|
+
if (readDenial)
|
|
66
|
+
auditInvalidatesCredentialReads.add(client);
|
|
67
|
+
const validation = impersonationValidation.getStore();
|
|
68
|
+
const validationDenial = validation?.client === client && config.impersonationResourceId !== undefined
|
|
69
|
+
&& operation === 'resources.get' && method === 'GET' && (status === 401 || status === 403);
|
|
70
|
+
// The wire can settle after apply has returned an unknown outcome.
|
|
71
|
+
if (readDenial || validationDenial || (status === 401 && isCategoryMutation(operation, method))) {
|
|
72
|
+
invalidateCredentialReads(pool, config, client, log);
|
|
73
|
+
}
|
|
74
|
+
if (validationDenial) {
|
|
75
|
+
validation.invalidated = true;
|
|
76
|
+
config.onAudit?.({ ...event, errorCode: status === 401 ? 'UNAUTHORIZED' : 'FORBIDDEN' });
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
38
79
|
}
|
|
39
80
|
config.onAudit?.(event);
|
|
40
81
|
},
|
|
@@ -55,7 +96,7 @@ export function deriveToolContext(deps, served = new Set()) {
|
|
|
55
96
|
description: toolDescription,
|
|
56
97
|
};
|
|
57
98
|
}
|
|
58
|
-
/**
|
|
99
|
+
/** An entity permission refusal applies only to a resolved direct identity. */
|
|
59
100
|
export function isDirectIdentity(deps) {
|
|
60
101
|
return deps.poolConfig !== undefined && deps.poolConfig.impersonationResourceId === undefined;
|
|
61
102
|
}
|
|
@@ -68,6 +109,8 @@ export function releaseClientOnError(deps, err) {
|
|
|
68
109
|
if (deps.pool === undefined || deps.poolConfig === undefined)
|
|
69
110
|
return;
|
|
70
111
|
if (isAutotaskError(err) && isAuthFailure(err, isDirectIdentity(deps))) {
|
|
112
|
+
if (invalidatedValidationErrors.has(err))
|
|
113
|
+
return;
|
|
71
114
|
if (err.category === 'auth' && isCredentialReadDenial(err.operation, err.httpStatus, !isDirectIdentity(deps))) {
|
|
72
115
|
if (!auditInvalidatesCredentialReads.has(deps.client)) {
|
|
73
116
|
invalidateCredentialReads(deps.pool, deps.poolConfig, deps.client instanceof AutotaskClient ? deps.client : undefined, deps.log);
|
|
@@ -53,7 +53,9 @@ export interface HourlyBudget {
|
|
|
53
53
|
/** The SDK operations the handler layer drives, bound in ONE place (the mock seam). */
|
|
54
54
|
export interface ToolOps {
|
|
55
55
|
/** The MCP request's AbortSignal, when the transport provides one: an abandoned request stops consuming vendor budget. */
|
|
56
|
-
invokeRead(client: ToolClient, operation: string, args?: readonly unknown[], opts?: InvokeOptions
|
|
56
|
+
invokeRead(client: ToolClient, operation: string, args?: readonly unknown[], opts?: InvokeOptions & {
|
|
57
|
+
freshMetadata?: true;
|
|
58
|
+
}, signal?: AbortSignal): Promise<unknown>;
|
|
57
59
|
invokeReadPages(client: ToolClient, operation: string, args: readonly unknown[], onPage: BoundedQueryPageConsumer, opts?: InvokeOptions, signal?: AbortSignal): Promise<BoundedQuerySummary | undefined>;
|
|
58
60
|
invokeWrite(client: ToolClient, operation: string, args?: readonly unknown[], opts?: InvokeOptions, signal?: AbortSignal): Promise<unknown>;
|
|
59
61
|
invokeDelete(client: ToolClient, operation: string, args?: readonly unknown[], opts?: InvokeOptions, signal?: AbortSignal): Promise<unknown>;
|
package/dist/tools/dispatch.d.ts
CHANGED
|
@@ -34,6 +34,8 @@ export declare class InputInvalidError extends AutotaskConfigError {
|
|
|
34
34
|
* 5. the correlation id stamped on the envelope (and the mirrored text block).
|
|
35
35
|
*/
|
|
36
36
|
export declare function runTool<A = Record<string, unknown>>(ctx: ToolContext, input: ClosedInput, rawArgs: unknown, extra: unknown, work: (args: A, signal: AbortSignal | undefined, extra: unknown) => Promise<ToolReturn>): Promise<ToolReturn | InputRequiredResult>;
|
|
37
|
+
/** Release and map the refusal under the identity that actually made the request. */
|
|
38
|
+
export declare function toolError(ctx: ToolContext, err: unknown): ToolReturn;
|
|
37
39
|
/** The typed answer when the MCP request was cancelled before the upstream call settled. */
|
|
38
40
|
export declare function abortedAnswer(corr: string): ToolReturn;
|
|
39
41
|
/**
|
package/dist/tools/dispatch.js
CHANGED
|
@@ -75,12 +75,14 @@ async function frame(ctx, input, rawArgs, extra, work) {
|
|
|
75
75
|
return await work(parsed.data, mcpSignal(extra), extra);
|
|
76
76
|
}
|
|
77
77
|
catch (err) {
|
|
78
|
-
|
|
79
|
-
// V23/FT-5: the request's own credential values ride into the error wrap so a vendor body
|
|
80
|
-
// that echoes them is value-scrubbed before it crosses.
|
|
81
|
-
return errorContent(err, ctx.correlationId, requestSecrets(ctx), isDirectIdentity(ctx));
|
|
78
|
+
return toolError(ctx, err);
|
|
82
79
|
}
|
|
83
80
|
}
|
|
81
|
+
/** Release and map the refusal under the identity that actually made the request. */
|
|
82
|
+
export function toolError(ctx, err) {
|
|
83
|
+
releaseClientOnError(ctx, err);
|
|
84
|
+
return errorContent(err, ctx.correlationId, requestSecrets(ctx), isDirectIdentity(ctx));
|
|
85
|
+
}
|
|
84
86
|
/**
|
|
85
87
|
* Stamp the serving unit's correlation id on a finished result (and its mirrored text block).
|
|
86
88
|
* An `input_required` result is not a tool result: it carries no envelope and is returned untouched.
|
package/dist/tools/lists.js
CHANGED
|
@@ -63,11 +63,13 @@ export function buildQuery(ctx) {
|
|
|
63
63
|
const parentField = staffReadParentFilter(args.resource);
|
|
64
64
|
const hint = parentField !== undefined
|
|
65
65
|
? `call again with {field: "${parentField}", op: "eq", value: "<parent id>"} for a parent or with {field: "id", op: "eq", value: "<row id>"} for a known record`
|
|
66
|
-
:
|
|
67
|
-
? 'pass
|
|
68
|
-
: args.resource
|
|
69
|
-
? '
|
|
70
|
-
:
|
|
66
|
+
: args.resource === 'document_categories'
|
|
67
|
+
? 'pass a filter on id for a known category or on parentCategoryID for categories under a known parent'
|
|
68
|
+
: isDeletedActivityAuditResource(args.resource)
|
|
69
|
+
? 'pass an audit filter such as {field: "id", op: "exist"} for bounded reads or counts'
|
|
70
|
+
: args.resource === 'internal_locations' || args.resource === 'shipping_types'
|
|
71
|
+
? 'call again with {field: "id", op: "eq", value: "<id>"} for a known record, or {field: "id", op: "exist"} for the whole entity'
|
|
72
|
+
: 'call again with a scope such as {field: "companyID", op: "eq", value: "<id>"} (time_entries: ticket.companyID), or {field: "id", op: "exist"} for the whole entity';
|
|
71
73
|
throw new InputInvalidError(`query: filter is missing or empty; ${hint}`, 'filter');
|
|
72
74
|
}
|
|
73
75
|
// #228: totals mode (group_by / sum / count) is the SDK's operations.aggregate over the same filter
|
package/dist/tools/meta.js
CHANGED
|
@@ -539,6 +539,9 @@ function servedUsage(rec) {
|
|
|
539
539
|
const u = rec.metadata?.usage;
|
|
540
540
|
if (typeof u !== 'string')
|
|
541
541
|
return undefined;
|
|
542
|
+
if (rec.id === 'document_categories.create' || rec.id === 'document_categories.update') {
|
|
543
|
+
return `For creation or reparenting, put parentCategoryID in data. The choice must be active and readable even when zero. Account-wide policy and vendor permissions apply. ${u}`;
|
|
544
|
+
}
|
|
542
545
|
if (rec.id === 'expense_report_attachments.get' || rec.id === 'resource_attachments.get') {
|
|
543
546
|
return `${u} Inline data, if present, is subject to the ${UNTRUSTED_TEXT_CAP}-character text cap. The ${TRUNCATION_MARKER} marker inside the data wrapper identifies an incomplete value. textCapped applies to the whole response.`;
|
|
544
547
|
}
|
package/dist/tools/reasons.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* The lists are pinned by a test: adding a value is a contract change.
|
|
9
9
|
*/
|
|
10
10
|
import { nextActionFor } from 'node-autotask';
|
|
11
|
-
import {
|
|
11
|
+
import { isEntityReadPermissionRefusal } from './catalog-data.js';
|
|
12
12
|
export const STATUSES = ['ok', 'needs_input', 'ambiguous', 'denied', 'error'];
|
|
13
13
|
export const NEXT_ACTIONS = [
|
|
14
14
|
'proceed',
|
|
@@ -106,13 +106,13 @@ export function classifyError(payload) {
|
|
|
106
106
|
const category = typeof payload.category === 'string' ? payload.category : undefined;
|
|
107
107
|
const callerCursor = code === 'RESPONSE_REJECTED' && payload.callerInput === true;
|
|
108
108
|
const upstream = typeof payload.httpStatus === 'number' || category === 'network' || category === 'server';
|
|
109
|
-
const
|
|
110
|
-
const reason =
|
|
109
|
+
const entityPermissionRefusal = isEntityReadPermissionRefusal(payload);
|
|
110
|
+
const reason = entityPermissionRefusal ? 'UPSTREAM_ERROR' :
|
|
111
111
|
REASON_BY_CODE[code] ??
|
|
112
112
|
(category === 'not_found' ? 'TARGET_NOT_FOUND' : category === 'validation' || callerCursor ? 'INPUT_INVALID' : upstream || code !== 'INTERNAL_ERROR' ? 'UPSTREAM_ERROR' : 'INTERNAL_ERROR');
|
|
113
113
|
// a payload without a category (not an SDK error) whose code names caller input is computed as validation
|
|
114
114
|
const fallbackCategory = category ?? (reason === 'INPUT_INVALID' || reason === 'TARGET_NOT_FOUND' ? 'validation' : undefined);
|
|
115
|
-
const next =
|
|
115
|
+
const next = entityPermissionRefusal || code.startsWith('CREDENTIAL_')
|
|
116
116
|
? 'stop'
|
|
117
117
|
: callerCursor
|
|
118
118
|
? 'supply_input'
|
|
@@ -3,7 +3,7 @@ import { credentialShapeProblem, errorFromStatus, isAutotaskError, MaintenanceEr
|
|
|
3
3
|
import { CREDENTIAL_LOAD_HINT } from '../../credential.js';
|
|
4
4
|
import { unknownKeysRefusal } from 'node-autotask/operations';
|
|
5
5
|
import { errorEnvelope, TRUNCATION_MARKER } from './envelope.js';
|
|
6
|
-
import { canonicalResolverResource, isStaffReadOperation,
|
|
6
|
+
import { canonicalResolverResource, isStaffReadOperation, isEntityReadPermissionRefusal } from '../catalog-data.js';
|
|
7
7
|
import { classifyError } from '../reasons.js';
|
|
8
8
|
import { UNTRUSTED_CLOSE, UNTRUSTED_OPEN } from 'node-autotask/untrusted';
|
|
9
9
|
import { cleanUntrustedText, EVERY_ITEM, LONG_TEXT_CAP, note, stripUnsafeChars, wrapOrSelf } from './untrusted.js';
|
|
@@ -297,7 +297,7 @@ export function isAuthFailure(err, directIdentity = false) {
|
|
|
297
297
|
if (err instanceof MaintenanceError)
|
|
298
298
|
return false;
|
|
299
299
|
const e = err;
|
|
300
|
-
if (directIdentity && e &&
|
|
300
|
+
if (directIdentity && e && isEntityReadPermissionRefusal(e))
|
|
301
301
|
return false;
|
|
302
302
|
const code = e?.code;
|
|
303
303
|
return (((e?.httpStatus === 401 || e?.httpStatus === 403) && e.category === 'auth') ||
|
|
@@ -310,7 +310,7 @@ export function isKnowledgeBaseRootOperation(operation) {
|
|
|
310
310
|
}
|
|
311
311
|
export function isShapeOnlyVendorOperation(operation) {
|
|
312
312
|
return operation !== undefined && (isKnowledgeBaseRootOperation(operation)
|
|
313
|
-
|| /^(inventory_items|inventory_locations|internal_locations|shipping_types|organizational_resources|resource_daily_availabilities)\./.test(operation)
|
|
313
|
+
|| /^(document_categories|inventory_items|inventory_locations|internal_locations|shipping_types|organizational_resources|resource_daily_availabilities)\./.test(operation)
|
|
314
314
|
|| /^products\.(get|fetchRecord|fetchByIds)$/.test(operation));
|
|
315
315
|
}
|
|
316
316
|
/** A vendor failure's canonical status code, also used in transport audit logs. */
|
|
@@ -330,8 +330,8 @@ export function resolveFaultCode(resource, error) {
|
|
|
330
330
|
export function shapeOnlyVendorCode(operation, httpStatus, error) {
|
|
331
331
|
if (!isShapeOnlyVendorOperation(operation))
|
|
332
332
|
return undefined;
|
|
333
|
-
const
|
|
334
|
-
if (
|
|
333
|
+
const typedFault = operation?.startsWith('document_categories.') === true || isStaffReadOperation(operation);
|
|
334
|
+
if (typedFault && error instanceof ResponseRejectedError)
|
|
335
335
|
return error.code;
|
|
336
336
|
const vendorError = error?.vendorError;
|
|
337
337
|
if (httpStatus === undefined && vendorError === undefined)
|
|
@@ -339,7 +339,7 @@ export function shapeOnlyVendorCode(operation, httpStatus, error) {
|
|
|
339
339
|
if (error instanceof MaintenanceError)
|
|
340
340
|
return 'MAINTENANCE';
|
|
341
341
|
// An auth-looking response status can be attached to an SDK response-policy rejection.
|
|
342
|
-
if (
|
|
342
|
+
if (typedFault && (httpStatus === 401 || httpStatus === 403) &&
|
|
343
343
|
(!isAutotaskError(error) || error.category !== 'auth')) {
|
|
344
344
|
return 'AUTOTASK_ERROR';
|
|
345
345
|
}
|
|
@@ -381,8 +381,8 @@ export function typedErrorPayload(err, correlationId, secrets = [], directIdenti
|
|
|
381
381
|
const authFailure = shapeOnlyVendorError
|
|
382
382
|
? vendorCode === 'UNAUTHORIZED' || vendorCode === 'FORBIDDEN'
|
|
383
383
|
: isAuthFailure(err, directIdentity);
|
|
384
|
-
const
|
|
385
|
-
if (authFailure && !
|
|
384
|
+
const entityPermissionRefusal = directIdentity && isEntityReadPermissionRefusal(e);
|
|
385
|
+
if (authFailure && !entityPermissionRefusal)
|
|
386
386
|
return unauthorizedPayload(correlationId, vendorShapeDiagnostic(err, secrets));
|
|
387
387
|
const code = vendorCode ?? str(e.code) ?? (isAutotaskError(err) ? 'AUTOTASK_ERROR' : undefined) ?? 'INTERNAL_ERROR';
|
|
388
388
|
const url = str(e.url);
|
|
@@ -415,10 +415,12 @@ export function typedErrorPayload(err, correlationId, secrets = [], directIdenti
|
|
|
415
415
|
? 'No inventory location was visible to this API user at the requested ID.'
|
|
416
416
|
: 'No record was visible to this API user at the requested ID.';
|
|
417
417
|
}
|
|
418
|
-
else if (
|
|
419
|
-
payload.message = '
|
|
418
|
+
else if (entityPermissionRefusal) {
|
|
419
|
+
payload.message = operation?.startsWith('document_categories.') === true
|
|
420
|
+
? 'Autotask refused permission for this document category read (HTTP 403).'
|
|
421
|
+
: 'Autotask refused permission for this staff read (HTTP 403).';
|
|
420
422
|
}
|
|
421
|
-
else if (isStaffReadOperation(operation) && err instanceof ResponseRejectedError) {
|
|
423
|
+
else if ((operation?.startsWith('document_categories.') === true || isStaffReadOperation(operation)) && err instanceof ResponseRejectedError) {
|
|
422
424
|
payload.message = code === 'RESPONSE_TOO_LARGE' ? 'The Autotask response exceeded the SDK response size limit.'
|
|
423
425
|
: code === 'REDIRECT_BLOCKED' ? 'The SDK blocked an Autotask response redirect.'
|
|
424
426
|
: 'The SDK rejected the Autotask response under its response policy.';
|
|
@@ -442,7 +444,7 @@ export function typedErrorPayload(err, correlationId, secrets = [], directIdenti
|
|
|
442
444
|
if (sdkValidation)
|
|
443
445
|
note(payload, 'message', 'long');
|
|
444
446
|
const suggestedAction = str(e.suggestedAction);
|
|
445
|
-
if (
|
|
447
|
+
if (entityPermissionRefusal) {
|
|
446
448
|
payload.suggestedAction = "Have an Autotask administrator verify the API user's permissions and feature activation before retrying.";
|
|
447
449
|
}
|
|
448
450
|
else if (!shapeOnlyVendorError && suggestedAction !== undefined) {
|