16 lines
851 B
TypeScript
16 lines
851 B
TypeScript
import { getSession, login, openErp, submit } from '../lib/api.js';
|
|
import { backgroundError } from '../lib/request-errors.js';
|
|
export default defineBackground(() => {
|
|
browser.runtime.onMessage.addListener(async (message: { type?: string; payload?: unknown; path?: string }) => {
|
|
try {
|
|
if (message?.type === 'atlas.session') return { session: await getSession() };
|
|
if (message?.type === 'atlas.login') return { session: await login() };
|
|
if (message?.type === 'atlas.collect') return { result: await submit(message.payload as import('@atlas/contracts').CollectedProductPayload) };
|
|
if (message?.type === 'atlas.open') { await openErp(message.path); return { ok: true }; }
|
|
return undefined;
|
|
} catch (error) {
|
|
return backgroundError(error);
|
|
}
|
|
});
|
|
});
|