Lint: fix all ESLint errors (391 -> 0), lint and typecheck tests
Mostly perfectionist import/key sorting and curly braces from --fix, plus: - spread instead of .apply() in the Meta Pixel stub - non-capturing group in the locale-code pattern - React 19 use(Context) / <Context value> in TurnstileProvider - email regex rewritten without super-linear backtracking (covered by a test) - console.warn/error allowed (deliberate server diagnostics) - test/tsconfig.json so the project service and tsc see test files Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -12,18 +12,18 @@ import type { BasePayload, Field } from 'payload'
|
||||
* busy form doesn't turn every submission into a DB write.
|
||||
*/
|
||||
|
||||
export type IntegrationState = 'ok' | 'degraded'
|
||||
export type IntegrationState = 'degraded' | 'ok'
|
||||
|
||||
export type IntegrationStatus = {
|
||||
state?: IntegrationState | null
|
||||
/** Machine code from the provider or the plugin, e.g. 'invalid-input-secret', 'missing-secret'. */
|
||||
code?: string | null
|
||||
/** Human explanation shown in the panel (English — panel language). */
|
||||
message?: string | null
|
||||
/** When the current state started. */
|
||||
since?: string | null
|
||||
/** Last time the integration was used (refreshed at most every REFRESH_MS). */
|
||||
checkedAt?: string | null
|
||||
checkedAt?: null | string
|
||||
/** Machine code from the provider or the plugin, e.g. 'invalid-input-secret', 'missing-secret'. */
|
||||
code?: null | string
|
||||
/** Human explanation shown in the panel (English — panel language). */
|
||||
message?: null | string
|
||||
/** When the current state started. */
|
||||
since?: null | string
|
||||
state?: IntegrationState | null
|
||||
}
|
||||
|
||||
const REFRESH_MS = 10 * 60_000
|
||||
@@ -53,8 +53,8 @@ export function buildIntegrationStatusBanner(statusField: string, label: string)
|
||||
admin: {
|
||||
components: {
|
||||
Field: {
|
||||
clientProps: { label, statusField },
|
||||
path: '@intecion/ipal-kit/client#IntegrationStatusBanner',
|
||||
clientProps: { statusField, label },
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -69,7 +69,7 @@ export async function recordIntegrationStatus(
|
||||
payload: BasePayload,
|
||||
field: string,
|
||||
previous: IntegrationStatus | null | undefined,
|
||||
next: { state: IntegrationState; code?: string; message?: string },
|
||||
next: { code?: string; message?: string; state: IntegrationState },
|
||||
): Promise<void> {
|
||||
const now = new Date()
|
||||
const changed = previous?.state !== next.state || (next.state === 'degraded' && previous?.code !== next.code)
|
||||
@@ -78,22 +78,22 @@ export async function recordIntegrationStatus(
|
||||
(!previous?.checkedAt || now.getTime() - new Date(previous.checkedAt).getTime() > REFRESH_MS)
|
||||
|
||||
// Healthy and already recorded as healthy (or never recorded) → nothing to do.
|
||||
if (!changed && !stale) return
|
||||
if (next.state === 'ok' && !previous?.state) return
|
||||
if (!changed && !stale) {return}
|
||||
if (next.state === 'ok' && !previous?.state) {return}
|
||||
|
||||
const status: IntegrationStatus = {
|
||||
state: next.state,
|
||||
checkedAt: now.toISOString(),
|
||||
code: next.code ?? null,
|
||||
message: next.message ?? null,
|
||||
since: changed ? now.toISOString() : (previous?.since ?? now.toISOString()),
|
||||
checkedAt: now.toISOString(),
|
||||
state: next.state,
|
||||
}
|
||||
try {
|
||||
await payload.updateGlobal({
|
||||
slug: SITE_INTEGRATIONS as never,
|
||||
context: { ipalIntegrationStatus: true },
|
||||
data: { [field]: status } as never,
|
||||
depth: 0,
|
||||
context: { ipalIntegrationStatus: true },
|
||||
})
|
||||
} catch (err) {
|
||||
console.warn(`[ipal] could not record ${field}:`, err instanceof Error ? err.message : err)
|
||||
|
||||
Reference in New Issue
Block a user