mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-22 22:02:38 +03:00
* test: extract testable services and pin current crypto behaviour Move the hashing, hmac, crc and ULA logic out of the single file components into service modules next to them, and cover them with characterization tests that pin the exact digests, encodings and ciphertexts the tools produce today. The encryption tool had no tests at all; it now has round trip coverage for every algorithm plus pinned ciphertexts for the deterministic ones, including OpenSSL salted payloads produced by previous versions of it-tools. No behaviour change: this is the reference point the dependency replacements that follow have to reproduce exactly. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mf5V2jMpFFXxGVXZU5rHBq * chore(deps): replace the five deprecated packages flagged by renovate Renovate's dependency dashboard lists five deprecated or replaced packages; this removes all of them, keeping the observable behaviour identical. - crypto-js -> crypto-es. Upstream discontinued crypto-js; crypto-es is its maintained ESM/TypeScript successor and is byte for byte compatible, which the characterization tests added in the previous commit verify: the same 1012 assertions pass before and after the swap, including the OpenSSL salted ciphertexts of the encryption tool. It ships its own types, so @types/crypto-js goes away too. - plausible-tracker -> @plausible-analytics/tracker, the official replacement. The app keeps providing the same 'plausible' injection shape, so nothing downstream changes. apiHost maps onto the new endpoint option and keeps posting to the very same url, trackLocalhost onto captureOnLocalhost, and the pageviews that enableAutoPageviews() used to start are now captured by init() itself. init() throws without a domain, unlike the old tracker, so an enabled but domain-less config now falls back to the no-op instance instead of breaking the app bootstrap. - svg2png-wasm -> @resvg/resvg-wasm, the replacement named in its deprecation notice. The renderer moves into a service covered by tests that rasterize real svg content, and the 2 MB binary no longer has to be committed under public/: vite emits it from the package as a hashed asset, so it can never drift from the js glue on upgrade. - @types/bcryptjs and @types/uuid are deprecated stubs, bcryptjs and uuid having shipped their own types for a while. Also drops the now dead renovate rules that only existed to keep uuid and @types/uuid in lockstep, and fixes the tool metadata a new guard test caught: the encryption tool advertised 'crypto-s' and the wysiwyg editor still advertised monaco and prettier. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mf5V2jMpFFXxGVXZU5rHBq * test: pin that svg text is actually drawn, document the load bearing empty iv The resvg swap is pixel identical to svg2png-wasm for shapes and gradients, and it also fixes text that names the embedded Roboto family: svg2png-wasm returned an empty canvas there, so the assertion guards a real improvement rather than only the image dimensions. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mf5V2jMpFFXxGVXZU5rHBq * fix: address review feedback on the plugin and renderer initialization Two of the review comments are real regressions against the behaviour the replaced packages had, so both are fixed with a test that fails without the fix: - The plausible plugin called init() on every install. init() throws on the second call, so installing the plugin on a second app instance (tests, hot reload) would have taken the app down, where the old tracker was happy to be constructed repeatedly. The tracker is now initialized once and reused. The api host also gets its trailing slash trimmed so the endpoint cannot end up with a double slash. - initializeSvgRenderer() memoized the initialization promise including its rejections, so one failed wasm download left the tool broken until a page reload. The old code only latched its flag after a successful load. A failed attempt is no longer cached. Also extends the tool metadata guard to the removed stub type packages, and pins the negative counters that verifyHOTP walks through when the window is wider than the counter: their hexadecimal form keeps the minus sign, which the hex parser reads as ffffffff rather than rejecting, and crypto-es reproduces that exactly. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mf5V2jMpFFXxGVXZU5rHBq --------- Co-authored-by: Claude <noreply@anthropic.com>
63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
import { noop } from 'es-toolkit/compat';
|
|
|
|
import { init, track } from '@plausible-analytics/tracker';
|
|
import type { App } from 'vue';
|
|
import type { PlausibleInstance } from '@/modules/tracker/tracker.types';
|
|
import { config } from '@/config';
|
|
|
|
function createFakePlausibleInstance(): PlausibleInstance {
|
|
return {
|
|
trackEvent: noop,
|
|
enableAutoPageviews: noop,
|
|
};
|
|
}
|
|
|
|
let isTrackerInitialized = false;
|
|
|
|
export function createPlausibleInstance({
|
|
config,
|
|
}: {
|
|
config: {
|
|
isTrackerEnabled: boolean
|
|
domain: string
|
|
apiHost: string
|
|
trackLocalhost: boolean
|
|
}
|
|
}): PlausibleInstance {
|
|
// `init` throws when no domain is configured. Without a domain the events would be attributed to
|
|
// nothing anyway, so stay with the no-op instance instead.
|
|
if (!config.isTrackerEnabled || !config.domain) {
|
|
return createFakePlausibleInstance();
|
|
}
|
|
|
|
// `init` also throws when called twice, which would take the whole app down as soon as the plugin
|
|
// is installed on a second app instance (tests, hot reload). The tracker is already running at
|
|
// that point, so reuse it rather than initializing it again.
|
|
if (!isTrackerInitialized) {
|
|
init({
|
|
domain: config.domain,
|
|
// the previous tracker took an api host and appended the path itself; keep the very same
|
|
// endpoint, including the relative one used when no api host is configured
|
|
endpoint: `${config.apiHost.replace(/\/$/, '')}/api/event`,
|
|
captureOnLocalhost: config.trackLocalhost,
|
|
});
|
|
|
|
isTrackerInitialized = true;
|
|
}
|
|
|
|
return {
|
|
trackEvent: eventName => track(eventName, {}),
|
|
// `init` already captures pageviews, `autoCapturePageviews` being enabled by default
|
|
enableAutoPageviews: noop,
|
|
};
|
|
}
|
|
|
|
export const plausible = {
|
|
install: (app: App) => {
|
|
const plausible = createPlausibleInstance({ config: config.plausible });
|
|
plausible.enableAutoPageviews();
|
|
|
|
app.provide('plausible', plausible);
|
|
},
|
|
};
|