diff --git a/.oxlintrc.json b/.oxlintrc.json index 5ea6ffb4d..c7c19d0a7 100644 --- a/.oxlintrc.json +++ b/.oxlintrc.json @@ -1,10 +1,14 @@ { "$schema": "./node_modules/oxlint/configuration_schema.json", - "plugins": ["eslint", "typescript", "react", "oxc"], + "plugins": ["eslint", "typescript", "react", "unicorn", "oxc"], "jsPlugins": [ { "name": "rules", "specifier": "./tools/oxlint/rules/index.ts" + }, + { + "name": "@stylistic", + "specifier": "@stylistic/eslint-plugin" } ], "categories": { @@ -38,8 +42,19 @@ }, "options": { "reportUnusedDisableDirectives": "warn", + "typeAware": true, "respectEslintDisableDirectives": true }, + "rules": { + // React's act() is typed void for sync callbacks but returns an awaitable at runtime. + "typescript/await-thenable": "off", + // String(label) is only reached with string labels; SelectOption types label as ReactNode. + "typescript/no-base-to-string": "off", + // Only flags spreading ASCII strings, where code-point splitting is harmless. + "typescript/no-misused-spread": "off", + // Props typed with method syntax are plain functions, so every hit is a false positive. + "typescript/unbound-method": "off" + }, "ignorePatterns": [ "public/**", "resources/views/**", @@ -62,7 +77,26 @@ "rules/no-unknown-type-aliases": "error", "rules/no-unsafe-dictionary-type": "error", "rules/no-widen-then-assert": "error", + "@stylistic/padding-line-between-statements": [ + "error", + { "blankLine": "always", "prev": ["const", "let"], "next": "*" }, + { "blankLine": "any", "prev": ["const", "let"], "next": ["const", "let"] }, + { "blankLine": "always", "prev": "block-like", "next": "*" }, + { "blankLine": "always", "prev": "*", "next": "return" } + ], + "arrow-body-style": ["error", "as-needed"], + "complexity": ["warn", { "max": 15 }], + "curly": ["error", "all"], "eqeqeq": "error", + "max-depth": ["warn", { "max": 3 }], + "max-nested-callbacks": ["warn", { "max": 3 }], + "no-implicit-coercion": ["error", { "allow": ["!!"] }], + "no-nested-ternary": "error", + "object-shorthand": "error", + "prefer-arrow-callback": "error", + "prefer-const": "error", + "prefer-exponentiation-operator": "error", + "prefer-template": "error", "no-use-before-define": "warn", "no-unused-expressions": [ "error", @@ -82,7 +116,34 @@ "react/react-in-jsx-scope": "off", "react/rules-of-hooks": "error", "react/exhaustive-deps": "warn", + "react/jsx-curly-brace-presence": "error", + "react/jsx-fragments": "error", + "react/jsx-no-useless-fragment": "error", "typescript/no-explicit-any": "error", + "typescript/array-type": "error", + "typescript/no-inferrable-types": "error", + "typescript/prefer-nullish-coalescing": [ + "error", + { + "ignorePrimitives": { + "bigint": true, + "boolean": true, + "number": true, + "string": true + } + } + ], + "typescript/prefer-optional-chain": "error", + "typescript/switch-exhaustiveness-check": "error", + "unicorn/no-array-for-each": "error", + "unicorn/no-negated-condition": "error", + "unicorn/no-useless-spread": "error", + "unicorn/no-useless-undefined": ["error", { "checkArguments": false }], + "unicorn/prefer-array-some": "error", + "unicorn/prefer-at": "error", + "unicorn/prefer-includes": "error", + "unicorn/prefer-spread": "error", + "unicorn/prefer-string-replace-all": "error", "typescript/no-non-null-assertion": "off", "typescript/consistent-type-imports": [ "error", @@ -226,6 +287,8 @@ "files": ["resources/scripts/api/generated/types.gen.ts"], "rules": { "rules/generated-api-types": "error", + "typescript/no-duplicate-type-constituents": "off", + "typescript/no-redundant-type-constituents": "off", "typescript/no-empty-object-type": "error" } } diff --git a/package-lock.json b/package-lock.json index bfde83d84..f45045022 100644 --- a/package-lock.json +++ b/package-lock.json @@ -65,6 +65,7 @@ "devDependencies": { "@hey-api/openapi-ts": "0.99.0", "@oxlint/plugins": "^1.77.0", + "@stylistic/eslint-plugin": "^5.10.0", "@tailwindcss/postcss": "^4", "@testing-library/dom": "^10", "@testing-library/jest-dom": "^6", @@ -77,6 +78,7 @@ "jsdom": "^26.1.0", "oxfmt": "^0.72.0", "oxlint": "^1.77.0", + "oxlint-tsgolint": "^7.0.2003", "postcss": "^8.5.6", "typescript": "^6", "vite": "^8", @@ -221,6 +223,32 @@ } } }, + "node_modules/@cacheable/memory": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@cacheable/memory/-/memory-2.2.0.tgz", + "integrity": "sha512-CTLKqLItRCEixEAewD3/j9DB3/o96gpTPD4eJ1v+DGOlxZRZncRQkGYqqnAGCscYd6RNeXfGeiuCphsPtqyIfQ==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "@cacheable/utils": "^2.5.0", + "@keyv/bigmap": "^1.3.1", + "hookified": "^1.15.1", + "keyv": "^5.6.0" + } + }, + "node_modules/@cacheable/utils": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/@cacheable/utils/-/utils-2.5.0.tgz", + "integrity": "sha512-buipgOVDkkPXNR5+xBpDw7Zk2n1EvU7qBJCNUcL7rhQ//kfpOXPAvQ511Os0vpLYJ1pZnvudNytkQt2hst3wqA==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "hashery": "^1.5.1", + "keyv": "^5.6.0" + } + }, "node_modules/@codemirror/autocomplete": { "version": "6.20.3", "resolved": "https://registry.npmjs.org/@codemirror/autocomplete/-/autocomplete-6.20.3.tgz", @@ -669,6 +697,119 @@ "tslib": "^2.4.0" } }, + "node_modules/@eslint-community/eslint-utils": { + "version": "4.10.1", + "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.10.1.tgz", + "integrity": "sha512-cuadcxVFE8sDK6iWJbs8Sn0av2Nrh2QSGQhVlBW9AaAHqHwjWsZHT8LJ4hFGPh7ASBV2deFdM7H/DPjulmh8rg==", + "dev": true, + "license": "MIT", + "dependencies": { + "eslint-visitor-keys": "^3.4.3" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + }, + "peerDependencies": { + "eslint": "^6.0.0 || ^7.0.0 || >=8.0.0" + } + }, + "node_modules/@eslint-community/eslint-utils/node_modules/eslint-visitor-keys": { + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz", + "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/@eslint-community/regexpp": { + "version": "4.12.2", + "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.12.2.tgz", + "integrity": "sha512-EriSTlt5OC9/7SXkRSCAhfSxxoSUgBm33OH+IkwbdpgoqsSsUg7y3uh+IICI/Qg4BBWr3U2i39RpmycbxMq4ew==", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": "^12.0.0 || ^14.0.0 || >=16.0.0" + } + }, + "node_modules/@eslint/config-array": { + "version": "0.23.5", + "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.23.5.tgz", + "integrity": "sha512-Y3kKLvC1dvTOT+oGlqNQ1XLqK6D1HU2YXPc52NmAlJZbMMWDzGYXMiPRJ8TYD39muD/OTjlZmNJ4ib7dvSrMBA==", + "dev": true, + "license": "Apache-2.0", + "peer": true, + "dependencies": { + "@eslint/object-schema": "^3.0.5", + "debug": "^4.3.1", + "minimatch": "^10.2.4" + }, + "engines": { + "node": "^20.19.0 || ^22.13.0 || >=24" + } + }, + "node_modules/@eslint/config-helpers": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@eslint/config-helpers/-/config-helpers-0.7.0.tgz", + "integrity": "sha512-DObd/KKUsU+FaFv4PLxSRenpXfQWmPXXP3pPZ6/K1PCrMu2vQpMDMuQe/BqYeoLcz8ro0bVDF1RxOJgfVEdhUw==", + "dev": true, + "license": "Apache-2.0", + "peer": true, + "dependencies": { + "@eslint/core": "^1.2.1" + }, + "engines": { + "node": "^20.19.0 || ^22.13.0 || >=24" + } + }, + "node_modules/@eslint/core": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@eslint/core/-/core-1.2.1.tgz", + "integrity": "sha512-MwcE1P+AZ4C6DWlpin/OmOA54mmIZ/+xZuJiQd4SyB29oAJjN30UW9wkKNptW2ctp4cEsvhlLY/CsQ1uoHDloQ==", + "dev": true, + "license": "Apache-2.0", + "peer": true, + "dependencies": { + "@types/json-schema": "^7.0.15" + }, + "engines": { + "node": "^20.19.0 || ^22.13.0 || >=24" + } + }, + "node_modules/@eslint/object-schema": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/@eslint/object-schema/-/object-schema-3.0.5.tgz", + "integrity": "sha512-vqTaUEgxzm+YDSdElad6PiRoX4t8VGDjCtt05zn4nU810UIx/uNEV7/lZJ6KwFThKZOzOxzXy48da+No7HZaMw==", + "dev": true, + "license": "Apache-2.0", + "peer": true, + "engines": { + "node": "^20.19.0 || ^22.13.0 || >=24" + } + }, + "node_modules/@eslint/plugin-kit": { + "version": "0.7.3", + "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.7.3.tgz", + "integrity": "sha512-IkO+/KEUvwbVpiURZg+P7zF74z5Jxe0UgJxVni+RtoHQ6IZieXaO02kmadomap/q+l6bc/jdPGGqTjhuZnuz1Q==", + "dev": true, + "license": "Apache-2.0", + "peer": true, + "dependencies": { + "@eslint/core": "^1.2.1", + "levn": "^0.4.1" + }, + "engines": { + "node": "^20.19.0 || ^22.13.0 || >=24" + } + }, "node_modules/@floating-ui/core": { "version": "1.7.5", "resolved": "https://registry.npmjs.org/@floating-ui/core/-/core-1.7.5.tgz", @@ -870,6 +1011,77 @@ "dev": true, "license": "MIT" }, + "node_modules/@humanfs/core": { + "version": "0.19.2", + "resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.2.tgz", + "integrity": "sha512-UhXNm+CFMWcbChXywFwkmhqjs3PRCmcSa/hfBgLIb7oQ5HNb1wS0icWsGtSAUNgefHeI+eBrA8I1fxmbHsGdvA==", + "dev": true, + "license": "Apache-2.0", + "peer": true, + "dependencies": { + "@humanfs/types": "^0.15.0" + }, + "engines": { + "node": ">=18.18.0" + } + }, + "node_modules/@humanfs/node": { + "version": "0.16.8", + "resolved": "https://registry.npmjs.org/@humanfs/node/-/node-0.16.8.tgz", + "integrity": "sha512-gE1eQNZ3R++kTzFUpdGlpmy8kDZD/MLyHqDwqjkVQI0JMdI1D51sy1H958PNXYkM2rAac7e5/CnIKZrHtPh3BQ==", + "dev": true, + "license": "Apache-2.0", + "peer": true, + "dependencies": { + "@humanfs/core": "^0.19.2", + "@humanfs/types": "^0.15.0", + "@humanwhocodes/retry": "^0.4.0" + }, + "engines": { + "node": ">=18.18.0" + } + }, + "node_modules/@humanfs/types": { + "version": "0.15.0", + "resolved": "https://registry.npmjs.org/@humanfs/types/-/types-0.15.0.tgz", + "integrity": "sha512-ZZ1w0aoQkwuUuC7Yf+7sdeaNfqQiiLcSRbfI08oAxqLtpXQr9AIVX7Ay7HLDuiLYAaFPu8oBYNq/QIi9URHJ3Q==", + "dev": true, + "license": "Apache-2.0", + "peer": true, + "engines": { + "node": ">=18.18.0" + } + }, + "node_modules/@humanwhocodes/module-importer": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz", + "integrity": "sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA==", + "dev": true, + "license": "Apache-2.0", + "peer": true, + "engines": { + "node": ">=12.22" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/nzakas" + } + }, + "node_modules/@humanwhocodes/retry": { + "version": "0.4.3", + "resolved": "https://registry.npmjs.org/@humanwhocodes/retry/-/retry-0.4.3.tgz", + "integrity": "sha512-bV0Tgo9K4hfPCek+aMAn81RppFKv2ySDQeMoSZuvTASywNTnVJCArCZE2FWqpvIatKu7VMRLWlR1EazvVhDyhQ==", + "dev": true, + "license": "Apache-2.0", + "peer": true, + "engines": { + "node": ">=18.18" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/nzakas" + } + }, "node_modules/@jridgewell/gen-mapping": { "version": "0.3.13", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz", @@ -927,6 +1139,32 @@ "dev": true, "license": "MIT" }, + "node_modules/@keyv/bigmap": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@keyv/bigmap/-/bigmap-1.3.1.tgz", + "integrity": "sha512-WbzE9sdmQtKy8vrNPa9BRnwZh5UF4s1KTmSK0KUVLo3eff5BlQNNWDnFOouNpKfPKDnms9xynJjsMYjMaT/aFQ==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "hashery": "^1.4.0", + "hookified": "^1.15.0" + }, + "engines": { + "node": ">= 18" + }, + "peerDependencies": { + "keyv": "^5.6.0" + } + }, + "node_modules/@keyv/serialize": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@keyv/serialize/-/serialize-1.1.1.tgz", + "integrity": "sha512-dXn3FZhPv0US+7dtJsIi2R+c7qWYiReoEh5zUntWCf4oSpMNib8FDhSoed6m3QyZdx5hK7iLFkYk3rNxwt8vTA==", + "dev": true, + "license": "MIT", + "peer": true + }, "node_modules/@lezer/common": { "version": "1.5.2", "resolved": "https://registry.npmjs.org/@lezer/common/-/common-1.5.2.tgz", @@ -1496,6 +1734,90 @@ "node": "^20.19.0 || >=22.12.0" } }, + "node_modules/@oxlint-tsgolint/darwin-arm64": { + "version": "7.0.2003", + "resolved": "https://registry.npmjs.org/@oxlint-tsgolint/darwin-arm64/-/darwin-arm64-7.0.2003.tgz", + "integrity": "sha512-TgV33rXr6ueXBwvc+0nssUkTBSXHJxv77I8p4RCjDjCnvexHtmoPiudVRDfj3S3puMDdeQdHW6jdUgUPy3nr/w==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@oxlint-tsgolint/darwin-x64": { + "version": "7.0.2003", + "resolved": "https://registry.npmjs.org/@oxlint-tsgolint/darwin-x64/-/darwin-x64-7.0.2003.tgz", + "integrity": "sha512-hY3FMAjIaPDdK3FNxyRXRfHPOFeoBn6dmnLyKZgQ2IbTTD1adXhl6PfCIqHhCPvurigv7nf7mYuWZZ19MmJzmg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@oxlint-tsgolint/linux-arm64": { + "version": "7.0.2003", + "resolved": "https://registry.npmjs.org/@oxlint-tsgolint/linux-arm64/-/linux-arm64-7.0.2003.tgz", + "integrity": "sha512-eAET4JpyfBbg8SO0K74o4R55tEjVC292pIyxGOw2XGf8x/HrPNyxwQ478jMYOM54FIVOHc8sJ6VRHxluy6lucw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@oxlint-tsgolint/linux-x64": { + "version": "7.0.2003", + "resolved": "https://registry.npmjs.org/@oxlint-tsgolint/linux-x64/-/linux-x64-7.0.2003.tgz", + "integrity": "sha512-GXdyO/XyqDJ3s/llR/oOktLsYNjZtWSQBy0JMc+/0gsNPvTcseKPhn9c6KcFyWmnr6H4vljYALbujonqSzzEGw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@oxlint-tsgolint/win32-arm64": { + "version": "7.0.2003", + "resolved": "https://registry.npmjs.org/@oxlint-tsgolint/win32-arm64/-/win32-arm64-7.0.2003.tgz", + "integrity": "sha512-TWauXnPfet0VgpmrstoAK58eJ4gbuwPUuUTQmYQAzE/RG1CpnxXtrKUJULf6lyerPE4KN3gM+DflIA1hOH+38Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@oxlint-tsgolint/win32-x64": { + "version": "7.0.2003", + "resolved": "https://registry.npmjs.org/@oxlint-tsgolint/win32-x64/-/win32-x64-7.0.2003.tgz", + "integrity": "sha512-DoRmfe7j8VqNlukp8liRVW45GQDhzRccNenjD/pdzelgtffW47pCMd1xbJLkPaPbKnTwID3onn3VZlL7JbebEA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, "node_modules/@oxlint/binding-android-arm-eabi": { "version": "1.77.0", "resolved": "https://registry.npmjs.org/@oxlint/binding-android-arm-eabi/-/binding-android-arm-eabi-1.77.0.tgz", @@ -2158,6 +2480,27 @@ "integrity": "sha512-e7Mew686owMaPJVNNLs55PUvgz371nKgwsc4vxE49zsODpJEnxgxRo2y/OKrqueavXgZNMDVj3DdHFlaSAeU8g==", "license": "MIT" }, + "node_modules/@stylistic/eslint-plugin": { + "version": "5.10.0", + "resolved": "https://registry.npmjs.org/@stylistic/eslint-plugin/-/eslint-plugin-5.10.0.tgz", + "integrity": "sha512-nPK52ZHvot8Ju/0A4ucSX1dcPV2/1clx0kLcH5wDmrE4naKso7TUC/voUyU1O9OTKTrR6MYip6LP0ogEMQ9jPQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@eslint-community/eslint-utils": "^4.9.1", + "@typescript-eslint/types": "^8.56.0", + "eslint-visitor-keys": "^4.2.1", + "espree": "^10.4.0", + "estraverse": "^5.3.0", + "picomatch": "^4.0.3" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "peerDependencies": { + "eslint": "^9.0.0 || ^10.0.0" + } + }, "node_modules/@swc/core": { "version": "1.15.40", "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.15.40.tgz", @@ -3127,6 +3470,14 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/esrecurse": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/@types/esrecurse/-/esrecurse-4.3.1.tgz", + "integrity": "sha512-xJBAbDifo5hpffDBuHl0Y8ywswbiAp/Wi7Y/GtAgSlZyIABppyurxVueOPE8LUQOxdlgi6Zqce7uoEpqNTeiUw==", + "dev": true, + "license": "MIT", + "peer": true + }, "node_modules/@types/estree": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.9.tgz", @@ -3177,6 +3528,20 @@ "integrity": "sha512-zFDAD+tlpf2r4asuHEj0XH6pY6i0g5NeAHPn+15wk3BV6JA69eERFXC1gyGThDkVa1zCyKr5jox1+2LbV/AMLg==", "license": "MIT" }, + "node_modules/@typescript-eslint/types": { + "version": "8.71.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.71.1.tgz", + "integrity": "sha512-ybYnPTUwg3VQQOFEiBPLs8Jxl1ry2vXdn1kVKguomBbvxpetdu3MKTNDqFNUrlG8ylP9MpZosmXMFYlGQHk1oQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, "node_modules/@vitejs/plugin-react-swc": { "version": "4.3.1", "resolved": "https://registry.npmjs.org/@vitejs/plugin-react-swc/-/plugin-react-swc-4.3.1.tgz", @@ -3307,6 +3672,29 @@ "url": "https://opencollective.com/vitest" } }, + "node_modules/acorn": { + "version": "8.19.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.19.0.tgz", + "integrity": "sha512-oJlA3XiRm7Cyk6qFD2Jn8ak9B7jSy0qy00ADO3+8dpT0LSjFihQYv4C02LFCSYJV3Q37xYwwRy5m+IpIiUzqWw==", + "dev": true, + "license": "MIT", + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/acorn-jsx": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", + "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" + } + }, "node_modules/agent-base": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", @@ -3319,6 +3707,24 @@ "node": ">= 6.0.0" } }, + "node_modules/ajv": { + "version": "6.15.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.15.0.tgz", + "integrity": "sha512-fgFx7Hfoq60ytK2c7DhnF8jIvzYgOMxfugjLOSMHjLIPgenqa7S7oaagATUq99mV6IYvN2tRmC0wnTYX6iPbMw==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, "node_modules/ansi-colors": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.3.tgz", @@ -3384,12 +3790,37 @@ "proxy-from-env": "^2.1.0" } }, + "node_modules/balanced-match": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", + "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": "18 || 20 || >=22" + } + }, "node_modules/boring-avatars": { "version": "1.11.2", "resolved": "https://registry.npmjs.org/boring-avatars/-/boring-avatars-1.11.2.tgz", "integrity": "sha512-3+wkwPeObwS4R37FGXMYViqc4iTrIRj5yzfX9Qy4mnpZ26sX41dGMhsAgmKks1r/uufY1pl4vpgzMWHYfJRb2A==", "license": "MIT" }, + "node_modules/brace-expansion": { + "version": "5.0.12", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.12.tgz", + "integrity": "sha512-YovQ3rzhaLMIrDjNDMkNS01tea93qhEhG5xy8f6+R0l+dw3Ki+5sCoIoI942iuLZTHWogWktgwVDhU09iNEimQ==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "balanced-match": "^4.0.2" + }, + "engines": { + "node": "20 || >=22" + } + }, "node_modules/bundle-name": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/bundle-name/-/bundle-name-4.1.0.tgz", @@ -3435,6 +3866,21 @@ } } }, + "node_modules/cacheable": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/cacheable/-/cacheable-2.5.0.tgz", + "integrity": "sha512-60cyAOytib/OzBw1JNSoSV/boK1AtHryDIjvVBk7XbN4ugfkM3+Sry7fEjNgPMGgOjuaZPAp8ruZ0Cxafwyq9g==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "@cacheable/memory": "^2.2.0", + "@cacheable/utils": "^2.5.0", + "hookified": "^1.15.0", + "keyv": "^5.6.0", + "qified": "^0.10.1" + } + }, "node_modules/call-bind-apply-helpers": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", @@ -3828,6 +4274,14 @@ "integrity": "sha512-qIMFpTMZmny+MMIitAB6D7iVPEorVw6YQRWkvarTkT4tBeSLLiHzcwj6q0MmYSFCiVpiqPJTJEYIrpcPzVEIvg==", "license": "MIT" }, + "node_modules/deep-is": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", + "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", + "dev": true, + "license": "MIT", + "peer": true + }, "node_modules/default-browser": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/default-browser/-/default-browser-5.5.0.tgz", @@ -4037,6 +4491,202 @@ "benchmarks" ] }, + "node_modules/escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/eslint": { + "version": "10.12.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-10.12.0.tgz", + "integrity": "sha512-npHjrHb2o4ehH3mE+YuxABR+0gyb0aVWCIolgJDArwCiHEIsonBm3ZKjel5b0U5+a+MbEvIyRCGCzD3eKKK2NA==", + "dev": true, + "license": "MIT", + "peer": true, + "workspaces": [ + "packages/*" + ], + "dependencies": { + "@eslint-community/eslint-utils": "^4.8.0", + "@eslint-community/regexpp": "^4.12.2", + "@eslint/config-array": "^0.23.5", + "@eslint/config-helpers": "^0.7.0", + "@eslint/core": "^1.2.1", + "@eslint/plugin-kit": "^0.7.3", + "@humanfs/node": "^0.16.6", + "@humanwhocodes/module-importer": "^1.0.1", + "@humanwhocodes/retry": "^0.4.2", + "@types/estree": "^1.0.6", + "ajv": "^6.14.0", + "cross-spawn": "^7.0.6", + "debug": "^4.3.2", + "escape-string-regexp": "^4.0.0", + "eslint-scope": "^9.1.2", + "eslint-visitor-keys": "^5.0.1", + "espree": "^11.2.0", + "esquery": "^1.7.0", + "esutils": "^2.0.2", + "fast-deep-equal": "^3.1.3", + "file-entry-cache": "11.1.5 || >11.1.6 <12", + "find-up": "^5.0.0", + "glob-parent": "^6.0.2", + "ignore": "^5.2.0", + "imurmurhash": "^0.1.4", + "is-glob": "^4.0.0", + "json-stable-stringify-without-jsonify": "^1.0.1", + "minimatch": "^10.2.5", + "natural-compare": "^1.4.0", + "optionator": "^0.9.3" + }, + "bin": { + "eslint": "bin/eslint.js" + }, + "engines": { + "node": "^20.19.0 || ^22.13.0 || >=24" + }, + "funding": { + "url": "https://eslint.org/donate" + }, + "peerDependencies": { + "jiti": "*" + }, + "peerDependenciesMeta": { + "jiti": { + "optional": true + } + } + }, + "node_modules/eslint-scope": { + "version": "9.1.2", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-9.1.2.tgz", + "integrity": "sha512-xS90H51cKw0jltxmvmHy2Iai1LIqrfbw57b79w/J7MfvDfkIkFZ+kj6zC3BjtUwh150HsSSdxXZcsuv72miDFQ==", + "dev": true, + "license": "BSD-2-Clause", + "peer": true, + "dependencies": { + "@types/esrecurse": "^4.3.1", + "@types/estree": "^1.0.8", + "esrecurse": "^4.3.0", + "estraverse": "^5.2.0" + }, + "engines": { + "node": "^20.19.0 || ^22.13.0 || >=24" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/eslint-visitor-keys": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.2.1.tgz", + "integrity": "sha512-Uhdk5sfqcee/9H/rCOJikYz67o0a2Tw2hGRPOG2Y1R2dg7brRe1uG0yaNQDHu+TO/uQPF/5eCapvYSmHUjt7JQ==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/eslint/node_modules/eslint-visitor-keys": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-5.0.1.tgz", + "integrity": "sha512-tD40eHxA35h0PEIZNeIjkHoDR4YjjJp34biM0mDvplBe//mB+IHCqHDGV7pxF+7MklTvighcCPPZC7ynWyjdTA==", + "dev": true, + "license": "Apache-2.0", + "peer": true, + "engines": { + "node": "^20.19.0 || ^22.13.0 || >=24" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/eslint/node_modules/espree": { + "version": "11.2.0", + "resolved": "https://registry.npmjs.org/espree/-/espree-11.2.0.tgz", + "integrity": "sha512-7p3DrVEIopW1B1avAGLuCSh1jubc01H2JHc8B4qqGblmg5gI9yumBgACjWo4JlIc04ufug4xJ3SQI8HkS/Rgzw==", + "dev": true, + "license": "BSD-2-Clause", + "peer": true, + "dependencies": { + "acorn": "^8.16.0", + "acorn-jsx": "^5.3.2", + "eslint-visitor-keys": "^5.0.1" + }, + "engines": { + "node": "^20.19.0 || ^22.13.0 || >=24" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/espree": { + "version": "10.4.0", + "resolved": "https://registry.npmjs.org/espree/-/espree-10.4.0.tgz", + "integrity": "sha512-j6PAQ2uUr79PZhBjP5C5fhl8e39FmRnOjsD5lGnWrFU8i2G776tBK7+nP8KuQUTTyAZUwfQqXAgrVH5MbH9CYQ==", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "acorn": "^8.15.0", + "acorn-jsx": "^5.3.2", + "eslint-visitor-keys": "^4.2.1" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/esquery": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.7.0.tgz", + "integrity": "sha512-Ap6G0WQwcU/LHsvLwON1fAQX9Zp0A2Y6Y/cJBl9r/JbW90Zyg4/zbG6zzKa2OTALELarYHmKu0GhpM5EO+7T0g==", + "dev": true, + "license": "BSD-3-Clause", + "peer": true, + "dependencies": { + "estraverse": "^5.1.0" + }, + "engines": { + "node": ">=0.10" + } + }, + "node_modules/esrecurse": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", + "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", + "dev": true, + "license": "BSD-2-Clause", + "peer": true, + "dependencies": { + "estraverse": "^5.2.0" + }, + "engines": { + "node": ">=4.0" + } + }, + "node_modules/estraverse": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", + "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=4.0" + } + }, "node_modules/estree-walker": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz", @@ -4047,6 +4697,17 @@ "@types/estree": "^1.0.0" } }, + "node_modules/esutils": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", + "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", + "dev": true, + "license": "BSD-2-Clause", + "peer": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/eventemitter3": { "version": "5.0.4", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.4.tgz", @@ -4070,6 +4731,30 @@ "dev": true, "license": "MIT" }, + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "dev": true, + "license": "MIT", + "peer": true + }, + "node_modules/fast-json-stable-stringify": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", + "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", + "dev": true, + "license": "MIT", + "peer": true + }, + "node_modules/fast-levenshtein": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", + "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", + "dev": true, + "license": "MIT", + "peer": true + }, "node_modules/fdir": { "version": "6.5.0", "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", @@ -4088,6 +4773,56 @@ } } }, + "node_modules/file-entry-cache": { + "version": "11.1.5", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-11.1.5.tgz", + "integrity": "sha512-+PFTHITI08JIGhnNpGNI8T8inUpgZfk3GNEqfT9R2zZV2iFXg3CvqzSl/uEhs7TSGujYRELEANyDvS8Fj7+S7Q==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "flat-cache": "^6.1.23" + } + }, + "node_modules/find-up": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", + "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "locate-path": "^6.0.0", + "path-exists": "^4.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/flat-cache": { + "version": "6.1.23", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-6.1.23.tgz", + "integrity": "sha512-f++BY9pTk+983xK1FLzlLpmM0i0z+jHmx3QESGkURMXujQZz1k5wzwX6hjnQ8goaD0B+sYnDK1yZ6MTyZfUaqA==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "cacheable": "^2.5.0", + "flatted": "^3.4.2", + "hookified": "^1.15.0" + } + }, + "node_modules/flatted": { + "version": "3.4.4", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.4.4.tgz", + "integrity": "sha512-5+ybhBZANEJxaH3X5evAFatUxLfEHSr7n6kYJ+1Qd0mUqr4eu9gIf6GDbWHf8RJijHrjjO8G+la14SlL2SeS1Q==", + "dev": true, + "license": "ISC", + "peer": true + }, "node_modules/follow-redirects": { "version": "1.16.0", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.16.0.tgz", @@ -4214,6 +4949,20 @@ "giget": "dist/cli.mjs" } }, + "node_modules/glob-parent": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", + "integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==", + "dev": true, + "license": "ISC", + "peer": true, + "dependencies": { + "is-glob": "^4.0.3" + }, + "engines": { + "node": ">=10.13.0" + } + }, "node_modules/gopd": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", @@ -4260,6 +5009,20 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/hashery": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/hashery/-/hashery-1.5.1.tgz", + "integrity": "sha512-iZyKG96/JwPz1N55vj2Ie2vXbhu440zfUfJvSwEqEbeLluk7NnapfGqa7LH0mOsnDxTF85Mx8/dyR6HfqcbmbQ==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "hookified": "^1.15.0" + }, + "engines": { + "node": ">=20" + } + }, "node_modules/hasown": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz", @@ -4272,6 +5035,14 @@ "node": ">= 0.4" } }, + "node_modules/hookified": { + "version": "1.15.1", + "resolved": "https://registry.npmjs.org/hookified/-/hookified-1.15.1.tgz", + "integrity": "sha512-MvG/clsADq1GPM2KGo2nyfaWVyn9naPiXrqIe4jYjXNZQt238kWyOGrsyc/DmRAQ+Re6yeo6yX/yoNCG5KAEVg==", + "dev": true, + "license": "MIT", + "peer": true + }, "node_modules/html-encoding-sniffer": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-4.0.0.tgz", @@ -4390,6 +5161,17 @@ "node": ">=0.10.0" } }, + "node_modules/ignore": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", + "integrity": "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">= 4" + } + }, "node_modules/immer": { "version": "11.1.8", "resolved": "https://registry.npmjs.org/immer/-/immer-11.1.8.tgz", @@ -4400,6 +5182,17 @@ "url": "https://opencollective.com/immer" } }, + "node_modules/imurmurhash": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", + "integrity": "sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=0.8.19" + } + }, "node_modules/indent-string": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz", @@ -4435,6 +5228,31 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "is-extglob": "^2.1.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/is-in-ssh": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-in-ssh/-/is-in-ssh-1.0.0.tgz", @@ -4647,6 +5465,48 @@ "node": ">=18" } }, + "node_modules/json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true, + "license": "MIT", + "peer": true + }, + "node_modules/json-stable-stringify-without-jsonify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", + "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", + "dev": true, + "license": "MIT", + "peer": true + }, + "node_modules/keyv": { + "version": "5.6.0", + "resolved": "https://registry.npmjs.org/keyv/-/keyv-5.6.0.tgz", + "integrity": "sha512-CYDD3SOtsHtyXeEORYRx2qBtpDJFjRTGXUtmNEMGyzYOKj1TE3tycdlho7kA1Ufx9OYWZzg52QFBGALTirzDSw==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "@keyv/serialize": "^1.1.1" + } + }, + "node_modules/levn": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", + "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "prelude-ls": "^1.2.1", + "type-check": "~0.4.0" + }, + "engines": { + "node": ">= 0.8.0" + } + }, "node_modules/lightningcss": { "version": "1.32.0", "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.32.0.tgz", @@ -4908,6 +5768,23 @@ "url": "https://opencollective.com/parcel" } }, + "node_modules/locate-path": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", + "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "p-locate": "^5.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/lucide-react": { "version": "1.17.0", "resolved": "https://registry.npmjs.org/lucide-react/-/lucide-react-1.17.0.tgz", @@ -4986,6 +5863,23 @@ "mini-svg-data-uri": "cli.js" } }, + "node_modules/minimatch": { + "version": "10.2.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.6.tgz", + "integrity": "sha512-vpLQEs+VLCr1nU0BXS07maYoFwlDAH0gngQuuttxIwutDFEMHq2blX+8vpgxDdK3J1PwjCJiep77OitTZ4Ll1A==", + "dev": true, + "license": "BlueOak-1.0.0", + "peer": true, + "dependencies": { + "brace-expansion": "^5.0.8" + }, + "engines": { + "node": "18 || 20 || >=22" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -5011,6 +5905,14 @@ "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" } }, + "node_modules/natural-compare": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", + "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", + "dev": true, + "license": "MIT", + "peer": true + }, "node_modules/node-fetch": { "version": "2.7.0", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", @@ -5080,6 +5982,25 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/optionator": { + "version": "0.9.4", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", + "integrity": "sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "deep-is": "^0.1.3", + "fast-levenshtein": "^2.0.6", + "levn": "^0.4.1", + "prelude-ls": "^1.2.1", + "type-check": "^0.4.0", + "word-wrap": "^1.2.5" + }, + "engines": { + "node": ">= 0.8.0" + } + }, "node_modules/oxfmt": { "version": "0.72.0", "resolved": "https://registry.npmjs.org/oxfmt/-/oxfmt-0.72.0.tgz", @@ -5181,6 +6102,58 @@ } } }, + "node_modules/oxlint-tsgolint": { + "version": "7.0.2003", + "resolved": "https://registry.npmjs.org/oxlint-tsgolint/-/oxlint-tsgolint-7.0.2003.tgz", + "integrity": "sha512-VnK4zlqgmgq/7ZcjzCk/WpN8kKFsYGcB85Io9qT3wL4K8Un3RKmJkp793crNETieMusPMKOA4a+Mw2wbteI6TQ==", + "dev": true, + "license": "MIT", + "bin": { + "tsgolint": "bin/tsgolint.js" + }, + "optionalDependencies": { + "@oxlint-tsgolint/darwin-arm64": "7.0.2003", + "@oxlint-tsgolint/darwin-x64": "7.0.2003", + "@oxlint-tsgolint/linux-arm64": "7.0.2003", + "@oxlint-tsgolint/linux-x64": "7.0.2003", + "@oxlint-tsgolint/win32-arm64": "7.0.2003", + "@oxlint-tsgolint/win32-x64": "7.0.2003" + } + }, + "node_modules/p-limit": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", + "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "yocto-queue": "^0.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/p-locate": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", + "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "p-limit": "^3.0.2" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/parse5": { "version": "7.3.0", "resolved": "https://registry.npmjs.org/parse5/-/parse5-7.3.0.tgz", @@ -5194,6 +6167,17 @@ "url": "https://github.com/inikulin/parse5?sponsor=1" } }, + "node_modules/path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=8" + } + }, "node_modules/path-key": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", @@ -5291,6 +6275,17 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/prelude-ls": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", + "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">= 0.8.0" + } + }, "node_modules/pretty-format": { "version": "27.5.1", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-27.5.1.tgz", @@ -5338,6 +6333,28 @@ "node": ">=6" } }, + "node_modules/qified": { + "version": "0.10.1", + "resolved": "https://registry.npmjs.org/qified/-/qified-0.10.1.tgz", + "integrity": "sha512-+Owyggi9IxT1ePKGafcI87ubSmxol6smwJ+RAHDQlx9+9cPwFWDiKFFCPuWhr9ignlGpZ9vDQLw67N4dcTVFEA==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "hookified": "^2.1.1" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/qified/node_modules/hookified": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/hookified/-/hookified-2.2.0.tgz", + "integrity": "sha512-p/LgFzRN5FeoD3DLS6bkUapeye6E4SI6yJs6KetENd18S+FBthqYq2amJUWpt5z0EQwwHemidjY5OqJGEKm5uA==", + "dev": true, + "license": "MIT", + "peer": true + }, "node_modules/qrcode.react": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/qrcode.react/-/qrcode.react-4.2.0.tgz", @@ -5880,6 +6897,20 @@ "license": "0BSD", "optional": true }, + "node_modules/type-check": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", + "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "prelude-ls": "^1.2.1" + }, + "engines": { + "node": ">= 0.8.0" + } + }, "node_modules/typescript": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.3.tgz", @@ -5901,6 +6932,17 @@ "dev": true, "license": "MIT" }, + "node_modules/uri-js": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", + "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", + "dev": true, + "license": "BSD-2-Clause", + "peer": true, + "dependencies": { + "punycode": "^2.1.0" + } + }, "node_modules/use-sync-external-store": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.6.0.tgz", @@ -6201,6 +7243,17 @@ "node": ">=8" } }, + "node_modules/word-wrap": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", + "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/ws": { "version": "8.21.1", "resolved": "https://registry.npmjs.org/ws/-/ws-8.21.1.tgz", @@ -6257,6 +7310,20 @@ "dev": true, "license": "MIT" }, + "node_modules/yocto-queue": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", + "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/zustand": { "version": "5.0.14", "resolved": "https://registry.npmjs.org/zustand/-/zustand-5.0.14.tgz", diff --git a/package.json b/package.json index b8dda3d9d..08d690b43 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "devDependencies": { "@hey-api/openapi-ts": "0.99.0", "@oxlint/plugins": "^1.77.0", + "@stylistic/eslint-plugin": "^5.10.0", "@tailwindcss/postcss": "^4", "@testing-library/dom": "^10", "@testing-library/jest-dom": "^6", @@ -75,6 +76,7 @@ "jsdom": "^26.1.0", "oxfmt": "^0.72.0", "oxlint": "^1.77.0", + "oxlint-tsgolint": "^7.0.2003", "postcss": "^8.5.6", "typescript": "^6", "vite": "^8", @@ -90,7 +92,7 @@ "test": "vitest run", "test:watch": "vitest", "tsc": "tsc --noEmit && tsc --project tools/oxlint/rules && npm --prefix packages/hello-world run typecheck", - "lint": "oxfmt --check resources/scripts packages/hello-world tools/oxlint && oxlint resources/scripts packages/hello-world/src/client", + "lint": "oxfmt --check resources/scripts packages/hello-world tools/oxlint && oxlint --type-aware resources/scripts packages/hello-world/src/client", "api:generate": "openapi-ts", "extension:api:generate": "node scripts/generate-extension-api.mjs", "api:refresh": "PTERODACTYL_EXTENSIONS_ENABLED=false composer docs:openapi:verify && npm run api:generate", diff --git a/packages/hello-world/src/client/FileDetails.tsx b/packages/hello-world/src/client/FileDetails.tsx index d345627b0..9c45d7a9d 100644 --- a/packages/hello-world/src/client/FileDetails.tsx +++ b/packages/hello-world/src/client/FileDetails.tsx @@ -3,6 +3,7 @@ import type { ComponentPartProps, ReplacementProps } from '@pterodactyl/sdk'; function FileName({ model }: ComponentPartProps<'server.files.details'>) { return
{model.name}
; } + export default function FileDetails({ Default }: ReplacementProps<'server.files.details'>) { return ; } diff --git a/packages/hello-world/src/client/HelloWorldCard.tsx b/packages/hello-world/src/client/HelloWorldCard.tsx index ae087b884..ca7e84995 100644 --- a/packages/hello-world/src/client/HelloWorldCard.tsx +++ b/packages/hello-world/src/client/HelloWorldCard.tsx @@ -23,7 +23,7 @@ export default function HelloWorldCard({ serverName }: { serverName: string }) { }; return ( - +

Hello, {user.username}! This extension is running on {serverName}. @@ -35,11 +35,11 @@ export default function HelloWorldCard({ serverName }: { serverName: string }) {

Latest server status event
-
{lastStatus ?? 'Waiting for the next status event.'}
+
{lastStatus ?? 'Waiting for the next status event.'}
Greetings this visit
-
{greetings}
+
{greetings}
diff --git a/packages/hello-world/src/client/HelloWorldScreen.tsx b/packages/hello-world/src/client/HelloWorldScreen.tsx index 87017db20..4a6747f26 100644 --- a/packages/hello-world/src/client/HelloWorldScreen.tsx +++ b/packages/hello-world/src/client/HelloWorldScreen.tsx @@ -5,7 +5,7 @@ export default function HelloWorldScreen() { const server = useCurrentServerRequired(); return ( - +

diff --git a/packages/hello-world/src/client/SubuserPresets.tsx b/packages/hello-world/src/client/SubuserPresets.tsx index a22e8872e..a63c8de3c 100644 --- a/packages/hello-world/src/client/SubuserPresets.tsx +++ b/packages/hello-world/src/client/SubuserPresets.tsx @@ -34,11 +34,12 @@ export default function SubuserPresets({ data }: { data: SubuserPermissionsSlotD const setReinstall = (enabled: boolean) => { const permissions = data.selectedPermissions.filter((permission) => permission !== reinstallPermission); + data.setPermissions(enabled ? [...permissions, reinstallPermission] : permissions); }; return ( - +

Choose a starting point, then adjust the checkboxes below. Presets replace permissions you can edit. @@ -47,7 +48,7 @@ export default function SubuserPresets({ data }: { data: SubuserPermissionsSlotD {presets.map((preset) => (

{ vi.spyOn(window, 'scrollTo').mockImplementation(() => {}); }); @@ -31,6 +32,7 @@ afterEach(() => { }); function renderInHost(children: ReactNode, server?: SdkServer) { host = createExtensionTestHost({ server }); + return render(children, { wrapper: host.Wrapper }); } @@ -56,7 +58,8 @@ it('registers a console slot, a permissions form slot, and a lazy server page', it('shows the current user and updates local state and websocket feedback', async () => { const feedback = vi.spyOn(toast, 'success'); const server = createTestServer({ identifier: 'test', name: 'Example server' }); - renderInHost(, server); + + renderInHost(, server); await screen.findByText('Greetings this visit'); fireEvent.click(screen.getByRole('button', { name: 'Say hello' })); @@ -81,6 +84,7 @@ it('preselects role permissions without submitting the surrounding form', async disabled: false, setPermissions, }; + renderInHost(
@@ -101,6 +105,7 @@ it('preselects role permissions without submitting the surrounding form', async it('changes only the reinstall selection when the switch is toggled', async () => { function Draft() { const [selectedPermissions, setPermissions] = useState(['file.read']); + return ( <> ); } + renderInHost(); fireEvent.click(await screen.findByRole('switch')); @@ -126,6 +132,7 @@ it('changes only the reinstall selection when the switch is toggled', async () = it('disables the reinstall shortcut when it cannot be granted', async () => { const setPermissions = vi.fn(); + renderInHost( { it('disables every shortcut while the host form is read-only or saving', async () => { const setPermissions = vi.fn(); + renderInHost( { model: createTestServerCard({ name: 'Survival' }), prefix: 'hw', }); + render(, { wrapper: host.Wrapper }); expect(screen.getByText('Survival')).toBeTruthy(); expect(screen.getByText('12.00 %')).toBeTruthy(); // The prefixed utility replaces the native card's own gap instead of sitting beside it. const card = screen.getByText('Survival').closest('.grid'); + expect(card?.classList.contains('hw:gap-3')).toBe(true); expect(card?.classList.contains('gap-4')).toBe(false); }); @@ -182,6 +192,7 @@ it('customizes only the file name while native size and timestamp remain availab const host = createComponentTestHost('server.files.details', { model: createTestFileDetails({ name: 'server.properties' }), }); + render(, { wrapper: host.Wrapper }); expect(screen.getByText('server.properties').classList.contains('hw:font-medium')).toBe(true); expect(screen.getByText('1 KiB')).toBeTruthy(); @@ -192,6 +203,7 @@ it('reports unsaved changes above the native file editor', () => { const host = createComponentTestHost('server.files.editor', { model: createTestFileEditor({ name: 'server.properties', dirty: true }), }); + render(, { wrapper: host.Wrapper }); expect(screen.getByRole('status').textContent).toBe('server.properties has unsaved changes.'); expect(screen.getByRole('button', { name: 'Save Content' })).toBeTruthy(); diff --git a/resources/scripts/api/account/api-keys/queries.spec.tsx b/resources/scripts/api/account/api-keys/queries.spec.tsx index 1c95ef994..3de1a2634 100644 --- a/resources/scripts/api/account/api-keys/queries.spec.tsx +++ b/resources/scripts/api/account/api-keys/queries.spec.tsx @@ -48,6 +48,7 @@ describe('account API key mutations', () => { const { queryClient, wrapper } = setup(); const created = apiKey('created'); const perCallSuccess = vi.fn(); + mocks.create.mockResolvedValue(created); queryClient.setQueryData(queryKey, { object: 'list', data: [] }); const { result } = renderHook(() => useCreateAccountApiKey(), { wrapper }); @@ -66,7 +67,8 @@ describe('account API key mutations', () => { it('rolls an optimistic delete back before reporting the error', async () => { const { queryClient, wrapper } = setup(); const existing = apiKey('existing'); - let rejectDelete: (error: Error) => void = () => undefined; + let rejectDelete: (error: Error) => void = () => {}; + mocks.delete.mockImplementation( () => new Promise((_resolve, reject) => { @@ -97,7 +99,8 @@ describe('account API key mutations', () => { const { queryClient, wrapper } = setup(); const existing = apiKey('existing'); const created = apiKey('created'); - let rejectDelete: (error: Error) => void = () => undefined; + let rejectDelete: (error: Error) => void = () => {}; + mocks.delete.mockImplementation( () => new Promise((_resolve, reject) => { @@ -108,6 +111,7 @@ describe('account API key mutations', () => { queryClient.setQueryData(queryKey, { object: 'list', data: [existing] }); const deletion = renderHook(() => useDeleteAccountApiKey(), { wrapper }); const creation = renderHook(() => useCreateAccountApiKey(), { wrapper }); + act(() => deletion.result.current.mutate({ path: { identifier: 'existing' }, diff --git a/resources/scripts/api/account/api-keys/queries.ts b/resources/scripts/api/account/api-keys/queries.ts index 5c9d7d794..116162dc4 100644 --- a/resources/scripts/api/account/api-keys/queries.ts +++ b/resources/scripts/api/account/api-keys/queries.ts @@ -61,11 +61,13 @@ export const useDeleteAccountApiKey = () => { if (queryClient.isMutating({ mutationKey: clientDeleteAccountApiKeyMutation().mutationKey }) === 1) { return queryClient.invalidateQueries({ queryKey }); } + return Promise.resolve(); }, onError: (error, _variables, context) => { if (context?.removed) { const removed = context.removed; + queryClient.setQueryData(queryKey, (current) => upsertListItem( current, @@ -74,6 +76,7 @@ export const useDeleteAccountApiKey = () => { ) ); } + notifyHttpError(error, 'Unable to delete API key'); }, }); diff --git a/resources/scripts/api/account/queries.spec.tsx b/resources/scripts/api/account/queries.spec.tsx index 79f1ff0e3..205bf60e2 100644 --- a/resources/scripts/api/account/queries.spec.tsx +++ b/resources/scripts/api/account/queries.spec.tsx @@ -71,6 +71,7 @@ describe('session queries', () => { }), })); const { result } = renderHook(() => useCurrentUser(), { wrapper }); + expect(result.current).toMatchObject({ uuid: 'user-uuid', email: 'alex@example.test', useTotp: false }); act(() => setCurrentUserQueryData(client, { useTotp: true })); diff --git a/resources/scripts/api/account/servers/queries.ts b/resources/scripts/api/account/servers/queries.ts index fbd711383..bfa79dd39 100644 --- a/resources/scripts/api/account/servers/queries.ts +++ b/resources/scripts/api/account/servers/queries.ts @@ -28,7 +28,10 @@ type ServerListParams = { const clientServersInput = ({ page, query, type }: ServerListParams = {}): Options => { const queryParameters: ClientServerListQuery = { page, type }; - if (query) queryParameters['filter[*]'] = query; + + if (query) { + queryParameters['filter[*]'] = query; + } return { query: queryParameters }; }; diff --git a/resources/scripts/api/account/ssh-keys/queries.ts b/resources/scripts/api/account/ssh-keys/queries.ts index 7777698c3..8fa28d529 100644 --- a/resources/scripts/api/account/ssh-keys/queries.ts +++ b/resources/scripts/api/account/ssh-keys/queries.ts @@ -65,11 +65,13 @@ export const useDeleteSSHKey = () => { if (queryClient.isMutating({ mutationKey: clientDeleteSshKeyMutation().mutationKey }) === 1) { return queryClient.invalidateQueries({ queryKey }); } + return Promise.resolve(); }, onError: (error, _variables, context) => { if (context?.removed) { const removed = context.removed; + queryClient.setQueryData(queryKey, (current) => upsertListItem( current, @@ -78,6 +80,7 @@ export const useDeleteSSHKey = () => { ) ); } + notifyHttpError(error, 'Unable to delete SSH key'); }, }); diff --git a/resources/scripts/api/activity.ts b/resources/scripts/api/activity.ts index f710108c7..19cd17e40 100644 --- a/resources/scripts/api/activity.ts +++ b/resources/scripts/api/activity.ts @@ -20,11 +20,25 @@ export const activityLogQuery = (filters?: ActivityLogFilters): ActivityLogQuery const timestamp = filters?.sorts?.timestamp; const query: ActivityLogQuery = { include: 'actor' }; - if (filters?.page !== undefined) query.page = filters.page; - if (event) query['filter[event_name]'] = event; - if (user !== undefined && Number.isFinite(Number(user))) query['filter[user_id]'] = Number(user); - if (timestamp === -1 || timestamp === 'desc') query.sort = '-timestamp'; - if (timestamp === 1 || timestamp === 'asc') query.sort = 'timestamp'; + if (filters?.page !== undefined) { + query.page = filters.page; + } + + if (event) { + query['filter[event_name]'] = event; + } + + if (user !== undefined && Number.isFinite(Number(user))) { + query['filter[user_id]'] = Number(user); + } + + if (timestamp === -1 || timestamp === 'desc') { + query.sort = '-timestamp'; + } + + if (timestamp === 1 || timestamp === 'asc') { + query.sort = 'timestamp'; + } return query; }; diff --git a/resources/scripts/api/admin/api-keys/queries.ts b/resources/scripts/api/admin/api-keys/queries.ts index c3739fb84..a76a71072 100644 --- a/resources/scripts/api/admin/api-keys/queries.ts +++ b/resources/scripts/api/admin/api-keys/queries.ts @@ -102,6 +102,7 @@ export const useCreateAdminApiKey = () => { onSuccess: async (apiKey) => { await invalidateGeneratedOperations(queryClient, ['adminListApiKeys']); const messages = resourceMutationMessages('application API key', 'create', apiKey.attributes.identifier); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => @@ -117,6 +118,7 @@ export const useDeleteAdminApiKey = () => { onSuccess: async (_data, variables) => { await invalidateGeneratedOperations(queryClient, ['adminListApiKeys']); const messages = resourceMutationMessages('application API key', 'delete', variables.path.identifier); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => diff --git a/resources/scripts/api/admin/database-hosts/queries.ts b/resources/scripts/api/admin/database-hosts/queries.ts index 2899e4d6f..ffdd1c55a 100644 --- a/resources/scripts/api/admin/database-hosts/queries.ts +++ b/resources/scripts/api/admin/database-hosts/queries.ts @@ -137,11 +137,13 @@ export const useAdminDatabaseHostDatabases = (id: number, page = 1, options?: Re export const useCreateAdminDatabaseHost = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminCreateDatabaseHostMutation(), onSuccess: async (host) => { await invalidateGeneratedOperations(queryClient, ['adminListDatabaseHosts']); const messages = resourceMutationMessages('database host', 'create', host.attributes.name); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('database host', 'create').errorTitle), @@ -150,6 +152,7 @@ export const useCreateAdminDatabaseHost = () => { export const useUpdateAdminDatabaseHost = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminUpdateDatabaseHostMutation(), onSuccess: async (host, variables) => { @@ -160,6 +163,7 @@ export const useUpdateAdminDatabaseHost = () => { }), ]); const messages = resourceMutationMessages('database host', 'update', host.attributes.name); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('database host', 'update').errorTitle), @@ -168,15 +172,18 @@ export const useUpdateAdminDatabaseHost = () => { export const useDeleteAdminDatabaseHost = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminDeleteDatabaseHostMutation(), onSuccess: async (_data, variables) => { const id = variables.path.databaseHost_id; + removeQueriesWhenUnobserved(queryClient, { queryKey: adminDatabaseHostDetailKey(id) }); removeQueriesWhenUnobserved(queryClient, { queryKey: adminDatabaseHostDatabasesKey(id) }); await invalidateGeneratedOperations(queryClient, ['adminListDatabaseHosts']); const name = variables.meta?.name; const messages = resourceMutationMessages('database host', 'delete', name); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('database host', 'delete').errorTitle), diff --git a/resources/scripts/api/admin/eggs/catalog.ts b/resources/scripts/api/admin/eggs/catalog.ts index 7780eb8f0..e5a3837dd 100644 --- a/resources/scripts/api/admin/eggs/catalog.ts +++ b/resources/scripts/api/admin/eggs/catalog.ts @@ -27,6 +27,7 @@ export const importAdminCatalogEggInput = (catalogId: string): Options { const queryClient = useQueryClient(); + return useMutation({ ...adminImportCatalogEggMutation(), onSuccess: async (egg) => { @@ -39,6 +40,7 @@ export const useImportAdminCatalogEgg = () => { export const useRefreshAdminEggCatalog = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminRefreshEggCatalogMutation(), onSuccess: () => queryClient.invalidateQueries({ queryKey: adminListEggCatalogQueryKey() }), diff --git a/resources/scripts/api/admin/eggs/queries.spec.tsx b/resources/scripts/api/admin/eggs/queries.spec.tsx index e962aae6c..b8e271be6 100644 --- a/resources/scripts/api/admin/eggs/queries.spec.tsx +++ b/resources/scripts/api/admin/eggs/queries.spec.tsx @@ -20,6 +20,7 @@ import { } from './queries'; const notifications = vi.hoisted(() => ({ success: vi.fn(), error: vi.fn() })); + vi.mock('sonner', () => ({ toast: { success: notifications.success } })); vi.mock('@/plugins/notifications', () => ({ notifyHttpError: notifications.error })); @@ -57,19 +58,23 @@ describe('mutation cache reconciliation', () => { it('stays pending through the list refresh even if the initiating component unmounts', async () => { let finishRefresh = () => {}; + adapter.mockImplementation((config) => { const response = { config, headers: {}, status: 200, statusText: 'OK' }; + if (config.method === 'get') { return new Promise((resolve) => { finishRefresh = () => resolve({ ...response, data: { object: 'list', data: [created] } }); }); } + return Promise.resolve({ ...response, data: created }); }); const list = renderHook(() => useAdminEggVariables(1), { wrapper }); const mutation = renderHook(() => useCreateAdminEggVariable(), { wrapper }); const finished = vi.fn(); let saving: Promise; + act(() => { saving = mutation.result.current.mutateAsync(input).then(finished); }); @@ -97,8 +102,11 @@ describe('mutation cache reconciliation', () => { ]; const otherEgg = adminEggQueryOptions(2).queryKey; const seed = () => { - for (const key of [...reads, otherEgg]) client.setQueryData(key, { object: 'egg', attributes: { id: 1 } }); + for (const key of [...reads, otherEgg]) { + client.setQueryData(key, { object: 'egg', attributes: { id: 1 } }); + } }; + adapter.mockImplementation(async (config) => ({ config, headers: {}, @@ -115,7 +123,10 @@ describe('mutation cache reconciliation', () => { updateAdminEggVariableInput(1, 5, { name: 'Port', env_variable: 'PORT', rules: 'required' }) ); }); - for (const key of reads) expect(client.getQueryState(key)?.isInvalidated).toBe(true); + for (const key of reads) { + expect(client.getQueryState(key)?.isInvalidated).toBe(true); + } + expect(client.getQueryState(otherEgg)?.isInvalidated).toBe(false); client.clear(); @@ -129,17 +140,24 @@ describe('mutation cache reconciliation', () => { }) ); }); - for (const key of reads) expect(client.getQueryState(key)?.isInvalidated).toBe(true); + for (const key of reads) { + expect(client.getQueryState(key)?.isInvalidated).toBe(true); + } + expect(client.getQueryState(otherEgg)?.isInvalidated).toBe(false); }); it('reports a refresh error without turning a successful write into a failed creation', async () => { adapter.mockImplementation(async (config) => { - if (config.method === 'get') throw new Error('Refresh failed'); + if (config.method === 'get') { + throw new Error('Refresh failed'); + } + return { config, headers: {}, status: 200, statusText: 'OK', data: created }; }); const list = renderHook(() => useAdminEggVariables(1), { wrapper }); const mutation = renderHook(() => useCreateAdminEggVariable(), { wrapper }); + await act(async () => { await expect(mutation.result.current.mutateAsync(input)).resolves.toEqual(created); }); diff --git a/resources/scripts/api/admin/eggs/queries.ts b/resources/scripts/api/admin/eggs/queries.ts index 8ef978060..20db5193d 100644 --- a/resources/scripts/api/admin/eggs/queries.ts +++ b/resources/scripts/api/admin/eggs/queries.ts @@ -165,6 +165,7 @@ const invalidateAdminEggVariables = (queryClient: QueryClient, eggId: number) => export const useImportAdminEgg = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminImportEggMutation(), onSuccess: async (egg) => { @@ -179,6 +180,7 @@ export const useImportAdminEgg = () => { export const useCreateAdminEgg = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminCreateEggMutation(), onSuccess: async (egg) => { @@ -187,6 +189,7 @@ export const useCreateAdminEgg = () => { queryClient.invalidateQueries({ queryKey: adminEggDetailKey(egg.attributes.id) }), ]); const messages = resourceMutationMessages('egg', 'create', egg.attributes.name); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('egg', 'create').errorTitle), @@ -195,6 +198,7 @@ export const useCreateAdminEgg = () => { export const useUpdateAdminEgg = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminUpdateEggMutation(), onSuccess: async (egg) => { @@ -203,6 +207,7 @@ export const useUpdateAdminEgg = () => { queryClient.invalidateQueries({ queryKey: adminEggDetailKey(egg.attributes.id) }), ]); const messages = resourceMutationMessages('egg', 'update', egg.attributes.name); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('egg', 'update').errorTitle), @@ -211,6 +216,7 @@ export const useUpdateAdminEgg = () => { export const useUpdateAdminEggScript = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminUpdateEggInstallScriptMutation(), onSuccess: async (egg) => { @@ -228,6 +234,7 @@ export const useUpdateAdminEggScript = () => { export const useUpdateAdminEggFromFile = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminUpdateEggFromImportMutation(), onSuccess: async (egg) => { @@ -247,16 +254,19 @@ export const useExportAdminEgg = (eggId: number) => useQuery(adminEggExportQuery export const useDeleteAdminEgg = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminDeleteEggMutation(), onSuccess: async (_data, variables) => { const eggId = variables.path.egg_id; + removeQueriesWhenUnobserved(queryClient, { queryKey: adminEggDetailKey(eggId) }); removeQueriesWhenUnobserved(queryClient, { queryKey: adminEggVariableListQueryKey(eggId) }); removeQueriesWhenUnobserved(queryClient, { queryKey: adminExportEggQueryKey({ path: { egg_id: eggId } }) }); await invalidateGeneratedOperations(queryClient, adminEggListOperations); const name = variables.meta?.name; const messages = resourceMutationMessages('egg', 'delete', name); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('egg', 'delete').errorTitle), @@ -265,11 +275,13 @@ export const useDeleteAdminEgg = () => { export const useCreateAdminEggVariable = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminCreateEggVariableMutation(), onSuccess: async (variable, variables) => { await invalidateAdminEggVariables(queryClient, variables.path.egg_id); const messages = resourceMutationMessages('variable', 'create', variable.attributes.name); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('variable', 'create').errorTitle), @@ -278,11 +290,13 @@ export const useCreateAdminEggVariable = () => { export const useUpdateAdminEggVariable = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminUpdateEggVariableMutation(), onSuccess: async (variable, variables) => { await invalidateAdminEggVariables(queryClient, variables.path.egg_id); const messages = resourceMutationMessages('variable', 'update', variable.attributes.name); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('variable', 'update').errorTitle), @@ -291,12 +305,14 @@ export const useUpdateAdminEggVariable = () => { export const useDeleteAdminEggVariable = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminDeleteEggVariableMutation(), onSuccess: async (_data, variables) => { await invalidateAdminEggVariables(queryClient, variables.path.egg_id); const name = variables.meta?.name; const messages = resourceMutationMessages('variable', 'delete', name); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('variable', 'delete').errorTitle), diff --git a/resources/scripts/api/admin/extensions/queries.ts b/resources/scripts/api/admin/extensions/queries.ts index f2b44bfb9..d3bcdfc2a 100644 --- a/resources/scripts/api/admin/extensions/queries.ts +++ b/resources/scripts/api/admin/extensions/queries.ts @@ -62,6 +62,7 @@ export const extensionReplacement = (cause: unknown): AdminExtensionReplacement const data: unknown = cause.response.data; const first: unknown = isObject(data) && 'errors' in data && Array.isArray(data.errors) ? data.errors[0] : null; const meta: unknown = isObject(first) && 'meta' in first ? first.meta : null; + if (!isObject(meta) || !('identifier' in meta) || !('version' in meta) || !isString(meta.identifier)) { return null; } @@ -132,6 +133,7 @@ export const useAdminExtensionSettings = (extension: string, options?: { enabled export const useUpdateAdminExtensionSettings = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminUpdateExtensionSettingsMutation(), onSuccess: async (_data, variables) => { @@ -141,6 +143,7 @@ export const useUpdateAdminExtensionSettings = () => { }), }); const name = variables.meta?.name ?? 'the extension'; + toast.success('Settings saved', { description: `Settings for ${name} have been updated.` }); }, onError: (error) => notifyHttpError(error, 'Unable to update extension settings'), @@ -149,6 +152,7 @@ export const useUpdateAdminExtensionSettings = () => { export const useUploadAdminExtensionSettingFile = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminUploadExtensionSettingFileMutation(), onSuccess: (data, variables) => { @@ -164,6 +168,7 @@ export const useUploadAdminExtensionSettingFile = () => { export const useClearAdminExtensionSettingFile = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminClearExtensionSettingFileMutation(), onSuccess: (data, variables) => { @@ -185,11 +190,13 @@ const notifyReloadToApply = (title: string, description: string) => export const useInstallAdminExtension = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminInstallExtensionMutation(), onSuccess: async (data) => { await queryClient.invalidateQueries({ queryKey: adminListExtensionsQueryKey() }); const description = `${data.data?.name ?? 'The extension'} has been installed.`; + if (data.data?.enabled) { notifyReloadToApply('Extension installed', description); } else { @@ -207,11 +214,13 @@ export const useInstallAdminExtension = () => { export const useEnableAdminExtension = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminEnableExtensionMutation(), onSuccess: async (data, variables) => { await queryClient.invalidateQueries({ queryKey: adminListExtensionsQueryKey() }); const fallback = variables.meta?.name ?? 'The extension'; + notifyReloadToApply('Extension enabled', `${data.data?.name ?? fallback} has been enabled.`); }, onError: (error) => notifyHttpError(error, 'Unable to enable extension'), @@ -220,11 +229,13 @@ export const useEnableAdminExtension = () => { export const useDisableAdminExtension = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminDisableExtensionMutation(), onSuccess: async (data, variables) => { await queryClient.invalidateQueries({ queryKey: adminListExtensionsQueryKey() }); const fallback = variables.meta?.name ?? 'The extension'; + notifyReloadToApply('Extension disabled', `${data.data?.name ?? fallback} has been disabled.`); }, onError: (error) => notifyHttpError(error, 'Unable to disable extension'), @@ -233,11 +244,13 @@ export const useDisableAdminExtension = () => { export const useRemoveAdminExtension = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminRemoveExtensionMutation(), onSuccess: async (_data, variables) => { await queryClient.invalidateQueries({ queryKey: adminListExtensionsQueryKey() }); const name = variables.meta?.name ?? 'The extension'; + notifyReloadToApply('Extension removed', `${name} has been removed.`); }, onError: (error) => notifyHttpError(error, 'Unable to remove extension'), diff --git a/resources/scripts/api/admin/locations/queries.ts b/resources/scripts/api/admin/locations/queries.ts index 0146997a7..c784857f6 100644 --- a/resources/scripts/api/admin/locations/queries.ts +++ b/resources/scripts/api/admin/locations/queries.ts @@ -111,6 +111,7 @@ export const useCreateAdminLocation = () => { onSuccess: async (location) => { await invalidateGeneratedOperations(queryClient, ['adminListLocations']); const messages = resourceMutationMessages('location', 'create', location.attributes.short); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('location', 'create').errorTitle), @@ -128,6 +129,7 @@ export const useUpdateAdminLocation = () => { queryClient.invalidateQueries({ queryKey: adminLocationDetailKey(variables.path.id) }), ]); const messages = resourceMutationMessages('location', 'update', location.attributes.short); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('location', 'update').errorTitle), @@ -144,6 +146,7 @@ export const useDeleteAdminLocation = () => { await invalidateGeneratedOperations(queryClient, ['adminListLocations']); const name = variables.meta?.short; const messages = resourceMutationMessages('location', 'delete', name); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('location', 'delete').errorTitle), diff --git a/resources/scripts/api/admin/mounts/queries.ts b/resources/scripts/api/admin/mounts/queries.ts index 7a8d2b739..40ede7c4a 100644 --- a/resources/scripts/api/admin/mounts/queries.ts +++ b/resources/scripts/api/admin/mounts/queries.ts @@ -162,11 +162,13 @@ export const useAdminMount = (id: number, options?: ResourceQueryOverrides) => export const useCreateAdminMount = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminCreateMountMutation(), onSuccess: async (mount) => { await invalidateGeneratedOperations(queryClient, ['adminListMounts']); const messages = resourceMutationMessages('mount', 'create', mount.attributes.name); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('mount', 'create').errorTitle), @@ -175,6 +177,7 @@ export const useCreateAdminMount = () => { export const useUpdateAdminMount = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminUpdateMountMutation(), onSuccess: async (mount, variables) => { @@ -183,6 +186,7 @@ export const useUpdateAdminMount = () => { queryClient.invalidateQueries({ queryKey: adminMountDetailKey(variables.path.id) }), ]); const messages = resourceMutationMessages('mount', 'update', mount.attributes.name); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('mount', 'update').errorTitle), @@ -191,6 +195,7 @@ export const useUpdateAdminMount = () => { export const useDeleteAdminMount = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminDeleteMountMutation(), onSuccess: async (_data, variables) => { @@ -198,6 +203,7 @@ export const useDeleteAdminMount = () => { await invalidateGeneratedOperations(queryClient, ['adminListMounts']); const name = variables.meta?.name; const messages = resourceMutationMessages('mount', 'delete', name); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('mount', 'delete').errorTitle), @@ -206,6 +212,7 @@ export const useDeleteAdminMount = () => { export const useAttachAdminMountEggs = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminAttachEggsToMountMutation(), onSuccess: async (mount) => { @@ -220,6 +227,7 @@ export const useAttachAdminMountEggs = () => { export const useAttachAdminMountNodes = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminAttachNodesToMountMutation(), onSuccess: async (mount) => { @@ -234,6 +242,7 @@ export const useAttachAdminMountNodes = () => { export const useDetachAdminMountEgg = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminDetachEggFromMountMutation(), onSuccess: async (_data, variables) => { @@ -242,6 +251,7 @@ export const useDetachAdminMountEgg = () => { queryClient.invalidateQueries({ queryKey: adminMountDetailKey(variables.path.mount_id) }), ]); const name = variables.meta?.name; + toast.success('Egg detached', { description: name ? `${name} has been detached from this mount.` @@ -254,6 +264,7 @@ export const useDetachAdminMountEgg = () => { export const useDetachAdminMountNode = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminDetachNodeFromMountMutation(), onSuccess: async (_data, variables) => { @@ -262,6 +273,7 @@ export const useDetachAdminMountNode = () => { queryClient.invalidateQueries({ queryKey: adminMountDetailKey(variables.path.mount_id) }), ]); const name = variables.meta?.name; + toast.success('Node detached', { description: name ? `${name} has been detached from this mount.` diff --git a/resources/scripts/api/admin/nodes/invalidation.ts b/resources/scripts/api/admin/nodes/invalidation.ts index 5bbcb1e1b..7c3b572d4 100644 --- a/resources/scripts/api/admin/nodes/invalidation.ts +++ b/resources/scripts/api/admin/nodes/invalidation.ts @@ -19,6 +19,7 @@ export const invalidateAdminNodeAllocations = async ( 'adminGetNode', 'adminListNodeAllocations', ]); + return; } diff --git a/resources/scripts/api/admin/nodes/queries.ts b/resources/scripts/api/admin/nodes/queries.ts index a8ddf3b93..d40107c37 100644 --- a/resources/scripts/api/admin/nodes/queries.ts +++ b/resources/scripts/api/admin/nodes/queries.ts @@ -366,11 +366,13 @@ export const useAdminNodeAllocations = (id: number, page: number, options?: Reso export const useCreateAdminNode = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminCreateNodeMutation(), onSuccess: async (node) => { await invalidateGeneratedOperations(queryClient, ['adminListNodes']); const messages = resourceMutationMessages('node', 'create', node.attributes.name); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('node', 'create').errorTitle), @@ -379,6 +381,7 @@ export const useCreateAdminNode = () => { export const useUpdateAdminNode = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminUpdateNodeMutation(), onSuccess: async (node, variables) => { @@ -390,6 +393,7 @@ export const useUpdateAdminNode = () => { }), ]); const messages = resourceMutationMessages('node', 'update', node.attributes.name); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('node', 'update').errorTitle), @@ -398,15 +402,18 @@ export const useUpdateAdminNode = () => { export const useDeleteAdminNode = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminDeleteNodeMutation(), onSuccess: async (_data, variables) => { for (const queryKey of adminNodeScopedKeys(variables.path.node_id)) { removeQueriesWhenUnobserved(queryClient, { queryKey }); } + await invalidateGeneratedOperations(queryClient, ['adminListNodes']); const name = variables.meta?.name; const messages = resourceMutationMessages('node', 'delete', name); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('node', 'delete').errorTitle), @@ -421,6 +428,7 @@ export const useGenerateAdminNodeDeployToken = () => export const useCreateAdminNodeAllocations = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminCreateNodeAllocationsMutation(), onSuccess: async (_data, variables) => { @@ -433,6 +441,7 @@ export const useCreateAdminNodeAllocations = () => { export const useUpdateAdminNodeAllocationAlias = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminUpdateNodeAllocationMutation(), onSuccess: (_data, variables) => invalidateAdminNodeAllocations(queryClient, [variables.path.node_id]), @@ -442,6 +451,7 @@ export const useUpdateAdminNodeAllocationAlias = () => { export const useDeleteAdminNodeAllocation = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminDeleteNodeAllocationMutation(), onSuccess: (_data, variables) => invalidateAdminNodeAllocations(queryClient, [variables.path.node_id]), @@ -451,6 +461,7 @@ export const useDeleteAdminNodeAllocation = () => { export const useBulkDeleteAdminNodeAllocations = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminBulkDeleteNodeAllocationsMutation(), onSuccess: async (_data, variables) => { @@ -463,6 +474,7 @@ export const useBulkDeleteAdminNodeAllocations = () => { export const useDeleteAdminNodeIpBlockAllocations = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminDeleteNodeAllocationIpBlockMutation(), onSuccess: async (_data, variables) => { diff --git a/resources/scripts/api/admin/servers/queries.spec.tsx b/resources/scripts/api/admin/servers/queries.spec.tsx index d2aa8e188..c2afe5d01 100644 --- a/resources/scripts/api/admin/servers/queries.spec.tsx +++ b/resources/scripts/api/admin/servers/queries.spec.tsx @@ -61,7 +61,9 @@ describe('admin server cache', () => { client.setQueryData(adminServerQueryOptions(7).queryKey, server); seed(adminServerDatabasesQueryOptions(7).queryKey, { object: 'list', data: [] }); for (const nodeId of [3, 4, 5]) { - for (const key of nodeReads(nodeId)) seed(key, { object: 'list', data: [] }); + for (const key of nodeReads(nodeId)) { + seed(key, { object: 'list', data: [] }); + } } }); @@ -94,8 +96,13 @@ describe('admin server cache', () => { detail.unmount(); expect(client.getQueryData(adminServerQueryOptions(7).queryKey)).toBeUndefined(); - for (const key of nodeReads(3)) expect(isInvalidated(key)).toBe(true); - for (const key of nodeReads(4)) expect(isInvalidated(key)).toBe(false); + for (const key of nodeReads(3)) { + expect(isInvalidated(key)).toBe(true); + } + + for (const key of nodeReads(4)) { + expect(isInvalidated(key)).toBe(false); + } } ); @@ -108,8 +115,13 @@ describe('admin server cache', () => { ); }); - for (const key of nodeReads(3)) expect(isInvalidated(key)).toBe(true); - for (const key of nodeReads(4)) expect(isInvalidated(key)).toBe(false); + for (const key of nodeReads(3)) { + expect(isInvalidated(key)).toBe(true); + } + + for (const key of nodeReads(4)) { + expect(isInvalidated(key)).toBe(false); + } }); it('refreshes the allocations of the source and destination nodes of a transfer', async () => { @@ -119,8 +131,13 @@ describe('admin server cache', () => { await transfer.result.current.mutateAsync(transferAdminServerInput(7, { node_id: 4, allocation_id: 1 })); }); - for (const key of [...nodeReads(3), ...nodeReads(4)]) expect(isInvalidated(key)).toBe(true); - for (const key of nodeReads(5)) expect(isInvalidated(key)).toBe(false); + for (const key of [...nodeReads(3), ...nodeReads(4)]) { + expect(isInvalidated(key)).toBe(true); + } + + for (const key of nodeReads(5)) { + expect(isInvalidated(key)).toBe(false); + } }); it('refreshes the node configuration after a node update', async () => { diff --git a/resources/scripts/api/admin/servers/queries.ts b/resources/scripts/api/admin/servers/queries.ts index ae98d70f3..6d0ee5668 100644 --- a/resources/scripts/api/admin/servers/queries.ts +++ b/resources/scripts/api/admin/servers/queries.ts @@ -213,7 +213,7 @@ const adminServerDetailIncludes = ['allocations', 'user', 'node', 'node.location const numericFilterValue = (value: NonNullable['node_id' | 'owner_id']) => { if (value === undefined || value === null || value === '') { - return undefined; + return; } const normalized = Array.isArray(value) ? value[0] : value; @@ -254,9 +254,17 @@ const toAdminServersQuery = ({ const nodeId = numericFilterValue(nodeIdFilter); const ownerId = numericFilterValue(ownerIdFilter); - if (nodeId !== undefined) query['filter[node_id]'] = nodeId; - if (ownerId !== undefined) query['filter[owner_id]'] = ownerId; - if (include.length > 0) query.include = include.join(','); + if (nodeId !== undefined) { + query['filter[node_id]'] = nodeId; + } + + if (ownerId !== undefined) { + query['filter[owner_id]'] = ownerId; + } + + if (include.length > 0) { + query.include = include.join(','); + } return query; }; @@ -425,6 +433,7 @@ export const useAdminServerTransferProgress = (id: number, options?: ResourceQue export const useCreateAdminServer = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminCreateServerMutation(), onSuccess: async (server) => { @@ -433,6 +442,7 @@ export const useCreateAdminServer = () => { invalidateAdminNodeAllocations(queryClient, [server.attributes.node]), ]); const messages = resourceMutationMessages('server', 'create', server.attributes.name); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('server', 'create').errorTitle), @@ -441,6 +451,7 @@ export const useCreateAdminServer = () => { export const useUpdateAdminServerDetails = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminUpdateServerDetailsMutation(), onSuccess: async (server, variables) => { @@ -458,6 +469,7 @@ export const useUpdateAdminServerDetails = () => { export const useUpdateAdminServerBuild = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminUpdateServerBuildMutation(), onSuccess: async (server) => { @@ -476,6 +488,7 @@ export const useUpdateAdminServerBuild = () => { export const useUpdateAdminServerStartup = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminUpdateServerStartupMutation(), onSuccess: async (server, variables) => { @@ -495,6 +508,7 @@ export const useUpdateAdminServerStartup = () => { const onAdminServerDeleted = async (queryClient: QueryClient, id: string) => { const nodeId = cachedAdminServerNode(queryClient, id); + for (const queryKey of adminServerScopedKeys(id)) { removeQueriesWhenUnobserved(queryClient, { queryKey }); } @@ -507,12 +521,14 @@ const onAdminServerDeleted = async (queryClient: QueryClient, id: string) => { export const useDeleteAdminServer = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminDeleteServerMutation(), onSuccess: async (_data, variables) => { await onAdminServerDeleted(queryClient, variables.path.server_admin_identifier); const name = variables.meta?.name; const messages = resourceMutationMessages('server', 'delete', name); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('server', 'delete').errorTitle), @@ -521,12 +537,14 @@ export const useDeleteAdminServer = () => { export const useForceDeleteAdminServer = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminForceDeleteServerMutation(), onSuccess: async (_data, variables) => { await onAdminServerDeleted(queryClient, variables.path.server_admin_identifier); const name = variables.meta?.name; const messages = resourceMutationMessages('server', 'delete', name); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('server', 'delete').errorTitle), @@ -535,11 +553,13 @@ export const useForceDeleteAdminServer = () => { export const useTransferAdminServer = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminTransferServerMutation(), onSuccess: async (_data, variables) => { const id = Number(variables.path.server_admin_identifier); const sourceNodeId = cachedAdminServerNode(queryClient, id); + await Promise.all([ invalidateGeneratedOperations(queryClient, ['adminListServers']), queryClient.invalidateQueries({ queryKey: adminServerDetailKey(id) }), @@ -561,6 +581,7 @@ export const useTransferAdminServer = () => { export const useCreateAdminServerDatabase = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminCreateServerDatabaseMutation(), onSuccess: async (database, variables) => { @@ -571,6 +592,7 @@ export const useCreateAdminServerDatabase = () => { invalidateGeneratedOperations(queryClient, ['adminListDatabaseHostDatabases']), ]); const messages = resourceMutationMessages('database', 'create', database.attributes.name); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('database', 'create').errorTitle), @@ -579,6 +601,7 @@ export const useCreateAdminServerDatabase = () => { export const useDeleteAdminServerDatabase = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminDeleteServerDatabaseMutation(), onSuccess: async (_data, variables) => { @@ -590,6 +613,7 @@ export const useDeleteAdminServerDatabase = () => { ]); const name = variables.meta?.name; const messages = resourceMutationMessages('database', 'delete', name); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('database', 'delete').errorTitle), @@ -598,6 +622,7 @@ export const useDeleteAdminServerDatabase = () => { export const useRotateAdminServerDatabasePassword = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminRotateServerDatabasePasswordMutation(), onSuccess: async (database, variables) => { @@ -614,6 +639,7 @@ export const useRotateAdminServerDatabasePassword = () => { export const useAttachAdminServerMount = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminAttachServerMountMutation(), onSuccess: async (_data, variables) => { @@ -621,6 +647,7 @@ export const useAttachAdminServerMount = () => { queryKey: adminServerMountListQueryKey(variables.path.server_admin_identifier), }); const name = variables.meta?.name; + toast.success('Mount attached', { description: name ? `${name} has been mounted to this server.` @@ -633,6 +660,7 @@ export const useAttachAdminServerMount = () => { export const useDetachAdminServerMount = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminDetachServerMountMutation(), onSuccess: async (_data, variables) => { @@ -640,6 +668,7 @@ export const useDetachAdminServerMount = () => { queryKey: adminServerMountListQueryKey(variables.path.server_admin_identifier), }); const name = variables.meta?.name; + toast.success('Mount detached', { description: name ? `${name} has been unmounted from this server.` @@ -652,6 +681,7 @@ export const useDetachAdminServerMount = () => { export const useReinstallAdminServer = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminReinstallServerMutation(), onSuccess: async (_data, variables) => { @@ -669,6 +699,7 @@ export const useReinstallAdminServer = () => { export const useToggleAdminServerInstallState = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminToggleServerInstallStateMutation(), onSuccess: async (_data, variables) => { @@ -686,6 +717,7 @@ export const useToggleAdminServerInstallState = () => { export const useUpdateAdminServerSuspension = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminUpdateServerSuspensionMutation(), onSuccess: async (_data, variables) => { diff --git a/resources/scripts/api/admin/settings/queries.spec.tsx b/resources/scripts/api/admin/settings/queries.spec.tsx index f18c6948e..f5b596ea5 100644 --- a/resources/scripts/api/admin/settings/queries.spec.tsx +++ b/resources/scripts/api/admin/settings/queries.spec.tsx @@ -35,6 +35,7 @@ describe('admin settings mutations', () => { const wrapper = ({ children }: PropsWithChildren) => ( {children} ); + mocks.updateMail.mockResolvedValue(undefined); const { result } = renderHook(() => useUpdateAdminMailSettings({ successNotification: false }), { wrapper }); diff --git a/resources/scripts/api/admin/settings/queries.ts b/resources/scripts/api/admin/settings/queries.ts index f1cf7c3a0..91703f923 100644 --- a/resources/scripts/api/admin/settings/queries.ts +++ b/resources/scripts/api/admin/settings/queries.ts @@ -118,6 +118,7 @@ export const useAdminSettings = (options?: AdminSettingsQueryOptions) => export const useUpdateAdminGeneralSettings = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminUpdateGeneralSettingsMutation(), onSuccess: async (_data, { body }) => { @@ -128,6 +129,7 @@ export const useUpdateAdminGeneralSettings = () => { })); await queryClient.invalidateQueries({ queryKey: adminGetSettingsQueryKey() }); const notification = adminSettingsUpdateToast('General'); + toast.success(notification.title, { description: notification.description }); }, onError: (error) => notifyHttpError(error, 'Unable to update general settings'), @@ -136,12 +138,14 @@ export const useUpdateAdminGeneralSettings = () => { export const useUpdateAdminMailSettings = ({ successNotification = true }: UpdateAdminMailSettingsOptions = {}) => { const queryClient = useQueryClient(); + return useMutation({ ...adminUpdateMailSettingsMutation(), onSuccess: async () => { await queryClient.invalidateQueries({ queryKey: adminGetSettingsQueryKey() }); if (successNotification) { const notification = adminSettingsUpdateToast('Mail'); + toast.success(notification.title, { description: notification.description }); } }, @@ -161,6 +165,7 @@ export const useSendTestAdminMail = () => export const useUpdateAdminAdvancedSettings = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminUpdateAdvancedSettingsMutation(), onSuccess: async (_data, { body }) => { @@ -173,6 +178,7 @@ export const useUpdateAdminAdvancedSettings = () => { })); await queryClient.invalidateQueries({ queryKey: adminGetSettingsQueryKey() }); const notification = adminSettingsUpdateToast('Advanced'); + toast.success(notification.title, { description: notification.description }); }, onError: (error) => notifyHttpError(error, 'Unable to update advanced settings'), diff --git a/resources/scripts/api/admin/tags/queries.spec.ts b/resources/scripts/api/admin/tags/queries.spec.ts index 64147abdb..8da6d4f83 100644 --- a/resources/scripts/api/admin/tags/queries.spec.ts +++ b/resources/scripts/api/admin/tags/queries.spec.ts @@ -47,6 +47,7 @@ describe('complete tag collection', () => { it.each([0, 1, 3])('loads a collection with %i pages without sharing the paginated cache', async (total) => { adapter.mockImplementation(async (config) => { const current = Number(new URL(config.url!, 'https://panel.test').searchParams.get('page')); + return { config, headers: {}, @@ -58,6 +59,7 @@ describe('complete tag collection', () => { const options = allAdminTagsQueryOptions(); const listOptions = adminTagsQueryOptions(); const firstPage = page(1, total); + client.setQueryData(listOptions.queryKey, firstPage); const result = await client.fetchQuery(options); @@ -73,13 +75,19 @@ describe('complete tag collection', () => { it('stops after bounded retries on page two and can explicitly retry', async () => { vi.useFakeTimers(); let fail = true; + adapter.mockImplementation(async (config) => { const current = Number(new URL(config.url!, 'https://panel.test').searchParams.get('page')); - if (current === 2 && fail) throw new Error('offline'); + + if (current === 2 && fail) { + throw new Error('offline'); + } + return { config, headers: {}, status: 200, statusText: 'OK', data: page(current, 2) }; }); const options = { ...allAdminTagsQueryOptions(), retry: 1, retryDelay: 10 }; const failed = expect(client.fetchQuery(options)).rejects.toThrow('offline'); + await vi.advanceTimersByTimeAsync(100); await failed; expect(adapter).toHaveBeenCalledTimes(4); @@ -93,9 +101,11 @@ describe('complete tag collection', () => { it('does not start another page after cancellation', async () => { const options = allAdminTagsQueryOptions(); + adapter.mockImplementation(async (config) => { await client.cancelQueries({ queryKey: options.queryKey }); expect(config.signal?.aborted).toBe(true); + return { config, headers: {}, status: 200, statusText: 'OK', data: page(1, 2) }; }); diff --git a/resources/scripts/api/admin/tags/queries.ts b/resources/scripts/api/admin/tags/queries.ts index 280908244..49746087b 100644 --- a/resources/scripts/api/admin/tags/queries.ts +++ b/resources/scripts/api/admin/tags/queries.ts @@ -100,6 +100,7 @@ export const useCreateAdminTag = () => { onSuccess: async (tag) => { await invalidateGeneratedOperations(queryClient, tagListOperations); const messages = resourceMutationMessages('tag', 'create', tag.attributes.name); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('tag', 'create').errorTitle), @@ -114,6 +115,7 @@ export const useUpdateAdminTag = () => { onSuccess: async (tag) => { await invalidateGeneratedOperations(queryClient, assignedTagOperations); const messages = resourceMutationMessages('tag', 'update', tag.attributes.name); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('tag', 'update').errorTitle), @@ -128,6 +130,7 @@ export const useDeleteAdminTag = () => { onSuccess: async (_data, variables) => { await invalidateGeneratedOperations(queryClient, assignedTagOperations); const messages = resourceMutationMessages('tag', 'delete', variables.meta?.name); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('tag', 'delete').errorTitle), diff --git a/resources/scripts/api/admin/users/queries.ts b/resources/scripts/api/admin/users/queries.ts index 9e329feae..2be89d185 100644 --- a/resources/scripts/api/admin/users/queries.ts +++ b/resources/scripts/api/admin/users/queries.ts @@ -125,11 +125,13 @@ const currentUserFields = ({ attributes }: AdminUser): Partial => ({ export const useCreateAdminUser = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminCreateUserMutation(), onSuccess: async (user) => { await invalidateGeneratedOperations(queryClient, ['adminListUsers']); const messages = resourceMutationMessages('user', 'create', user.attributes.email); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('user', 'create').errorTitle), @@ -138,17 +140,20 @@ export const useCreateAdminUser = () => { export const useUpdateAdminUser = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminUpdateUserMutation(), onSuccess: async (user, variables) => { if (queryClient.getQueryData(currentUserQueryKey)?.uuid === user.attributes.uuid) { setCurrentUserQueryData(queryClient, currentUserFields(user)); } + await Promise.all([ invalidateGeneratedOperations(queryClient, ['adminListUsers']), queryClient.invalidateQueries({ queryKey: adminUserDetailKey(variables.path.id) }), ]); const messages = resourceMutationMessages('user', 'update', user.attributes.email); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('user', 'update').errorTitle), @@ -157,6 +162,7 @@ export const useUpdateAdminUser = () => { export const useDeleteAdminUser = () => { const queryClient = useQueryClient(); + return useMutation({ ...adminDeleteUserMutation(), onSuccess: async (_data, variables) => { @@ -164,6 +170,7 @@ export const useDeleteAdminUser = () => { await invalidateGeneratedOperations(queryClient, ['adminListUsers']); const name = variables.meta?.email; const messages = resourceMutationMessages('user', 'delete', name); + toast.success(messages.success.title, { description: messages.success.description }); }, onError: (error) => notifyHttpError(error, resourceMutationMessages('user', 'delete').errorTitle), diff --git a/resources/scripts/api/extensionProgress.ts b/resources/scripts/api/extensionProgress.ts index 676037c5e..01cdfa851 100644 --- a/resources/scripts/api/extensionProgress.ts +++ b/resources/scripts/api/extensionProgress.ts @@ -7,11 +7,14 @@ export function extensionJobProgressQueryOptions(extension: string, job: string, const result = serverUuid ? await clientGetServerExtensionJobProgress({ path: { extension, job, server_uuid: serverUuid }, signal }) : await clientGetExtensionJobProgress({ path: { extension, job }, signal }); + return result.data.data; }; + const options = queryOptions({ queryKey: ['extension-progress', extension, serverUuid ?? null, job], queryFn, }); + return { queryKey: options.queryKey, queryFn }; } diff --git a/resources/scripts/api/generated/types.gen.ts b/resources/scripts/api/generated/types.gen.ts index 0df90f26c..fa4a374a6 100644 --- a/resources/scripts/api/generated/types.gen.ts +++ b/resources/scripts/api/generated/types.gen.ts @@ -13,7 +13,7 @@ export type AdminActivityLogAttributes = { ip: string | null; description: string | null; properties: { - [key: string]: string | number | number | boolean | Array | { + [key: string]: string | number | boolean | Array | { [key: string]: string; }; }; @@ -1086,7 +1086,7 @@ export type ClientActivityLogAttributes = { ip: string | null; description: string | null; properties: { - [key: string]: string | number | number | boolean | Array | { + [key: string]: string | number | boolean | Array | { [key: string]: string; }; }; diff --git a/resources/scripts/api/http.ts b/resources/scripts/api/http.ts index 547b7e0f3..bd3f80752 100644 --- a/resources/scripts/api/http.ts +++ b/resources/scripts/api/http.ts @@ -61,6 +61,7 @@ export function httpErrorToHuman(cause: unknown): string { if (isObject(data) && 'errors' in data && Array.isArray(data.errors)) { const firstError = data.errors[0]; + if (isObject(firstError) && 'detail' in firstError && isString(firstError.detail)) { return firstError.detail; } diff --git a/resources/scripts/api/interceptors.ts b/resources/scripts/api/interceptors.ts index 8233931cb..dc72d8140 100644 --- a/resources/scripts/api/interceptors.ts +++ b/resources/scripts/api/interceptors.ts @@ -11,16 +11,18 @@ export const setupInterceptors = () => { const data = error.response.data; const firstError = isObject(data) && 'errors' in data && Array.isArray(data.errors) ? data.errors[0] : null; + if ( isObject(firstError) && 'code' in firstError && firstError.code === 'TwoFactorAuthRequiredException' ) { if (!window.location.pathname.startsWith('/account')) { - router.navigate({ to: '/account', replace: true, state: { twoFactorRedirect: true } }); + void router.navigate({ to: '/account', replace: true, state: { twoFactorRedirect: true } }); } } } + throw error; } ); diff --git a/resources/scripts/api/mutationUtils.spec.ts b/resources/scripts/api/mutationUtils.spec.ts index b2a0967e8..3e396fe49 100644 --- a/resources/scripts/api/mutationUtils.spec.ts +++ b/resources/scripts/api/mutationUtils.spec.ts @@ -12,11 +12,12 @@ describe('mutation utilities', () => { const nodes = [{ _id: 'adminListNodes' }] as const; const servers = [{ _id: 'adminListServers' }] as const; const users = [{ _id: 'adminListUsers' }] as const; + queryClient.setQueryData(nodes, 'nodes'); queryClient.setQueryData(servers, 'servers'); queryClient.setQueryData(users, 'users'); - invalidateGeneratedOperations(queryClient, ['adminListNodes', 'adminListServers']); + void invalidateGeneratedOperations(queryClient, ['adminListNodes', 'adminListServers']); expect(queryClient.getQueryState(nodes)?.isInvalidated).toBe(true); expect(queryClient.getQueryState(servers)?.isInvalidated).toBe(true); @@ -27,7 +28,7 @@ describe('mutation utilities', () => { const queryClient = new QueryClient(); const invalidate = vi.spyOn(queryClient, 'invalidateQueries'); - invalidateGeneratedOperations(queryClient, []); + void invalidateGeneratedOperations(queryClient, []); expect(invalidate).not.toHaveBeenCalled(); }); @@ -38,7 +39,11 @@ describe('mutation utilities', () => { const observedKey = ['server', 7, 'detail']; const idleKey = ['server', 7, 'databases']; const otherKey = ['server', 8, 'detail']; - for (const key of [observedKey, idleKey, otherKey]) queryClient.setQueryData(key, 'cached'); + + for (const key of [observedKey, idleKey, otherKey]) { + queryClient.setQueryData(key, 'cached'); + } + const observers = [1, 2].map( () => new QueryObserver(queryClient, { queryKey: observedKey, queryFn, staleTime: Infinity }) ); diff --git a/resources/scripts/api/pagination.spec.ts b/resources/scripts/api/pagination.spec.ts index 7f8784262..bf97590fc 100644 --- a/resources/scripts/api/pagination.spec.ts +++ b/resources/scripts/api/pagination.spec.ts @@ -41,6 +41,7 @@ describe('fetchAllPages', () => { it('does not request anything once aborted', async () => { const controller = new AbortController(); + controller.abort(); const fetchPage = vi.fn(async (page: number) => list(page, 1, [1])); @@ -52,6 +53,7 @@ describe('fetchAllPages', () => { const controller = new AbortController(); const fetchPage = vi.fn(async (page: number) => { controller.abort(); + return list(page, 3, [page]); }); diff --git a/resources/scripts/api/pagination.spec.tsx b/resources/scripts/api/pagination.spec.tsx index 7b92a4518..f762e34fb 100644 --- a/resources/scripts/api/pagination.spec.tsx +++ b/resources/scripts/api/pagination.spec.tsx @@ -31,6 +31,7 @@ const serve = ( attributes: (id: number) => Record = () => ({}) ) => { const requests: string[] = []; + adapter.mockImplementation(async (config) => { const url = new URL(config.url!, 'https://panel.test'); const page = Number(url.searchParams.get('page') ?? '1'); @@ -40,6 +41,7 @@ const serve = ( const data = Array.from({ length: Math.max(0, Math.min(100, total - first + 1)) }, (_, index) => item(first + index, attributes(first + index)) ); + requests.push(`${url.pathname}?page=${page}&per_page=${url.searchParams.get('per_page')}`); return { diff --git a/resources/scripts/api/pagination.ts b/resources/scripts/api/pagination.ts index 2b6b013ff..93f03a5f6 100644 --- a/resources/scripts/api/pagination.ts +++ b/resources/scripts/api/pagination.ts @@ -21,11 +21,14 @@ export const fetchAllPages = async >( signal.throwIfAborted(); // eslint-disable-next-line no-await-in-loop -- Each response determines whether another page is needed. const list = await fetchPage(page); + signal.throwIfAborted(); const { current_page, total_pages, per_page, total } = list.meta.pagination; + if (current_page !== page || !Number.isFinite(total_pages)) { throw new Error('List pagination did not advance as expected.'); } + items.push(...list.data); if (page >= total_pages) { return { @@ -43,6 +46,7 @@ export const fetchAllPages = async >( }, }; } + page += 1; } }; diff --git a/resources/scripts/api/queryLifecycle.spec.tsx b/resources/scripts/api/queryLifecycle.spec.tsx index 20015ec15..f7fb16234 100644 --- a/resources/scripts/api/queryLifecycle.spec.tsx +++ b/resources/scripts/api/queryLifecycle.spec.tsx @@ -57,8 +57,10 @@ describe('native query lifecycle', () => { vi.useFakeTimers({ toFake: ['Date'] }); const now = Date.now(); const options = serverQueryOptions('server'); + await client.ensureQueryData({ ...options, revalidateIfStale: true }); const { result } = renderHook(() => [useServerQuery('server'), useServerQuery('server')], { wrapper }); + await waitFor(() => expect(result.current[0]?.data).toEqual(server)); await client.ensureQueryData({ ...options, revalidateIfStale: true }); expect(adapter).toHaveBeenCalledOnce(); @@ -89,6 +91,7 @@ describe('native query lifecycle', () => { })); await client.ensureQueryData({ ...adminEggsQueryOptions(), revalidateIfStale: true }); const { result } = renderHook(() => useAdminEggs(), { wrapper }); + expect(result.current.data?.data).toEqual([]); await act(async () => { await client.ensureQueryData({ ...adminEggsQueryOptions(), revalidateIfStale: true }); @@ -98,17 +101,21 @@ describe('native query lifecycle', () => { it('does not notify permission subscribers for an unrelated server update', async () => { const options = serverQueryOptions('server'); + client.setQueryData(options.queryKey, server); const renders = vi.fn(); const { result } = renderHook( () => { const permissions = useCurrentServerPermissions(); + renders(permissions); + return permissions; }, { wrapper } ); const initialRenders = renders.mock.calls.length; + await act(async () => { client.setQueryData(options.queryKey, { ...server, attributes: { ...server.attributes, name: 'Renamed' } }); await new Promise((resolve) => setTimeout(resolve, 0)); @@ -128,6 +135,7 @@ describe('native query lifecycle', () => { const { result } = renderHook(() => useServerQuery('server', (data) => data.attributes.internal_id), { wrapper, }); + expectTypeOf(result.current.data).toEqualTypeOf(); expectTypeOf(result.current.error).toEqualTypeOf | null>(); expect(result.current.data).toBe(1); @@ -135,21 +143,27 @@ describe('native query lifecycle', () => { it('prevents an older read from overwriting a completed mutation', async () => { const options = serverQueryOptions('server'); + client.setQueryData(options.queryKey, server); let finishRead = () => {}; + adapter.mockImplementation((config) => { const response = { config, headers: {}, status: 200, statusText: 'OK' }; + if (config.method === 'get') { return new Promise((resolve) => { finishRead = () => resolve({ ...response, data: server }); }); } + return Promise.resolve({ ...response, data: {} }); }); renderHook(() => useServerQuery('server'), { wrapper }); const pendingRead = client.refetchQueries({ queryKey: options.queryKey }); + await waitFor(() => expect(adapter).toHaveBeenCalledOnce()); const mutation = renderHook(() => useRenameServer('server'), { wrapper }); + await act(async () => { await mutation.result.current.mutateAsync({ path: { server_uuid: 'server' }, body: { name: 'Renamed' } }); finishRead(); @@ -167,6 +181,7 @@ describe('native query lifecycle', () => { }), { wrapper } ); + await act(async () => { await Promise.resolve(); }); @@ -179,6 +194,7 @@ describe('native query lifecycle', () => { const { result } = renderHook(() => useQuery({ ...serverQueryOptions('server'), refetchInterval: 10 }), { wrapper, }); + await waitFor(() => expect(result.current.data).toEqual(server)); await waitFor(() => expect(adapter.mock.calls.length).toBeGreaterThan(1)); }); diff --git a/resources/scripts/api/queryParameters.ts b/resources/scripts/api/queryParameters.ts index 00f734b78..da63d0c34 100644 --- a/resources/scripts/api/queryParameters.ts +++ b/resources/scripts/api/queryParameters.ts @@ -1,6 +1,6 @@ type QueryFilterPrimitive = string | number | boolean | null; -export type QueryFilterValue = QueryFilterPrimitive | undefined | ReadonlyArray; +export type QueryFilterValue = QueryFilterPrimitive | undefined | readonly QueryFilterPrimitive[]; export type QuerySortValue = -1 | 0 | 1 | 'asc' | 'desc' | null | undefined; export interface QueryBuilderParams { @@ -15,7 +15,7 @@ export interface QueryBuilderParams { if (value === undefined || value === null || value === '') { - return undefined; + return; } const normalized = Array.isArray(value) ? value.join(',') : String(value); @@ -25,7 +25,7 @@ export const queryFilterValue = (value: QueryFilterValue) => { export const querySortValue = (field: string, value: QuerySortValue) => { if (!value || !['asc', 'desc', 1, -1].includes(value)) { - return undefined; + return; } return value === -1 || value === 'desc' ? `-${field}` : field; @@ -51,11 +51,13 @@ export const listSorts = ( ): Partial> | undefined => { const descending = sort?.startsWith('-') === true; const field = fields.find((candidate) => candidate === (descending ? sort?.slice(1) : sort)); + if (field === undefined) { return undefined; } const sorts: Partial> = {}; + sorts[field] = descending ? 'desc' : 'asc'; return sorts; @@ -72,16 +74,29 @@ export const listQuery = ( perPage?: number ): ListQuery => { const filters: Partial> = {}; + for (const [field, value] of Object.entries(params.filters ?? {}) as [TFilter, QueryFilterValue][]) { const normalized = queryFilterValue(value); - if (normalized !== undefined) filters[`filter[${field}]` as const] = normalized; + + if (normalized !== undefined) { + filters[`filter[${field}]` as const] = normalized; + } } const query: ListQuery = { ...filters }; const sorts = querySortList(params.sorts); - if (sorts.length > 0) query.sort = sorts.join(','); - if (params.page !== undefined) query.page = params.page; - if (perPage !== undefined) query.per_page = perPage; + + if (sorts.length > 0) { + query.sort = sorts.join(','); + } + + if (params.page !== undefined) { + query.page = params.page; + } + + if (perPage !== undefined) { + query.per_page = perPage; + } return query; }; diff --git a/resources/scripts/api/server/backups/queries.spec.tsx b/resources/scripts/api/server/backups/queries.spec.tsx index 13232f929..59389c279 100644 --- a/resources/scripts/api/server/backups/queries.spec.tsx +++ b/resources/scripts/api/server/backups/queries.spec.tsx @@ -22,8 +22,10 @@ const mocks = vi.hoisted(() => ({ const backupQueryKey = (input: { path: { server_uuid: string }; query?: { page?: number } }) => { const key = { _id: 'clientListServerBackups', path: input.path }; + return input.query ? [{ ...key, query: input.query }] : [key]; }; + type BackupListInput = Parameters[0]; vi.mock('sonner', () => ({ toast: { success: mocks.toastSuccess } })); @@ -61,6 +63,7 @@ describe('server backup mutations', () => { const { queryClient, wrapper } = setup(); const created = backup('new', 'nightly'); const queryKey = backupQueryKey({ path: { server_uuid: 'server' }, query: { page: 3 } }); + mocks.create.mockResolvedValue(created); queryClient.setQueryData(queryKey, { object: 'list', @@ -76,6 +79,7 @@ describe('server backup mutations', () => { await act(async () => result.current.mutateAsync(input)); const cached = queryClient.getQueryData(queryKey); + expect(cached?.data).toEqual([]); expect(queryClient.getQueryState(queryKey)?.isInvalidated).toBe(true); expect(mocks.create).toHaveBeenCalledWith(input, expect.anything()); @@ -85,6 +89,7 @@ describe('server backup mutations', () => { it('updates current server state before notifying when a restore starts', async () => { const { wrapper } = setup(); const selected = backup('backup', 'before-upgrade'); + mocks.restore.mockResolvedValue(undefined); const { result } = renderHook(() => useRestoreServerBackup(selected), { wrapper }); diff --git a/resources/scripts/api/server/databases/queries.ts b/resources/scripts/api/server/databases/queries.ts index 72ff9ac3e..7ec88f405 100644 --- a/resources/scripts/api/server/databases/queries.ts +++ b/resources/scripts/api/server/databases/queries.ts @@ -63,6 +63,7 @@ export const useServerDatabases = (uuid: string) => const upsertDatabase = async (queryClient: QueryClient, uuid: string, database: ServerDatabase) => { await queryClient.cancelQueries({ queryKey: clientListServerDatabasesQueryKey(serverDatabasesInput(uuid)) }); + return queryClient.setQueryData( clientListServerDatabasesQueryKey(serverDatabasesInput(uuid)), (current) => @@ -77,6 +78,7 @@ const upsertDatabase = async (queryClient: QueryClient, uuid: string, database: const removeDatabase = async (queryClient: QueryClient, uuid: string, databaseId: string) => { await queryClient.cancelQueries({ queryKey: clientListServerDatabasesQueryKey(serverDatabasesInput(uuid)) }); + return queryClient.setQueryData( clientListServerDatabasesQueryKey(serverDatabasesInput(uuid)), (current) => removeListItems(current, (database) => database.attributes.id === databaseId) @@ -104,6 +106,7 @@ export const useDeleteServerDatabase = () => { onSuccess: async (_data, variables) => { await removeDatabase(queryClient, variables.path.server_uuid, variables.path.database_id); const name = variables.meta?.name; + toast.success('Database deleted', { description: name ? `${name} has been removed.` : undefined }); }, onError: (error) => notifyHttpError(error, 'Unable to delete database'), diff --git a/resources/scripts/api/server/files/queries.spec.tsx b/resources/scripts/api/server/files/queries.spec.tsx index 93a22eb92..e13d01c4c 100644 --- a/resources/scripts/api/server/files/queries.spec.tsx +++ b/resources/scripts/api/server/files/queries.spec.tsx @@ -19,6 +19,7 @@ import { } from './queries'; const mocks = vi.hoisted(() => ({ error: vi.fn(), success: vi.fn() })); + vi.mock('@/plugins/notifications', () => ({ notifyHttpError: mocks.error })); vi.mock('sonner', () => ({ toast: { success: mocks.success, error: vi.fn() } })); @@ -55,9 +56,11 @@ const file = (name: string) => new File([name], name, { type: 'text/plain' }); function upload(files: File[]) { const { result } = renderHook(() => useUploadFiles(), { wrapper }); let done: Promise | undefined; + act(() => { done = result.current.mutateAsync({ uuid: 'server', directory: '/config', files, callbacks }); }); + return done!; } @@ -104,9 +107,12 @@ describe('useUploadFiles', () => { posts[0].finish(); await waitFor(() => expect(posts).toHaveLength(4)); - posts.slice(1).forEach((post) => post.finish()); + for (const post of posts.slice(1)) { + post.finish(); + } const summary = await done; + expect(summary.uploaded.map((uploaded) => uploaded.name)).toEqual(['a.txt', 'a.txt', 'b.txt', 'c.txt']); expect(settled.map(([, outcome]) => outcome)).toEqual(['uploaded', 'uploaded', 'uploaded', 'uploaded']); expect(mocks.success).toHaveBeenCalledWith('Upload complete'); @@ -115,6 +121,7 @@ describe('useUploadFiles', () => { it('settles a cancelled and a failed file on their own and still refreshes the listing', async () => { const done = upload([file('a.txt'), file('b.txt'), file('c.txt')]); + await waitFor(() => expect(posts).toHaveLength(3)); queued[1].controller.abort(); @@ -122,6 +129,7 @@ describe('useUploadFiles', () => { posts[0].finish(); const summary = await done; + expect(summary.uploaded.map((uploaded) => uploaded.name)).toEqual(['a.txt']); expect(summary.cancelled.map((cancelled) => cancelled.name)).toEqual(['b.txt']); expect(summary.failed.map((failed) => failed.name)).toEqual(['c.txt']); @@ -139,12 +147,16 @@ describe('useUploadFiles', () => { it('never starts a queued file cancelled before its turn', async () => { const done = upload([file('a.txt'), file('b.txt'), file('c.txt'), file('d.txt')]); + await waitFor(() => expect(posts).toHaveLength(3)); queued[3].controller.abort(); - posts.forEach((post) => post.finish()); + for (const post of posts) { + post.finish(); + } const summary = await done; + expect(posts.map((post) => post.name)).toEqual(['a.txt', 'b.txt', 'c.txt']); expect(summary.cancelled.map((cancelled) => cancelled.name)).toEqual(['d.txt']); expect(mocks.error).not.toHaveBeenCalled(); @@ -154,6 +166,7 @@ describe('useUploadFiles', () => { describe('file queries', () => { it('refreshes the destination listing after a move', async () => { const destination = serverFilesQueryKey('server', '/config/plugins'); + client.setQueryData(destination, { object: 'list', data: [] }); const { result } = renderHook(() => useRenameFiles(), { wrapper }); @@ -167,8 +180,10 @@ describe('file queries', () => { it('sends chmod modes to wings as octal strings and patches the cached listing', async () => { let sent: unknown; + http.defaults.adapter = (async (config) => { sent = JSON.parse(config.data as string); + return respond(config, '', 204); }) satisfies AxiosAdapter; client.setQueryData(listing, { diff --git a/resources/scripts/api/server/files/queries.ts b/resources/scripts/api/server/files/queries.ts index 1a0011419..37c08f0a9 100644 --- a/resources/scripts/api/server/files/queries.ts +++ b/resources/scripts/api/server/files/queries.ts @@ -150,11 +150,13 @@ const serverFilesQueryUpdate = async ( updater: (current: ClientListFilesResponse | undefined) => ClientListFilesResponse | undefined ) => { await queryClient.cancelQueries({ queryKey: serverFilesQueryKey(uuid, directory) }); + return queryClient.setQueryData(serverFilesQueryKey(uuid, directory), updater); }; const updateServerFileContent = async (queryClient: QueryClient, uuid: string, file: string, content: string) => { await queryClient.cancelQueries({ queryKey: serverFileContentQueryKey(uuid, file) }); + return queryClient.setQueryData(serverFileContentQueryKey(uuid, file), content); }; @@ -200,17 +202,22 @@ export const isFileObjectArchiveType = ({ attributes }: FileObject) => 'application/x-7z-compressed', // .7z ].includes(attributes.mimetype); -export const fileObjectKind = (file: FileObject): 'file' | 'directory' | 'archive' | 'symlink' => - !file.attributes.is_file - ? 'directory' - : file.attributes.is_symlink - ? 'symlink' - : isFileObjectArchiveType(file) - ? 'archive' - : 'file'; +export const fileObjectKind = (file: FileObject): 'file' | 'directory' | 'archive' | 'symlink' => { + if (!file.attributes.is_file) { + return 'directory'; + } + + if (file.attributes.is_symlink) { + return 'symlink'; + } + + return isFileObjectArchiveType(file) ? 'archive' : 'file'; +}; export const isFileObjectEditable = (file: FileObject) => { - if (isFileObjectArchiveType(file) || !file.attributes.is_file) return false; + if (isFileObjectArchiveType(file) || !file.attributes.is_file) { + return false; + } const matches = ['application/jar', 'application/octet-stream', 'inode/directory', /^image\/(?!svg\+xml)/]; @@ -260,6 +267,7 @@ export const useCreateDirectory = () => { data: [...(files?.data ?? []), generateDirectoryData(body.name)], })); } + toast.success('Directory created'); }, onError: (error) => notifyHttpError(error, 'Unable to create directory'), @@ -286,6 +294,7 @@ export const useRenameFiles = () => { : removeListItems(current, (file) => file.attributes.name === from) ); } + await queryClient.invalidateQueries({ queryKey: allServerFilesQueryKey(path.server_uuid) }); toast.success('Files updated'); }, @@ -318,9 +327,11 @@ export const useChmodFiles = () => { ) ); } + if (body?.root) { await queryClient.invalidateQueries({ queryKey: serverFilesQueryKey(path.server_uuid, body.root) }); } + toast.success('Permissions updated'); }, onError: (error) => notifyHttpError(error, 'Unable to update permissions'), @@ -335,10 +346,12 @@ export const useDeleteFiles = () => { onSuccess: async (_data, { path, body }) => { if (body?.root && body.files) { const files = body.files; + await serverFilesQueryUpdate(queryClient, path.server_uuid, body.root, (current) => removeListItems(current, (file) => files.includes(file.attributes.name)) ); } + toast.success(body?.files?.length === 1 ? 'File deleted' : 'Files deleted'); }, onError: (error) => notifyHttpError(error, 'Unable to delete files'), @@ -354,6 +367,7 @@ export const useCopyFile = (directory: string) => { if (directory) { await queryClient.invalidateQueries({ queryKey: serverFilesQueryKey(path.server_uuid, directory) }); } + toast.success('File copied'); }, onError: (error) => notifyHttpError(error, 'Unable to copy file'), @@ -369,6 +383,7 @@ export const useCompressFiles = () => { if (body?.root) { await queryClient.invalidateQueries({ queryKey: serverFilesQueryKey(path.server_uuid, body.root) }); } + toast.success('Archive started'); }, onError: (error) => notifyHttpError(error, 'Unable to archive files'), @@ -384,6 +399,7 @@ export const useDecompressFile = () => { if (body?.root) { await queryClient.invalidateQueries({ queryKey: serverFilesQueryKey(path.server_uuid, body.root) }); } + toast.success('Unarchive started'); }, onError: (error) => notifyHttpError(error, 'Unable to unarchive file'), @@ -412,8 +428,12 @@ export const useSaveFileContent = () => { const runPooled = async (items: readonly T[], concurrency: number, task: (item: T) => Promise) => { let next = 0; const worker = async (): Promise => { - if (next >= items.length) return; + if (next >= items.length) { + return; + } + await task(items[next++]); + return worker(); }; @@ -428,6 +448,7 @@ const uploadFile = async ( onUploadProgress: (progress: AxiosProgressEvent) => void ) => { const url = await getFileUploadUrl(uuid, signal); + await axios.post( url, { files: file }, @@ -459,6 +480,7 @@ export const useUploadFiles = () => { const queued = files.map((file) => { const id = `upload-${++uploadSequence}`; const controller = new AbortController(); + callbacks.onFileQueued(id, file, controller); return { id, file, controller }; @@ -467,6 +489,7 @@ export const useUploadFiles = () => { await runPooled(queued, UPLOAD_CONCURRENCY, async ({ id, file, controller }) => { let outcome: FileUploadOutcome = 'cancelled'; + if (!controller.signal.aborted) { try { await uploadFile(uuid, directory, file, controller.signal, (progress) => diff --git a/resources/scripts/api/server/network/queries.ts b/resources/scripts/api/server/network/queries.ts index 349e40634..d40ad577c 100644 --- a/resources/scripts/api/server/network/queries.ts +++ b/resources/scripts/api/server/network/queries.ts @@ -64,6 +64,7 @@ export const useServerAllocations = (uuid: string) => const upsertAllocation = async (queryClient: QueryClient, uuid: string, allocation: ServerAllocation) => { await queryClient.cancelQueries({ queryKey: clientListServerAllocationsQueryKey(serverAllocationsInput(uuid)) }); + return queryClient.setQueryData( clientListServerAllocationsQueryKey(serverAllocationsInput(uuid)), (current) => upsertListItem(current, allocation, (item) => item.attributes.id === allocation.attributes.id) @@ -72,6 +73,7 @@ const upsertAllocation = async (queryClient: QueryClient, uuid: string, allocati const removeAllocation = async (queryClient: QueryClient, uuid: string, allocationId: number) => { await queryClient.cancelQueries({ queryKey: clientListServerAllocationsQueryKey(serverAllocationsInput(uuid)) }); + return queryClient.setQueryData( clientListServerAllocationsQueryKey(serverAllocationsInput(uuid)), (current) => removeListItems(current, (allocation) => allocation.attributes.id === allocationId) diff --git a/resources/scripts/api/server/queries.ts b/resources/scripts/api/server/queries.ts index 23ef74b29..f68c5c275 100644 --- a/resources/scripts/api/server/queries.ts +++ b/resources/scripts/api/server/queries.ts @@ -86,12 +86,14 @@ export const useServerQuery = (id: string, select?: (server: Ser export const useCurrentServer = (select?: (server: Server) => TData) => { const id = useServerRouteId(); + return useServerQuery(id ?? '', select).data; }; const selectServerUuid = (server: Server) => server.attributes.uuid; const selectServerIdentifier = (server: Server) => server.attributes.identifier; const selectServerName = (server: Server) => server.attributes.name; + export const selectServerPermissions = (server: Server) => server.meta?.is_server_owner ? ownerPermissions : (server.meta?.user_permissions ?? emptyPermissions); @@ -106,7 +108,9 @@ export const useUpdateCurrentServer = () => { return useCallback( (updater: (server: ClientServerResource) => ClientServerResource) => { - if (!id) return; + if (!id) { + return; + } updateServerQueryData(queryClient, id, updater); }, diff --git a/resources/scripts/api/server/queryDomains.ts b/resources/scripts/api/server/queryDomains.ts index de1c0b036..973842810 100644 --- a/resources/scripts/api/server/queryDomains.ts +++ b/resources/scripts/api/server/queryDomains.ts @@ -16,6 +16,7 @@ const domainKeys = { path: { server_uuid: id }, query: { file: '' }, }); + return [key]; }, startup: (id: string) => clientGetStartupConfigurationQueryKey({ path: { server_uuid: id } }), diff --git a/resources/scripts/api/server/schedules/queries.ts b/resources/scripts/api/server/schedules/queries.ts index 4cbf4fe8c..43ad4457d 100644 --- a/resources/scripts/api/server/schedules/queries.ts +++ b/resources/scripts/api/server/schedules/queries.ts @@ -150,11 +150,13 @@ const cacheServerSchedule = async ( ) => { const detailKey = clientGetServerScheduleQueryKey(serverScheduleInput(uuid, schedule.attributes.id)); const listKey = clientListServerSchedulesQueryKey(serverSchedulesInput(uuid)); + await Promise.all([ queryClient.cancelQueries({ queryKey: detailKey }), queryClient.cancelQueries({ queryKey: listKey }), ]); const updated = updater ? updater(queryClient.getQueryData(detailKey) ?? schedule) : schedule; + queryClient.setQueryData(detailKey, updated); queryClient.setQueryData(listKey, (current) => upsertListItem(current, updated, (item) => item.attributes.id === updated.attributes.id) @@ -163,6 +165,7 @@ const cacheServerSchedule = async ( const removeServerSchedule = async (queryClient: QueryClient, uuid: string, scheduleId: number) => { await queryClient.cancelQueries({ queryKey: clientListServerSchedulesQueryKey(serverSchedulesInput(uuid)) }); + return queryClient.setQueryData( clientListServerSchedulesQueryKey(serverSchedulesInput(uuid)), (current) => removeListItems(current, (schedule) => schedule.attributes.id === scheduleId) @@ -224,6 +227,7 @@ export const useServerSchedule = (uuid: string, scheduleId: number) => export const useCreateServerSchedule = () => { const queryClient = useQueryClient(); + return useMutation({ ...clientCreateServerScheduleMutation(), onSuccess: async (schedule, { path }) => { @@ -236,6 +240,7 @@ export const useCreateServerSchedule = () => { export const useUpdateServerSchedule = () => { const queryClient = useQueryClient(); + return useMutation({ ...clientUpdateServerScheduleMutation(), onSuccess: async (schedule, { path }) => { @@ -248,6 +253,7 @@ export const useUpdateServerSchedule = () => { export const useDeleteServerSchedule = () => { const queryClient = useQueryClient(); + return useMutation({ ...clientDeleteServerScheduleMutation(), onSuccess: async (_data, { path }) => { @@ -263,6 +269,7 @@ export const useDeleteServerSchedule = () => { export const useTriggerServerScheduleExecution = (schedule: Schedule) => { const queryClient = useQueryClient(); + return useMutation({ ...clientExecuteServerScheduleMutation(), onSuccess: async (_data, { path }) => { @@ -278,6 +285,7 @@ export const useTriggerServerScheduleExecution = (schedule: Schedule) => { export const useCreateServerScheduleTask = (schedule: Schedule) => { const queryClient = useQueryClient(); + return useMutation({ ...clientCreateScheduleTaskMutation(), onSuccess: async (task, { path }) => { @@ -292,6 +300,7 @@ export const useCreateServerScheduleTask = (schedule: Schedule) => { export const useUpdateServerScheduleTask = (schedule: Schedule) => { const queryClient = useQueryClient(); + return useMutation({ ...clientUpdateScheduleTaskMutation(), onSuccess: async (task, { path }) => { @@ -306,6 +315,7 @@ export const useUpdateServerScheduleTask = (schedule: Schedule) => { export const useDeleteServerScheduleTask = (schedule: Schedule) => { const queryClient = useQueryClient(); + return useMutation({ ...clientDeleteScheduleTaskMutation(), onSuccess: async (_data, { path }) => { diff --git a/resources/scripts/api/server/startup/queries.spec.tsx b/resources/scripts/api/server/startup/queries.spec.tsx index 9c4e79ee7..88ab39c8d 100644 --- a/resources/scripts/api/server/startup/queries.spec.tsx +++ b/resources/scripts/api/server/startup/queries.spec.tsx @@ -10,6 +10,7 @@ import VariableBox from '@/components/server/startup/VariableBox'; import { serverStartupQueryOptions, useServerStartup, type ServerStartupVariable } from './queries'; const mocks = vi.hoisted(() => ({ uuid: 'server', error: vi.fn() })); + vi.mock('@/api/server/queries', () => ({ useCurrentServerUuid: () => mocks.uuid, useUpdateCurrentServer: () => vi.fn(), @@ -41,13 +42,14 @@ const variable = (value: string): ServerStartupVariable => ({ const adapter = vi.fn(); const originalAdapter = http.defaults.adapter; let client: QueryClient; -let saves: Array<{ value: string; finish: () => void; fail: () => void }>; +let saves: { value: string; finish: () => void; fail: () => void }[]; const wrapper = ({ children }: PropsWithChildren) => ( {children} ); function Editor({ uuid }: { uuid: string }) { const { data } = useServerStartup(uuid); + return data?.data[0] ? : null; } @@ -70,11 +72,13 @@ describe('startup autosaves', () => { meta: { startup_command: 'start original', raw_startup_command: 'start {{PORT}}', docker_images: {} }, }); } + http.defaults.adapter = adapter; adapter.mockImplementation( (config) => new Promise((resolve, reject) => { const { value } = JSON.parse(String(config.data)) as { value: string }; + saves.push({ value, finish: () => @@ -95,6 +99,7 @@ describe('startup autosaves', () => { it('serializes saves and preserves the newest draft while earlier saves finish', async () => { render(, { wrapper }); const input = screen.getByRole('textbox'); + fireEvent.change(input, { target: { value: 'first' } }); await advance(500); expect(saves).toHaveLength(1); @@ -121,6 +126,7 @@ describe('startup autosaves', () => { it('keeps failed drafts and saves edits made without a keyboard event', async () => { render(, { wrapper }); const input = screen.getByRole('textbox'); + fireEvent.input(input, { target: { value: 'pasted' } }); await advance(500); expect(saves[0]?.value).toBe('pasted'); @@ -138,6 +144,7 @@ describe('startup autosaves', () => { it('saves unsent edits to their original server on resource change and unmount', async () => { const view = render(, { wrapper }); + fireEvent.change(screen.getByRole('textbox'), { target: { value: 'submitted' } }); await advance(500); fireEvent.change(screen.getByRole('textbox'), { target: { value: 'unsent' } }); diff --git a/resources/scripts/api/server/users/queries.ts b/resources/scripts/api/server/users/queries.ts index f918430f9..fee736f5e 100644 --- a/resources/scripts/api/server/users/queries.ts +++ b/resources/scripts/api/server/users/queries.ts @@ -61,6 +61,7 @@ export const deleteServerSubuserInput = (uuid: string, subuser: Subuser): Option const upsertSubuser = async (queryClient: QueryClient, uuid: string, subuser: Subuser) => { await queryClient.cancelQueries({ queryKey: clientListServerSubusersQueryKey(serverSubusersInput(uuid)) }); + return queryClient.setQueryData( clientListServerSubusersQueryKey(serverSubusersInput(uuid)), (current) => upsertListItem(current, subuser, (item) => item.attributes.uuid === subuser.attributes.uuid) @@ -69,6 +70,7 @@ const upsertSubuser = async (queryClient: QueryClient, uuid: string, subuser: Su const removeSubuser = async (queryClient: QueryClient, uuid: string, subuserUuid: string) => { await queryClient.cancelQueries({ queryKey: clientListServerSubusersQueryKey(serverSubusersInput(uuid)) }); + return queryClient.setQueryData( clientListServerSubusersQueryKey(serverSubusersInput(uuid)), (current) => removeListItems(current, (subuser) => subuser.attributes.uuid === subuserUuid) diff --git a/resources/scripts/components/App.tsx b/resources/scripts/components/App.tsx index df2359874..f71f93a61 100644 --- a/resources/scripts/components/App.tsx +++ b/resources/scripts/components/App.tsx @@ -13,6 +13,7 @@ const App = () => { useEffect(() => { void loadExtensions(); }, []); + return ( diff --git a/resources/scripts/components/NavigationBar.tsx b/resources/scripts/components/NavigationBar.tsx index 68d3bd9f7..7a0814670 100644 --- a/resources/scripts/components/NavigationBar.tsx +++ b/resources/scripts/components/NavigationBar.tsx @@ -27,57 +27,50 @@ export default function NavigationBar() { const onTriggerLogout = () => logout.mutate({}); return ( -
+
-
-
+
+ -
- +
+ - + {rootAdmin && ( - - + + )} - - - + + + - - - +
diff --git a/resources/scripts/components/admin/AdminListEmpty.spec.tsx b/resources/scripts/components/admin/AdminListEmpty.spec.tsx index dc457e7f2..37956bec1 100644 --- a/resources/scripts/components/admin/AdminListEmpty.spec.tsx +++ b/resources/scripts/components/admin/AdminListEmpty.spec.tsx @@ -13,10 +13,10 @@ describe('AdminListEmpty', () => { render( New server} + description='Create a server to get started.' + action={} /> ); @@ -27,14 +27,15 @@ describe('AdminListEmpty', () => { it('explains a search miss and clears the search instead of offering creation', async () => { const onClearFilter = vi.fn(); + render( New server} + description='Create a server to get started.' + action={} /> ); diff --git a/resources/scripts/components/admin/AdminListEmpty.tsx b/resources/scripts/components/admin/AdminListEmpty.tsx index df1152b4a..8d4a9d2a1 100644 --- a/resources/scripts/components/admin/AdminListEmpty.tsx +++ b/resources/scripts/components/admin/AdminListEmpty.tsx @@ -34,14 +34,14 @@ export default function AdminListEmpty({ return ( - + {filter ? `No matching ${noun}` : `No ${noun} yet`} {filter ? ( <> - No {noun} match {filter}. + No {noun} match {filter}. ) : ( description diff --git a/resources/scripts/components/admin/AdminResourceTables.spec.tsx b/resources/scripts/components/admin/AdminResourceTables.spec.tsx index 5e3314b77..825550305 100644 --- a/resources/scripts/components/admin/AdminResourceTables.spec.tsx +++ b/resources/scripts/components/admin/AdminResourceTables.spec.tsx @@ -123,7 +123,7 @@ const host = { function SingleRowTable({ row, columns }: { row: TData; columns: ColumnDef[] }) { const table = useReactTable({ data: [row], columns, getCoreRowModel: getCoreRowModel() }); - return ; + return ; } describe('admin resource tables', () => { diff --git a/resources/scripts/components/admin/AdminSidebar.spec.tsx b/resources/scripts/components/admin/AdminSidebar.spec.tsx index 3cab41328..bb5566076 100644 --- a/resources/scripts/components/admin/AdminSidebar.spec.tsx +++ b/resources/scripts/components/admin/AdminSidebar.spec.tsx @@ -42,6 +42,7 @@ async function renderSidebar(pathname: string) { history: createMemoryHistory({ initialEntries: [pathname] }), defaultHashScrollIntoView: false, }); + await router.load(); render(); await screen.findByText('Admin screen'); diff --git a/resources/scripts/components/admin/AdminSidebar.tsx b/resources/scripts/components/admin/AdminSidebar.tsx index 8a627d48d..fd7ed63c9 100644 --- a/resources/scripts/components/admin/AdminSidebar.tsx +++ b/resources/scripts/components/admin/AdminSidebar.tsx @@ -81,25 +81,25 @@ export default function AdminSidebar() { return (
diff --git a/resources/scripts/components/admin/activity/ActivityContainer.tsx b/resources/scripts/components/admin/activity/ActivityContainer.tsx index e576eb897..4ca023b7c 100644 --- a/resources/scripts/components/admin/activity/ActivityContainer.tsx +++ b/resources/scripts/components/admin/activity/ActivityContainer.tsx @@ -16,11 +16,9 @@ export default function ActivityContainer() { return ( navigate({ to: '/panel/activity', search, replace: true, viewTransition: false }) } diff --git a/resources/scripts/components/admin/api/ApiKeyTable.tsx b/resources/scripts/components/admin/api/ApiKeyTable.tsx index c909db97f..6e5cedc33 100644 --- a/resources/scripts/components/admin/api/ApiKeyTable.tsx +++ b/resources/scripts/components/admin/api/ApiKeyTable.tsx @@ -23,8 +23,8 @@ const ApiKeyActionsCell = ({ apiKey }: { apiKey: AdminApiKey }) => { return ( apiKey.attributes.memo, - header: ({ column }) => , + header: ({ column }) => , cell: ({ row }) => ( -
-

+

+

{row.original.attributes.memo || 'No description provided'}

-

+

{row.original.attributes.identifier}

@@ -64,7 +64,7 @@ export const apiKeyColumns = [ { id: 'permissions', header: 'Permissions', - cell: ({ row }) => {grantedCount(row.original)} granted, + cell: ({ row }) => {grantedCount(row.original)} granted, enableSorting: false, meta: { headerClassName: 'hidden w-28 @md:table-cell', cellClassName: 'hidden w-28 @md:table-cell' }, }, @@ -73,17 +73,18 @@ export const apiKeyColumns = [ header: 'Created by', cell: ({ row }) => { const createdBy = row.original.attributes.created_by; + return createdBy ? ( {createdBy.username} ) : ( - Unknown + Unknown ); }, enableSorting: false, @@ -94,8 +95,9 @@ export const apiKeyColumns = [ header: 'Last used', cell: ({ row }) => { const lastUsedAt = row.original.attributes.last_used_at; + return ( - + {lastUsedAt ? dayjs(lastUsedAt).format('MMM D, YYYY') : 'Never'} ); @@ -106,10 +108,10 @@ export const apiKeyColumns = [ { id: 'created_at', accessorFn: (apiKey) => apiKey.attributes.created_at, - header: ({ column }) => , + header: ({ column }) => , cell: ({ row }) => (