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
5 changes: 5 additions & 0 deletions .changeset/rename-team-to-sub-org.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@monad-inc/embed': patch
---

Docs: refer to Monad "teams" as "sub-orgs" (sub-organizations) in the README, USAGE guide, OpenAPI spec and JSDoc. No API changes.
16 changes: 8 additions & 8 deletions packages/embed/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Zero runtime dependencies.
## How it works

Two pieces of code: a **session-mint endpoint on your backend** mints
a short-lived, team-scoped token from your long-lived Monad API key,
a short-lived, sub-org-scoped token from your long-lived Monad API key,
and a **`createConnectorFrame()` call on your frontend** mounts the
iframe using that token. Both shown below.

Expand All @@ -31,14 +31,14 @@ iframe using that token. Both shown below.
## Step 1 — Mint a session token from your backend

Your backend exchanges its long-lived Monad API key for a short-lived,
team-scoped session token, then hands that token to your frontend.
sub-org-scoped session token, then hands that token to your frontend.

Example (any HTTP framework — shown here as a Next.js Route Handler):

```ts
// app/api/monad/session/route.ts
export async function POST(req: Request) {
const { teamId } = await req.json(); // your tenant → Monad team mapping
const { subOrgId } = await req.json(); // your tenant → Monad sub-org mapping

const r = await fetch('https://app.monad.com/api/v3/sessions', {
method: 'POST',
Expand All @@ -47,12 +47,12 @@ export async function POST(req: Request) {
Authorization: `ApiKey ${process.env.MONAD_API_KEY}`
},
body: JSON.stringify({
organization_id: teamId,
organization_id: subOrgId,
ttl_seconds: 1800
})
});
const { session_token, expires_at } = await r.json();
return Response.json({ session_token, expires_at, organizationId: teamId });
return Response.json({ session_token, expires_at, organizationId: subOrgId });
}
```

Expand All @@ -79,7 +79,7 @@ import { createConnectorFrame } from '@monad-inc/embed/connect';
// Fetch a fresh session from your own backend.
const { session_token, organizationId } = await fetch('/api/monad/session', {
method: 'POST',
body: JSON.stringify({ teamId: currentUser.teamId })
body: JSON.stringify({ subOrgId: currentUser.subOrgId })
}).then((r) => r.json());

const frame = createConnectorFrame({
Expand Down Expand Up @@ -109,7 +109,7 @@ controls the surrounding chrome.
| ----------------------- | ---------------------------- | -------- | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| `container` | `HTMLElement \| string` | ✅ | — | Element (or CSS selector) the iframe is appended to. |
| `sessionToken` | `string` | ✅ | — | Short-lived token from `POST /v3/sessions` (your backend mints this). |
| `organizationId` | `string` | ✅ | — | Monad team org id the session is scoped to. Same value you passed to `/v3/sessions`. |
| `organizationId` | `string` | ✅ | — | Monad sub-org id the session is scoped to. Same value you passed to `/v3/sessions`. |
| `kind` | `'input' \| 'output'` | ✅ | — | Which catalog the connector belongs to. |
| `typeId` | `string` | ✅ | — | Connector type slug, e.g. `'aws-cloudtrail'`, `'okta-systemlog'`. |
| `existingId` | `string` | ⛔ | — | Pass to edit an existing connector. Omit to create a new one. |
Expand Down Expand Up @@ -231,7 +231,7 @@ that's a change to the connector itself; file an issue.
on your domain. Browser same-origin policy means your JavaScript
cannot read the iframe's DOM or any value the user types.
- **Session tokens are short-lived.** Default 30 min, scoped to a
single team. Compromise of a session token is bounded; compromise
single sub-org. Compromise of a session token is bounded; compromise
of the long-lived API key is not — keep it on your backend.
- **postMessage with strict origin checks.** Every message between
your page and the iframe is validated against the expected origin
Expand Down
4 changes: 2 additions & 2 deletions packages/embed/openapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ to scaffold servers. It is used to:
- **camelCase everywhere.** Backends normalize the Monad API's mixed casing at
their boundary so this host-facing contract stays uniform.
- **Auth is the host's.** Routes run inside the host app behind its existing
auth. The backend derives the Monad team (`organizationId`) from the request
auth. The backend derives the Monad sub-org (`organizationId`) from the request
via its own `getCustomerOrgID` hook; the browser never sends a tenant id.
- **The pre-provisioned side is server-resolved.** Ingress's store output,
egress's source input, and the delete cleanup policy are decided server-side,
Expand All @@ -40,7 +40,7 @@ to scaffold servers. It is used to:
| Method · path | operationId | Purpose |
| ------------------------------- | ---------------------- | ----------------------------------------------- |
| `GET /embed/config` | `getConfig` | Non-secret iframe config (public). |
| `POST /embed/session` | `createSession` | Mint a short-lived, team-scoped token. |
| `POST /embed/session` | `createSession` | Mint a short-lived, sub-org-scoped token. |
| `GET /embed/catalog` | `listCatalog` | Offered connector types for a kind. |
| `GET /embed/connectors` | `listConnectors` | A tenant's configured connectors. |
| `POST /embed/pipelines/ingress` | `buildIngressPipeline` | Wire a configured input → the tenant's store. |
Expand Down
18 changes: 9 additions & 9 deletions packages/embed/openapi/embed.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ info:
contract stays uniformly camelCase.
- **Auth is the host's.** These routes run inside the host app and are
protected by its existing session/auth. The backend derives the Monad
team (`organizationId`) from the authenticated request via its own
sub-org (`organizationId`) from the authenticated request via its own
`getCustomerOrgID` hook — the browser never sends a tenant id.
- **The pre-provisioned side is server-resolved.** For ingress the store
output, for egress the source input, and the delete cleanup policy are
Expand All @@ -50,7 +50,7 @@ tags:
- name: Config
description: Non-secret configuration the browser needs to mount the iframe.
- name: Session
description: Minting short-lived, team-scoped tokens for the iframe.
description: Minting short-lived, sub-org-scoped tokens for the iframe.
- name: Catalog
description: Which connector types are offered, and what a tenant has configured.
- name: Pipelines
Expand Down Expand Up @@ -90,12 +90,12 @@ paths:
summary: Mint an embed session token
description: >
Trades the host's long-lived Monad API key for a short-lived,
team-scoped session token. The tenant is derived from the authenticated
sub-org-scoped session token. The tenant is derived from the authenticated
request server-side (never sent by the browser). The returned token is
the only credential that crosses into the iframe.
responses:
'200':
description: A freshly minted session, scoped to the caller's tenant team.
description: A freshly minted session, scoped to the caller's tenant sub-org.
content:
application/json:
schema:
Expand Down Expand Up @@ -390,7 +390,7 @@ components:
The host application's own session/auth. These routes are mounted inside
the host app and protected by its existing middleware; the cookie shown
here is illustrative — use whatever your app already uses. The backend
derives the Monad team (`organizationId`) from this authenticated request
derives the Monad sub-org (`organizationId`) from this authenticated request
via its `getCustomerOrgID` hook. `GET /embed/config` is the only unauthenticated
route.

Expand Down Expand Up @@ -439,10 +439,10 @@ components:
properties:
sessionToken:
type: string
description: Short-lived, team-scoped token. Pass to the iframe; never log or persist.
description: Short-lived, sub-org-scoped token. Pass to the iframe; never log or persist.
organizationId:
type: string
description: The Monad team (org) id the token is scoped to.
description: The Monad sub-org id the token is scoped to.
expiresAt:
type: string
format: date-time
Expand Down Expand Up @@ -623,7 +623,7 @@ components:
Forbidden:
description: >
Authenticated, but not permitted for the requested tenant or resource —
for example the host's `getCustomerOrgID` could not map the caller to a Monad team.
for example the host's `getCustomerOrgID` could not map the caller to a Monad sub-org.
content:
application/json:
schema:
Expand Down Expand Up @@ -651,7 +651,7 @@ components:
$ref: '#/components/schemas/Error'
example:
code: conflict
message: A connector with that name already exists in this team.
message: A connector with that name already exists in this sub-org.
UpstreamError:
description: The Monad API returned an error or was unreachable.
content:
Expand Down
2 changes: 1 addition & 1 deletion packages/embed/src/connect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export interface ConnectorFrameOptions {
/** Short-lived embed session token (host backend mints it). */
sessionToken: string;
/**
* Team org id the session is scoped to. The host backend already knows
* Sub-org id the session is scoped to. The host backend already knows
* this — it's the same value passed to `/v1/embed/sessions` when minting
* the token. Forwarded into the iframe so it can build `/v1/<org>/*` and
* `/v2/<org>/*` URLs.
Expand Down
4 changes: 2 additions & 2 deletions packages/embed/src/connect/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* its long-lived API key and base URL. Path is the full API path,
* e.g. `/v2/{org}/pipelines/{id}`.
*/
export type MonadRequest = (path: string, init?: RequestInit) => Promise<any>;

Check warning on line 25 in packages/embed/src/connect/lifecycle.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type

/* ===== resolve ===== */

Expand Down Expand Up @@ -53,8 +53,8 @@
*
* The pipelines list is slim (no node wiring), so this fetches each
* pipeline's detail and scans for the input node. Fine for the modest
* pipeline counts a single tenant team has; a host managing many
* pipelines per team should instead persist the `pipelineId`
* pipeline counts a single tenant sub-org has; a host managing many
* pipelines per sub-org should instead persist the `pipelineId`
* buildDevNullPipeline returns and skip the lookup.
*
* Returns null when the input has no pipeline.
Expand All @@ -66,13 +66,13 @@
}): Promise<ResolvedIntegration | null> {
const { request, org, inputId } = opts;
const listed = await request(`/v2/${org}/pipelines/`);
const pipelines: any[] = Array.isArray(listed)

Check warning on line 69 in packages/embed/src/connect/lifecycle.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
? listed
: (listed?.pipelines ?? listed?.data ?? []);

for (const summary of pipelines) {
if (!summary?.id) continue;
let detail: any;

Check warning on line 75 in packages/embed/src/connect/lifecycle.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
try {
detail = await request(`/v2/${org}/pipelines/${summary.id}`);
} catch {
Expand Down Expand Up @@ -130,14 +130,14 @@
name: pipeline.name,
description: pipeline.description ?? '',
enabled,
nodes: (pipeline.nodes ?? []).map((n: any) => ({

Check warning on line 133 in packages/embed/src/connect/lifecycle.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
id: n.id,
slug: n.slug,
component_id: n.component_id,
component_type: n.component_type,
enabled: n.enabled ?? true
})),
edges: (pipeline.edges ?? []).map((e: any) => ({

Check warning on line 140 in packages/embed/src/connect/lifecycle.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
name: e.name,
description: e.description ?? '',
from_node_instance_id: e.from_node_instance_id,
Expand Down
2 changes: 1 addition & 1 deletion packages/embed/src/connect/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export interface InitMessage {
/** Monad API base, e.g. "https://api.monad.com" or dev "http://localhost/api". */
apiBase: string;
/**
* Team org id the session token is scoped to. The iframe uses this to
* Sub-org id the session token is scoped to. The iframe uses this to
* build `/v1/<org>/*` and `/v2/<org>/*` URLs. Must match the token's
* `org` claim — server-side `org_access.Middleware` will 403 if not.
*/
Expand Down
Loading