Skip to content

Commit 1ebb6ad

Browse files
authored
[MOB-11554] Resolve lint warnings (#506)
* [MOB-11554] Resolve lint warnings in Users * [MOB-11554] Resolve lint warnings in Commerce * [MOB-11554] Resolve lint warnings in EventsForm * [MOB-11554] Resolve lint warnings in EmbeddedMsgsImpressionTracker * [MOB-11554] Resolve lint warnings in EmbeddedMsgs * [MOB-11554] Resolve lint warnings in EmbeddedForm * [MOB-11554] Clean up lint disables
1 parent 76f6c0b commit 1ebb6ad

11 files changed

Lines changed: 83 additions & 67 deletions

File tree

react-example/src/components/EmbeddedForm.tsx

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
import { FC, FormEvent, useState } from 'react';
1+
/* eslint-disable no-console */
22
import {
33
IterableEmbeddedManager,
44
IterableEmbeddedMessageUpdateHandler,
5-
trackEmbeddedSession,
6-
trackEmbeddedReceived,
5+
IterableResponse,
76
trackEmbeddedClick,
8-
trackEmbeddedDismiss
7+
trackEmbeddedDismiss,
8+
trackEmbeddedReceived,
9+
trackEmbeddedSession
910
} from '@iterable/web-sdk';
11+
import { AxiosError, AxiosResponse, isAxiosError } from 'axios';
12+
import { FC, FormEvent, useState } from 'react';
1013
import { v4 as uuidv4 } from 'uuid';
11-
import { TextField } from './TextField';
1214
import {
13-
StyledButton,
1415
EndpointWrapper,
1516
Form,
1617
Heading,
17-
Response
18+
Response,
19+
StyledButton
1820
} from '../views/Components.styled';
21+
import { TextField } from './TextField';
1922

2023
interface Props {
2124
endpointName: string;
@@ -63,8 +66,10 @@ export const EmbeddedForm: FC<Props> = ({
6366
await embeddedManager.syncMessages('my-website', () =>
6467
console.log('Synced message')
6568
);
66-
} catch (error: any) {
67-
setTrackResponse(JSON.stringify(error?.response?.data));
69+
} catch (error: unknown) {
70+
setTrackResponse(
71+
JSON.stringify(isAxiosError(error) ? error.response?.data : error)
72+
);
6873
}
6974
};
7075

@@ -80,11 +85,11 @@ export const EmbeddedForm: FC<Props> = ({
8085
};
8186

8287
trackEmbeddedReceived(receivedMessage.messageId, 'my-website')
83-
.then((response: any) => {
88+
.then((response: AxiosResponse<IterableResponse>) => {
8489
setTrackResponse(JSON.stringify(response.data));
8590
setTrackingEvent(false);
8691
})
87-
.catch((error: any) => {
92+
.catch((error: AxiosError<IterableResponse>) => {
8893
setTrackResponse(JSON.stringify(error.response.data));
8994
setTrackingEvent(false);
9095
});
@@ -111,11 +116,11 @@ export const EmbeddedForm: FC<Props> = ({
111116
targetUrl,
112117
appPackageName
113118
})
114-
.then((response: any) => {
119+
.then((response: AxiosResponse<IterableResponse>) => {
115120
setTrackResponse(JSON.stringify(response.data));
116121
setTrackingEvent(false);
117122
})
118-
.catch((error: any) => {
123+
.catch((error: AxiosError<IterableResponse>) => {
119124
setTrackResponse(JSON.stringify(error.response.data));
120125
setTrackingEvent(false);
121126
});
@@ -139,11 +144,11 @@ export const EmbeddedForm: FC<Props> = ({
139144
};
140145

141146
trackEmbeddedDismiss(sessionData)
142-
.then((response: any) => {
147+
.then((response: AxiosResponse<IterableResponse>) => {
143148
setTrackResponse(JSON.stringify(response.data));
144149
setTrackingEvent(false);
145150
})
146-
.catch((error: any) => {
151+
.catch((error: AxiosError<IterableResponse>) => {
147152
setTrackResponse(JSON.stringify(error.response.data));
148153
setTrackingEvent(false);
149154
});
@@ -177,11 +182,11 @@ export const EmbeddedForm: FC<Props> = ({
177182
};
178183

179184
trackEmbeddedSession(sessionData)
180-
.then((response: any) => {
185+
.then((response: AxiosResponse<IterableResponse>) => {
181186
setTrackResponse(JSON.stringify(response.data));
182187
setTrackingEvent(false);
183188
})
184-
.catch((error: any) => {
189+
.catch((error: AxiosError<IterableResponse>) => {
185190
setTrackResponse(JSON.stringify(error.response.data));
186191
setTrackingEvent(false);
187192
});

react-example/src/components/EventsForm.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1+
import {
2+
InAppEventRequestParams,
3+
InAppTrackRequestParams,
4+
IterablePromise,
5+
IterableResponse
6+
} from '@iterable/web-sdk';
7+
import { AxiosError, AxiosResponse } from 'axios';
18
import { ChangeEvent, FC, FormEvent, useState } from 'react';
2-
import { IterablePromise, IterableResponse } from '@iterable/web-sdk';
39
import {
4-
StyledButton,
510
EndpointWrapper,
611
Form,
712
Heading,
8-
Response
13+
Response,
14+
StyledButton
915
} from '../views/Components.styled';
1016
import { TextField } from './TextField';
1117

1218
interface Props {
1319
endpointName: string;
1420
heading: string;
1521
needsEventName?: boolean;
16-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
17-
method: (...args: any) => IterablePromise<IterableResponse>;
22+
method: (
23+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
24+
args: InAppEventRequestParams | InAppTrackRequestParams
25+
) => IterablePromise<IterableResponse>;
1826
}
1927

2028
export const EventsForm: FC<Props> = ({
@@ -44,11 +52,11 @@ export const EventsForm: FC<Props> = ({
4452
appPackageName: 'my-website'
4553
}
4654
})
47-
.then((response: any) => {
55+
.then((response: AxiosResponse<IterableResponse>) => {
4856
setTrackResponse(JSON.stringify(response.data));
4957
setTrackingEvent(false);
5058
})
51-
.catch((e: any) => {
59+
.catch((e: AxiosError<IterableResponse>) => {
5260
setTrackResponse(JSON.stringify(e.response.data));
5361
setTrackingEvent(false);
5462
});

react-example/src/views/Commerce.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
import { IterableResponse, trackPurchase, updateCart } from '@iterable/web-sdk';
2+
import { AxiosError, AxiosResponse } from 'axios';
13
import { FC, FormEvent, useState } from 'react';
2-
import { updateCart, trackPurchase } from '@iterable/web-sdk';
34
import { TextField } from '../components/TextField';
45
import {
5-
StyledButton,
66
EndpointWrapper,
77
Form,
88
Heading,
9-
Response
9+
Response,
10+
StyledButton
1011
} from './Components.styled';
1112

1213
interface Props {}
@@ -31,11 +32,11 @@ export const Commerce: FC<Props> = () => {
3132
updateCart({
3233
items: [{ name: cartItem, id: 'fdsafds', price: 100, quantity: 2 }]
3334
})
34-
.then((response: any) => {
35+
.then((response: AxiosResponse<IterableResponse>) => {
3536
setUpdateCartResponse(JSON.stringify(response.data));
3637
setUpdatingCart(false);
3738
})
38-
.catch((e: any) => {
39+
.catch((e: AxiosError<IterableResponse>) => {
3940
setUpdateCartResponse(JSON.stringify(e.response.data));
4041
setUpdatingCart(false);
4142
});
@@ -48,11 +49,11 @@ export const Commerce: FC<Props> = () => {
4849
items: [{ name: purchaseItem, id: 'fdsafds', price: 100, quantity: 2 }],
4950
total: 200
5051
})
51-
.then((response: any) => {
52+
.then((response: AxiosResponse<IterableResponse>) => {
5253
setTrackingPurchase(false);
5354
setTrackPurchaseResponse(JSON.stringify(response.data));
5455
})
55-
.catch((e: any) => {
56+
.catch((e: AxiosError<IterableResponse>) => {
5657
setTrackingPurchase(false);
5758
setTrackPurchaseResponse(JSON.stringify(e.response.data));
5859
});

react-example/src/views/EmbeddedMsgs.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import { FC, useState, useEffect } from 'react';
1+
/* eslint-disable no-console */
22
import {
3-
IterableEmbeddedCard,
4-
IterableEmbeddedNotification,
3+
IterableAction,
4+
IterableConfig,
5+
IterableCustomActionHandler,
56
IterableEmbeddedBanner,
7+
IterableEmbeddedCard,
68
IterableEmbeddedManager,
79
IterableEmbeddedMessage,
810
IterableEmbeddedMessageUpdateHandler,
9-
IterableUrlHandler,
10-
IterableCustomActionHandler,
11-
IterableAction,
12-
IterableConfig
11+
IterableEmbeddedNotification,
12+
IterableUrlHandler
1313
} from '@iterable/web-sdk';
14+
import { FC, useEffect, useState } from 'react';
1415
import { Button } from '../components/Button';
1516
import { useUser } from '../context/Users';
1617

@@ -113,7 +114,7 @@ export const EmbeddedMsgs: FC<Props> = () => {
113114
await embeddedManager.syncMessages('my-website', () => {
114115
console.log('messages', JSON.stringify(embeddedManager.getMessages()));
115116
});
116-
} catch (error: any) {
117+
} catch (error: unknown) {
117118
console.log('error', error);
118119
}
119120
};
@@ -236,7 +237,7 @@ export const EmbeddedMsgs: FC<Props> = () => {
236237
appPackageName,
237238
message,
238239
...(useCustomStyles && { htmlElements: StyleOverrides }),
239-
errorCallback: (error: any) =>
240+
errorCallback: (error: unknown) =>
240241
console.log('handleError: ', error)
241242
});
242243
return (
@@ -252,7 +253,7 @@ export const EmbeddedMsgs: FC<Props> = () => {
252253
appPackageName,
253254
message,
254255
...(useCustomStyles && { htmlElements: StyleOverrides }),
255-
errorCallback: (error: any) =>
256+
errorCallback: (error: unknown) =>
256257
console.log('handleError: ', error)
257258
});
258259
return (
@@ -268,7 +269,7 @@ export const EmbeddedMsgs: FC<Props> = () => {
268269
appPackageName,
269270
message,
270271
...(useCustomStyles && { htmlElements: StyleOverrides }),
271-
errorCallback: (error: any) =>
272+
errorCallback: (error: unknown) =>
272273
console.log('handleError: ', error)
273274
});
274275
return (

react-example/src/views/EmbeddedMsgsImpressionTracker.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { FC, useState, useEffect, useRef } from 'react';
1+
/* eslint-disable no-console */
22
import {
33
IterableEmbeddedCard,
44
IterableEmbeddedManager,
55
IterableEmbeddedMessage,
66
IterableEmbeddedMessageUpdateHandler,
77
IterableEmbeddedSessionManager
88
} from '@iterable/web-sdk';
9+
import { FC, useEffect, useRef, useState } from 'react';
910
import { useUser } from '../context/Users';
1011

1112
interface Props {}
@@ -51,7 +52,7 @@ export const EmbeddedMsgsImpressionTracker: FC<Props> = () => {
5152
);
5253
};
5354

54-
let observersCard: any[] = [];
55+
let observersCard: IntersectionObserver[] = [];
5556

5657
useEffect(() => {
5758
observersCard = getCardObserver();
@@ -93,7 +94,7 @@ export const EmbeddedMsgsImpressionTracker: FC<Props> = () => {
9394
await embeddedManager.syncMessages('my-website', () => {
9495
console.log('messages', JSON.stringify(embeddedManager.getMessages()));
9596
});
96-
} catch (error: any) {
97+
} catch (error: unknown) {
9798
console.log('error', error);
9899
}
99100
};

react-example/src/views/Users.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
import { FC, FormEvent, useState } from 'react';
21
import {
3-
updateUser,
2+
IterableResponse,
43
updateSubscriptions,
4+
updateUser,
55
updateUserEmail
66
} from '@iterable/web-sdk';
7+
import { AxiosError, AxiosResponse } from 'axios';
8+
import { FC, FormEvent, useState } from 'react';
79
import { TextField } from '../components/TextField';
8-
910
import { useUser } from '../context/Users';
1011
import {
11-
StyledButton,
1212
EndpointWrapper,
1313
Form,
1414
Heading,
15-
Response
15+
Response,
16+
StyledButton
1617
} from './Components.styled';
1718

1819
interface Props {}
@@ -43,11 +44,11 @@ export const Users: FC<Props> = () => {
4344
updateUser({
4445
dataFields: { [userDataField]: 'test-data' }
4546
})
46-
.then((response: any) => {
47+
.then((response: AxiosResponse<IterableResponse>) => {
4748
setUpdateUserResponse(JSON.stringify(response.data));
4849
setUpdatingUser(false);
4950
})
50-
.catch((e: any) => {
51+
.catch((e: AxiosError<IterableResponse>) => {
5152
setUpdateUserResponse(JSON.stringify(e.response.data));
5253
setUpdatingUser(false);
5354
});
@@ -57,12 +58,12 @@ export const Users: FC<Props> = () => {
5758
e.preventDefault();
5859
setUpdatingUserEmail(true);
5960
updateUserEmail(email)
60-
.then((response: any) => {
61+
.then((response: AxiosResponse<IterableResponse>) => {
6162
setUpdatingUserEmail(false);
6263
setUpdateUserEmailResponse(JSON.stringify(response.data));
6364
setLoggedInUser({ type: 'user_update', data: email });
6465
})
65-
.catch((e: any) => {
66+
.catch((e: AxiosError<IterableResponse>) => {
6667
setUpdatingUserEmail(false);
6768
setUpdateUserEmailResponse(JSON.stringify(e.response.data));
6869
});
@@ -73,11 +74,11 @@ export const Users: FC<Props> = () => {
7374

7475
setUpdatingSubscriptions(true);
7576
updateSubscriptions({ emailListIds: [+emailListID] })
76-
.then((response: any) => {
77+
.then((response: AxiosResponse<IterableResponse>) => {
7778
setUpdatingSubscriptions(false);
7879
setUpdateSubscriptionsResponse(JSON.stringify(response.data));
7980
})
80-
.catch((e: any) => {
81+
.catch((e: AxiosError<IterableResponse>) => {
8182
setUpdatingSubscriptions(false);
8283
setUpdateSubscriptionsResponse(JSON.stringify(e.response.data));
8384
});

src/authorization/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export const cancelAxiosRequestAndMakeFetch = (
8282
'Api-Key': authToken,
8383
Authorization: `Bearer ${jwtToken}`
8484
},
85-
body: JSON.stringify({ ...config?.data, ...additionalData } || {}),
85+
body: JSON.stringify({ ...config?.data, ...additionalData }),
8686
keepalive: true
8787
}).catch();
8888

src/inapp/cache.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable no-console */
2+
import { isAxiosError } from 'axios';
13
import { setMany } from 'idb-keyval';
24
import { BrowserStorageEstimate, CachedMessage, InAppMessage } from './types';
35

@@ -32,11 +34,10 @@ export const determineRemainingStorageQuota = async () => {
3234
const remainingQuota = usage && messageQuota - usage;
3335

3436
return remainingQuota || 0;
35-
} catch (err: any /* eslint-disable-line @typescript-eslint/no-explicit-any */) {
36-
// eslint-disable-next-line no-console
37+
} catch (err: unknown) {
3738
console.warn(
3839
'Error determining remaining storage quota',
39-
err?.response?.data?.clientErrors ?? err
40+
isAxiosError(err) ? err.response?.data?.clientErrors : err
4041
);
4142
}
4243
/** Do not try to add to cache if we cannot determine storage space. */
@@ -113,11 +114,10 @@ export const addNewMessagesToCache = async (
113114

114115
try {
115116
await setMany(messagesToAddToCache);
116-
} catch (err: any /* eslint-disable-line @typescript-eslint/no-explicit-any */) {
117-
// eslint-disable-next-line no-console
117+
} catch (err: unknown) {
118118
console.warn(
119119
'Error adding new messages to the browser cache',
120-
err?.response?.data?.clientErrors ?? err
120+
isAxiosError(err) ? err.response?.data?.clientErrors : err
121121
);
122122
}
123123
}

0 commit comments

Comments
 (0)