Skip to main content

Shares API (B13)

Feature 003 (Organisations, Team & Access), user story 7 — external access. A share grants a CUSTOMER org, a PARTNER org, or an individual (by account or by email) read/write access to a named set of an operator's plants, at one of five fixed levels, without that grantee ever becoming a member of the operator's own organisation.

:::caution Code-complete, not yet captured against a real deployment As of 2026-10-03, packages/core/src/repositories/shares.ts and packages/api/src/handlers/shares.ts (plus the CDK route wiring and packages/core/src/projections/share-counters.ts and the access-index.ts/stream-router.ts fan-out that keeps plant links and USER-grantee legacy indexes in sync) are landed and unit-tested. Every request/response shape below is still illustrative — derived from the OpenAPI schema (docs/openapi.yaml) and the Zod schemas in packages/core/src/schemas.ts (ShareGrantee, ShareSelector, Share, CreateShareInput, PatchShareInput, ShareListItem, SharesScreen) and from the already-landed, pure effectiveAccess evaluator (packages/core/src/access/evaluator.ts) that every share ultimately feeds into — not a captured execution against a running stack. :::

Known gaps (accurate as of the same landing):

  • Selector validation is PLANTS-only. A PLANTS selector's ids are checked against the org's real plants (assertPlantsOperatedBy — a foreign plant is 422). A TAG/REGION selector's ids are not validated against the organisation's actual tag/region catalog — that catalog is feature 004's territory and doesn't exist yet. Don't rely on the API to reject a nonsense tag/region id today.
  • levels[].can/cannot are raw category keys ("plants", "commands", …), not human-readable UI copy — there is no copy catalog in packages/core for this yet. The FE owns turning these into display strings (the per-category meaning is the ceiling table further down this page).

How this differs from a membership​

Everywhere else on this site, a person gets access to an org's plants by being a member of that org, with a role and a scope (see Team). A share is the other direction: the operator organisation that owns the plants hands a slice of access to an outside org or person, who never joins the operator's org at all. The grantee's effective permissions on a shared plant are computed by the same canonical evaluator as every other access path (Architecture → Authorization model), with one addition specific to shares: a fixed ceiling per external level (below) that the grantee's own role can never exceed.

Overview​

OpMethod + pathAuthIdempotency
ListGET /v1/orgs/{orgId}/sharessharing ≥ VIEW—
CreatePOST /v1/orgs/{orgId}/sharessharing ≥ MANAGE, caller must be an OPERATOR memberRequired
UpdatePATCH /v1/orgs/{orgId}/shares/{shareId}sharing ≥ MANAGE— (versioned)
Revoke — removed 2026-11-27DELETE /v1/orgs/{orgId}/shares/{shareId}——

Update and revoke are versioned (If-Match/ETag), same mechanism as Team's PATCH .../members/{sub}. Create is a strict route (CR-13) and requires Idempotency-Key (CR-7) — identical convention to Invitations' create.

All four routes are {orgId}-scoped to the operator organisation — the org that owns the plants being shared, never the grantee's own org. A grantee org calling these routes about its OWN org id gets 403 FORBIDDEN ("no re-sharing" below), not a list of shares granted to it (that's GET /v1/me/context's territory, not this page).

Authorization — the sharing category, plus "no re-sharing"​

Every route uses the caller's sharing level in the operator org (ADR 0014; it was customers, and a role stored before then derives sharing from customers, so effective access is unchanged — see Roles & permissions) — the same 15-category permission map every other 003 route uses (see Architecture → Authorization model):

Rolesharing level
Super AdminFULL
AdministratorFULL
Business (R-90)MANAGE
Installer (R-91 template and copies)MANAGE (was NONE before 2026-11-03; VIEW 2026-11-23 → 2026-11-26, RBAC-S6, reversed by the owner)

So GET (≥ VIEW) and the three write routes (sharing ≥ MANAGE) are reachable by Super Admin, Administrator, Business and Installer. An Installer reaches every plant of its Business (scope ALL), so it may share any of them, whoever added the plant. A scope still applies to other scoped members: a share for a plant outside their scope is refused, and every share level and permsLimit is capped at the Installer's own levels (403 FORBIDDEN, details.reason: "ESCALATION"). Roles retired on 2026-11-03 (Viewer NONE, Operations Manager VIEW, Sales MANAGE, Technician and Compliance Auditor NONE) keep these levels for members who still hold them. A caller with no ACTIVE membership in {orgId} gets 404 NOT_FOUND (the org is invisible, not merely under-permissioned) — same requireOrgLevel/SC-003 convention as every other 003 route.

No re-sharing (FR-047): only a member of the OPERATOR org that owns the plants may create, change or revoke a share. A member of the grantee organisation — even one holding FULL on every category in their own org — gets 403 FORBIDDEN calling any of these four routes, because requireOrgLevel finds no real customers membership path for them in the operator's org id; their access to the shared plants comes entirely through the effectiveAccess evaluator reading the share, never through calling this API themselves.

Exception — re-share by a Connected End User (2026-11-03). A person who reaches a plant through a share granted to them personally, or through their customer portal, with sharing ≥ MANAGE there (only possible through the FULL-tier opt-in below) may share that one plant with another individual via POST /v1/plants/{plantId}/shares. The re-share is stored under the plant's operator org, so it appears in this org's GET …/shares list with a parent field, and the operator can PATCH or DELETE it like any other share. The org routes on this page stay closed to grantees.

Shares made by "Share with a business" (ADR 0032, 2026-11-27)​

When a Business accepts an independent End User's request, an ordinary share is created in the End User's personal org:

  • Grantee: { kind: ORG, orgId: <business> }.
  • Selector: PLANTS [plantId].
  • Level: VIEW.
  • origin: BUSINESS_SHARE, with the same id as the request.

Who it reaches:

  • Only shares with this origin reach a Business's members.
  • They reach the members with scope ALL, at min(own role, ceiling). PLANTS-scoped members aren't covered.

What you can do with it on this page:

  • It's listed by GET /v1/orgs/{personalOrgId}/shares.
  • It can be revoked here.
  • PATCH refuses it with 409 INVALID_STATE BUSINESS_SHARE_NOT_EDITABLE.

Use the guide routes, which keep the request in step.

The five external levels and their per-category ceiling​

A share's level is one of VIEW < MONITOR < EDIT < SERVICE < FULL (cumulative, but a separate scale from the internal role levels NONE < VIEW < EDIT < MANAGE < FULL — do not confuse SERVICE/MONITOR with anything on Team's role table). Each external level maps to a fixed per-category ceiling (packages/core/src/access/ceilings.ts, 07-security.md §3.3) — an ORG grantee's effective level per category is min(their own role's level in the grantee org, the ceiling); an individual (USER) grantee gets exactly the ceiling, with no role of their own to intersect against:

CategoryVIEWMONITOREDITSERVICEFULL
plantsVIEWVIEWEDITEDITEDIT
devicesVIEW (serials/engineering redacted)VIEW (redacted)VIEWVIEWEDIT
alertsVIEWVIEWVIEWEDITEDIT
commandsNONENONENONEEDIT (risk ≤ LOW: restart, read config)MANAGE (risk ≤ MEDIUM; never platformOnly)
firmwareNONENONENONENONENONE (never granted through a share, at any level)
serviceNONENONENONEMANAGEMANAGE
reportsNONEEDIT (generate/download/receive)EDITEDITEDIT
customersNONENONEEDIT (contacts only)EDITEDIT
teamNONENONENONENONEEDIT (grant access to own staff only)
settingsNONENONENONENONENONE
registersReadVIEWVIEWVIEWVIEWVIEW
registersWriteNONENONENONEEDITMANAGE
sharingNONENONEEDITEDITEDIT
rolesNONENONENONENONEVIEW
auditNONENONENONENONEEDIT

Changed by ADR 0014 phase 2a (2026-10-29): the FULL column now has registersRead: VIEW (was EDIT); reading registers has no level above VIEW, so no plant access changes. The granter's escalation check skips roles and audit (org-level categories no plant path reads), so a BUSINESS caller can grant FULL.

Per-permission limit (permsLimit, ADR 0014 phase 2a)​

A share may carry an optional permsLimit: a partial map of any of the 15 categories to an internal Level (NONE/VIEW/EDIT/MANAGE/FULL). The share's effective ceiling per category is min(tier ceiling, limit) (ceilingOf in ceilings.ts). An absent key keeps the tier's value; a limit never raises a category, so the tier still decides redaction (VIEW/MONITOR), the command risk cap, and firmware stays NONE. See Roles & permissions for the toggle mapping.

FULL-tier opt-in (only exception to "never raises"). On a FULL share, permsLimit may RAISE two categories up to MANAGE: plants (archive and restore the plant) and sharing (re-share it). Without the key, FULL keeps EDIT for both, so shares stored earlier are unchanged. The escalation check runs on the result, so only a granter holding MANAGE in those categories (e.g. a Business) can switch them on; otherwise 403, details.reason: "ESCALATION". On every other tier, and for every other category, a limit still only lowers.

// illustrative example — POST /v1/orgs/{orgId}/shares body
{ "grantee": { "kind": "USER", "email": "owner@example.com" }, "level": "FULL",
"selector": { "kind": "PLANTS", "ids": ["01JB7R0000000000000000000P"] },
"permsLimit": { "plants": "MANAGE", "sharing": "MANAGE" } }

Worked example (unit-tested, packages/api/test/authz/share-paths.test.ts): a PARTNER org's own Technician (internal role: service: EDIT, commands: VIEW) holds a SERVICE share on plant P. Effective access on P is min(EDIT, SERVICE-ceiling MANAGE) = EDIT for service, and min(VIEW, SERVICE-ceiling EDIT) = VIEW for commands — the Technician's own role already capped commands below what the share would have allowed. On any other plant not in that share's selector, the same Technician has nothing at all from this share (zero paths, not a lower level).

An expired (expiresAt passed) or non-ACTIVE (SUSPENDED/REVOKED) share contributes nothing, evaluated fresh on every request (FR-049) — this is why the GET list below returns a derived expired: true/false flag rather than ever deleting the row.

Expiry is never written. No sweeper changes a share's stored status when expiresAt passes — it stays ACTIVE (or INVITED/SUSPENDED) in DynamoDB. EXPIRED is derived at read time (packages/core/src/repositories/shares.ts: a non-REVOKED share whose expiresAt is in the past reads as EXPIRED), so the list returns status: "EXPIRED" and expired: true together. A ?status=EXPIRED filter is applied after the page is fetched, not in the DynamoDB query.

GET /v1/orgs/{orgId}/shares​

Purpose: the "Shared access" list — every share this operator has granted, with a summary of what each level means.

  • Query parameters: granteeKind (ORG|USER), status (INVITED|ACTIVE|SUSPENDED|REVOKED|EXPIRED), level (VIEW|MONITOR|EDIT|SERVICE|FULL), limit (≤ 50; default 15 on the first page, 10 with a cursor (lazy loading)), cursor (opaque).
  • First page only: a levels array — one row per external level with can/cannot category lists (the ceiling table above, condensed) and shareCount at that level. Omitted on later pages (same convention GET /v1/orgs/{orgId}/members uses for its summary tiles).
  • Scoped callers (an Installer, or any member whose scope is not ALL, 2026-11-12): only shares on their own plants are returned and shareCount counts those rows on the page. PATCH/DELETE of any other share → 404 NOT_FOUND; POST (or a selector change) reaching outside their plants → 403 FORBIDDEN, details.reason: "OUTSIDE_SCOPE". See Role boundaries.

Response (illustrative)​

{
levels?: Array<{ level: "VIEW"|"MONITOR"|"EDIT"|"SERVICE"|"FULL"; can: string[]; cannot: string[]; shareCount: number }>;
items: Array<{
shareId: string; code: string; // "SH-0001"
grantee: { kind: "ORG"|"USER"; orgId?: string; orgKind?: "CUSTOMER"|"PARTNER"; name: string; contactMasked?: string };
level: "VIEW"|"MONITOR"|"EDIT"|"SERVICE"|"FULL";
permsLimit?: Partial<Record<Category, Level>>; // only when set
// only on a re-share: the grant it was made through + the re-sharer's sub
parent?: { kind: "SHARE"; shareId: string; sub: string }
| { kind: "PORTAL"; customerOrgId: string; sub: string };
selector: { kind: "PLANTS"|"TAG"|"REGION"; ids: string[]; label?: string; plantCountApprox?: number };
status: "INVITED"|"ACTIVE"|"SUSPENDED"|"REVOKED"|"EXPIRED";
expired: boolean;
expiresAt?: string;
note?: string;
sharedBy: { sub: string; name: string };
since: string;
version: number;
}>;
nextCursor?: string;
}

Status codes​

StatuscodeWhenFE action
200—OKRender the list; the levels band only appears on page 1.
401UNAUTHENTICATEDMissing/invalid/expired tokenRefresh token / re-authenticate
403FORBIDDENcustomers < VIEW in orgIdHide the "Shared access" section
500/503INTERNAL / DEPENDENCY_UNAVAILABLEUnexpected / AWS dependency issueRetry with backoff (503 carries Retry-After)

POST /v1/orgs/{orgId}/shares​

Purpose: the "Share plant access" drawer — grant a new share.

Request​

Headers

HeaderRequiredNotes
Idempotency-KeyYes[A-Za-z0-9_-]{1,128}. Missing → 428 PRECONDITION_REQUIRED, details.header: "Idempotency-Key" (CR-7) — never 400.
Content-TypeYesapplication/json

Body

FieldTypeRequiredNotes
grantee{orgId} | {email} | {sub}YesExactly one of the three. orgId — an existing CUSTOMER/PARTNER org (ORG grantee). A Business (OPERATOR org) is refused: 422 VALIDATION_FAILED BUSINESS_GRANTEE_NOT_ALLOWED (2026-11-27, ADR 0032) — except for a Super Admin / Administrator of the platform org (ADR 0034): their share with a Business is created ACTIVE at once with origin: BUSINESS_SHARE, at any level up to FULL, with no request and no notice. An Administrator may also do this inside an End User's personal org. Such a share never gave the Business any access; an independent End User shares a plant with a Business through Share with a business instead. sub — an existing account (USER grantee). email — if no account matches, creates an EXTERNAL invitation (FR-050) and the share starts INVITED. Never the operator org itself, never the PLATFORM org.
levelVIEW|MONITOR|EDIT|SERVICE|FULLYesSee the ceiling table above.
selector{kind, ids}Yeskind: PLANTS — ≤ 500 plant IDs, all must be operated by orgId. kind: TAG|REGION — ≤ 10 IDs, ORG grantees only; a USER grantee's selector must be PLANTS (OQ-05). There is no ALL selector kind for shares — unlike a membership's scope, a share can never cover "every plant" implicitly.
expiresAt——Removed 2026-11-27 (ADR 0035): sending it is 422 SHARE_EXPIRY_REMOVED. Shares have no end date.
notestring, ≤ 500 charsNo
permsLimitPermsLimit (partial map category → Level)NoLowers the tier's ceiling per category. Unknown key or bad level → 422. {} is treated as no limit and not stored.

Strict (.strict() Zod, CreateShareInput): an unknown field is 422.

Response — 201​

Same shape as one GET list item (ShareView), plus an invitation block only when grantee.email had no matching account:

{
"shareId": "01JA3K...",
"code": "SH-0007",
"grantee": { "kind": "USER", "name": "contact@partnerco.example" },
"level": "SERVICE",
"permsLimit": { "commands": "NONE" },
"selector": { "kind": "PLANTS", "ids": ["01J9Z...PLANT1"] },
"status": "INVITED",
"expired": false,
"sharedBy": { "sub": "...", "name": "Admin" },
"since": "2026-10-03T12:00:00.000Z",
"version": 1,
"invitation": { "inviteId": "01JA3K...", "expiresAt": "2026-11-02T12:00:00.000Z" }
}

(Illustrative — derived from CreateShareInput/ShareView/ShareInvitationSummary in docs/openapi.yaml, not a captured run.)

Status codes​

StatuscodeWhenFE action
201—CreatedShow the share; if invitation is present and the stage is non-production, an acceptUrl convention identical to Invitations applies. Invitations are in-app only, never emailed.
401UNAUTHENTICATEDNo/bad tokenRe-authenticate
403FORBIDDENsharing < MANAGE (ADR 0014; was customers), the caller's org is itself only a grantee (re-sharing attempt, FR-047), or details.reason: "ESCALATION" — the requested level's ceiling, after permsLimit, exceeds the caller's own role perms in the operator org (a share can never grant more than the person creating it already holds)Hide the "Share" action, or (ESCALATION) offer a lower level / explain why
403FORBIDDENdetails.reason: "PLATFORM_PERSONAL_ORG" — a personal account opened only through the platform fallback; platform staff cannot create lasting access there (revalidation 2026-11-03)Don't retry; the action is not available to platform staff here
409ALREADY_EXISTSAn ACTIVE share already exists for the same grantee with an identical selectorSurface the existing share instead of retrying the create
422VALIDATION_FAILEDALL selector, a plant not operated by this org, grantee is the operator or PLATFORM, TAG/REGION selector on a USER grantee, or a selector over its capShow the specific field error; re-fetch plant list if a selected plant was foreign
428PRECONDITION_REQUIREDMissing Idempotency-KeyGenerate a key, retry
500/503INTERNAL / DEPENDENCY_UNAVAILABLE—Retry with backoff

Idempotent replay: same Idempotency-Key + same body within the retention window replays the original 201 without creating a second share — same mechanism as every other idempotent-create route on this site (see Overview → Idempotency).

PATCH /v1/orgs/{orgId}/shares/{shareId}​

Purpose: the share "Change" drawer — narrow/widen level or selector, change the note. Since 2026-11-27 (ADR 0035) a share can only be widened: a lower level, a permsLimit that lowers a category, or fewer plants is 422 SHARE_NARROWING_REMOVED. status is refused too (422 VALIDATION_FAILED, details.reason: "SHARE_STATUS_CHANGE_REMOVED"): a share can no longer be suspended, reactivated or revoked.

Request​

Headers: If-Match required (missing → 428, details.header: "If-Match"; stale version → 409 VERSION_CONFLICT, details.currentVersion).

Body — any of, all optional, at least one required:

FieldTypeNotes
levelExternalLevelA decrease publishes access.revoked.v1 (reason: SHARE_NARROWED).
selector{kind, ids}Same validation as create. Removing plants from the selector also narrows and publishes the event.
expiresAt—Removed 2026-11-27 (ADR 0035): any value, null included, is 422 SHARE_EXPIRY_REMOVED.
notestring ≤ 500 | nullnull clears it.
status—Removed 2026-11-27 (ADR 0035): any value is 422 SHARE_STATUS_CHANGE_REMOVED.
permsLimitPermsLimit | nullReplaces the whole map; null or {} removes it. Lowering any category counts as narrowing (access.revoked.v1, SHARE_NARROWED). Logged as SHARE_UPDATED with changes.permsLimit.

Any change to level or permsLimit re-runs the escalation check on the resulting limited ceiling. Responses carry permsLimit only when one is set.

Status codes​

StatuscodeWhenFE action
200—Updated — full ShareView returned, including the new versionUpdate ETag/version held locally
401UNAUTHENTICATED—Re-authenticate
403FORBIDDENsharing < MANAGE, or details.reason: "ESCALATION" — the new level/limit ceiling exceeds your own permsHide the action, or (ESCALATION) offer a lower level or tighter limit
403FORBIDDENdetails.reason: "PLATFORM_PERSONAL_ORG" — a personal account opened only through the platform fallback; platform staff cannot create lasting access there (revalidation 2026-11-03)Don't retry; the action is not available to platform staff here
404NOT_FOUNDUnknown shareId in this orgRefresh the list
409VERSION_CONFLICTStale If-MatchRe-fetch the share, re-apply, retry
422VALIDATION_FAILEDSame business rules as create, applied to the new level/selectorShow the field error
428PRECONDITION_REQUIREDMissing If-MatchFetch the current ETag first
500/503——Retry with backoff

DELETE /v1/orgs/{orgId}/shares/{shareId}​

Removed 2026-11-27 (ADR 0035, owner decision). A share can no longer be revoked through this route; API Gateway returns 404 for it. PATCH and the carried-in-share route below are unchanged.

Shares carried into a Business (RBAC v2, 2026-11-14)​

When an End User joins a Business their plants move into it, but the shares they made from their personal org stay there and keep granting, capped at the End User's own level in the Business (no commands or register writes while their remote-control switch is off; nothing while they are suspended). They are listed through the Business, not through /v1/orgs/{personalOrgId}/shares (that org is closed): GET /v1/orgs/{businessOrgId}/members/{sub}/shares and (the DELETE …/members/{sub}/shares/{shareId} revoke was removed 2026-11-27, ADR 0035) — see RBAC v2 → Carried-in shares. After a detach they are managed from the personal org again.

How this reaches the grantee (FE-visible effects)​

  • Revoke/suspend/narrow publishes access.revoked.v1 on the internal bus (scope: "ORG" for an organisation grantee — every one of that org's users loses access on their NEXT request; scope: "USER" for an individual grantee). Authorization is re-evaluated on every request (never cached in the token, same rule as every other 003 access change) — there is no separate "push" the FE needs to listen for; a revoked share simply stops contributing on the grantee's very next call.
  • An expired share (expiresAt passed) is never deleted — it stays visible in the operator's GET list with expired: true, but contributes nothing to any grantee's effective access from the moment it expires (FR-049). The FE should treat expired: true the same as REVOKED for "does this still work" purposes, while still letting the operator see and potentially re-extend it via PATCH expiresAt (no longer possible since 2026-11-27, ADR 0035).
  • EXTERNAL invitations (the email-grantee, no-account case) are accepted through the same POST /v1/invitations:accept endpoint as internal invitations (see Invitations → Accept) — the response's kind: "EXTERNAL" carries a share block instead of a membership block, and the share flips INVITED → ACTIVE as part of that same accept call.
  • An operator member's own view never changes because of shares — shares only ever add access for an outside org/person; an operator's own staff access plants through their membership/role/scope exactly as described on Team, independent of anything on this page.

Audit and known gaps​

  • Every create/update/suspend/restore/revoke writes one access-change log entry (SHARE_CREATED|SHARE_UPDATED|SHARE_SUSPENDED| SHARE_RESTORED|SHARE_REVOKED) with impact.plants — not yet exposed on a dedicated FE-facing audit page on this site (see Known issues if this is still open when you read this).
  • Access requests (a grantee-side org asking for a share, or a level increase, rather than the operator initiating one) are a separate route family — see Access requests (B15, FR-051/FR-052).
  • Every create/update/suspend/restore/revoke above, and every access-request decision, also writes to the access-change log — see that page for the full type catalog and the team ≥ MANAGE-gated changes field.
  • Public share links (an unauthenticated, revocable, read-only URL) are a distinct, not-yet-built mechanism (07-security.md §5 "Security controls") — do not confuse with the authenticated shares documented here.

Web console additions​

See Web console additions (N-37 … N-51) for the newer, not-yet-deployed fields and routes on this area.