TenantAtlas/apps/platform/public/js/tenantpilot/livewire-intercept-shim.js
ahmido ce0615a9c1 Spec 182: relocate Laravel platform to apps/platform (#213)
## Summary
- move the Laravel application into `apps/platform` and keep the repository root for orchestration, docs, and tooling
- update the local command model, Sail/Docker wiring, runtime paths, and ignore rules around the new platform location
- add relocation quickstart/contracts plus focused smoke coverage for bootstrap, command model, routes, and runtime behavior

## Validation
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/PlatformRelocation`
- integrated browser smoke validated `/up`, `/`, `/admin`, `/admin/choose-workspace`, and tenant route semantics for `200`, `403`, and `404`

## Remaining Rollout Checks
- validate Dokploy build context and working-directory assumptions against the new `apps/platform` layout
- confirm web, queue, and scheduler processes all start from the expected working directory in staging/production
- verify no legacy volume mounts or asset-publish paths still point at the old root-level `public/` or `storage/` locations

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #213
2026-04-08 08:40:47 +00:00

99 lines
3.0 KiB
JavaScript

(() => {
// TenantPilot shim: ensure Livewire interceptMessage callbacks run in a safe order.
// This prevents Filament's notifications asset (and others) from calling an undefined
// animation callback when onSuccess fires before onFinish.
if (typeof window === 'undefined') {
return;
}
const applyShim = () => {
const Livewire = window.Livewire;
if (!Livewire || typeof Livewire.interceptMessage !== 'function') {
return false;
}
if (Livewire.__tenantpilotInterceptMessageShimApplied) {
return true;
}
const original = Livewire.interceptMessage.bind(Livewire);
Livewire.interceptMessage = (handler) => {
if (typeof handler !== 'function') {
return original(handler);
}
return original((context) => {
if (!context || typeof context !== 'object') {
return handler(context);
}
const originalOnFinish = context.onFinish;
const originalOnSuccess = context.onSuccess;
if (typeof originalOnFinish !== 'function' || typeof originalOnSuccess !== 'function') {
return handler(context);
}
const finishCallbacks = [];
const onFinish = (callback) => {
if (typeof callback === 'function') {
finishCallbacks.push(callback);
}
return originalOnFinish(callback);
};
const onSuccess = (callback) => {
return originalOnSuccess((...args) => {
// Ensure any registered finish callbacks are run before success callbacks.
// We don't swallow errors; we just stabilize ordering.
for (const finishCallback of finishCallbacks) {
finishCallback(...args);
}
if (typeof callback === 'function') {
return callback(...args);
}
});
};
return handler({
...context,
onFinish,
onSuccess,
});
});
};
Livewire.__tenantpilotInterceptMessageShimApplied = true;
return true;
};
if (applyShim()) {
return;
}
// Livewire may not be initialized yet when this script runs (depending on
// script tag order). Try again on `livewire:init` and with a short fallback poll.
const onInit = () => {
applyShim();
};
window.addEventListener('livewire:init', onInit, { once: true });
document.addEventListener('livewire:init', onInit, { once: true });
let tries = 0;
const maxTries = 50;
const timer = setInterval(() => {
tries += 1;
if (applyShim() || tries >= maxTries) {
clearInterval(timer);
}
}, 100);
})();