Skip to content

Commit

Permalink
chore: cleanup doc comments in code
Browse files Browse the repository at this point in the history
  • Loading branch information
andrueastman committed Oct 30, 2024
1 parent 0536e6b commit 82bd4af
Show file tree
Hide file tree
Showing 45 changed files with 312 additions and 426 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import { type AuthenticationProvider } from "./authenticationProvider";

/** This authentication provider does not perform any authentication. */
export class AnonymousAuthenticationProvider implements AuthenticationProvider {
public authenticateRequest = (
_: RequestInformation,
_2?: Record<string, unknown>,
): Promise<void> => {
public authenticateRequest = (_: RequestInformation, _2?: Record<string, unknown>): Promise<void> => {
return Promise.resolve();
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export function validateProtocol(url: string): void {
}
}


/**
* Checks if the window url starts with https.
* @returns True if the window url starts with https, false otherwise.
Expand Down
5 changes: 1 addition & 4 deletions packages/abstractions/src/multipartBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,7 @@ export const serializeMultipartBody = (writer: SerializationWriter, multipartBod
writer.writeStringValue(undefined, "\r\n");
};

export const deserializeIntoMultipartBody = (

_: Partial<MultipartBody> | undefined = new MultipartBody(),
): Record<string, (node: ParseNode) => void> => {
export const deserializeIntoMultipartBody = (_: Partial<MultipartBody> | undefined = new MultipartBody()): Record<string, (node: ParseNode) => void> => {
throw new Error("Not implemented");
};
export const createMessageFromDiscriminatorValue = (parseNode: ParseNode | undefined) => {
Expand Down
10 changes: 3 additions & 7 deletions packages/abstractions/src/requestInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class RequestInformation implements RequestInformationSetContent {
* Sets the request body from a model with the specified content type.
* @param requestAdapter The adapter service to get the serialization writer from.
* @param contentType the content type.
* @param value the models.
* @param value the models.
* @param modelSerializerFunction the serialization function for the model type.
*/
public setContentFromParsable = <T extends Parsable>(requestAdapter?: RequestAdapter, contentType?: string, value?: T[] | T, modelSerializerFunction?: ModelSerializerFunction<T>): void => {
Expand All @@ -154,11 +154,7 @@ export class RequestInformation implements RequestInformationSetContent {

if (Array.isArray(value)) {
span.setAttribute(RequestInformation.requestTypeKey, "object[]");
writer.writeCollectionOfObjectValues(
undefined,
value,
modelSerializerFunction,
);
writer.writeCollectionOfObjectValues(undefined, value, modelSerializerFunction);
} else {
span.setAttribute(RequestInformation.requestTypeKey, "object");
writer.writeObjectValue(undefined, value, modelSerializerFunction);
Expand Down Expand Up @@ -187,7 +183,7 @@ export class RequestInformation implements RequestInformationSetContent {
* Sets the request body from a model with the specified content type.
* @param requestAdapter The adapter service to get the serialization writer from.
* @param contentType the content type.
* @param value the scalar values to serialize.
* @param value the scalar values to serialize.
*/
public setContentFromScalar = <T extends PrimitiveTypesForDeserializationType>(requestAdapter: RequestAdapter | undefined, contentType: string | undefined, value: T[] | T): void => {
trace.getTracer(RequestInformation.tracerKey).startActiveSpan("setContentFromScalar", (span) => {
Expand Down
1 change: 0 additions & 1 deletion packages/abstractions/src/serialization/untypedNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* -------------------------------------------------------------------------------------------
*/


import type { Parsable } from "./parsable";
import type { ParseNode } from "./parseNode";
import type { SerializationWriter } from "./serializationWriter";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { type ObservabilityOptions, ObservabilityOptionsImpl } from "./observabi
/** Access token provider that leverages the Azure Identity library to retrieve an access token. */
export class AzureIdentityAccessTokenProvider implements AccessTokenProvider {
/**
*@constructor
*@param credentials The tokenCredential implementation to use for authentication.
*@param scopes The scopes to use for authentication.
*@param options The options to use for authentication.
Expand Down Expand Up @@ -55,15 +54,15 @@ export class AzureIdentityAccessTokenProvider implements AccessTokenProvider {
}
});
};
private getAuthorizationTokenInternal = async (url?: string, additionalAuthenticationContext?: Record<string, unknown>, span?: Span): Promise<string> => {
private readonly getAuthorizationTokenInternal = async (url?: string, additionalAuthenticationContext?: Record<string, unknown>, span?: Span): Promise<string> => {
if (!url || !this.allowedHostsValidator.isUrlHostValid(url)) {
span?.setAttribute("com.microsoft.kiota.authentication.is_url_valid", false);
return "";
}
validateProtocol(url);
span?.setAttribute("com.microsoft.kiota.authentication.is_url_valid", true);
let decodedClaims = "";
if (additionalAuthenticationContext && additionalAuthenticationContext[AzureIdentityAccessTokenProvider.claimsKey]) {
if (additionalAuthenticationContext?.[AzureIdentityAccessTokenProvider.claimsKey]) {
const rawClaims = additionalAuthenticationContext[AzureIdentityAccessTokenProvider.claimsKey] as string;
decodedClaims = inNodeEnv() ? Buffer.from(rawClaims, "base64").toString() : atob(rawClaims);
}
Expand All @@ -81,7 +80,7 @@ export class AzureIdentityAccessTokenProvider implements AccessTokenProvider {
const result = await this.credentials.getToken(this.scopes, localOptions);
return result?.token ?? "";
};
private getSchemeAndHostFromUrl = (url: string): string[] => {
private readonly getSchemeAndHostFromUrl = (url: string): string[] => {
const urlParts = url.split("://");
if (urlParts.length === 0) {
// relative url
Expand All @@ -96,13 +95,13 @@ export class AzureIdentityAccessTokenProvider implements AccessTokenProvider {
throw new Error("invalid url");
}
};
private getSchemeFromLocation = (): string => {
private readonly getSchemeFromLocation = (): string => {
if (!inNodeEnv()) {
return window.location.protocol.replace(":", "");
}
return "";
};
private getHostFromLocation = (): string => {
private readonly getHostFromLocation = (): string => {
if (!inNodeEnv()) {
return window.location.host;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export class AzureAdSpfxAccessTokenProvider implements AccessTokenProvider {
private readonly allowedHostsValidator: AllowedHostsValidator;

/**
*@constructor
*@param tokenProvider The tokenProvider provided by the SharePoint framework
*@param applicationIdUri The application ID URI of the Azure AD App that we want to Authenticate
*@param allowedHosts The allowed hosts to use for authentication.
*@param useCachedToken Allows the developer to specify if cached tokens should be returned.
*@param observabilityOptions The observability options to use for authentication.
*/
public constructor(
private readonly tokenProvider: AadTokenProvider,
Expand Down Expand Up @@ -52,9 +52,9 @@ export class AzureAdSpfxAccessTokenProvider implements AccessTokenProvider {
}
});
};
private getAuthorizationTokenInternal = async (
private readonly getAuthorizationTokenInternal = async (
url?: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars

additionalAuthenticationContext?: Record<string, unknown>,
span?: Span,
): Promise<string> => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import { type ObservabilityOptions, ObservabilityOptionsImpl } from "./observabi

export class AzureAdSpfxAuthenticationProvider extends BaseBearerTokenAuthenticationProvider {
/**
*@constructor
*@param tokenProvider The tokenProvider provided by the SharePoint framework
*@param applicationIdUri The application ID URI of the Azure AD App that we want to Authenticate
*@param allowedHosts The allowed hosts to use for authentication.
*@param useCachedToken Allows the developer to specify if cached tokens should be returned.
*@param observabilityOptions The observability options to use.
*/
public constructor(tokenProvider: AadTokenProvider, applicationIdUri: string, allowedHosts: Set<string> = new Set<string>(["graph.microsoft.com", "graph.microsoft.us", "dod-graph.microsoft.us", "graph.microsoft.de", "microsoftgraph.chinacloudapi.cn", "canary.graph.microsoft.com"]), useCachedToken?: boolean, observabilityOptions: ObservabilityOptions = new ObservabilityOptionsImpl()) {
super(new AzureAdSpfxAccessTokenProvider(tokenProvider, applicationIdUri, allowedHosts, useCachedToken, observabilityOptions));
Expand Down
2 changes: 0 additions & 2 deletions packages/bundle/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@
* -------------------------------------------------------------------------------------------
*/



export * from "./defaultRequestAdapter";
54 changes: 28 additions & 26 deletions packages/http/fetch/src/fetchRequestAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ export class FetchRequestAdapter implements RequestAdapter {
this.observabilityOptions = new ObservabilityOptionsImpl(observabilityOptions);
}
}
private getResponseContentType = (response: Response): string | undefined => {
private readonly getResponseContentType = (response: Response): string | undefined => {
const header = response.headers.get("content-type")?.toLowerCase();
if (!header) return undefined;
const segments = header.split(";");
if (segments.length === 0) return undefined;
else return segments[0];
};
private getResponseHandler = (response: RequestInformation): ResponseHandler | undefined => {
private readonly getResponseHandler = (response: RequestInformation): ResponseHandler | undefined => {
const options = response.getRequestOptions();
const responseHandlerOption = options[ResponseHandlerOptionKey] as ResponseHandlerOption;
return responseHandlerOption?.responseHandler;
Expand Down Expand Up @@ -157,7 +157,7 @@ export class FetchRequestAdapter implements RequestAdapter {
}
});
};
private startTracingSpan = <T>(requestInfo: RequestInformation, methodName: string, callback: (arg0: Span) => Promise<T>): Promise<T> => {
private readonly startTracingSpan = <T>(requestInfo: RequestInformation, methodName: string, callback: (arg0: Span) => Promise<T>): Promise<T> => {
const urlTemplate = decodeURIComponent(requestInfo.urlTemplate ?? "");
const telemetryPathValue = urlTemplate.replace(/\{\?[^}]+\}/gi, "");
return trace.getTracer(this.observabilityOptions.getTracerInstrumentationName()).startActiveSpan(`${methodName} - ${telemetryPathValue}`, async (span) => {
Expand Down Expand Up @@ -221,7 +221,6 @@ export class FetchRequestAdapter implements RequestAdapter {
if (this.shouldReturnUndefined(response)) return undefined;
switch (responseType) {
case "ArrayBuffer":
// eslint-disable-next-line no-case-declarations
if (!response.body) {
return undefined;
}
Expand Down Expand Up @@ -264,7 +263,7 @@ export class FetchRequestAdapter implements RequestAdapter {
} finally {
span.end();
}
}) as Promise<ResponseType | undefined>;
});
};
public sendNoResponseContent = (requestInfo: RequestInformation, errorMappings: ErrorMappings | undefined): Promise<void> => {
if (!requestInfo) {
Expand Down Expand Up @@ -308,7 +307,7 @@ export class FetchRequestAdapter implements RequestAdapter {
try {
span.setAttribute(FetchRequestAdapter.responseTypeAttributeKey, "enum");
const result = rootNode.getEnumValue(enumObject);
return result as unknown as EnumObject[keyof EnumObject];
return result as EnumObject[keyof EnumObject];
} finally {
deserializeSpan.end();
}
Expand Down Expand Up @@ -356,15 +355,15 @@ export class FetchRequestAdapter implements RequestAdapter {
}
});
};
public enableBackingStore = (backingStoreFactory?: BackingStoreFactory | undefined): void => {
public enableBackingStore = (backingStoreFactory?: BackingStoreFactory): void => {
this.parseNodeFactory = enableBackingStoreForParseNodeFactory(this.parseNodeFactory);
this.serializationWriterFactory = enableBackingStoreForSerializationWriterFactory(this.serializationWriterFactory);
if (!this.serializationWriterFactory || !this.parseNodeFactory) throw new Error("unable to enable backing store");
if (backingStoreFactory) {
BackingStoreFactorySingleton.instance = backingStoreFactory;
}
};
private getRootParseNode = (response: Response): Promise<ParseNode> => {
private readonly getRootParseNode = (response: Response): Promise<ParseNode> => {
return trace.getTracer(this.observabilityOptions.getTracerInstrumentationName()).startActiveSpan("getRootParseNode", async (span) => {
try {
const payload = await response.arrayBuffer();
Expand All @@ -377,18 +376,21 @@ export class FetchRequestAdapter implements RequestAdapter {
}
});
};
private shouldReturnUndefined = (response: Response): boolean => {
private readonly shouldReturnUndefined = (response: Response): boolean => {
return response.status === 204 || !response.body;
};
/** purges the response body if it hasn't been read to release the connection to the server */
private purgeResponseBody = async (response: Response): Promise<void> => {
/**
* purges the response body if it hasn't been read to release the connection to the server
* @param response the response to purge
*/
private readonly purgeResponseBody = async (response: Response): Promise<void> => {
if (!response.bodyUsed && response.body) {
await response.arrayBuffer();
}
};
public static readonly errorMappingFoundAttributeName = "com.microsoft.kiota.error.mapping_found";
public static readonly errorBodyFoundAttributeName = "com.microsoft.kiota.error.body_found";
private throwIfFailedResponse = (response: Response, errorMappings: ErrorMappings | undefined, spanForAttributes: Span): Promise<void> => {
private readonly throwIfFailedResponse = (response: Response, errorMappings: ErrorMappings | undefined, spanForAttributes: Span): Promise<void> => {
return trace.getTracer(this.observabilityOptions.getTracerInstrumentationName()).startActiveSpan("throwIfFailedResponse", async (span) => {
try {
if (response.ok) return;
Expand All @@ -415,17 +417,17 @@ export class FetchRequestAdapter implements RequestAdapter {
spanForAttributes.setAttribute(FetchRequestAdapter.errorMappingFoundAttributeName, true);

const rootNode = await this.getRootParseNode(response);
let error = trace.getTracer(this.observabilityOptions.getTracerInstrumentationName()).startActiveSpan("getObjectValue", (deserializeSpan) => {
let deserializedError = trace.getTracer(this.observabilityOptions.getTracerInstrumentationName()).startActiveSpan("getObjectValue", (deserializeSpan) => {
try {
return rootNode.getObjectValue(factory);
} finally {
deserializeSpan.end();
}
});
spanForAttributes.setAttribute(FetchRequestAdapter.errorBodyFoundAttributeName, !!error);
spanForAttributes.setAttribute(FetchRequestAdapter.errorBodyFoundAttributeName, !!deserializedError);

if (!error) error = new DefaultApiError("unexpected error type" + typeof error) as unknown as Parsable;
const errorObject = error as ApiError;
if (!deserializedError) deserializedError = new DefaultApiError("unexpected error type" + typeof deserializedError) as unknown as Parsable;
const errorObject = deserializedError as ApiError;
errorObject.responseStatusCode = statusCode;
errorObject.responseHeaders = responseHeaders;
spanForAttributes.recordException(errorObject);
Expand All @@ -435,7 +437,7 @@ export class FetchRequestAdapter implements RequestAdapter {
}
});
};
private getHttpResponseMessage = (requestInfo: RequestInformation, spanForAttributes: Span, claims?: string): Promise<Response> => {
private readonly getHttpResponseMessage = (requestInfo: RequestInformation, spanForAttributes: Span, claims?: string): Promise<Response> => {
return trace.getTracer(this.observabilityOptions.getTracerInstrumentationName()).startActiveSpan("getHttpResponseMessage", async (span) => {
try {
if (!requestInfo) {
Expand All @@ -444,7 +446,7 @@ export class FetchRequestAdapter implements RequestAdapter {
this.setBaseUrlForRequestInformation(requestInfo);
const additionalContext = {} as Record<string, unknown>;
if (claims) {
additionalContext["claims"] = claims;
additionalContext.claims = claims;
}
await this.authenticationProvider.authenticateRequest(requestInfo, additionalContext);
const request = await this.getRequestFromRequestInformation(requestInfo, spanForAttributes);
Expand Down Expand Up @@ -473,7 +475,7 @@ export class FetchRequestAdapter implements RequestAdapter {
});
};
public static readonly authenticateChallengedEventKey = "com.microsoft.kiota.authenticate_challenge_received";
private retryCAEResponseIfRequired = async (requestInfo: RequestInformation, response: Response, spanForAttributes: Span, claims?: string) => {
private readonly retryCAEResponseIfRequired = async (requestInfo: RequestInformation, response: Response, spanForAttributes: Span, claims?: string) => {
return trace.getTracer(this.observabilityOptions.getTracerInstrumentationName()).startActiveSpan("retryCAEResponseIfRequired", async (span) => {
try {
const responseClaims = this.getClaimsFromResponse(response, claims);
Expand All @@ -489,7 +491,7 @@ export class FetchRequestAdapter implements RequestAdapter {
}
});
};
private getClaimsFromResponse = (response: Response, claims?: string) => {
private readonly getClaimsFromResponse = (response: Response, claims?: string) => {
if (response.status === 401 && !claims) {
// avoid infinite loop, we only retry once
// no need to check for the content since it's an array and it doesn't need to be rewound
Expand All @@ -506,16 +508,16 @@ export class FetchRequestAdapter implements RequestAdapter {
}
return undefined;
};
private setBaseUrlForRequestInformation = (requestInfo: RequestInformation): void => {
requestInfo.pathParameters["baseurl"] = this.baseUrl;
private readonly setBaseUrlForRequestInformation = (requestInfo: RequestInformation): void => {
requestInfo.pathParameters.baseurl = this.baseUrl;
};
private getRequestFromRequestInformation = (requestInfo: RequestInformation, spanForAttributes: Span): Promise<RequestInit> => {
return trace.getTracer(this.observabilityOptions.getTracerInstrumentationName()).startActiveSpan("getRequestFromRequestInformation", async (span) => {
private readonly getRequestFromRequestInformation = (requestInfo: RequestInformation, spanForAttributes: Span): Promise<RequestInit> => {
return trace.getTracer(this.observabilityOptions.getTracerInstrumentationName()).startActiveSpan("getRequestFromRequestInformation", (span) => {
try {
const method = requestInfo.httpMethod?.toString();
const uri = requestInfo.URL;
spanForAttributes.setAttribute("http.request.method", method ?? "");
const uriContainsScheme = uri.indexOf("://") > -1;
const uriContainsScheme = uri.includes("://");
const schemeSplatUri = uri.split("://");
if (uriContainsScheme) {
spanForAttributes.setAttribute("server.address", schemeSplatUri[0]);
Expand Down Expand Up @@ -548,7 +550,7 @@ export class FetchRequestAdapter implements RequestAdapter {
}
});
};
private foldHeaderValue = (value: string[] | null): string => {
private readonly foldHeaderValue = (value: string[] | null): string => {
if (!value || value.length < 1) {
return "";
} else if (value.length === 1) {
Expand Down
Loading

0 comments on commit 82bd4af

Please sign in to comment.