Skip to content

Commit d2aa0a5

Browse files
committed
feat(msw-plugin): add automation trigger functionality to ObjectStackServer
1 parent 76dc5c0 commit d2aa0a5

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

packages/plugins/plugin-msw/src/msw-plugin.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,29 @@ export class ObjectStackServer {
272272
}
273273
}
274274

275+
static async triggerAutomation(request: any) {
276+
if (!this.protocol) {
277+
throw new Error('ObjectStackServer not initialized. Call ObjectStackServer.init() first.');
278+
}
279+
280+
this.logger?.debug?.('MSW: Triggering automation', { request });
281+
try {
282+
const result = await this.protocol.triggerAutomation(request);
283+
this.logger?.info?.('MSW: Automation triggered', { result });
284+
return {
285+
status: 200,
286+
data: result
287+
};
288+
} catch (error) {
289+
this.logger?.error?.('MSW: Automation trigger failed', error);
290+
const message = error instanceof Error ? error.message : 'Unknown error';
291+
return {
292+
status: 400,
293+
data: { error: message }
294+
};
295+
}
296+
}
297+
275298
// Legacy method names for compatibility
276299
static async getUser(id: string) {
277300
return this.getData('user', id);
@@ -662,6 +685,18 @@ export class MSWPlugin implements Plugin {
662685
}
663686
}),
664687

688+
// Automation Operations
689+
http.post(`${baseUrl}/automation/trigger`, async ({ request }) => {
690+
try {
691+
const body = await request.json();
692+
const result = await ObjectStackServer.triggerAutomation(body);
693+
return HttpResponse.json(result.data, { status: result.status });
694+
} catch (error) {
695+
const message = error instanceof Error ? error.message : 'Unknown error';
696+
return HttpResponse.json({ error: message }, { status: 400 });
697+
}
698+
}),
699+
665700
// Add custom handlers
666701
...(this.options.customHandlers || [])
667702
];

0 commit comments

Comments
 (0)