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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "miakapi",
"version": "4.5.0",
"version": "4.5.1",
"description": "Typed coordinator and trusted-browser SDK for Miakapp",
"type": "module",
"packageManager": "bun@1.2.23",
Expand Down
5 changes: 4 additions & 1 deletion src/internal/browser-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,14 @@ export function browserRelayFailure(
retryable: boolean,
outcome: DispatchOutcome,
correlation?: FailureOptions['correlation'],
message?: unknown,
): BrowserClientError {
const options: FailureOptions = correlation === undefined
? { code, retryable }
: { code, retryable, correlation };
return new BrowserClientError(kindFromCode(code), outcome, 'Relay rejected the operation', options);
// A coordinator's own refusal (2000-2999) keeps its sentence: the app shows it to the resident.
const application = code >= 2_000 && code <= 2_999 && typeof message === 'string' && message.length > 0 && message.length <= 256;
return new BrowserClientError(kindFromCode(code), outcome, application ? message : 'Relay rejected the operation', options);
}

export function safeBrowserLog(
Expand Down
2 changes: 1 addition & 1 deletion src/internal/user-calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export class UserCallManager implements BrowserCalls {
: call.wasAccepted ? 'accepted' : 'not_dispatched';
const failure = browserRelayFailure(code, retryable, outcome, {
kind: 'call', localId: call.localId,
});
}, frame.payload[3]);
this.#fail(call, failure);
this.#host.emitFailure(failure);
return true;
Expand Down
14 changes: 14 additions & 0 deletions test/browser-state-calls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,20 @@ describe('browser state and calls', () => {
await harness.client.stop();
});

test('keeps a coordinator\'s own refusal sentence, never the relay\'s', async () => {
const harness = createBrowserTestHarness();
const { connection } = await startBrowserReady(harness);
const refused = harness.client.calls.start({ function: 'home.echo', arguments: null, timeoutMs: 5_000 });
await connection.nextClientFrame(Opcode.Call);
connection.send({ opcode: Opcode.CallError, payload: [1, 2605, false, 'Ce lien n’est pas valable', null] });
expect(await refused.result.catch((error: unknown) => error)).toMatchObject({ code: 2605, message: 'Ce lien n’est pas valable' });
const relay = harness.client.calls.start({ function: 'home.echo', arguments: null, timeoutMs: 5_000 });
await connection.nextClientFrame(Opcode.Call);
connection.send({ opcode: Opcode.CallError, payload: [2, 1200, false, 'internal detail', null] });
expect(await relay.result.catch((error: unknown) => error)).toMatchObject({ code: 1200, message: 'Relay rejected the operation' });
await harness.client.stop();
});

test('ignores a correlated terminal frame after a local deadline settles the call', async () => {
const harness = createBrowserTestHarness();
const failures: Array<{ kind: string }> = [];
Expand Down
2 changes: 1 addition & 1 deletion test/direct-node.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ test('a resident uses the home through the direct transport without the internet
assert.equal(lamp, true);

const refused = client.calls.start({ function: 'lamp.set', arguments: { on: 'yes' }, timeoutMs: 5_000 });
await assert.rejects(refused.result, (error: { code?: unknown }) => error.code === 2001);
await assert.rejects(refused.result, (error: { code?: unknown; message?: unknown }) => error.code === 2001 && error.message === 'on must be a boolean');

// The ticket was renewed over the direct session itself.
await waitFor(async () => (saved !== record ? saved : undefined));
Expand Down
Loading