Skip to content

Commit

Permalink
chore: Enable typescript strict mode (aws-observability#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
qhanam authored Sep 28, 2022
1 parent b775969 commit e858cf9
Show file tree
Hide file tree
Showing 25 changed files with 282 additions and 207 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ module.exports = {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-misused-new': 'error',
'@typescript-eslint/no-namespace': 'error',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-parameter-properties': 'off',
'@typescript-eslint/no-shadow': [
'off',
Expand Down Expand Up @@ -128,6 +129,7 @@ module.exports = {
'@typescript-eslint/require-await': 'warn',
'@typescript-eslint/no-unsafe-member-access': 'warn',
'@typescript-eslint/no-this-alias': 'warn',
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
'@typescript-eslint/member-ordering': 'off',
'@typescript-eslint/triple-slash-reference': [
'error',
Expand Down
123 changes: 77 additions & 46 deletions package-lock.json

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

22 changes: 19 additions & 3 deletions src/CommandQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ import { CredentialProvider, Credentials } from '@aws-sdk/types';
import { PartialConfig, Orchestration } from './orchestration/Orchestration';
import { getRemoteConfig } from './remote-config/remote-config';

export type CommandFunction = (payload?: any) => void;

interface CommandFunctions {
setAwsCredentials: CommandFunction;
recordPageView: CommandFunction;
recordError: CommandFunction;
registerDomEvents: CommandFunction;
dispatch: CommandFunction;
dispatchBeacon: CommandFunction;
enable: CommandFunction;
disable: CommandFunction;
allowCookies: CommandFunction;
}

/**
* An AWS RUM Client command.
*/
Expand Down Expand Up @@ -32,7 +46,7 @@ export type AwsRumClientInit = {
export class CommandQueue {
private orchestration!: Orchestration;

private commandHandlerMap = {
private commandHandlerMap: CommandFunctions = {
setAwsCredentials: (
payload: Credentials | CredentialProvider
): void => {
Expand Down Expand Up @@ -93,7 +107,9 @@ export class CommandQueue {
* Add a command to the command queue.
*/
public async push(command: Command) {
const commandHandler = this.commandHandlerMap[command.c];
const commandHandler = this.commandHandlerMap[
command.c as keyof CommandFunctions
];
if (commandHandler) {
commandHandler(command.p);
} else {
Expand All @@ -110,7 +126,7 @@ export class CommandQueue {
);

// Overwrite the global API to use CommandQueue
window[awsRum.n] = (c: string, p: any) => {
(window as any)[awsRum.n] = (c: string, p: any) => {
this.push({ c, p });
};

Expand Down
10 changes: 5 additions & 5 deletions src/dispatch/Authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class Authentication {
private credentials: Credentials | undefined;

constructor(config: Config) {
const region: string = config.identityPoolId.split(':')[0];
const region: string = config.identityPoolId!.split(':')[0];
this.config = config;
this.stsClient = new StsClient({
fetchRequestHandler: new FetchHttpHandler(),
Expand Down Expand Up @@ -70,7 +70,7 @@ export class Authentication {
// The credentials have expired.
return reject();
}
resolve(this.credentials);
resolve(this.credentials!);
});
};

Expand All @@ -83,7 +83,7 @@ export class Authentication {
return new Promise<Credentials>((resolve, reject) => {
let credentials;
try {
credentials = JSON.parse(localStorage.getItem(CRED_KEY));
credentials = JSON.parse(localStorage.getItem(CRED_KEY)!);
} catch (e) {
// Error retrieving, decoding or parsing the cred string -- abort
return reject();
Expand Down Expand Up @@ -113,14 +113,14 @@ export class Authentication {
private AnonymousCognitoCredentialsProvider = async (): Promise<Credentials> => {
return this.cognitoIdentityClient
.getId({
IdentityPoolId: this.config.identityPoolId
IdentityPoolId: this.config.identityPoolId as string
})
.then((getIdResponse) =>
this.cognitoIdentityClient.getOpenIdToken(getIdResponse)
)
.then((getOpenIdTokenResponse) =>
this.stsClient.assumeRoleWithWebIdentity({
RoleArn: this.config.guestRoleArn,
RoleArn: this.config.guestRoleArn as string,
RoleSessionName: 'cwr',
WebIdentityToken: getOpenIdTokenResponse.Token
})
Expand Down
6 changes: 3 additions & 3 deletions src/dispatch/CognitoIdentityClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class CognitoIdentityClient {
response.body
.getReader()
.read()
.then(({ value }) =>
.then(({ value }: { value: number[] }) =>
JSON.parse(String.fromCharCode.apply(null, value))
)
)
Expand All @@ -76,7 +76,7 @@ export class CognitoIdentityClient {
response.body
.getReader()
.read()
.then(({ value }) =>
.then(({ value }: { value: number[] }) =>
JSON.parse(String.fromCharCode.apply(null, value))
)
)
Expand All @@ -100,7 +100,7 @@ export class CognitoIdentityClient {
return response.body
.getReader()
.read()
.then(({ value }) => {
.then(({ value }: { value: number[] }) => {
const { IdentityId, Credentials } = JSON.parse(
String.fromCharCode.apply(null, value)
);
Expand Down
Loading

0 comments on commit e858cf9

Please sign in to comment.