Watch what your app decides
Subscribe to network, access and action events, assert on them in a test, and print them while you debug a refused call.
Status Status is where the work is: Planned (in a milestone, not started), Building (tickets in progress), Preview (usable, may change), then the stability it ships at.
Stability The promise an interface ships with.
- Stable Follows semantic versioning; breaking changes need a new major, 12 months of overlap and a codemod.
- Beta Usable in production; may change before it becomes stable.
- Experimental May change or go away; needs an explicit opt-in in main.yaml.
You will watch the decisions your app makes (which hosts it may call, who may do what), check them in a test, and print them while you debug. It takes about 10 minutes.
You need
- A MainSDK app with a
main.yaml, run from the repository (nothing here is published to npm). - A
network.allowlist with at least one host.
Steps
Subscribe to the network decisions. The callback runs off the request path and can't change a call.
lib/watch.ts import { observe } from "mainsdk"; export const stop = observe("mainsdk:network.decision", (e) => { console.log(e.data.host, e.data.decision); });
Assert on events in a test.
createTestApp()records them as they happen, so no flush is needed.test/network.test.ts const app = createTestApp(); await app.access.check({ subject: { id: "u1", roles: [] }, action: "orders.write", resource: { type: "orders" }, }); assert.equal(app.events("mainsdk:access.decision")[0]?.data.decision, "deny");
- Print while you debug. In development, set
MAINSDK_DEBUG=mainsdk:access.*and run the app. Each matching event prints one line with its channel, decision and reasons.
What you get
Every event is redacted before an observer sees it and holds no request body, prompt or secret. Read the channels reference for each payload, and observe for the calls.
Was this page helpful?