Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.

### Added
- **Tracked-change types in the package entry** - `TrackedChange`, `ProjectReview`, `ListTrackedChangesOptions`, the acceptance and rejection plan types, `TrackedChangeKind`, `TrackedChangeAuthor`, `ShareJsTextOp` and `RejectConflictError` are exported from `@aloth/olcli`, so code that uses `listReview`, `listTrackedChanges` or `rejectTrackedChanges` as a library can name what they return and catch the conflict error
- **Accept tracked changes of one doc with a single request** - `acceptTrackedChangesInDoc(projectId, docId, ids)` sends just the editor's accept request. `acceptTrackedChanges` reads the whole project before and after to resolve the ids and check the result, which is right for the CLI but costs two passes over every doc; an editor integration that already holds the changes and re-reads the project after every write can skip both. `acceptTrackedChanges` now uses it for each doc, so the request is built in one place

## [0.16.2] - 2026-11-11

Expand Down
30 changes: 20 additions & 10 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2601,16 +2601,7 @@ export class OverleafClient {
const byDoc = new Map<string, TrackedChange[]>();
for (const change of selected) byDoc.set(change.docId, [...(byDoc.get(change.docId) ?? []), change]);
for (const [docId, changes] of byDoc) {
const response = await this.httpRequest(`${this.baseUrl}/project/${projectId}/doc/${docId}/changes/accept`, {
method: 'POST',
headers: this.getHeaders(true),
body: JSON.stringify({ change_ids: changes.map(change => change.id) }),
expect: 'text'
});
if (!response.ok) {
throw httpError(`Failed to accept tracked changes in ${changes[0].path}`, response.status);
}
this.applySetCookieHeaders(response.headers['set-cookie'] as string[] | undefined);
await this.acceptTrackedChangesInDoc(projectId, docId, changes.map(change => change.id), changes[0].path);
}

const after = await this.listTrackedChanges(projectId);
Expand All @@ -2621,6 +2612,25 @@ export class OverleafClient {
return selected;
}

/**
* Accept tracked changes of one doc with a single request, the editor's
* route, without listing the project before or after. For callers that
* already hold the changes and their doc id and re-read the project anyway;
* `acceptTrackedChanges` resolves ids and checks the result for you.
*/
async acceptTrackedChangesInDoc(projectId: string, docId: string, ids: string[], label = docId): Promise<void> {
const response = await this.httpRequest(`${this.baseUrl}/project/${projectId}/doc/${docId}/changes/accept`, {
method: 'POST',
headers: this.getHeaders(true),
body: JSON.stringify({ change_ids: ids }),
expect: 'text'
});
if (!response.ok) {
throw httpError(`Failed to accept tracked changes in ${label}`, response.status);
}
this.applySetCookieHeaders(response.headers['set-cookie'] as string[] | undefined);
}

private selectTrackedChanges(all: TrackedChange[], ids: string[]): TrackedChange[] {
const wanted = [...new Set(ids)];
if (wanted.length === 0) throw new Error('No tracked change id given');
Expand Down
9 changes: 9 additions & 0 deletions test/tracked-changes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ test('acceptTrackedChanges posts the ids per doc and verifies they are gone', as
assert.deepEqual(state.posts[0].body.change_ids.sort(), ['d', 'i']);
});

test('acceptTrackedChangesInDoc posts once and reads nothing', async () => {
const { client, state } = reviewClient('foo quux baz', replaced);
let listed = 0;
client.joinDocument = async () => { listed++; throw new Error('must not list'); };
await client.acceptTrackedChangesInDoc('p', 'd1', ['i']);
assert.equal(listed, 0);
assert.deepEqual(state.posts.map((x: any) => [x.url.replace(/^.*\/project/, '/project'), x.body]), [['/project/p/doc/d1/changes/accept', { change_ids: ['i'] }]]);
});

test('acceptTrackedChanges sends nothing when an id is unknown', async () => {
const { client, state } = reviewClient('foo quux baz', replaced);
await assert.rejects(client.acceptTrackedChanges('p', ['i', 'nope']), /not found: nope/);
Expand Down
Loading