Compare commits

..

2 Commits

4 changed files with 38 additions and 22 deletions

View File

@@ -1,5 +1,11 @@
# Changelog
## 2025-12-04 - 3.2.2 - fix(typedrequest)
Add skipHooks flag to TypedRequest to optionally suppress global hooks for internal requests
- Introduce public skipHooks boolean on TypedRequest (default false) with documentation comment explaining it should be used for internal/logging requests to prevent infinite loops.
- Guard calls to global hooks (onOutgoingRequest and onIncomingResponse) in TypedRequest.fire() so hooks are not invoked when skipHooks is true.
## 2025-12-04 - 3.2.1 - fix(typedrouter)
Use globalThis-backed globalHooks for TypedRouter to enable cross-bundle sharing; fix merging and clearing of global hooks.

View File

@@ -1,6 +1,6 @@
{
"name": "@api.global/typedrequest",
"version": "3.2.1",
"version": "3.2.2",
"private": false,
"description": "A TypeScript library for making typed requests towards APIs, including facilities for handling requests, routing, and virtual stream handling.",
"main": "dist_ts/index.js",

View File

@@ -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.'
}

View File

@@ -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;
}