diff options
author | Markus Hatvan <markus_hatvan@aon.at> | 2021-10-02 09:24:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-02 09:24:32 +0200 |
commit | bfe8847d72cd0893230f2e654242658214943e61 (patch) | |
tree | 3384b02ebad7a74cbb106ddd95546e0e24ff0bb8 /src/api | |
parent | fix: Fix navigation shortcut accelerator for non-macos (fixes #1172) (#2012) (diff) | |
download | ferdium-app-bfe8847d72cd0893230f2e654242658214943e61.tar.gz ferdium-app-bfe8847d72cd0893230f2e654242658214943e61.tar.zst ferdium-app-bfe8847d72cd0893230f2e654242658214943e61.zip |
chore: convert various files from JS to TS (#2010)
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/AppApi.ts (renamed from src/api/AppApi.js) | 4 | ||||
-rw-r--r-- | src/api/FeaturesApi.ts (renamed from src/api/FeaturesApi.js) | 4 | ||||
-rw-r--r-- | src/api/LocalApi.ts (renamed from src/api/LocalApi.js) | 10 | ||||
-rw-r--r-- | src/api/NewsApi.ts (renamed from src/api/NewsApi.js) | 8 | ||||
-rw-r--r-- | src/api/RecipePreviewsApi.ts (renamed from src/api/RecipePreviewsApi.js) | 6 | ||||
-rw-r--r-- | src/api/RecipesApi.ts (renamed from src/api/RecipesApi.js) | 8 | ||||
-rw-r--r-- | src/api/ServicesApi.ts (renamed from src/api/ServicesApi.js) | 18 | ||||
-rw-r--r-- | src/api/UserApi.ts (renamed from src/api/UserApi.js) | 17 | ||||
-rw-r--r-- | src/api/index.ts (renamed from src/api/index.js) | 10 | ||||
-rw-r--r-- | src/api/utils/auth.ts (renamed from src/api/utils/auth.js) | 8 |
10 files changed, 62 insertions, 31 deletions
diff --git a/src/api/AppApi.js b/src/api/AppApi.ts index 411c187f4..6e5e5c806 100644 --- a/src/api/AppApi.js +++ b/src/api/AppApi.ts | |||
@@ -1,5 +1,7 @@ | |||
1 | export default class AppApi { | 1 | export default class AppApi { |
2 | constructor(server) { | 2 | server: any; |
3 | |||
4 | constructor(server: any) { | ||
3 | this.server = server; | 5 | this.server = server; |
4 | } | 6 | } |
5 | 7 | ||
diff --git a/src/api/FeaturesApi.js b/src/api/FeaturesApi.ts index c66f28f5b..ccad4a189 100644 --- a/src/api/FeaturesApi.js +++ b/src/api/FeaturesApi.ts | |||
@@ -1,5 +1,7 @@ | |||
1 | export default class FeaturesApi { | 1 | export default class FeaturesApi { |
2 | constructor(server) { | 2 | server: any; |
3 | |||
4 | constructor(server: any) { | ||
3 | this.server = server; | 5 | this.server = server; |
4 | } | 6 | } |
5 | 7 | ||
diff --git a/src/api/LocalApi.js b/src/api/LocalApi.ts index ccdedd3f5..0140a5450 100644 --- a/src/api/LocalApi.js +++ b/src/api/LocalApi.ts | |||
@@ -1,14 +1,18 @@ | |||
1 | export default class LocalApi { | 1 | export default class LocalApi { |
2 | constructor(server, local) { | 2 | server: any; |
3 | |||
4 | local: any; | ||
5 | |||
6 | constructor(server: any, local: any) { | ||
3 | this.server = server; | 7 | this.server = server; |
4 | this.local = local; | 8 | this.local = local; |
5 | } | 9 | } |
6 | 10 | ||
7 | getAppSettings(type) { | 11 | getAppSettings(type: any) { |
8 | return this.local.getAppSettings(type); | 12 | return this.local.getAppSettings(type); |
9 | } | 13 | } |
10 | 14 | ||
11 | updateAppSettings(type, data) { | 15 | updateAppSettings(type: any, data: any) { |
12 | return this.local.updateAppSettings(type, data); | 16 | return this.local.updateAppSettings(type, data); |
13 | } | 17 | } |
14 | 18 | ||
diff --git a/src/api/NewsApi.js b/src/api/NewsApi.ts index 294957511..31d3d903b 100644 --- a/src/api/NewsApi.js +++ b/src/api/NewsApi.ts | |||
@@ -1,5 +1,9 @@ | |||
1 | export default class NewsApi { | 1 | export default class NewsApi { |
2 | constructor(server, local) { | 2 | server: any; |
3 | |||
4 | local: any; | ||
5 | |||
6 | constructor(server: any, local: any) { | ||
3 | this.server = server; | 7 | this.server = server; |
4 | this.local = local; | 8 | this.local = local; |
5 | } | 9 | } |
@@ -8,7 +12,7 @@ export default class NewsApi { | |||
8 | return this.server.getLatestNews(); | 12 | return this.server.getLatestNews(); |
9 | } | 13 | } |
10 | 14 | ||
11 | hide(id) { | 15 | hide(id: any) { |
12 | return this.server.hideNews(id); | 16 | return this.server.hideNews(id); |
13 | } | 17 | } |
14 | } | 18 | } |
diff --git a/src/api/RecipePreviewsApi.js b/src/api/RecipePreviewsApi.ts index a56fa587f..78f2a9596 100644 --- a/src/api/RecipePreviewsApi.js +++ b/src/api/RecipePreviewsApi.ts | |||
@@ -1,5 +1,7 @@ | |||
1 | export default class RecipePreviewsApi { | 1 | export default class RecipePreviewsApi { |
2 | constructor(server) { | 2 | server: any; |
3 | |||
4 | constructor(server: any) { | ||
3 | this.server = server; | 5 | this.server = server; |
4 | } | 6 | } |
5 | 7 | ||
@@ -11,7 +13,7 @@ export default class RecipePreviewsApi { | |||
11 | return this.server.getFeaturedRecipePreviews(); | 13 | return this.server.getFeaturedRecipePreviews(); |
12 | } | 14 | } |
13 | 15 | ||
14 | search(needle) { | 16 | search(needle: string) { |
15 | return this.server.searchRecipePreviews(needle); | 17 | return this.server.searchRecipePreviews(needle); |
16 | } | 18 | } |
17 | } | 19 | } |
diff --git a/src/api/RecipesApi.js b/src/api/RecipesApi.ts index 800888b00..11d2241b5 100644 --- a/src/api/RecipesApi.js +++ b/src/api/RecipesApi.ts | |||
@@ -1,5 +1,7 @@ | |||
1 | export default class RecipesApi { | 1 | export default class RecipesApi { |
2 | constructor(server) { | 2 | server: any; |
3 | |||
4 | constructor(server: any) { | ||
3 | this.server = server; | 5 | this.server = server; |
4 | } | 6 | } |
5 | 7 | ||
@@ -7,11 +9,11 @@ export default class RecipesApi { | |||
7 | return this.server.getInstalledRecipes(); | 9 | return this.server.getInstalledRecipes(); |
8 | } | 10 | } |
9 | 11 | ||
10 | install(recipeId) { | 12 | install(recipeId: string) { |
11 | return this.server.getRecipePackage(recipeId); | 13 | return this.server.getRecipePackage(recipeId); |
12 | } | 14 | } |
13 | 15 | ||
14 | update(recipes) { | 16 | update(recipes: any) { |
15 | return this.server.getRecipeUpdates(recipes); | 17 | return this.server.getRecipeUpdates(recipes); |
16 | } | 18 | } |
17 | } | 19 | } |
diff --git a/src/api/ServicesApi.js b/src/api/ServicesApi.ts index 85efd26a6..5bd8aa60e 100644 --- a/src/api/ServicesApi.js +++ b/src/api/ServicesApi.ts | |||
@@ -1,30 +1,34 @@ | |||
1 | export default class ServicesApi { | 1 | export default class ServicesApi { |
2 | constructor(server, local) { | 2 | server: any; |
3 | this.local = local; | 3 | |
4 | local: any; | ||
5 | |||
6 | constructor(server: any, local: any) { | ||
4 | this.server = server; | 7 | this.server = server; |
8 | this.local = local; | ||
5 | } | 9 | } |
6 | 10 | ||
7 | all() { | 11 | all() { |
8 | return this.server.getServices(); | 12 | return this.server.getServices(); |
9 | } | 13 | } |
10 | 14 | ||
11 | create(recipeId, data) { | 15 | create(recipeId: string, data: any) { |
12 | return this.server.createService(recipeId, data); | 16 | return this.server.createService(recipeId, data); |
13 | } | 17 | } |
14 | 18 | ||
15 | delete(serviceId) { | 19 | delete(serviceId: string) { |
16 | return this.server.deleteService(serviceId); | 20 | return this.server.deleteService(serviceId); |
17 | } | 21 | } |
18 | 22 | ||
19 | update(serviceId, data) { | 23 | update(serviceId: string, data: any) { |
20 | return this.server.updateService(serviceId, data); | 24 | return this.server.updateService(serviceId, data); |
21 | } | 25 | } |
22 | 26 | ||
23 | reorder(data) { | 27 | reorder(data: any) { |
24 | return this.server.reorderService(data); | 28 | return this.server.reorderService(data); |
25 | } | 29 | } |
26 | 30 | ||
27 | clearCache(serviceId) { | 31 | clearCache(serviceId: string) { |
28 | return this.local.clearCache(serviceId); | 32 | return this.local.clearCache(serviceId); |
29 | } | 33 | } |
30 | } | 34 | } |
diff --git a/src/api/UserApi.js b/src/api/UserApi.ts index edfb88988..31c8acead 100644 --- a/src/api/UserApi.js +++ b/src/api/UserApi.ts | |||
@@ -1,12 +1,17 @@ | |||
1 | import { BinaryLike } from 'crypto'; | ||
1 | import { hash } from '../helpers/password-helpers'; | 2 | import { hash } from '../helpers/password-helpers'; |
2 | 3 | ||
3 | export default class UserApi { | 4 | export default class UserApi { |
4 | constructor(server, local) { | 5 | server: any; |
6 | |||
7 | local: any; | ||
8 | |||
9 | constructor(server: any, local: any) { | ||
5 | this.server = server; | 10 | this.server = server; |
6 | this.local = local; | 11 | this.local = local; |
7 | } | 12 | } |
8 | 13 | ||
9 | login(email, password) { | 14 | login(email: string, password: BinaryLike) { |
10 | return this.server.login(email, hash(password)); | 15 | return this.server.login(email, hash(password)); |
11 | } | 16 | } |
12 | 17 | ||
@@ -14,18 +19,18 @@ export default class UserApi { | |||
14 | return this; | 19 | return this; |
15 | } | 20 | } |
16 | 21 | ||
17 | signup(data) { | 22 | signup(data: { password: BinaryLike }) { |
18 | Object.assign(data, { | 23 | Object.assign(data, { |
19 | password: hash(data.password), | 24 | password: hash(data.password), |
20 | }); | 25 | }); |
21 | return this.server.signup(data); | 26 | return this.server.signup(data); |
22 | } | 27 | } |
23 | 28 | ||
24 | password(email) { | 29 | password(email: string) { |
25 | return this.server.retrievePassword(email); | 30 | return this.server.retrievePassword(email); |
26 | } | 31 | } |
27 | 32 | ||
28 | invite(data) { | 33 | invite(data: any) { |
29 | return this.server.inviteUser(data); | 34 | return this.server.inviteUser(data); |
30 | } | 35 | } |
31 | 36 | ||
@@ -33,7 +38,7 @@ export default class UserApi { | |||
33 | return this.server.userInfo(); | 38 | return this.server.userInfo(); |
34 | } | 39 | } |
35 | 40 | ||
36 | updateInfo(data) { | 41 | updateInfo(data: { oldPassword: string; newPassword: string }) { |
37 | const userData = data; | 42 | const userData = data; |
38 | if (userData.oldPassword && userData.newPassword) { | 43 | if (userData.oldPassword && userData.newPassword) { |
39 | userData.oldPassword = hash(userData.oldPassword); | 44 | userData.oldPassword = hash(userData.oldPassword); |
diff --git a/src/api/index.js b/src/api/index.ts index ed6c13488..73f613da1 100644 --- a/src/api/index.js +++ b/src/api/index.ts | |||
@@ -7,12 +7,12 @@ import LocalApi from './LocalApi'; | |||
7 | import NewsApi from './NewsApi'; | 7 | import NewsApi from './NewsApi'; |
8 | import FeaturesApi from './FeaturesApi'; | 8 | import FeaturesApi from './FeaturesApi'; |
9 | 9 | ||
10 | export default (server, local) => ({ | 10 | export default (server: any, local: any) => ({ |
11 | app: new AppApi(server, local), | 11 | app: new AppApi(server), |
12 | services: new ServicesApi(server, local), | 12 | services: new ServicesApi(server, local), |
13 | recipePreviews: new RecipePreviewsApi(server, local), | 13 | recipePreviews: new RecipePreviewsApi(server), |
14 | recipes: new RecipesApi(server, local), | 14 | recipes: new RecipesApi(server), |
15 | features: new FeaturesApi(server, local), | 15 | features: new FeaturesApi(server), |
16 | user: new UserApi(server, local), | 16 | user: new UserApi(server, local), |
17 | local: new LocalApi(server, local), | 17 | local: new LocalApi(server, local), |
18 | news: new NewsApi(server, local), | 18 | news: new NewsApi(server, local), |
diff --git a/src/api/utils/auth.js b/src/api/utils/auth.ts index 07b0c096b..98295d1a4 100644 --- a/src/api/utils/auth.js +++ b/src/api/utils/auth.ts | |||
@@ -15,6 +15,7 @@ export const prepareAuthRequest = ( | |||
15 | 'X-Franz-platform': process.platform, | 15 | 'X-Franz-platform': process.platform, |
16 | 'X-Franz-Timezone-Offset': new Date().getTimezoneOffset(), | 16 | 'X-Franz-Timezone-Offset': new Date().getTimezoneOffset(), |
17 | 'X-Franz-System-Locale': ferdiLocale, | 17 | 'X-Franz-System-Locale': ferdiLocale, |
18 | // @ts-expect-error Property 'headers' does not exist on type '{ method: string; }'. | ||
18 | ...options.headers, | 19 | ...options.headers, |
19 | }, | 20 | }, |
20 | }); | 21 | }); |
@@ -28,5 +29,10 @@ export const prepareAuthRequest = ( | |||
28 | return request; | 29 | return request; |
29 | }; | 30 | }; |
30 | 31 | ||
31 | export const sendAuthRequest = (url, options, auth) => | 32 | export const sendAuthRequest = ( |
33 | url: RequestInfo, | ||
34 | options: { method: string } | undefined, | ||
35 | auth?: boolean, | ||
36 | ) => | ||
37 | // @ts-expect-error Argument of type '{ method: string; } & { mode: string; headers: any; }' is not assignable to parameter of type 'RequestInit | undefined'. | ||
32 | window.fetch(url, prepareAuthRequest(options, auth)); | 38 | window.fetch(url, prepareAuthRequest(options, auth)); |