Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
33165e8
build: enforce consistent file names
mrafnadeem-apimatic Jun 2, 2025
de4d337
build: enforce strict type checking
mrafnadeem-apimatic Jun 2, 2025
b17e31d
refactor: make oneOf discriminators type-safe
mrafnadeem-apimatic Jun 3, 2025
0f0849c
refactor: move common logic to typeUtils
mrafnadeem-apimatic Jun 3, 2025
d8dde36
refactor: fix types for anyOf discriminator
mrafnadeem-apimatic Jun 3, 2025
004b3da
refactor: use const union instead of strings
mrafnadeem-apimatic Jun 3, 2025
1fc39fd
refactor: update types to match func signature
mrafnadeem-apimatic Jun 3, 2025
bf05651
refactor: use generic to fix compiler error
mrafnadeem-apimatic Jun 4, 2025
8ad5cbe
test: validateAndMap for numberEnum
mrafnadeem-apimatic Jun 4, 2025
3af1e30
fix: compiler errors in tests
mrafnadeem-apimatic Jun 4, 2025
b442e3a
fix: compiler errors in core
mrafnadeem-apimatic Jun 4, 2025
804c29c
fix: compiler error in test-utilities
mrafnadeem-apimatic Jun 4, 2025
608628b
build: suppress type errors in auth adapter
mrafnadeem-apimatic Jun 4, 2025
d9f54c2
Revert "fix: compiler errors in core"
mrafnadeem-apimatic Jun 4, 2025
ccd36f4
build: disable unknown in catch variables
mrafnadeem-apimatic Jun 4, 2025
aa711a7
build: suppress errors in core
mrafnadeem-apimatic Jun 4, 2025
fd4488d
fix: handle compiler errors in tests
mrafnadeem-apimatic Jun 4, 2025
a3965ed
format: apiLogger test file
mrafnadeem-apimatic Jun 4, 2025
4564d77
revert: instanceof checks for errors in tests
mrafnadeem-apimatic Jun 4, 2025
3a0c8e5
Merge branch 'master' into build-strict-checking
mrafnadeem-apimatic Jul 17, 2025
f88e00a
Merge branch 'master' into build-strict-checking
mrafnadeem-apimatic Aug 18, 2025
ab02a56
fix: use type name instead of this
mrafnadeem-apimatic Aug 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ function findMatchingAuth<T extends string>(
return securityRequirements.find(
(andRequirements) =>
Object.keys(andRequirements).every(
// @ts-ignore TODO: REMOVE THIS COMMENT. DO NOT COPY.
// THIS WAS ONLY FOR MIGRATING UNCHECKED CODE TO STRICT TYPE CHECKING.
// As for the actual compiler error, TS does not support generic keys with the `in` operator.
// https://github.com/microsoft/TypeScript/issues/21732#issuecomment-1423655000
(key) => key in providerConfig && providerConfig[key]
) && Object.values(andRequirements).every((value) => value)
);
Expand All @@ -145,7 +149,11 @@ function getHttpInterceptorsForAuths<T extends string>(
): Array<HttpInterceptorInterface<RequestOptions | undefined>> {
return Object.entries(matchingRequirements).map(
([authProvider, authParam]) => {
// @ts-ignore TODO: REMOVE THIS COMMENT. DO NOT COPY.
// THIS WAS ONLY FOR MIGRATING UNCHECKED CODE TO STRICT TYPE CHECKING.
if (providerConfig[authProvider] !== undefined) {
// @ts-ignore TODO: REMOVE THIS COMMENT. DO NOT COPY.
// THIS WAS ONLY FOR MIGRATING UNCHECKED CODE TO STRICT TYPE CHECKING.
return providerConfig[authProvider](authParam);
} else {
return passThroughInterceptor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('test access token authentication scheme', () => {
const authenticationProvider = accessTokenAuthenticationProvider(config);
const handler = authenticationProvider(true);
const interceptor = [handler];
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
Expand All @@ -51,7 +51,7 @@ describe('test access token authentication scheme', () => {
const authenticationProvider = accessTokenAuthenticationProvider(config);
const handler = authenticationProvider(false);
const interceptor = [handler];
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('test basic authentication scheme', () => {
);
const handler = authenticationProvider(enableAuthentication);
const interceptor = [handler];
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('test composite authentication adapter with false or empty security req
const securityRequirements = false;
const provider = compositeAuthenticationProvider(authConfig);
const interceptor = [provider(securityRequirements)];
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
Expand All @@ -91,10 +91,10 @@ describe('test composite authentication adapter with false or empty security req
method: 'GET',
url: 'http://apimatic.hopto.org:3000/test/requestBuilder',
};
const securityRequirements = [];
const securityRequirements: any[] = [];
const provider = compositeAuthenticationProvider(authConfig);
const interceptor = [provider(securityRequirements)];
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
Expand Down Expand Up @@ -143,7 +143,7 @@ describe('test composite authentication adapter with missing credentials object
const securityRequirements = [{ apiKey: true }, { apiHeader: true }];
const provider = compositeAuthenticationProvider(authConfig);
const interceptor = [provider(securityRequirements)];
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
Expand Down Expand Up @@ -181,7 +181,7 @@ describe('test composite authentication adapter with missing credentials object
const securityRequirements = [{ apiKey: true }, { apiHeader: true }];
const provider = compositeAuthenticationProvider(authConfig);
const interceptor = [provider(securityRequirements)];
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
Expand Down Expand Up @@ -220,7 +220,7 @@ describe('test composite authentication adapter with missing credentials object
const securityRequirements = [{ apiKey: false }, { apiHeader: true }];
const provider = compositeAuthenticationProvider(authConfig);
const interceptor = [provider(securityRequirements)];
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
Expand Down Expand Up @@ -263,7 +263,7 @@ describe('test composite authentication adapter with missing credentials object
const securityRequirements = [{ apiKey: true }, { apiHeader: false }];
const provider = compositeAuthenticationProvider(authConfig);
const interceptor = [provider(securityRequirements)];
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
Expand Down Expand Up @@ -299,7 +299,7 @@ describe('test composite authentication adapter with missing credentials object
const securityRequirements = [{ apiKey: false }, { apiHeader: false }];
const provider = compositeAuthenticationProvider(authConfig);
const interceptor = [provider(securityRequirements)];
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
Expand Down Expand Up @@ -342,7 +342,7 @@ describe('test composite authentication adapter with missing credentials object
const securityRequirements = [{ apiKey: true, apiHeader: true }];
const provider = compositeAuthenticationProvider(authConfig);
const interceptor = [provider(securityRequirements)];
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
Expand Down Expand Up @@ -387,7 +387,7 @@ describe('test composite authentication adapter with missing credentials object
const securityRequirements = [{ apiKey: true, apiHeader: false }];
const provider = compositeAuthenticationProvider(authConfig);
const interceptor = [provider(securityRequirements)];
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
Expand Down Expand Up @@ -432,7 +432,7 @@ describe('test composite authentication adapter with missing credentials object
const securityRequirements = [{ apiKey: false, apiHeader: true }];
const provider = compositeAuthenticationProvider(authConfig);
const interceptor = [provider(securityRequirements)];
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
Expand Down Expand Up @@ -473,7 +473,7 @@ describe('test composite authentication adapter with missing credentials object
const securityRequirements = [{ apiKey: false, apiHeader: false }];
const provider = compositeAuthenticationProvider(authConfig);
const interceptor = [provider(securityRequirements)];
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
Expand Down Expand Up @@ -563,7 +563,7 @@ describe('test composite authentication adapter with security requirements combi
const securityRequirements = [{ accessToken: true }, { basicAuth: true }];
const provider = compositeAuthenticationProvider(authConfig);
const interceptor = [provider(securityRequirements)];
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
Expand All @@ -582,7 +582,7 @@ describe('test composite authentication adapter with security requirements combi
const securityRequirements = [{ accessToken: true }, { basicAuth: false }];
const provider = compositeAuthenticationProvider(authConfig);
const interceptor = [provider(securityRequirements)];
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
Expand All @@ -601,7 +601,7 @@ describe('test composite authentication adapter with security requirements combi
const securityRequirements = [{ accessToken: false }, { basicAuth: true }];
const provider = compositeAuthenticationProvider(authConfig);
const interceptor = [provider(securityRequirements)];
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
Expand All @@ -625,7 +625,7 @@ describe('test composite authentication adapter with security requirements combi
];
const provider = compositeAuthenticationProvider(authConfig);
const interceptor = [provider(securityRequirements)];
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
Expand All @@ -648,7 +648,7 @@ describe('test composite authentication adapter with security requirements combi
const securityRequirements = [{ accessToken: false, basicAuth: true }];
const provider = compositeAuthenticationProvider(authConfig);
const interceptor = [provider(securityRequirements)];
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
Expand All @@ -672,7 +672,7 @@ describe('test composite authentication adapter with security requirements combi
const securityRequirements = [{ accessToken: true, basicAuth: true }];
const provider = compositeAuthenticationProvider(authConfig);
const interceptor = [provider(securityRequirements)];
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
Expand All @@ -695,7 +695,7 @@ describe('test composite authentication adapter with security requirements combi
const securityRequirements = [{ accessToken: true, basicAuth: false }];
const provider = compositeAuthenticationProvider(authConfig);
const interceptor = [provider(securityRequirements)];
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
Expand All @@ -721,7 +721,7 @@ describe('test composite authentication adapter with security requirements combi
];
const provider = compositeAuthenticationProvider(authConfig);
const interceptor = [provider(securityRequirements)];
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
Expand Down Expand Up @@ -750,7 +750,7 @@ describe('test composite authentication adapter with security requirements combi
];
const provider = compositeAuthenticationProvider(authConfig);
const interceptor = [provider(securityRequirements)];
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
Expand All @@ -769,7 +769,7 @@ describe('test composite authentication adapter with security requirements combi
const securityRequirements = [{ oAuthACG: true, oAuthCCG: true }];
const provider = compositeAuthenticationProvider(authConfig);
const interceptor = [provider(securityRequirements)];
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
Expand Down Expand Up @@ -811,7 +811,7 @@ describe('test composite authentication adapter with security requirements combi
const securityRequirements = [{ oAuthACG: true }, { oAuthCCG: true }];
const provider = compositeAuthenticationProvider(auth1Config);
const interceptor = [provider(securityRequirements)];
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('test custom header authentication scheme', () => {
);
const handler = authenticationProvider(enableAuthentication);
const interceptor = [handler];
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('test custom query authentication scheme', () => {
);
const handler = authenticationProvider(enableAuthentication);
const interceptor = [handler];
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('test access token authentication scheme', () => {
it('should test access token auth with enabled authentication', async () => {
const handler = noneAuthenticationProvider();
const interceptor = [handler];
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response };
};
const executor = callHttpInterceptors(interceptor, client);
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/http/httpInterceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ export function callHttpInterceptors<T>(
client: HttpCallExecutor<T>
): HttpCallExecutor<T> {
return (request, options) =>
// @ts-ignore TODO: REMOVE THIS COMMENT. DO NOT COPY.
// THIS WAS ONLY FOR MIGRATING UNCHECKED CODE TO STRICT TYPE CHECKING.
combineHttpInterceptors(interceptors)(request, options, client);
}
18 changes: 12 additions & 6 deletions packages/core/src/http/requestBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,13 @@ export interface RequestBuilder<BaseUrlParamType, AuthParams> {
): RequestBuilder<BaseUrlParamType, AuthParams>;
paginate<TItem, TPagedResponse>(
createPagedIterable: (
req: this,
req: RequestBuilder<BaseUrlParamType, AuthParams>,
updater: (
req: this
) => (pointer: string | null, setter: (value: any) => any) => this
req: RequestBuilder<BaseUrlParamType, AuthParams>
) => (
pointer: string | null,
setter: (value: any) => any
) => RequestBuilder<BaseUrlParamType, AuthParams>
) => PagedAsyncIterable<TItem, TPagedResponse>
): PagedAsyncIterable<TItem, TPagedResponse>;
call(requestOptions?: RequestOptions): Promise<ApiResponse<void>>;
Expand Down Expand Up @@ -555,10 +558,13 @@ export class DefaultRequestBuilder<BaseUrlParamType, AuthParams>
}
public paginate<TItem, TPagedResponse>(
createPagedIterable: (
req: this,
req: RequestBuilder<BaseUrlParamType, AuthParams>,
updater: (
req: this
) => (pointer: string | null, setter: (value: any) => any) => this
req: RequestBuilder<BaseUrlParamType, AuthParams>
) => (
pointer: string | null,
setter: (value: any) => any
) => RequestBuilder<BaseUrlParamType, AuthParams>
) => PagedAsyncIterable<TItem, TPagedResponse>
): PagedAsyncIterable<TItem, TPagedResponse> {
return createPagedIterable(this, (req) =>
Expand Down
19 changes: 15 additions & 4 deletions packages/core/test/http/apiLogger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { callHttpInterceptors } from '../../src/http/httpInterceptor';
import { NullLogger } from '../../src/logger/nullLogger';
import { mergeLoggingOptions } from '../../src/logger/defaultLoggingConfiguration';

let loggerSpy;
let loggerSpy: jest.SpyInstance<
void,
[message?: any, ...optionalParams: any[]]
>;
beforeEach(() => {
// Reset the spy on console.log() before each test
loggerSpy = jest.spyOn(console, 'log').mockImplementation();
Expand Down Expand Up @@ -304,7 +307,11 @@ describe('APILogger with NullLogging', () => {

function mockInterceptor(loggingOpt: LoggingOptions) {
const apiLogger = new ApiLogger(loggingOpt);
return async (req, options, next) => {
return async (
req: HttpRequest,
options: any,
next: (arg0: any, arg1: any) => any
) => {
apiLogger.logRequest(req);
const context = await next(req, options);
apiLogger.logResponse(context.response);
Expand Down Expand Up @@ -344,14 +351,18 @@ function mockResponse(): HttpResponse {
}

async function mockClient(loggingOpts: LoggingOptions) {
const client = async (req) => {
const client = async (req: HttpRequest) => {
return { request: req, response: mockResponse() };
};
const executor = callHttpInterceptors([mockInterceptor(loggingOpts)], client);
return await executor(mockRequest(), undefined);
}

function expectLogsToBeLogged(logSpy, expectedConsoleLogs, index = 0) {
function expectLogsToBeLogged(
logSpy: jest.SpyInstance<void, [message?: any, ...optionalParams: any[]]>,
expectedConsoleLogs: string | any[],
index = 0
) {
for (let i = index; i < expectedConsoleLogs.length; i++) {
expect(logSpy.mock.calls[i][0]).toEqual(expectedConsoleLogs[i]);
}
Expand Down
Loading