fix(typedrequest): Add skipHooks flag to TypedRequest to optionally suppress global hooks for internal requests
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@api.global/typedrequest',
|
||||
version: '3.2.1',
|
||||
version: '3.2.2',
|
||||
description: 'A TypeScript library for making typed requests towards APIs, including facilities for handling requests, routing, and virtual stream handling.'
|
||||
}
|
||||
|
||||
@@ -33,6 +33,12 @@ export class TypedRequest<T extends plugins.typedRequestInterfaces.ITypedRequest
|
||||
|
||||
public method: string;
|
||||
|
||||
/**
|
||||
* When true, hooks will not be called for this request.
|
||||
* Use this for internal/logging requests to prevent infinite loops.
|
||||
*/
|
||||
public skipHooks: boolean = false;
|
||||
|
||||
/**
|
||||
* @param postEndPointArg
|
||||
* @param methodArg
|
||||
@@ -69,15 +75,17 @@ export class TypedRequest<T extends plugins.typedRequestInterfaces.ITypedRequest
|
||||
}
|
||||
});
|
||||
|
||||
// Hook: outgoing request
|
||||
callGlobalHook('onOutgoingRequest', {
|
||||
correlationId: payloadSending.correlation.id,
|
||||
method: this.method,
|
||||
direction: 'outgoing',
|
||||
phase: 'request',
|
||||
timestamp: requestStartTime,
|
||||
payload: fireArg,
|
||||
});
|
||||
// Hook: outgoing request (skip if this is an internal request)
|
||||
if (!this.skipHooks) {
|
||||
callGlobalHook('onOutgoingRequest', {
|
||||
correlationId: payloadSending.correlation.id,
|
||||
method: this.method,
|
||||
direction: 'outgoing',
|
||||
phase: 'request',
|
||||
timestamp: requestStartTime,
|
||||
payload: fireArg,
|
||||
});
|
||||
}
|
||||
|
||||
let payloadReceiving: plugins.typedRequestInterfaces.ITypedRequest;
|
||||
payloadReceiving = await this.postTrObject(payloadSending, useCacheArg);
|
||||
@@ -89,17 +97,19 @@ export class TypedRequest<T extends plugins.typedRequestInterfaces.ITypedRequest
|
||||
}
|
||||
});
|
||||
|
||||
// Hook: incoming response (for this outgoing request)
|
||||
callGlobalHook('onIncomingResponse', {
|
||||
correlationId: payloadSending.correlation.id,
|
||||
method: this.method,
|
||||
direction: 'incoming',
|
||||
phase: 'response',
|
||||
timestamp: Date.now(),
|
||||
durationMs: Date.now() - requestStartTime,
|
||||
payload: payloadReceiving?.response,
|
||||
error: payloadReceiving?.error?.text,
|
||||
});
|
||||
// Hook: incoming response (skip if this is an internal request)
|
||||
if (!this.skipHooks) {
|
||||
callGlobalHook('onIncomingResponse', {
|
||||
correlationId: payloadSending.correlation.id,
|
||||
method: this.method,
|
||||
direction: 'incoming',
|
||||
phase: 'response',
|
||||
timestamp: Date.now(),
|
||||
durationMs: Date.now() - requestStartTime,
|
||||
payload: payloadReceiving?.response,
|
||||
error: payloadReceiving?.error?.text,
|
||||
});
|
||||
}
|
||||
|
||||
return payloadReceiving.response;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user