Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
980455b
feat(webapp): maintenance operations panel and My data exports
evereq Nov 20, 2026
95d6506
fix(webapp): review findings on the maintenance and exports sections
evereq Nov 20, 2026
64985b5
refactor(webapp): SonarCloud findings on the new sections
evereq Nov 20, 2026
7bf0606
fix(webapp): My data exports stays hidden where the API serves the we…
evereq Nov 20, 2026
beff982
fix(api): Ever Connect / Ever ID races from the 0.24.0 release review
evereq Nov 20, 2026
e8348ec
test(webapp): cover the status-200 parse error through a stubbed Http…
evereq Nov 20, 2026
662e9b6
feat(webapp): warn when backups are allowed without a backup directory
evereq Nov 20, 2026
e0e76dc
fix(api): review findings on the 0.24.1 race fixes
evereq Nov 20, 2026
764cdcd
fix(api): sort the locked account ids with a compare function (Sonar)
evereq Nov 20, 2026
af5a931
Merge pull request #637 from ever-co/feat/ever-connect-ui-panels
evereq Nov 20, 2026
b250e9e
fix(api): a refresh that met a concurrent change reads Ever Platform …
evereq Nov 20, 2026
8852d0a
Merge remote-tracking branch 'origin/develop' into fix/ever-connect-r…
evereq Nov 20, 2026
168a6ff
Merge pull request #638 from ever-co/fix/ever-connect-races-0.24.1
evereq Nov 20, 2026
48b1d09
chore(release): 0.24.1
evereq Nov 20, 2026
3407575
Merge pull request #641 from ever-co/chore/release-0.24.1
evereq Nov 20, 2026
addbef3
fix: end in-flight Ever ID sign-ins on subject logout, renew lease be…
evereq Nov 21, 2026
2756ff4
Merge pull request #644 from ever-co/fix/0.24.1-greptile-lease-logout
evereq Nov 21, 2026
be74b90
Merge pull request #642 from ever-co/develop
evereq Nov 21, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ever-traduora/api",
"version": "0.24.0",
"version": "0.24.1",
"license": "AGPL-3.0-only",
"homepage": "https://traduora.co",
"repository": {
Expand Down
27 changes: 20 additions & 7 deletions api/src/controllers/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,8 @@ export class AuthController {
code_verifier?: string;
}): Promise<{ data: { id: string; email: string; name: string; accessToken: string } }> {
const slug = payload.provider;
// Before the code exchange and the account checks: a subject-only logout after this ends the sign-in
const signedInAt = Date.now();
const identity = await this.verifyOidcCode(slug, payload);

const linked = await this.everIdSessions.findIdentity(identity.issuer, identity.subject);
Expand All @@ -538,8 +540,9 @@ export class AuthController {
throw new AuthProviderException(HttpStatus.BAD_REQUEST, 'sign_in_failed', 'The account of this identity no longer exists');
}
await this.everIdSessions.touchLastLogin(linked.id);
// Unlike the Google sign-in, no pending invite is accepted here: the account accepts them itself
const accessToken = await this.signOidcUserToken(user, identity.issuer, identity.subject, identity.sid);
// Unlike the Google sign-in, no pending invite is accepted here: the account accepts them itself. A logout naming
// only the subject that lands while this sign-in is under way (code exchange, account lookup) ends it too
const accessToken = await this.signOidcUserToken(user, identity.issuer, identity.subject, identity.sid, new Date(signedInAt));
return { data: { id: user.id, email: user.email, name: user.name, accessToken } };
}

Expand All @@ -562,7 +565,10 @@ export class AuthController {
throw new AuthProviderException(HttpStatus.FORBIDDEN, 'signup_disabled', 'Signups are invitation based only.');
}

const pending = this.everIdSessions.seal({ purpose: 'signup', ...this.everIdSessions.pendingFrom(slug, identity) }, SIGNUP_PENDING_TTL_SECONDS);
const pending = this.everIdSessions.seal(
{ purpose: 'signup', ...this.everIdSessions.pendingFrom(slug, identity), signedInAt },
SIGNUP_PENDING_TTL_SECONDS,
);
throw new AuthProviderException(HttpStatus.CONFLICT, 'signup_confirmation_required', 'Confirm to create your account', {
pending,
name: identity.name,
Expand Down Expand Up @@ -634,7 +640,13 @@ export class AuthController {
);

await this.welcomeNewUser(account, true);
const accessToken = await this.signOidcUserToken(account, pending.issuer, pending.subject, pending.sid);
const accessToken = await this.signOidcUserToken(
account,
pending.issuer,
pending.subject,
pending.sid,
new Date(typeof pending.signedInAt === 'number' ? pending.signedInAt : (pending.exp - SIGNUP_PENDING_TTL_SECONDS) * 1000),
);
return { data: { id: account.id, email: account.email, name: account.name, accessToken } };
}

Expand Down Expand Up @@ -849,9 +861,10 @@ export class AuthController {
* Signs an access token for a sign-in with an OpenID Connect provider. Like any user token, plus the provider's
* session (`sid`), which a back-channel logout ends, and the token's own id (`jti`).
*/
private async signOidcUserToken(user: User, issuer: string, subject: string, providerSid: string | undefined): Promise<string> {
// Only while the identity is still the account's (a disconnect at the same moment ends the sign-in)
const session = await this.everIdSessions.openSession(user.id, issuer, providerSid, subject);
private async signOidcUserToken(user: User, issuer: string, subject: string, providerSid: string | undefined, signedInAt?: Date): Promise<string> {
// Only while the identity is still the account's (a disconnect at the same moment ends the sign-in), and not after
// a logout that named only the subject once the person signed in with the provider
const session = await this.everIdSessions.openSession(user.id, issuer, providerSid, subject, signedInAt);
if (!session) {
throw new AuthProviderException(HttpStatus.BAD_REQUEST, 'session_ended', 'This Ever ID session has ended, please sign in again');
}
Expand Down
30 changes: 30 additions & 0 deletions api/src/ever-connect/ever-connect-managed.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,36 @@ describeOnSqlite('EverConnectManagedService', () => {
expect((await history())[0].unsentResult).toBeNull();
});

it('checks the lease before each saved result it sends again, and stops once another process holds it', async () => {
const { connect, managed, client } = await connected();
await consent(connect);
await managed.update({ optIn: true, kinds: ['health_report'], windows: ALL_WEEK }, 'user:u1');
const saved = [request('health_report'), request('health_report')];
platform.unreachable = true;
for (const op of saved) {
await expect(managed.handle(client, op, 'kid-1')).rejects.toThrow();
}
platform.unreachable = false;
const later = Date.now() + 3600000;
const deferred = request('health_report', { notBefore: later });
await managed.handle(client, deferred, 'kid-1');
const unsent = async () => (await history()).filter(row => row.unsentResult !== null).length;
expect(await unsent()).toBe(2);

// The lease holds for the first send only
let checks = 0;
expect(await managed.runDue(client, 'kid-1', later + 1000, async () => ++checks === 1)).toBe(0);
expect(checks).toBe(2);
expect(saved.filter(op => platform.managedResults[op.operation_id])).toHaveLength(1);
expect(await unsent()).toBe(1);
expect(platform.managedResults[deferred.operation_id]).toBeUndefined();

// The next round that holds the lease sends the rest, then runs the due work
expect(await managed.runDue(client, 'kid-1', later + 1000)).toBe(1);
expect(await unsent()).toBe(0);
expect(platform.managedResults[deferred.operation_id]).toMatchObject({ status: 'succeeded' });
});

it("keeps the operator's settings checked, and the backup directory write-only", async () => {
const { managed } = await connected();
await expect(managed.update({ kinds: ['update'] }, 'user:u1')).rejects.toMatchObject({ code: 'invalid_managed' });
Expand Down
3 changes: 3 additions & 0 deletions api/src/ever-connect/ever-connect-managed.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,9 @@ export class EverConnectManagedService {
{ status: 'failed', reason: 'interrupted', unsentResult: JSON.stringify({ status: 'failed' }) },
);
for (const row of await this.operations.find({ where: { unsentResult: Not(IsNull()), connectionKid } })) {
// Before each send, as before each due run: once another process holds the lease (or the connection changed), it
// sends the rest and runs the due work
if (!(await stillCurrent())) return 0;
try {
await this.deliver(client, row);
} catch (error) {
Expand Down
11 changes: 11 additions & 0 deletions api/src/ever-connect/ever-connect-person.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,17 @@ describeOnSqlite('EverConnectPersonService', () => {
expect(platform.calls).toEqual([]);
});

it('stops a round once the scheduler lost its lease', async () => {
const { connect, person } = await connected();
await enableEverIdLogin(connect);
await linkIdentity(alice, 's1', { method: IdentityLinkMethod.Explicit });
await linkIdentity(bob, 's2', { method: IdentityLinkMethod.Jit });
let asked = 0;
expect(await person.syncLinks(Date.now(), true, async () => ++asked <= 1)).toEqual({ reported: 1, removed: 0 });
// The next round (with the lease) reports the other one
expect(await person.syncLinks(Date.now(), true)).toEqual({ reported: 1, removed: 0 });
});

it('reports each Ever ID a user signed in with, once, and never anything else', async () => {
const { connect, person } = await connected();
await enableEverIdLogin(connect);
Expand Down
26 changes: 24 additions & 2 deletions api/src/ever-connect/ever-connect-person.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { EverConnectAuditService } from './ever-connect-audit.service';
import { EverConnectPlatformClient, PersonRequestAnswer, PlatformEvent, problemOf } from './ever-connect-platform.client';
import { CONNECTION_ID, EverConnectService } from './ever-connect.service';
import { EVER_CONNECT_SETTINGS, EverConnectSettings } from './ever-connect.settings';
import { lockAccount } from '../services/ever-id-session.service';

/** The feed events of a person's requests, by the kind of request. */
export const PERSON_REQUEST_TYPES: Readonly<Record<string, 'deletion' | 'export'>> = Object.freeze({
Expand Down Expand Up @@ -291,6 +292,11 @@ export class EverConnectPersonService {
*/
private async deleteIdentities(manager: EntityManager, matches: IdentityRow[]): Promise<void> {
const now = Date.now();
// Each account's row locked first, as a sign-in that opens a session locks it (in one order: two deletions never
// deadlock), so a sign-in that read the identity just before cannot open a session once it is removed
for (const userId of Array.from(new Set(matches.map(identity => identity.userId))).sort((a, b) => a.localeCompare(b))) {
await lockAccount(manager, userId);
}
for (const identity of matches) {
await manager.update(EverIdSession, { userId: identity.userId, revokedAt: IsNull() }, { revokedAt: new Date(now) });
await manager.delete(UserIdentity, { id: identity.id });
Expand Down Expand Up @@ -482,7 +488,11 @@ export class EverConnectPersonService {
* tenant link) is reported, while the integration allows it. A call that fails is tried again an hour later, so other
* links go first meanwhile. Calls nothing while there is nothing to tell.
*/
async syncLinks(now = Date.now(), force = false): Promise<{ reported: number; removed: number }> {
/**
* `keepLease` is asked before each call to Ever Platform (the scheduler renews its lease there): once it answers
* false, another API process holds the background calls and this round stops.
*/
async syncLinks(now = Date.now(), force = false, keepLease?: () => Promise<boolean>): Promise<{ reported: number; removed: number }> {
if (!force && !this.syncRequested && now - this.lastSyncAt < PERSON_LINK_SYNC_MS) {
return { reported: 0, removed: 0 };
}
Expand All @@ -504,8 +514,15 @@ export class EverConnectPersonService {
let reported = 0;

// Removals first: a removal names the user, so a link reported for the same user afterwards is not removed with it
let leaseLost = false;
const leaseHeld = async (): Promise<boolean> => {
if (!keepLease || (await keepLease())) return true;
leaseLost = true;
return false;
};
for (const row of await this.links.find()) {
if (byId.has(row.userIdentityId) || waiting(row) || calls >= PERSON_LINK_CALLS_PER_SYNC) continue;
if (!(await leaseHeld())) break;
calls += 1;
try {
await client.removePersonLink(row.userId);
Expand All @@ -522,6 +539,9 @@ export class EverConnectPersonService {
removed += 1;
}

if (leaseLost) {
return { reported, removed };
}
if (!(await this.reporting())) {
// Nothing is reported while the integration is off; once it is on again, every link is reported again
await this.links.update({ reportedAt: Not(IsNull()) }, { reportedAt: null, tenantLinkId: null, updatedAt: now });
Expand All @@ -533,7 +553,9 @@ export class EverConnectPersonService {
const row = known.get(identity.id);
const current = !!row && !!row.reportedAt && row.tenantLinkId === tenantLinkId;
if (current || waiting(row) || calls >= PERSON_LINK_CALLS_PER_SYNC) continue;
// Checked again before each report: once the integration is switched off here, no further report starts
if (!(await leaseHeld())) break;
// Checked again before each report (after the lease renewal): once the integration is switched off here, no
// further report starts
if (!(await this.reporting())) break;
calls += 1;
try {
Expand Down
16 changes: 14 additions & 2 deletions api/src/ever-connect/ever-connect-scheduler.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ export class EverConnectSchedulerService implements OnModuleInit, OnModuleDestro
return result.affected === 1;
}

/** Extends the lease while this process still holds it; false once another process took it over. */
private renew(): Promise<boolean> {
return this.acquire(Date.now());
}

private async release(): Promise<void> {
await this.connections
.createQueryBuilder()
Expand Down Expand Up @@ -175,16 +180,23 @@ export class EverConnectSchedulerService implements OnModuleInit, OnModuleDestro
await this.connect.syncStatsLink(connection.kid).catch(error => this.connect.handleCallError(error, 'stats_link', connection.kid));
}
if (connection.status === 'active' && this.person) {
await this.person.syncLinks().catch(error => this.connect.handleCallError(error, 'person_link', connection.kid));
// Long rounds renew the lease before each call and stop once another process holds it, or once this connection
// is no longer the active one (as the maintenance round below)
if (!(await this.renew())) return;
await this.person
.syncLinks(Date.now(), false, async () => (await this.renew()) && (await this.isCurrent(connection.kid)))
.catch(error => this.connect.handleCallError(error, 'person_link', connection.kid));
}
if (connection.status === 'active' && this.managed) {
// Stop when another process took the lease during the person-link round
if (!(await this.renew())) return;
const live = await this.connect.liveClient();
// Only for the connection that is still active now (the feed may have ended it)
if (live && live.connection.status === 'active' && live.connection.kid === connection.kid) {
// Not while a state refresh of the feed failed: a revoked consent may not have been applied yet
if (!this.feedFailed) {
await this.managed
.runDue(live.client, connection.kid, Date.now(), () => this.isCurrent(connection.kid))
.runDue(live.client, connection.kid, Date.now(), async () => (await this.renew()) && (await this.isCurrent(connection.kid)))
Comment thread
evereq marked this conversation as resolved.
Resolved
.catch(error => this.connect.handleCallError(error, 'managed', connection.kid));
}
}
Expand Down
35 changes: 35 additions & 0 deletions api/src/ever-connect/ever-connect.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,41 @@ describe('EverConnectService', () => {
expect(links()).toEqual([{ statsInstanceId: reset.instanceId }]);
});

it('never lets a refresh undo an integration the operator switched off while it read the states', async () => {
let during: (() => Promise<void>) | null = null;
const original = platform.factory;
Object.assign(platform, {
factory: (options => {
const client = original(options);
const integrations = client.integrations;
client.integrations = async () => {
const states = await integrations();
if (during) {
const run = during;
during = null;
await run();
}
return states;
};
return client;
}) as typeof platform.factory,
});
const { connect } = build();
await connect.connect('EVC-TEST-0000-0001', '', 'user:u1');
platform.integrationStates.instance_url = { state: 'enabled', enabled: true, consentId: 'c1', scopeVersion: 1 };
await connect.refreshIntegrations();
expect((await connect.integrations()).find(view => view.key === 'instance_url').state).toBe('enabled');

// The states are read as enabled, then the operator switches the integration off before they are stored
during = async () => {
await connect.disableIntegration('instance_url', 'user:u1');
};
const views = await connect.refreshIntegrations();
// The stale enabled state is never stored: the refresh reads again and finds the consent gone at Ever Platform
expect(views.find(view => view.key === 'instance_url').state).toBe('available');
expect(platform.names().filter(name => name === 'integrations').length).toBeGreaterThanOrEqual(3);
});

it('waits for approval, reading only its own state, then starts', async () => {
const { connect, scheduler } = build();
platform.redeemStatus = 'pending_approval';
Expand Down
Loading