Skip to content

Send and receive SMS messages using your Android phone programmatically via a simple HTTP API

fix(web): resolve Codacy static analysis type-safety warnings

Acho Arnoldc291ad3c8c5e
diff --git a/web/app/composables/useApi.ts b/web/app/composables/useApi.ts
index 2b8c577c..fd3ec71a 100644
--- a/web/app/composables/useApi.ts
+++ b/web/app/composables/useApi.ts
@@ -1,3 +1,5 @@
+import type { $Fetch } from "ofetch";
+
let authToken: string | null = null;
let apiKey: string | null = null;
@@ -9,9 +11,9 @@ export function setApiKey(key: string | null) {
apiKey = key;
}
-function createApiFetch() {
+function createApiFetch(): $Fetch {
const config = useRuntimeConfig();
- const baseURL = config.public.apiBaseUrl as string;
+ const baseURL = (config.public as Record<string, string>).apiBaseUrl;
return $fetch.create({
baseURL,
diff --git a/web/app/composables/useFilters.ts b/web/app/composables/useFilters.ts
index bcdc1cbc..a02f6a0e 100644
--- a/web/app/composables/useFilters.ts
+++ b/web/app/composables/useFilters.ts
@@ -6,8 +6,8 @@ import {
formatDecimal,
formatBillingPeriod,
humanizeTime,
-} from "~/utils/filters";
-import { capitalize } from "~/utils/capitalize";
+} from "../utils/filters";
+import { capitalize } from "../utils/capitalize";
export function useFilters() {
return {
diff --git a/web/app/middleware/auth.ts b/web/app/middleware/auth.ts
index 94de7eda..0cd5930f 100644
--- a/web/app/middleware/auth.ts
+++ b/web/app/middleware/auth.ts
@@ -1,4 +1,6 @@
-export default defineNuxtRouteMiddleware((to) => {
+import { useAuthStore } from "../stores/auth";
+
+export default defineNuxtRouteMiddleware((to: { path: string }) => {
const authStore = useAuthStore();
if (authStore.authUser === null) {
return navigateTo({ path: "/login", query: { to: to.path } });
diff --git a/web/app/plugins/firebase.client.ts b/web/app/plugins/firebase.client.ts
index d0c86a3b..aabdfe0f 100644
--- a/web/app/plugins/firebase.client.ts
+++ b/web/app/plugins/firebase.client.ts
@@ -1,11 +1,14 @@
import { initializeApp, getApps } from "firebase/app";
+import type { FirebaseApp } from "firebase/app";
import { getAuth, onAuthStateChanged } from "firebase/auth";
+import { useAuthStore } from "../stores/auth";
export default defineNuxtPlugin(() => {
const config = useRuntimeConfig();
+ const publicConfig = config.public as Record<string, string>;
// Skip initialization if no API key is configured
- if (!config.public.firebaseApiKey) {
+ if (!publicConfig.firebaseApiKey) {
console.warn(
"[firebase] No FIREBASE_API_KEY configured. Auth will not work.",
);
@@ -13,27 +16,34 @@ export default defineNuxtPlugin(() => {
}
const firebaseConfig = {
- apiKey: config.public.firebaseApiKey,
- authDomain: config.public.firebaseAuthDomain,
- projectId: config.public.firebaseProjectId,
- storageBucket: config.public.firebaseStorageBucket,
- messagingSenderId: config.public.firebaseMessagingSenderId,
- appId: config.public.firebaseAppId,
- measurementId: config.public.firebaseMeasurementId,
+ apiKey: publicConfig.firebaseApiKey,
+ authDomain: publicConfig.firebaseAuthDomain,
+ projectId: publicConfig.firebaseProjectId,
+ storageBucket: publicConfig.firebaseStorageBucket,
+ messagingSenderId: publicConfig.firebaseMessagingSenderId,
+ appId: publicConfig.firebaseAppId,
+ measurementId: publicConfig.firebaseMeasurementId,
};
// Initialize Firebase (only once)
- const app =
+ const app: FirebaseApp =
getApps().length === 0 ? initializeApp(firebaseConfig) : getApps()[0];
const auth = getAuth(app);
// Also initialize the compat SDK for FirebaseUI
if (import.meta.client) {
- import("firebase/compat/app").then((firebase) => {
- if (!firebase.default.apps.length) {
- firebase.default.initializeApp(firebaseConfig);
- }
- });
+ import("firebase/compat/app").then(
+ (firebase: {
+ default: {
+ apps: unknown[];
+ initializeApp: (config: typeof firebaseConfig) => void;
+ };
+ }) => {
+ if (!firebase.default.apps.length) {
+ firebase.default.initializeApp(firebaseConfig);
+ }
+ },
+ );
}
// Listen for auth state changes and update the auth store
diff --git a/web/app/plugins/vPhoneInput.client.ts b/web/app/plugins/vPhoneInput.client.ts
index 7d5f6738..4ac09c3e 100644
--- a/web/app/plugins/vPhoneInput.client.ts
+++ b/web/app/plugins/vPhoneInput.client.ts
@@ -5,9 +5,10 @@ import {
autocompletePhoneCountryInput,
VPhoneCountryFlagSvg,
} from "v-phone-input";
+import type { Plugin } from "vue";
export default defineNuxtPlugin((nuxtApp) => {
- const vPhoneInput = createVPhoneInput({
+ const vPhoneInput: Plugin = createVPhoneInput({
...autocompletePhoneCountryInput,
countryDisplayComponent: VPhoneCountryFlagSvg,
validate: null,
diff --git a/web/app/stores/app.ts b/web/app/stores/app.ts
index 0bf383f8..3303e3ae 100644
--- a/web/app/stores/app.ts
+++ b/web/app/stores/app.ts
@@ -14,21 +14,24 @@ export const useAppStore = defineStore("app", () => {
const polling = ref(false);
const appData = computed<AppData>(() => {
- let url = (config.public.appUrl as string) || "";
- if (url.length > 0 && url[url.length - 1] === "/") {
+ const publicConfig = config.public as Record<string, string>;
+ let url = publicConfig.appUrl || "";
+ if (url.endsWith("/")) {
url = url.substring(0, url.length - 1);
}
return {
url,
- env: config.public.appEnv as string,
- appDownloadUrl: config.public.appDownloadUrl as string,
- documentationUrl: config.public.appDocumentationUrl as string,
- githubUrl: config.public.appGithubUrl as string,
- name: config.public.appName as string,
+ env: publicConfig.appEnv,
+ appDownloadUrl: publicConfig.appDownloadUrl,
+ documentationUrl: publicConfig.appDocumentationUrl,
+ githubUrl: publicConfig.appGithubUrl,
+ name: publicConfig.appName,
};
});
- const isLocal = computed(() => config.public.appEnv === "local");
+ const isLocal = computed(
+ () => (config.public as Record<string, string>).appEnv === "local",
+ );
function setPolling(value: boolean) {
polling.value = value;
diff --git a/web/app/types/nuxt-shims.d.ts b/web/app/types/nuxt-shims.d.ts
new file mode 100644
index 00000000..7bd26f63
--- /dev/null
+++ b/web/app/types/nuxt-shims.d.ts
@@ -0,0 +1,40 @@
+/**
+ * Type declarations for Nuxt auto-imports.
+ * These are normally generated in .nuxt/ by `nuxt prepare` but are provided
+ * here so that external static analysis tools (e.g. Codacy) can resolve types
+ * without running the Nuxt build pipeline.
+ */
+
+import type { $Fetch } from "ofetch";
+import type { App } from "vue";
+
+declare global {
+ // Nuxt composables
+ function useRuntimeConfig(): {
+ public: Record<string, string>;
+ [key: string]: unknown;
+ };
+
+ // Nuxt fetch utility
+ const $fetch: $Fetch;
+
+ // Nuxt plugin helper
+ function defineNuxtPlugin(
+ plugin: (nuxtApp: { vueApp: App }) => void | Record<string, unknown>,
+ ): unknown;
+
+ // Nuxt route middleware helper
+ function defineNuxtRouteMiddleware(
+ middleware: (to: {
+ path: string;
+ query?: Record<string, string>;
+ }) => unknown,
+ ): unknown;
+
+ // Nuxt navigation
+ function navigateTo(
+ to: string | { path: string; query?: Record<string, string | undefined> },
+ ): unknown;
+}
+
+export {};
diff --git a/web/tsconfig.json b/web/tsconfig.json
index 307b2134..875ee5af 100644
--- a/web/tsconfig.json
+++ b/web/tsconfig.json
@@ -14,5 +14,17 @@
{
"path": "./.nuxt/tsconfig.node.json"
}
- ]
+ ],
+ "compilerOptions": {
+ "strict": true,
+ "moduleResolution": "bundler",
+ "module": "ESNext",
+ "target": "ESNext",
+ "paths": {
+ "~/*": ["./app/*"],
+ "~~/*": ["./*"],
+ "#imports": ["./app/types/nuxt-shims"]
+ }
+ },
+ "include": ["app/**/*.ts", "app/**/*.d.ts", "shared/**/*.ts"]
}