Skip to content

Commit

Permalink
Revert "ApiClientConfigurator: getCustomMiddleware"
Browse files Browse the repository at this point in the history
  • Loading branch information
ksvirkou-hubspot authored Jan 27, 2025
1 parent b329900 commit e451950
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 48 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 0 additions & 41 deletions src/configuration/ApiClientConfigurator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,50 +112,9 @@ export class ApiClientConfigurator {
)
}

if (config.middleware) {
middleware.push(
...this.getCustomMiddleware<
RequestContextType,
ResponseContextType,
ObservableRequestContextType,
ObservableResponseContextType
>(config, observableRequestContextParam, observableResponseContextParam),
)
}

return middleware
}

protected static getCustomMiddleware<
RequestContextType extends IRequestContext,
ResponseContextType,
ObservableRequestContextType,
ObservableResponseContextType,
>(
config: IConfiguration,
observableRequestContextParam: new (promise: Promise<RequestContextType>) => ObservableRequestContextType,
observableResponseContextParam: new (promise: Promise<ResponseContextType>) => ObservableResponseContextType,
) {
return (
config.middleware
?.filter((m) => m.pre || m.post)
.map((m) => ({
pre: (context: RequestContextType): ObservableRequestContextType => {
if (m.pre && typeof m.pre === 'function') {
return new observableRequestContextParam(Promise.resolve(m.pre(context) as RequestContextType))
}
return new observableRequestContextParam(Promise.resolve(context))
},
post: (context: ResponseContextType): ObservableResponseContextType => {
if (m.post && typeof m.post === 'function') {
return new observableResponseContextParam(Promise.resolve(m.post(context) as ResponseContextType))
}
return new observableResponseContextParam(Promise.resolve(context))
},
})) ?? []
)
}

protected static getHeaderMiddleware<
RequestContextType extends IRequestContext,
ResponseContextType,
Expand Down
4 changes: 0 additions & 4 deletions src/configuration/IConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,4 @@ export default interface IConfiguration {
limiterOptions?: Bottleneck.ConstructorOptions
limiterJobOptions?: Bottleneck.JobOptions
httpAgent?: http.Agent | https.Agent
middleware?: Array<{
pre(ctx: unknown): unknown
post(ctx: unknown): unknown
}>
}

0 comments on commit e451950

Please sign in to comment.