Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.
chore(lint): share one ESLint config and lint the backend
spacesdriveece355e8d94e
diff --git a/backend/lib/redis.js b/backend/lib/redis.jsindex affc6de..fbfcea7 100644--- a/backend/lib/redis.js+++ b/backend/lib/redis.js@@ -1,8 +1,8 @@import { Redis } from '@upstash/redis';export function getRedis(env) {- const url = env.UPSTASH_REDIS_REST_URL?.replace(/^/, '').trim();- const token = env.UPSTASH_REDIS_REST_TOKEN?.replace(/^/, '').trim();+ const url = env.UPSTASH_REDIS_REST_URL?.replace(/^\uFEFF/, '').trim();+ const token = env.UPSTASH_REDIS_REST_TOKEN?.replace(/^\uFEFF/, '').trim();if (!url || !token) return null;return new Redis({ url, token });}diff --git a/backend/lib/supabase.js b/backend/lib/supabase.jsindex a207116..fd53ebd 100644--- a/backend/lib/supabase.js+++ b/backend/lib/supabase.js@@ -1,12 +1,12 @@import { createClient } from '@supabase/supabase-js';function clean(s) {- return s?.replace(/^/, '').trim();+ return s?.replace(/^\uFEFF/, '').trim();}// workers reject the `cache` RequestInit field, so supabase requests drop itfunction workerFetch(url, options = {}) {- const { cache, ...rest } = options;+ const { cache: _cache, ...rest } = options;return fetch(url, rest);}diff --git a/backend/routes/accounts.js b/backend/routes/accounts.jsindex bfd4153..d25f971 100644--- a/backend/routes/accounts.js+++ b/backend/routes/accounts.js@@ -26,7 +26,7 @@ app.get('/accounts', async (c) => {app.post('/resolve-channel', async (c) => {try {const { input } = await c.req.json();- const apiKey = c.env.YOUTUBE_API_KEY?.replace(/^/, '').trim();+ const apiKey = c.env.YOUTUBE_API_KEY?.replace(/^\uFEFF/, '').trim();if (!apiKey) return c.json({ success: false, message: 'YouTube API key not configured on server' }, 400);const channelId = await resolveChannelId(input, apiKey);const channelData = await fetchChannelData(channelId, apiKey);@@ -39,7 +39,7 @@ app.post('/resolve-channel', async (c) => {app.post('/accounts', async (c) => {try {const { input } = await c.req.json();- const apiKey = c.env.YOUTUBE_API_KEY?.replace(/^/, '').trim();+ const apiKey = c.env.YOUTUBE_API_KEY?.replace(/^\uFEFF/, '').trim();if (!apiKey) return c.json({ success: false, message: 'YouTube API key not configured on server' }, 400);const account = await addYouTubeAccount(c.get('supabase'), c.get('userId'), input, apiKey);return c.json({ success: true, account });diff --git a/backend/routes/analytics.js b/backend/routes/analytics.jsindex 982d71e..08f7d93 100644--- a/backend/routes/analytics.js+++ b/backend/routes/analytics.js@@ -30,7 +30,7 @@ app.get('/accounts/:id/analytics', async (c) => {try {const supabase = c.get('supabase');const userId = c.get('userId');- const apiKey = c.env.YOUTUBE_API_KEY?.replace(/^/, '').trim();+ const apiKey = c.env.YOUTUBE_API_KEY?.replace(/^\uFEFF/, '').trim();if (!apiKey) return c.json({ success: false, message: 'No API key' }, 400);const account = await getAccountById(supabase, c.req.param('id'), userId);@@ -65,7 +65,7 @@ app.get('/accounts/:id/videos', async (c) => {return c.json({ success: true, videos: cached.videos, fetchedAt: cached.fetchedAt });}- const apiKey = c.env.YOUTUBE_API_KEY?.replace(/^/, '').trim();+ const apiKey = c.env.YOUTUBE_API_KEY?.replace(/^\uFEFF/, '').trim();if (!apiKey) return c.json({ success: false, message: 'No API key' }, 400);const account = await getAccountById(supabase, id, userId);diff --git a/backend/routes/overview.js b/backend/routes/overview.jsindex 4ccbd69..8406ea1 100644--- a/backend/routes/overview.js+++ b/backend/routes/overview.js@@ -19,7 +19,7 @@ router.get('/overview', async (c) => {const userId = c.get('userId');const supabase = c.get('supabase');const redis = c.get('redis');- const apiKey = c.env.YOUTUBE_API_KEY?.replace(/^/, '').trim();+ const apiKey = c.env.YOUTUBE_API_KEY?.replace(/^\uFEFF/, '').trim();try {const [accounts, tracked] = await Promise.all([diff --git a/backend/routes/trackedContent.js b/backend/routes/trackedContent.jsindex 6bc4c54..d090e8a 100644--- a/backend/routes/trackedContent.js+++ b/backend/routes/trackedContent.js@@ -25,7 +25,7 @@ async function redditCookieFor(supabase, accountId, userId) {// returns the fetched data, or an error response the handler sends unchangedasync function fetchNewTrackedData(c, contentType, url, accountId) {if (contentType === 'youtube') {- const apiKey = c.env.YOUTUBE_API_KEY?.replace(/^/, '').trim();+ const apiKey = c.env.YOUTUBE_API_KEY?.replace(/^\uFEFF/, '').trim();if (!apiKey) return { response: c.json({ error: 'YouTube API key not configured on this server' }, 400) };return { data: await fetchTrackedYouTubeData(url, apiKey) };}@@ -149,7 +149,7 @@ router.post('/tracked-content/:id/refresh', async (c) => {let fetchedData;if (contentType === 'youtube') {- const apiKey = c.env.YOUTUBE_API_KEY?.replace(/^/, '').trim();+ const apiKey = c.env.YOUTUBE_API_KEY?.replace(/^\uFEFF/, '').trim();if (!apiKey) return c.json({ error: 'YouTube API key not configured on this server' }, 400);fetchedData = await fetchTrackedYouTubeData(existing.url, apiKey);} else {diff --git a/backend/services/instagramOAuth.js b/backend/services/instagramOAuth.jsindex 4001b51..2ca15d0 100644--- a/backend/services/instagramOAuth.js+++ b/backend/services/instagramOAuth.js@@ -13,11 +13,11 @@ const OAUTH_SCOPES = 'instagram_business_basic,instagram_business_manage_message// pasted secrets can carry a byte order mark or stray whitespacefunction cleanSecret(value) {- return value?.replace(/^/, '').trim();+ return value?.replace(/^\uFEFF/, '').trim();}function cleanUrl(value, fallback) {- return (value || fallback).replace(/^/, '').trim();+ return (value || fallback).replace(/^\uFEFF/, '').trim();}export function readInstagramOAuthConfig(env) {diff --git a/eslint.config.mjs b/eslint.config.mjsnew file mode 100644index 0000000..2773ea0--- /dev/null+++ b/eslint.config.mjs@@ -0,0 +1,51 @@+import js from '@eslint/js'+import globals from 'globals'+import reactHooks from 'eslint-plugin-react-hooks'+import reactRefresh from 'eslint-plugin-react-refresh'+import { defineConfig, globalIgnores } from 'eslint/config'++export default defineConfig([+ globalIgnores(['**/dist', '**/.wrangler', '**/node_modules']),+ {+ files: ['frontend/**/*.{js,jsx}'],+ extends: [+ js.configs.recommended,+ reactHooks.configs.flat.recommended,+ reactRefresh.configs.vite,+ ],+ languageOptions: {+ ecmaVersion: 2020,+ globals: globals.browser,+ parserOptions: {+ ecmaVersion: 'latest',+ ecmaFeatures: { jsx: true },+ sourceType: 'module',+ },+ },+ rules: {+ 'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }],+ },+ },+ {+ // the worker runs on the web platform, so it gets service worker globals, not node+ files: ['backend/**/*.js'],+ extends: [js.configs.recommended],+ languageOptions: {+ ecmaVersion: 'latest',+ sourceType: 'module',+ globals: globals.serviceworker,+ },+ rules: {+ 'no-unused-vars': ['error', { varsIgnorePattern: '^_', argsIgnorePattern: '^_', caughtErrors: 'none' }],+ },+ },+ {+ files: ['backend/tests/**/*.js', 'backend/**/*.test.js', 'scripts/**/*.js', '*.js', '*.mjs'],+ extends: [js.configs.recommended],+ languageOptions: {+ ecmaVersion: 'latest',+ sourceType: 'module',+ globals: globals.node,+ },+ },+])diff --git a/frontend/eslint.config.js b/frontend/eslint.config.jsdeleted file mode 100644index 4fa125d..0000000--- a/frontend/eslint.config.js+++ /dev/null@@ -1,29 +0,0 @@-import js from '@eslint/js'-import globals from 'globals'-import reactHooks from 'eslint-plugin-react-hooks'-import reactRefresh from 'eslint-plugin-react-refresh'-import { defineConfig, globalIgnores } from 'eslint/config'--export default defineConfig([- globalIgnores(['dist']),- {- files: ['**/*.{js,jsx}'],- extends: [- js.configs.recommended,- reactHooks.configs.flat.recommended,- reactRefresh.configs.vite,- ],- languageOptions: {- ecmaVersion: 2020,- globals: globals.browser,- parserOptions: {- ecmaVersion: 'latest',- ecmaFeatures: { jsx: true },- sourceType: 'module',- },- },- rules: {- 'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }],- },- },-])