Share context between your apps
Let apps of one owner on one machine share a person's language or progress, only with their yes, and see what flows with mainsdk context.
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 declare one purpose, ask for the person's consent, send a setting to a peer app and check what flowed. It takes about 10 minutes. Nothing leaves the machine unless you declare a sink.
You need
- Two MainSDK apps of one owner on the same machine, mutual peers (
apps.registry: on).
1. Declare the purpose
context:
group: acme-learning
identity: first-party
purposes:
personalise:
description: "Use the same language and theme in every Acme app"
attributes: [locale, theme]
retention: 30d
share-with: [prj_01JD8X]2. Ask, then share
import { app } from "mainsdk";
const ctx = app().sharedContext;
const user = { id: "u_123" };
await ctx.consent.set(user, "personalise", true);
await ctx.shared.put({ purpose: "personalise", attributes: { locale: "hi-IN" } }, { user });A peer without its own yes drops the message and answers held.
Check it worked
mainsdk contextIt prints the group, each purpose with its share-with, and how many people consented and how many flows went out and came in. --json gives the same for a tool. It never shows a context id, a user id or a value.
Was this page helpful?