diff --git a/Packages/SubstratalKit/Sources/SubstratalAPI/openapi.yaml b/Packages/SubstratalKit/Sources/SubstratalAPI/openapi.yaml index 0446904..0f93a99 100644 --- a/Packages/SubstratalKit/Sources/SubstratalAPI/openapi.yaml +++ b/Packages/SubstratalKit/Sources/SubstratalAPI/openapi.yaml @@ -2,12 +2,12 @@ openapi: 3.1.0 info: title: Substratal Apps — Platform API - version: 1.0.0-draft.9 + version: 1.0.0-draft.36 summary: User accounts, auth, roles, per-app entitlements (the on/off access switch), profiles, settings, organizations, tenancy, subscription billing, and push notifications for applications built on Substratal Apps. Target contract for an API that is not yet implemented; the prose specification is authoritative. - description: 'Full documentation: https://compositecode.github.io/substratalapps.com/ — read /api-reference/conventions/ - first (IDs, pagination, PATCH semantics, ETag/If-Match, idempotency, error shape). + description: 'Full documentation: https://docs.substratalapps.com/ — read /api-reference/conventions/ first (IDs, pagination, + PATCH semantics, ETag/If-Match, idempotency, error shape). Every request must send the API version in a `Substratal-Version` header (currently `1`, the only version); every response echoes the version that served it. A missing header is `400 api_version_required`, and an unknown version is `400 unsupported_api_version`, @@ -17,13 +17,16 @@ info: Vendor extensions used here: `x-substratal-destructive` (`always` | `conditional`) marks operations annotated destructiveHint for MCP and rejected for API Keys with restrict_destructive=true. For `conditional`, only requests matching `x-substratal-destructive-when` - are rejected; the rest of the operation stays callable. Application and Role ids are derived (app_, role__), - not random; every other id is a prefix plus a ULID. `x-substratal-phase` gives the roadmap phase an operation ships in.' + are rejected; the rest of the operation stays callable. `x-substratal-step-up` (`always` | `conditional`) marks operations + that need a recent MFA check from a User session (Auth → Step-up): without one within the last 10 minutes they return + 403 reauthentication_required. For `conditional`, only requests matching `x-substratal-step-up-when` need it. Application + and Role ids are derived (app_, role__), not random; every other id is a prefix plus a ULID. `x-substratal-phase` + gives the roadmap phase an operation ships in.' license: name: Unlicensed draft — internal specification, not yet released externalDocs: description: Substratal Apps Platform API documentation - url: https://compositecode.github.io/substratalapps.com/ + url: https://docs.substratalapps.com/ servers: - url: https://api.substratalapps.com description: Production @@ -41,10 +44,14 @@ tags: - name: Tenancy - name: Billing - name: Audit +- name: Usage & stats + description: Request usage per Application, API Key, and operation, and the console home screen's live counts. - name: Webhooks - name: Notifications description: Push notifications (APNs, FCM, Web Push) and the notification inbox. - name: API Keys +- name: Platform + description: Runtime operational switches (signup, read-only maintenance) and client feature flags. - name: Meta paths: /health: @@ -177,6 +184,8 @@ paths: tags: - Auth summary: Complete a login that returned an MFA challenge + description: Send the mfa_token and exactly one of code (TOTP), recovery_code, or passkey (an assertion for options + from POST /auth/mfa/passkey-options). A passkey sign-in adds hwk to the session's amr. security: [] x-substratal-phase: mvp requestBody: @@ -195,6 +204,8 @@ paths: pattern: ^[0-9]{6}$ recovery_code: type: string + passkey: + $ref: '#/components/schemas/PasskeyAssertion' responses: '400': $ref: '#/components/responses/BadRequest' @@ -210,6 +221,44 @@ paths: $ref: '#/components/responses/Forbidden' '429': $ref: '#/components/responses/TooManyRequests' + /auth/mfa/passkey-options: + post: + operationId: auth.mfaPasskeyOptions + parameters: [] + tags: + - Auth + summary: Get WebAuthn request options to complete an MFA challenge with a passkey + description: Returns PublicKeyCredentialRequestOptions limited to the User's own passkeys, with a fresh challenge valid + for 5 minutes and usable once. Pass publicKey to navigator.credentials.get() and send the result to POST /auth/mfa/verify + as passkey, with the same mfa_token. 409 passkey_not_registered when the User has no passkey. + security: [] + x-substratal-phase: mvp + requestBody: + required: true + content: + application/json: + schema: + type: object + required: + - mfa_token + properties: + mfa_token: + type: string + responses: + '400': + $ref: '#/components/responses/BadRequest' + '200': + description: Request options + content: + application/json: + schema: + $ref: '#/components/schemas/PasskeyRequestOptions' + '401': + $ref: '#/components/responses/Unauthorized' + '409': + $ref: '#/components/responses/Conflict' + '429': + $ref: '#/components/responses/TooManyRequests' /auth/token/refresh: post: operationId: auth.refreshToken @@ -269,6 +318,72 @@ paths: $ref: '#/components/responses/BadRequest' '401': $ref: '#/components/responses/Unauthorized' + /auth/reauthenticate: + post: + operationId: auth.reauthenticate + parameters: [] + tags: + - Auth + summary: Prove a second factor again, for step-up (User token, MFA enabled) + description: 'Records a fresh MFA check on the calling session (mfa_verified_at), so operations marked x-substratal-step-up + work for the next 10 minutes. Send exactly one of code (a current TOTP code), recovery_code (a single-use recovery + code), or passkey (an assertion for options from POST /auth/reauthenticate/passkey-options). The response is a new + access token carrying the updated mfa_verified_at claim; the refresh token is unchanged. Wrong codes and failed assertions + count toward a lockout: after 5 in 15 minutes it is 429 too_many_attempts. 409 mfa_not_enabled when the User has neither + TOTP nor a passkey.' + x-substratal-phase: mvp + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + code: + type: string + pattern: ^[0-9]{6}$ + recovery_code: + type: string + passkey: + $ref: '#/components/schemas/PasskeyAssertion' + responses: + '400': + $ref: '#/components/responses/BadRequest' + '200': + description: Re-authenticated + content: + application/json: + schema: + $ref: '#/components/schemas/Reauthentication' + '401': + $ref: '#/components/responses/Unauthorized' + '409': + $ref: '#/components/responses/Conflict' + '429': + $ref: '#/components/responses/TooManyRequests' + /auth/reauthenticate/passkey-options: + post: + operationId: auth.reauthenticatePasskeyOptions + parameters: [] + tags: + - Auth + summary: Get WebAuthn request options to re-authenticate with a passkey (User token) + description: 'Like POST /auth/mfa/passkey-options, for the calling User''s session: send the assertion to POST /auth/reauthenticate + as passkey. 409 passkey_not_registered when the User has no passkey.' + x-substratal-phase: mvp + responses: + '400': + $ref: '#/components/responses/BadRequest' + '200': + description: Request options + content: + application/json: + schema: + $ref: '#/components/schemas/PasskeyRequestOptions' + '401': + $ref: '#/components/responses/Unauthorized' + '409': + $ref: '#/components/responses/Conflict' /auth/app-tokens: post: operationId: auth.createAppToken @@ -649,7 +764,10 @@ paths: tags: - Auth summary: Begin TOTP enrollment (self only) + description: A User who already has a passkey needs a recent MFA check (step-up), like registering another passkey. x-substratal-phase: mvp + x-substratal-step-up: conditional + x-substratal-step-up-when: the User already has an MFA method responses: '400': $ref: '#/components/responses/BadRequest' @@ -673,7 +791,9 @@ paths: parameters: [] tags: - Auth - summary: Support reset of a user's TOTP (requires users.manage) + summary: Support reset of a user's MFA, TOTP and passkeys (requires users.manage) + description: Removes TOTP, every passkey, and the recovery codes, and revokes every session. 409 mfa_not_enabled when + the User has neither. x-substratal-phase: mvp x-substratal-destructive: always responses: @@ -694,7 +814,11 @@ paths: tags: - Auth summary: Confirm TOTP enrollment with a first code; returns recovery codes once + description: recovery_codes is present only when TOTP is the User's first MFA method. A User who already has a passkey + keeps their existing codes, and needs a recent MFA check (step-up). x-substratal-phase: mvp + x-substratal-step-up: conditional + x-substratal-step-up-when: the User already has an MFA method requestBody: required: true content: @@ -764,6 +888,168 @@ paths: $ref: '#/components/responses/Conflict' '429': $ref: '#/components/responses/TooManyRequests' + /users/{id}/mfa/passkeys/registration-options: + parameters: + - $ref: '#/components/parameters/UserIdOrMe' + post: + operationId: auth.passkeyRegistrationOptions + parameters: [] + tags: + - Auth + summary: Begin registering a passkey (self only) + description: Returns PublicKeyCredentialCreationOptions (user verification required, resident key preferred, the User's + existing passkeys excluded) with a challenge valid for 5 minutes and usable once. Pass publicKey to navigator.credentials.create() + and send the result to POST /users/{id}/mfa/passkeys. A User who already has an MFA method needs a recent MFA check + (step-up); one enrolling their first method needs a session signed in with a password in the last 10 minutes (403 + recent_sign_in_required). 409 passkey_limit_reached at 10 passkeys; 409 mfa_not_applicable without a password identity. + x-substratal-phase: mvp + x-substratal-step-up: conditional + x-substratal-step-up-when: the User already has an MFA method + responses: + '400': + $ref: '#/components/responses/BadRequest' + '200': + description: Creation options + content: + application/json: + schema: + $ref: '#/components/schemas/PasskeyCreationOptions' + '403': + $ref: '#/components/responses/Forbidden' + '409': + $ref: '#/components/responses/Conflict' + /users/{id}/mfa/passkeys: + parameters: + - $ref: '#/components/parameters/UserIdOrMe' + get: + operationId: auth.listPasskeys + parameters: [] + tags: + - Auth + summary: List a User's passkeys (self or users.manage) + description: Oldest first. Never includes key material. + x-substratal-phase: mvp + responses: + '400': + $ref: '#/components/responses/BadRequest' + '200': + description: The User's passkeys + content: + application/json: + schema: + $ref: '#/components/schemas/PasskeyList' + '403': + $ref: '#/components/responses/Forbidden' + '404': + $ref: '#/components/responses/NotFound' + post: + operationId: auth.registerPasskey + parameters: [] + tags: + - Auth + summary: Finish registering a passkey (self only) + description: Verifies the attestation against the challenge from registration-options, which must have been issued to + this session, and stores the credential. MFA is then enabled. When this is the User's first MFA method the response + also carries ten recovery codes, shown once. Writes user.passkey_added. 400 passkey_invalid when the attestation fails + (wrong origin or RP ID, unknown, expired, or used challenge, user verification missing); 409 passkey_limit_reached; + 409 passkey_already_registered. + x-substratal-phase: mvp + requestBody: + required: true + content: + application/json: + schema: + type: object + required: + - credential + properties: + credential: + $ref: '#/components/schemas/PasskeyAttestation' + name: + type: string + description: A label for the User, at most 64 characters. Default Passkey. + responses: + '400': + $ref: '#/components/responses/BadRequest' + '201': + description: Registered + content: + application/json: + schema: + $ref: '#/components/schemas/PasskeyRegistration' + '403': + $ref: '#/components/responses/Forbidden' + '409': + $ref: '#/components/responses/Conflict' + '422': + $ref: '#/components/responses/Unprocessable' + /users/{id}/mfa/passkeys/{passkeyId}: + parameters: + - $ref: '#/components/parameters/UserIdOrMe' + - name: passkeyId + in: path + required: true + schema: + type: string + patch: + operationId: auth.updatePasskey + tags: + - Auth + summary: Rename a passkey (self only) + x-substratal-phase: mvp + parameters: + - $ref: '#/components/parameters/IfMatch' + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + name: + type: string + description: 1 to 64 characters. + responses: + '400': + $ref: '#/components/responses/BadRequest' + '200': + description: The updated passkey + headers: + ETag: + $ref: '#/components/headers/ETag' + content: + application/json: + schema: + $ref: '#/components/schemas/Passkey' + '403': + $ref: '#/components/responses/Forbidden' + '404': + $ref: '#/components/responses/NotFound' + '409': + $ref: '#/components/responses/Conflict' + '422': + $ref: '#/components/responses/Unprocessable' + delete: + operationId: auth.deletePasskey + parameters: [] + tags: + - Auth + summary: Remove a passkey (self only) + description: Needs a recent MFA check (step-up). Writes user.passkey_removed. Removing the User's last MFA method (no + TOTP, no other passkey) also deletes the recovery codes, writes user.mfa_disabled, and alerts the User, as turning + TOTP off does. + x-substratal-phase: mvp + x-substratal-destructive: always + x-substratal-step-up: always + responses: + '400': + $ref: '#/components/responses/BadRequest' + '204': + description: Removed + '403': + $ref: '#/components/responses/Forbidden' + '404': + $ref: '#/components/responses/NotFound' /users/{id}/sessions: parameters: - $ref: '#/components/parameters/UserIdOrMe' @@ -875,6 +1161,7 @@ paths: parameters: - $ref: '#/components/parameters/Limit' - $ref: '#/components/parameters/Cursor' + - $ref: '#/components/parameters/Include' - name: status in: query description: deleted is allowed for users.manage only @@ -981,84 +1268,185 @@ paths: $ref: '#/components/responses/Conflict' '422': $ref: '#/components/responses/Unprocessable' - /users/{id}: - parameters: - - $ref: '#/components/parameters/UserIdOrMe' - get: - operationId: users.get - parameters: [] - tags: - - Users - summary: Fetch one user - x-substratal-phase: mvp - responses: - '400': - $ref: '#/components/responses/BadRequest' - '200': - description: The user - headers: - ETag: - $ref: '#/components/headers/ETag' - content: - application/json: - schema: - $ref: '#/components/schemas/User' - '404': - $ref: '#/components/responses/NotFound' - patch: - operationId: users.update + /users/bulk-invite: + post: + operationId: users.bulkInvite tags: - Users - summary: Update email (self, pending verification) or status (users.manage) + summary: Invite up to 25 users in one call (users.manage) + description: 'Requires users.manage. Each email is POST /users with status invited and an invitation email, processed + independently: one failing email doesn''t stop the others, and each success writes its own user.created Audit Event. + Each email counts against POST /users''s rate limit (20/min), so emails past it get a per-item 429. The response is + 200 with one result per email, in request order; an item''s status is what POST /users would have returned (201, 409 + email_taken, 422 validation_failed, 429 rate_limited). application_id, if given, becomes each new User''s signup_application_id + and brands the invitation email. See /api-reference/conventions/#bulk-operations.' x-substratal-phase: mvp - x-substratal-destructive: conditional - x-substratal-destructive-when: status becomes suspended parameters: - - $ref: '#/components/parameters/IfMatch' + - $ref: '#/components/parameters/IdempotencyKey' requestBody: + required: true content: application/json: schema: type: object + required: + - emails properties: - email: - type: string - format: email - status: - type: string - description: users.manage only. active on a deleted User restores it. - expires_at: + emails: + type: array + minItems: 1 + maxItems: 25 + items: + type: string + application_id: type: string - format: date-time - description: users.manage only, test-mode Users only. At least 15 minutes from now and at most 30 days after - created_at. Moving it later on an expired User brings them back and fires access.granted (test_user_extended). responses: '400': $ref: '#/components/responses/BadRequest' '200': - description: Updated user + description: One result per email, in request order content: application/json: schema: - $ref: '#/components/schemas/User' + $ref: '#/components/schemas/BulkInviteResults' '403': $ref: '#/components/responses/Forbidden' + '404': + $ref: '#/components/responses/NotFound' '409': $ref: '#/components/responses/Conflict' '422': $ref: '#/components/responses/Unprocessable' - delete: - operationId: users.delete - parameters: [] + /users/bulk-suspend: + post: + operationId: users.bulkSuspend tags: - Users - summary: Soft-delete a user (self or users.manage) + summary: Suspend up to 25 users in one call (users.manage) + description: Requires users.manage. Each id is POST /users/{id}/suspend with the shared reason, processed independently, + each with its own user.suspended Audit Event and webhooks. The protected superadmin is a per-item 409 user_protected. + Like POST /users/{id}/suspend it needs a recent MFA check (403 reauthentication_required for the whole batch). Each + id counts against POST /users/{id}/suspend's rate limit. The response is 200 with one result per id, in request order; + an item's status is what POST /users/{id}/suspend would have returned. See /api-reference/conventions/#bulk-operations. x-substratal-phase: mvp x-substratal-destructive: always - responses: - '400': - $ref: '#/components/responses/BadRequest' - '204': + x-substratal-step-up: always + parameters: + - $ref: '#/components/parameters/IdempotencyKey' + requestBody: + required: true + content: + application/json: + schema: + type: object + required: + - user_ids + properties: + user_ids: + type: array + minItems: 1 + maxItems: 25 + items: + type: string + reason: + type: string + maxLength: 2000 + responses: + '400': + $ref: '#/components/responses/BadRequest' + '200': + description: One result per id, in request order + content: + application/json: + schema: + $ref: '#/components/schemas/BulkResults' + '403': + $ref: '#/components/responses/Forbidden' + '409': + $ref: '#/components/responses/Conflict' + '422': + $ref: '#/components/responses/Unprocessable' + /users/{id}: + parameters: + - $ref: '#/components/parameters/UserIdOrMe' + get: + operationId: users.get + parameters: [] + tags: + - Users + summary: Fetch one user + x-substratal-phase: mvp + responses: + '400': + $ref: '#/components/responses/BadRequest' + '200': + description: The user + headers: + ETag: + $ref: '#/components/headers/ETag' + content: + application/json: + schema: + $ref: '#/components/schemas/User' + '404': + $ref: '#/components/responses/NotFound' + patch: + operationId: users.update + tags: + - Users + summary: Update email (self, pending verification) or status (users.manage) + x-substratal-phase: mvp + x-substratal-destructive: conditional + x-substratal-destructive-when: status becomes suspended + x-substratal-step-up: conditional + x-substratal-step-up-when: status becomes suspended + parameters: + - $ref: '#/components/parameters/IfMatch' + requestBody: + content: + application/json: + schema: + type: object + properties: + email: + type: string + format: email + status: + type: string + description: users.manage only. active on a deleted User restores it. + expires_at: + type: string + format: date-time + description: users.manage only, test-mode Users only. At least 15 minutes from now and at most 30 days after + created_at. Moving it later on an expired User brings them back and fires access.granted (test_user_extended). + responses: + '400': + $ref: '#/components/responses/BadRequest' + '200': + description: Updated user + content: + application/json: + schema: + $ref: '#/components/schemas/User' + '403': + $ref: '#/components/responses/Forbidden' + '409': + $ref: '#/components/responses/Conflict' + '422': + $ref: '#/components/responses/Unprocessable' + delete: + operationId: users.delete + parameters: [] + tags: + - Users + summary: Soft-delete a user (self or users.manage) + x-substratal-phase: mvp + x-substratal-destructive: always + x-substratal-step-up: always + responses: + '400': + $ref: '#/components/responses/BadRequest' + '204': description: Deleted '403': $ref: '#/components/responses/Forbidden' @@ -1075,6 +1463,7 @@ paths: summary: Suspend a user (users.manage) x-substratal-phase: mvp x-substratal-destructive: always + x-substratal-step-up: always requestBody: content: application/json: @@ -1148,6 +1537,7 @@ paths: summary: Request right-to-erasure (soft-delete now, hard-delete cascade in 7 days) x-substratal-phase: mvp x-substratal-destructive: always + x-substratal-step-up: always requestBody: content: application/json: @@ -1169,6 +1559,29 @@ paths: /users/{id}/erasure-requests/current: parameters: - $ref: '#/components/parameters/UserIdOrMe' + get: + operationId: users.getErasure + parameters: [] + tags: + - Users + summary: Read the User's pending erasure request + description: Self, or users.manage. Returns the erasure request while it's scheduled; 404 erasure_not_scheduled when + none is pending (never requested, cancelled, or completed). A soft-deleted User 404s (user_not_found) for anyone without + users.manage, as on cancel. + x-substratal-phase: mvp + responses: + '400': + $ref: '#/components/responses/BadRequest' + '200': + description: The scheduled erasure request + content: + application/json: + schema: + $ref: '#/components/schemas/ErasureRequest' + '403': + $ref: '#/components/responses/Forbidden' + '404': + $ref: '#/components/responses/NotFound' delete: operationId: users.cancelErasure parameters: [] @@ -1234,6 +1647,109 @@ paths: $ref: '#/components/responses/Conflict' '422': $ref: '#/components/responses/Unprocessable' + /users/{id}/avatar/uploads: + parameters: + - $ref: '#/components/parameters/UserIdOrMe' + post: + operationId: profiles.createAvatarUpload + tags: + - Profiles + summary: Start an avatar upload (self or users.manage) + description: 'Returns a presigned POST: send the image straight to url as multipart/form-data, with every entry of fields + and then the file as the last field, named file, within 5 minutes. The API never sees the bytes. Then call POST /users/{id}/avatar/uploads/{uploadId}/complete. + PNG, JPEG, or WebP, at most 2 MB (a larger content_length is 422 validation_failed). 10 upload starts per caller per + hour, shared with Application icons.' + x-substratal-phase: mvp + parameters: + - $ref: '#/components/parameters/IdempotencyKeyOptional' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/ImageUploadRequest' + responses: + '400': + $ref: '#/components/responses/BadRequest' + '201': + description: Where and how to upload + content: + application/json: + schema: + $ref: '#/components/schemas/ImageUpload' + '403': + $ref: '#/components/responses/Forbidden' + '404': + $ref: '#/components/responses/NotFound' + '422': + $ref: '#/components/responses/Unprocessable' + '429': + $ref: '#/components/responses/TooManyRequests' + '503': + $ref: '#/components/responses/ServiceUnavailable' + /users/{id}/avatar/uploads/{uploadId}/complete: + parameters: + - $ref: '#/components/parameters/UserIdOrMe' + - name: uploadId + in: path + required: true + schema: + type: string + post: + operationId: profiles.completeAvatarUpload + tags: + - Profiles + summary: Check an uploaded avatar and make it the Profile's avatar_url (self or users.manage) + description: Checks the uploaded file's magic bytes against the declared content_type, its size, and its dimensions + (at most 2048 × 2048), stores it at a content-addressed https://assets.substratalapps.com/avatars/… URL, sets avatar_url, + and deletes the previous hosted avatar. A file that fails a check is deleted, and the call is 422 invalid_image with + details.reason. An upload that was never sent, or was already completed, is 404 upload_not_found. Writes profile.avatar_changed + when someone other than the User does it. + x-substratal-phase: mvp + parameters: [] + responses: + '400': + $ref: '#/components/responses/BadRequest' + '200': + description: The updated Profile + headers: + ETag: + $ref: '#/components/headers/ETag' + content: + application/json: + schema: + $ref: '#/components/schemas/Profile' + '403': + $ref: '#/components/responses/Forbidden' + '404': + $ref: '#/components/responses/NotFound' + '422': + $ref: '#/components/responses/Unprocessable' + '503': + $ref: '#/components/responses/ServiceUnavailable' + /users/{id}/avatar: + parameters: + - $ref: '#/components/parameters/UserIdOrMe' + delete: + operationId: profiles.deleteAvatar + tags: + - Profiles + summary: Remove the avatar (self or users.manage) + description: Sets avatar_url to null and deletes the hosted image, if it is one; an external https URL is just cleared. + PATCH /users/{id}/profile with avatar_url null does the same. Writes profile.avatar_changed when someone other than + the User does it. + x-substratal-phase: mvp + x-substratal-destructive: always + parameters: [] + responses: + '400': + $ref: '#/components/responses/BadRequest' + '204': + description: Removed + '403': + $ref: '#/components/responses/Forbidden' + '404': + $ref: '#/components/responses/NotFound' /users/{id}/settings: parameters: - $ref: '#/components/parameters/UserIdOrMe' @@ -1410,10 +1926,15 @@ paths: tags: - Applications summary: List the catalog (filtered by visibility rules) + description: 'Newest first by created_at, ties broken by id. With applications.manage, review_status=pending_review + is the review queue and defaults to oldest-waiting first, by review_requested_at (falling back to created_at). sort + sets the order explicitly by created_at: created_at for oldest first, -created_at for newest first, in the queue too. + A cursor is only valid under the sort it was issued with.' x-substratal-phase: mvp parameters: - $ref: '#/components/parameters/Limit' - $ref: '#/components/parameters/Cursor' + - $ref: '#/components/parameters/Include' - name: visibility in: query schema: @@ -1442,9 +1963,27 @@ paths: in: query schema: type: string + - name: q + in: query + description: Case-insensitive prefix match on name or slug + schema: + type: string + - name: include_inactive + in: query + description: Include retired Applications (also included by review_status=retired) + schema: + type: boolean + default: false + - name: sort + in: query + description: created_at (oldest first) or -created_at (newest first). Ties are broken by id in the same direction. + schema: + type: string responses: '400': $ref: '#/components/responses/BadRequest' + '422': + $ref: '#/components/responses/Unprocessable' '200': description: A page of Applications (trimmed view) content: @@ -1458,9 +1997,10 @@ paths: summary: Register an Application (applications.manage, or self-service into review) description: 'applications.manage creates any Application, approved by default (concierge onboarding). Any other User with a verified email may submit their own: it''s owned by the caller (or an Organization they''re an org_admin of), - starts in pending_review, and can''t set visibility, access_tier, review_status, or review_notes (403 moderation_field_forbidden). - Unverified email is 403 email_not_verified; API Keys without applications.manage are 403 forbidden. Self-service submissions - are limited to 10 per User per day.' + starts in pending_review, and can''t set visibility, review_status, or review_notes (403 moderation_field_forbidden). + Its access_tier is free or restricted (the default); standard is 422 access_tier_reserved. Unverified email is 403 + email_not_verified; API Keys without applications.manage are 403 forbidden. Self-service submissions are limited to + 10 per User per day.' x-substratal-phase: mvp parameters: - $ref: '#/components/parameters/IdempotencyKeyOptional' @@ -1528,7 +2068,8 @@ paths: summary: Update a catalog entry (owner — configuration; applications.manage — anything) x-substratal-phase: mvp x-substratal-destructive: conditional - x-substratal-destructive-when: review_status becomes rejected or suspended, or available_app_roles/permissions shrink + x-substratal-destructive-when: review_status becomes rejected, suspended, or retired, or available_app_roles/permissions + shrink parameters: - $ref: '#/components/parameters/IfMatch' requestBody: @@ -1551,6 +2092,145 @@ paths: $ref: '#/components/responses/Conflict' '422': $ref: '#/components/responses/Unprocessable' + '429': + $ref: '#/components/responses/TooManyRequests' + delete: + operationId: applications.delete + tags: + - Applications + summary: Delete an unreferenced test-mode Application (applications.manage) + description: 'Only a test-mode Application that nothing references can be deleted; a live one is 409 application_not_deletable + (retire it with review_status: retired instead). Anything still referencing it (Entitlements, API Keys, webhooks, + devices, notifications, settings or profile rows, push credentials, role assignments, refresh tokens, Users who signed + up through it) is 409 application_in_use, naming each kind in `references`. Its own Roles go with it; audit history + is kept. Writes application.deleted.' + x-substratal-phase: mvp + x-substratal-destructive: always + parameters: [] + responses: + '400': + $ref: '#/components/responses/BadRequest' + '204': + description: Deleted + '403': + $ref: '#/components/responses/Forbidden' + '404': + $ref: '#/components/responses/NotFound' + '409': + $ref: '#/components/responses/Conflict' + /applications/{id}/icon/uploads: + parameters: + - name: id + in: path + required: true + schema: + type: string + post: + operationId: applications.createIconUpload + tags: + - Applications + summary: Start an icon upload (the owner or applications.manage) + description: 'Returns a presigned POST, as for avatars: send the image straight to url with every entry of fields and + then the file as the last field, named file, within 5 minutes, then call POST /applications/{id}/icon/uploads/{uploadId}/complete. + PNG, JPEG, or WebP, square, at most 1 MB (a larger content_length is 422 validation_failed). 10 upload starts per + caller per hour, shared with avatars.' + x-substratal-phase: mvp + parameters: + - $ref: '#/components/parameters/IdempotencyKeyOptional' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/ImageUploadRequest' + responses: + '400': + $ref: '#/components/responses/BadRequest' + '201': + description: Where and how to upload + content: + application/json: + schema: + $ref: '#/components/schemas/ImageUpload' + '403': + $ref: '#/components/responses/Forbidden' + '404': + $ref: '#/components/responses/NotFound' + '422': + $ref: '#/components/responses/Unprocessable' + '429': + $ref: '#/components/responses/TooManyRequests' + '503': + $ref: '#/components/responses/ServiceUnavailable' + /applications/{id}/icon/uploads/{uploadId}/complete: + parameters: + - name: id + in: path + required: true + schema: + type: string + - name: uploadId + in: path + required: true + schema: + type: string + post: + operationId: applications.completeIconUpload + tags: + - Applications + summary: Check an uploaded icon and make it the Application's icon_url (the owner or applications.manage) + description: Checks the uploaded file's magic bytes against the declared content_type, its size, and its dimensions + (square, at most 2048 × 2048), stores it at a content-addressed https://assets.substratalapps.com/apps/… URL, sets + icon_url, and deletes the previous hosted icon. A file that fails a check is deleted, and the call is 422 invalid_image + with details.reason. An upload that was never sent, or was already completed, is 404 upload_not_found. Writes application.icon_changed. + x-substratal-phase: mvp + parameters: [] + responses: + '400': + $ref: '#/components/responses/BadRequest' + '200': + description: The updated Application + headers: + ETag: + $ref: '#/components/headers/ETag' + content: + application/json: + schema: + $ref: '#/components/schemas/Application' + '403': + $ref: '#/components/responses/Forbidden' + '404': + $ref: '#/components/responses/NotFound' + '422': + $ref: '#/components/responses/Unprocessable' + '503': + $ref: '#/components/responses/ServiceUnavailable' + /applications/{id}/icon: + parameters: + - name: id + in: path + required: true + schema: + type: string + delete: + operationId: applications.deleteIcon + tags: + - Applications + summary: Remove the icon (the owner or applications.manage) + description: Sets icon_url to null and deletes the hosted image, if it is one; an external https URL is just cleared. + Writes application.icon_changed. + x-substratal-phase: mvp + x-substratal-destructive: always + parameters: [] + responses: + '400': + $ref: '#/components/responses/BadRequest' + '204': + description: Removed + '403': + $ref: '#/components/responses/Forbidden' + '404': + $ref: '#/components/responses/NotFound' /users/{id}/entitlements: parameters: - $ref: '#/components/parameters/UserIdOrMe' @@ -1563,6 +2243,7 @@ paths: parameters: - $ref: '#/components/parameters/Limit' - $ref: '#/components/parameters/Cursor' + - $ref: '#/components/parameters/Include' - name: application_id in: query schema: @@ -1647,6 +2328,7 @@ paths: parameters: - $ref: '#/components/parameters/Limit' - $ref: '#/components/parameters/Cursor' + - $ref: '#/components/parameters/Include' - name: application_id in: query schema: @@ -1793,6 +2475,63 @@ paths: $ref: '#/components/responses/NotFound' '409': $ref: '#/components/responses/Conflict' + /entitlements/bulk-update: + post: + operationId: entitlements.bulkUpdate + tags: + - Entitlements + summary: Change the status of up to 25 Entitlements in one call + description: 'Each item is PATCH /entitlements/{id} with its status and disabled_reason: the same access rules and transition + table, processed independently, each with its own Audit Event and webhooks. Each item counts against PATCH /entitlements/{id}''s + rate limit. The response is 200 with one result per item, in request order; an item''s status is what the PATCH would + have returned. An item that disables or revokes is refused (403 destructive_operation_restricted) for a restrict_destructive + key; the other items go ahead. See /api-reference/conventions/#bulk-operations.' + x-substratal-phase: mvp + x-substratal-destructive: conditional + x-substratal-destructive-when: an item's status becomes disabled or revoked + parameters: + - $ref: '#/components/parameters/IdempotencyKey' + requestBody: + required: true + content: + application/json: + schema: + type: object + required: + - items + properties: + items: + type: array + minItems: 1 + maxItems: 25 + items: + type: object + required: + - id + - status + properties: + id: + type: string + status: + $ref: '#/components/schemas/EntitlementStatus' + disabled_reason: + type: string + maxLength: 255 + responses: + '400': + $ref: '#/components/responses/BadRequest' + '200': + description: One result per item, in request order + content: + application/json: + schema: + $ref: '#/components/schemas/BulkResults' + '403': + $ref: '#/components/responses/Forbidden' + '409': + $ref: '#/components/responses/Conflict' + '422': + $ref: '#/components/responses/Unprocessable' /permissions: get: operationId: permissions.list @@ -1823,10 +2562,17 @@ paths: tags: - Roles & Permissions summary: List Roles + description: 'Any authenticated caller; each sees only the Roles visible to it. Platform Roles are visible to Users + holding any platform permission and to platform keys. An Application''s Roles are visible to platform roles.manage + and applications.manage holders, the Application''s own key, and the Application''s owner (its owner_user_id, or any + active org_admin of its owner_organization_id), with no platform permission needed. An owner sees only the Roles of + Applications they own: never another Application''s, and never platform Roles unless they also hold a platform permission. + A scope the caller can''t see returns an empty page, not an error.' x-substratal-phase: mvp parameters: - $ref: '#/components/parameters/Limit' - $ref: '#/components/parameters/Cursor' + - $ref: '#/components/parameters/Include' - name: scope in: query description: '''platform'' or an application_id' @@ -1902,6 +2648,14 @@ paths: tags: - Roles & Permissions summary: Change a Role's permissions or description + description: An app Role may be changed by platform roles.manage or applications.manage, the Application's own key holding + roles.manage, or the Application's owner (its owner_user_id, or any active org_admin of its owner_organization_id) + with no platform permission needed. Assigning it still takes roles.manage, the owner, or the app's own key. Its permissions + must be keys its own Application declares; a platform key, another Application's key, or an undeclared key returns + 422 unknown_permission. A platform Role needs platform roles.manage, and every permission it grants must be one the + caller holds (403 role_escalation_forbidden); seed Roles can't be changed (403 seed_role_immutable). A Role the caller + can't see (another Application's, or a platform Role for a caller with no platform permission) returns 404 role_not_found; + one it can see but not change returns 403 forbidden. x-substratal-phase: mvp x-substratal-destructive: conditional x-substratal-destructive-when: permissions shrink @@ -1932,6 +2686,8 @@ paths: $ref: '#/components/schemas/Role' '403': $ref: '#/components/responses/Forbidden' + '404': + $ref: '#/components/responses/NotFound' '409': $ref: '#/components/responses/Conflict' '422': @@ -1992,7 +2748,11 @@ paths: tags: - Roles & Permissions summary: Assign a Role (idempotent — 200 if already held) + description: Assigning a platform Role that grants a permission to a User without MFA succeeds, but the Role takes effect + only once they enroll TOTP; the response's mfa_enrollment_required says so (Auth → Staff MFA). x-substratal-phase: mvp + x-substratal-step-up: conditional + x-substratal-step-up-when: the Role is a platform Role responses: '400': $ref: '#/components/responses/BadRequest' @@ -2020,6 +2780,8 @@ paths: summary: Remove a Role assignment (idempotent) x-substratal-phase: mvp x-substratal-destructive: always + x-substratal-step-up: conditional + x-substratal-step-up-when: the Role is a platform Role responses: '400': $ref: '#/components/responses/BadRequest' @@ -2061,6 +2823,7 @@ paths: parameters: - $ref: '#/components/parameters/Limit' - $ref: '#/components/parameters/Cursor' + - $ref: '#/components/parameters/Include' - name: status in: query schema: @@ -2190,6 +2953,7 @@ paths: parameters: - $ref: '#/components/parameters/Limit' - $ref: '#/components/parameters/Cursor' + - $ref: '#/components/parameters/Include' - name: role in: query schema: @@ -2703,6 +3467,84 @@ paths: $ref: '#/components/responses/Forbidden' '409': $ref: '#/components/responses/Conflict' + /billing/prices: + get: + operationId: billing.listPrices + tags: + - Billing + summary: Standard's prices, monthly and yearly (User token) + description: Any signed-in User. Each price is in cents per user per interval, the amount Checkout charges. 503 billing_unavailable + when billing isn't configured or the prices can't be read. + x-substratal-phase: phase2 + parameters: [] + responses: + '200': + description: Standard's prices + content: + application/json: + schema: + type: object + required: + - data + properties: + data: + type: array + items: + $ref: '#/components/schemas/PlanPrice' + '400': + $ref: '#/components/responses/BadRequest' + '503': + $ref: '#/components/responses/ServiceUnavailable' + /subscriptions: + get: + operationId: billing.listSubscriptions + tags: + - Billing + summary: List every subscriber's subscription (billing.manage) + description: Requires billing.manage. Every User's and Organization's subscription in the caller's mode, most recently + updated first, with the subscriber's email or name for display. Revenue and invoices stay with the payment processor. + x-substratal-phase: phase2 + parameters: + - $ref: '#/components/parameters/Limit' + - $ref: '#/components/parameters/Cursor' + - $ref: '#/components/parameters/Include' + - name: status + in: query + description: Subscriptions in any of these statuses. Repeatable. + style: form + explode: true + schema: + type: array + items: + $ref: '#/components/schemas/SubscriptionStatus' + maxItems: 8 + - name: subscriber_type + in: query + schema: + type: string + - name: cancel_at_period_end + in: query + schema: + type: boolean + - name: current_period_end_before + in: query + description: Subscriptions whose current period ends before this time. + schema: + type: string + format: date-time + responses: + '400': + $ref: '#/components/responses/BadRequest' + '200': + description: A page of subscriptions + content: + application/json: + schema: + $ref: '#/components/schemas/SubscriptionPage' + '403': + $ref: '#/components/responses/Forbidden' + '422': + $ref: '#/components/responses/Unprocessable' /users/{id}/subscription: parameters: - $ref: '#/components/parameters/UserIdOrMe' @@ -2731,7 +3573,7 @@ paths: operationId: billing.createUserCheckoutSession tags: - Billing - summary: Start a Stripe Checkout to subscribe yourself to Standard (User token) + summary: Start a Checkout to subscribe yourself to Standard (User token) x-substratal-phase: phase2 parameters: - $ref: '#/components/parameters/IdempotencyKey' @@ -2756,13 +3598,44 @@ paths: $ref: '#/components/responses/Unprocessable' '503': $ref: '#/components/responses/ServiceUnavailable' + /users/me/billing/checkout-sessions/{session_id}/confirm: + parameters: + - name: session_id + in: path + required: true + schema: + type: string + description: The Checkout Session id from success_url's session_id parameter. + post: + operationId: billing.confirmUserCheckoutSession + tags: + - Billing + summary: Sync your subscription from a returning Checkout, without waiting for the webhook (User token) + description: Call it when the person lands on success_url. It reads the Checkout Session and, if it's complete, applies + the subscription at once (the same sync the billing webhook runs), then returns what GET /users/me/subscription would. + An open or expired session changes nothing. Idempotent. 404 checkout_session_not_found if the session isn't this User's. + x-substratal-phase: phase2 + parameters: [] + responses: + '200': + description: The User's plan and individual subscription, after the sync + content: + application/json: + schema: + $ref: '#/components/schemas/UserSubscription' + '400': + $ref: '#/components/responses/BadRequest' + '404': + $ref: '#/components/responses/NotFound' + '503': + $ref: '#/components/responses/ServiceUnavailable' /users/me/billing/portal-sessions: post: operationId: billing.createUserPortalSession parameters: [] tags: - Billing - summary: Open the Stripe Customer Portal for your own subscription (User token) + summary: Open the billing portal for your own subscription (User token) x-substratal-phase: phase2 requestBody: required: true @@ -2866,7 +3739,7 @@ paths: operationId: billing.createOrganizationCheckoutSession tags: - Billing - summary: Start a Stripe Checkout to subscribe the Organization to Standard (org admin, User token) + summary: Start a Checkout to subscribe the Organization to Standard (org admin, User token) x-substratal-phase: phase2 parameters: - $ref: '#/components/parameters/IdempotencyKey' @@ -2887,22 +3760,62 @@ paths: items: type: string responses: - '201': - description: Checkout URL + '201': + description: Checkout URL + content: + application/json: + schema: + $ref: '#/components/schemas/RedirectSession' + '400': + $ref: '#/components/responses/BadRequest' + '403': + $ref: '#/components/responses/Forbidden' + '404': + $ref: '#/components/responses/NotFound' + '409': + $ref: '#/components/responses/Conflict' + '422': + $ref: '#/components/responses/Unprocessable' + '503': + $ref: '#/components/responses/ServiceUnavailable' + /organizations/{id}/billing/checkout-sessions/{session_id}/confirm: + parameters: + - name: id + in: path + required: true + schema: + type: string + - name: session_id + in: path + required: true + schema: + type: string + description: The Checkout Session id from success_url's session_id parameter. + post: + operationId: billing.confirmOrganizationCheckoutSession + tags: + - Billing + summary: Sync the Organization's subscription from a returning Checkout (org admin, User token) + description: 'The Organization form of billing.confirmUserCheckoutSession: returns what GET /organizations/{id}/subscription + would, after the sync.' + x-substratal-phase: phase2 + parameters: [] + responses: + '200': + description: The Organization's plan and subscription, after the sync + headers: + ETag: + $ref: '#/components/headers/ETag' content: application/json: schema: - $ref: '#/components/schemas/RedirectSession' + $ref: '#/components/schemas/OrganizationSubscription' '400': $ref: '#/components/responses/BadRequest' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' - '409': - $ref: '#/components/responses/Conflict' - '422': - $ref: '#/components/responses/Unprocessable' '503': $ref: '#/components/responses/ServiceUnavailable' /organizations/{id}/billing/portal-sessions: @@ -2917,7 +3830,7 @@ paths: parameters: [] tags: - Billing - summary: Open the Stripe Customer Portal for the Organization's subscription (org admin or billing.manage, User token) + summary: Open the billing portal for the Organization's subscription (org admin or billing.manage, User token) x-substratal-phase: phase2 requestBody: required: true @@ -2952,6 +3865,7 @@ paths: parameters: - $ref: '#/components/parameters/Limit' - $ref: '#/components/parameters/Cursor' + - $ref: '#/components/parameters/Include' - name: target_user_id in: query schema: @@ -2992,6 +3906,12 @@ paths: in: query schema: type: string + - name: request_id + in: query + description: 'Events written by one request: the X-Request-Id it sent or was given. Exact match.' + schema: + type: string + maxLength: 128 - name: since in: query schema: @@ -3019,6 +3939,8 @@ paths: $ref: '#/components/schemas/AuditEventPage' '403': $ref: '#/components/responses/Forbidden' + '422': + $ref: '#/components/responses/Unprocessable' /audit-events/{id}: parameters: - name: id @@ -3105,6 +4027,100 @@ paths: $ref: '#/components/schemas/AuditExport' '404': $ref: '#/components/responses/NotFound' + /usage: + get: + operationId: usage.get + tags: + - Usage & stats + summary: Request counts, errors, and latency per day, week, or month + description: 'From a daily rollup of the request log, refreshed hourly: the current UTC day covers up to the last complete + hour. Buckets are UTC; week is ISO (Monday start); period is the bucket''s first day, so the buckets at either end + of the range may be partial. Rows are in the caller''s mode. Platform operations.view sees every row. An app-confined + API Key sees only its own Application''s rows, and an Application''s owner sees only that Application''s rows by passing + application_id; both are forced. Anyone else gets 403.' + x-substratal-phase: phase3 + parameters: + - name: since + in: query + description: 'First day included (UTC). Default: 30 days before until.' + schema: + type: string + format: date + - name: until + in: query + description: 'First day not included (UTC). Default: tomorrow, so today is included. At most 13 months after since.' + schema: + type: string + format: date + - name: granularity + in: query + schema: + type: string + default: day + - name: group_by + in: query + description: Split rows by these dimensions. Repeat for several. Without it, one row per period. + style: form + explode: true + schema: + type: array + items: + type: string + - name: application_id + in: query + schema: + type: string + - name: api_key_id + in: query + schema: + type: string + - name: operation + in: query + description: An operationId, such as users.list. + schema: + type: string + responses: + '400': + $ref: '#/components/responses/BadRequest' + '200': + description: The usage report + content: + application/json: + schema: + $ref: '#/components/schemas/UsageReport' + '403': + $ref: '#/components/responses/Forbidden' + '422': + $ref: '#/components/responses/Unprocessable' + /stats: + get: + operationId: stats.get + tags: + - Usage & stats + summary: Current counts for the console's home screen, in one call + description: Live counts, grouped by status, computed at most once a minute per server instance (generated_at says when). + Every known status is present, with 0 when nothing has it. Counts are in the caller's mode. Platform-wide with operations.view + or users.list. With tenant_id, the counts are that Tenant's only, and its owner may call it too; users, subscriptions, + and organizations are then null, since they don't belong to a Tenant. + x-substratal-phase: phase3 + parameters: + - name: tenant_id + in: query + schema: + type: string + responses: + '400': + $ref: '#/components/responses/BadRequest' + '200': + description: The counts + content: + application/json: + schema: + $ref: '#/components/schemas/Stats' + '403': + $ref: '#/components/responses/Forbidden' + '404': + $ref: '#/components/responses/NotFound' /webhooks: get: operationId: webhooks.list @@ -3115,10 +4131,27 @@ paths: parameters: - $ref: '#/components/parameters/Limit' - $ref: '#/components/parameters/Cursor' + - $ref: '#/components/parameters/Include' - name: application_id in: query schema: type: string + - name: status + in: query + description: Subscriptions in any of these statuses. Repeatable. + style: form + explode: true + schema: + type: array + items: + type: string + maxItems: 3 + - name: scope + in: query + description: '"platform" returns only platform-scoped subscriptions. Callers without webhooks.manage see none, so + they get an empty page. Can''t be combined with application_id (400 invalid_request).' + schema: + type: string responses: '400': $ref: '#/components/responses/BadRequest' @@ -3310,9 +4343,16 @@ paths: application/json: schema: type: object + required: + - delivery_id + - event_id properties: delivery_id: type: string + description: The new delivery's id (`dlv_…`). + event_id: + type: string + description: The webhook.test event's id (`wev_…`), the envelope's `id`. /webhooks/{id}/deliveries: parameters: - name: id @@ -3329,6 +4369,7 @@ paths: parameters: - $ref: '#/components/parameters/Limit' - $ref: '#/components/parameters/Cursor' + - $ref: '#/components/parameters/Include' - name: event_id in: query schema: @@ -3358,6 +4399,90 @@ paths: type: array items: $ref: '#/components/schemas/WebhookDelivery' + /webhook-deliveries: + get: + operationId: webhooks.listAllDeliveries + tags: + - Webhooks + summary: Delivery attempts across every subscription visible to the caller (30-day log) + description: 'Scoped like GET /webhooks: webhooks.manage sees every subscription''s deliveries, an Application''s owner + and its app keys see only that Application''s. A caller with no visible subscriptions gets an empty page. Newest first.' + x-substratal-phase: phase2 + parameters: + - $ref: '#/components/parameters/Limit' + - $ref: '#/components/parameters/Cursor' + - $ref: '#/components/parameters/Include' + - name: status + in: query + schema: + type: string + - name: since + in: query + description: Deliveries created at or after this time. + schema: + type: string + format: date-time + - name: until + in: query + description: Deliveries created before this time. + schema: + type: string + format: date-time + - name: application_id + in: query + schema: + type: string + - name: subscription_id + in: query + schema: + type: string + - name: event_type + in: query + schema: + $ref: '#/components/schemas/WebhookEvent' + responses: + '400': + $ref: '#/components/responses/BadRequest' + '200': + description: A page of deliveries + content: + application/json: + schema: + $ref: '#/components/schemas/WebhookDeliveryPage' + '422': + $ref: '#/components/responses/Unprocessable' + /webhooks/{id}/deliveries/{deliveryId}: + parameters: + - name: id + in: path + required: true + schema: + type: string + - name: deliveryId + in: path + required: true + schema: + type: string + get: + operationId: webhooks.getDelivery + parameters: [] + tags: + - Webhooks + summary: Fetch one delivery attempt (30-day log) + description: Visible to whoever can read GET /webhooks/{id}/deliveries. 404 delivery_not_found when the delivery isn't + on that subscription or is older than the 30-day log. + x-substratal-phase: phase2 + responses: + '400': + $ref: '#/components/responses/BadRequest' + '200': + description: The delivery + content: + application/json: + schema: + $ref: '#/components/schemas/WebhookDelivery' + '404': + $ref: '#/components/responses/NotFound' /webhooks/{id}/deliveries/{deliveryId}/redeliver: parameters: - name: id @@ -3384,6 +4509,43 @@ paths: description: Enqueued '404': $ref: '#/components/responses/NotFound' + /push-credentials: + get: + operationId: pushCredentials.listAll + tags: + - Notifications + summary: List push credentials across Applications (applications.manage, an owner's own, or an app key's own) + description: applications.manage sees every Application's credentials. A User without it sees only the credentials of + Applications they own (owner_user_id, or an active org_admin of the owning Organization); owning none is an empty + list. An app-scoped key sees only its own Application's credentials, with no extra permission, the same rows as GET + /applications/{id}/push-credentials. A platform key without applications.manage gets 403. Never returns key material. + Newest first. + x-substratal-phase: phase2 + parameters: + - $ref: '#/components/parameters/Limit' + - $ref: '#/components/parameters/Cursor' + - $ref: '#/components/parameters/Include' + - name: status + in: query + schema: + type: string + - name: provider + in: query + schema: + $ref: '#/components/schemas/PushProvider' + responses: + '400': + $ref: '#/components/responses/BadRequest' + '200': + description: A page of push credentials + content: + application/json: + schema: + $ref: '#/components/schemas/PushCredentialPage' + '403': + $ref: '#/components/responses/Forbidden' + '422': + $ref: '#/components/responses/Unprocessable' /applications/{id}/push-credentials: parameters: - name: id @@ -3503,30 +4665,127 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/PushCredential' + $ref: '#/components/schemas/PushCredential' + '400': + $ref: '#/components/responses/BadRequest' + '404': + $ref: '#/components/responses/NotFound' + '409': + $ref: '#/components/responses/Conflict' + '422': + $ref: '#/components/responses/Unprocessable' + delete: + operationId: pushCredentials.delete + parameters: [] + tags: + - Notifications + summary: Remove a push provider (User token only) + description: Pending deliveries to that provider are skipped. Removing web_push deactivates every web_push device of + the Application (inactive_reason credential_removed), because browser subscriptions are bound to the VAPID key. + x-substratal-phase: phase2 + x-substratal-destructive: always + responses: + '204': + description: Removed + '400': + $ref: '#/components/responses/BadRequest' + '404': + $ref: '#/components/responses/NotFound' + /applications/{id}/bff-keys: + parameters: + - name: id + in: path + required: true + schema: + type: string + get: + operationId: bffKeys.list + tags: + - Applications + summary: List a first-party Application's BFF signing keys (applications.manage, the owner, or the app's own key) + description: The Ed25519 public keys the Application's backend (its BFF) signs forwarded client IPs and user agents + with (NFR → Authentication → First-party BFF forwarding). Only public keys are stored, so nothing here is secret. + Revoked keys are listed too, newest first. At most 2 active keys at a time, so the list isn't paginated. + x-substratal-phase: phase2 + parameters: [] + responses: + '400': + $ref: '#/components/responses/BadRequest' + '200': + description: Every key, active and revoked + content: + application/json: + schema: + $ref: '#/components/schemas/BFFKeyList' + '404': + $ref: '#/components/responses/NotFound' + post: + operationId: bffKeys.create + tags: + - Applications + summary: Register a BFF signing key for a first-party Application (applications.manage, User token only) + description: Registers the public half of an Ed25519 key pair the Application's backend generated; the private key never + leaves that backend. public_key is the raw 32-byte key in base64url or base64, or a PEM "PUBLIC KEY" (SPKI) block. + Only a first_party Application can have keys (409 application_not_first_party), and not a retired one (409 application_retired). + At most 2 active keys, to rotate without downtime (409 bff_key_limit_reached); the same public key twice is 409 bff_key_exists. + Writes application.bff_key_added. + x-substratal-phase: phase2 + x-substratal-step-up: always + parameters: + - $ref: '#/components/parameters/IdempotencyKeyOptional' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/BFFKeyCreate' + responses: + '201': + description: Key registered + content: + application/json: + schema: + $ref: '#/components/schemas/BFFKey' '400': $ref: '#/components/responses/BadRequest' + '403': + $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' '409': $ref: '#/components/responses/Conflict' '422': $ref: '#/components/responses/Unprocessable' + /applications/{id}/bff-keys/{keyId}: + parameters: + - name: id + in: path + required: true + schema: + type: string + - name: keyId + in: path + required: true + schema: + type: string delete: - operationId: pushCredentials.delete - parameters: [] + operationId: bffKeys.revoke tags: - - Notifications - summary: Remove a push provider (User token only) - description: Pending deliveries to that provider are skipped. Removing web_push deactivates every web_push device of - the Application (inactive_reason credential_removed), because browser subscriptions are bound to the VAPID key. + - Applications + summary: Revoke a BFF signing key (applications.manage, User token only) + description: Forwards signed with the key stop being trusted within a minute on every server. The key stays listed with + revoked_at set. Revoking a revoked key is a no-op 204. Writes application.bff_key_revoked. x-substratal-phase: phase2 x-substratal-destructive: always + x-substratal-step-up: always + parameters: [] responses: '204': - description: Removed + description: Revoked '400': $ref: '#/components/responses/BadRequest' + '403': + $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' /users/{id}/devices: @@ -3980,6 +5239,7 @@ paths: parameters: - $ref: '#/components/parameters/Limit' - $ref: '#/components/parameters/Cursor' + - $ref: '#/components/parameters/Include' - name: scope in: query schema: @@ -3992,6 +5252,11 @@ paths: in: query schema: type: string + - name: q + in: query + description: Case-insensitive prefix match on name + schema: + type: string - name: include_inactive in: query description: Include revoked and expired keys @@ -4014,6 +5279,8 @@ paths: - API Keys summary: Create a key (api_keys.manage, or the Application's owner for an app-scoped key) x-substratal-phase: mvp + x-substratal-step-up: conditional + x-substratal-step-up-when: scope is platform requestBody: required: true content: @@ -4060,10 +5327,12 @@ paths: $ref: '#/components/responses/NotFound' patch: operationId: apiKeys.update + x-substratal-step-up: conditional + x-substratal-step-up-when: rate_limit_per_minute is sent parameters: [] tags: - API Keys - summary: Change name, permissions, or restrict_destructive + summary: Change name, permissions, restrict_destructive, or rate_limit_per_minute (api_keys.manage only) x-substratal-phase: mvp x-substratal-destructive: conditional x-substratal-destructive-when: restrict_destructive set to false @@ -4083,6 +5352,11 @@ paths: type: string restrict_destructive: type: boolean + rate_limit_per_minute: + type: integer + minimum: 1 + maximum: 10000 + description: Platform api_keys.manage only (403 forbidden otherwise). Null restores the platform default. responses: '400': $ref: '#/components/responses/BadRequest' @@ -4137,6 +5411,86 @@ paths: $ref: '#/components/schemas/ApiKeyWithSecret' '404': $ref: '#/components/responses/NotFound' + /platform/settings: + get: + operationId: platform.getSettings + tags: + - Platform + summary: Read the platform's runtime switches and client feature flags + description: 'Authentication is optional. Without a Bearer token: signup_open and announcement, for live mode, or for + test mode with test_mode=true. With one: the caller''s own mode, plus client_flags. With operations.view, also read_only + and updated_at, read fresh; everyone else may get a copy up to 30 seconds old. ETag is the row''s version.' + security: + - {} + - bearerAuth: [] + x-substratal-phase: phase3 + parameters: + - name: test_mode + in: query + required: false + description: 'Unauthenticated callers only: read test mode''s settings. An authenticated caller always reads its own + mode.' + schema: + type: boolean + default: false + responses: + '400': + $ref: '#/components/responses/BadRequest' + '200': + description: The settings visible to this caller + headers: + ETag: + $ref: '#/components/headers/ETag' + content: + application/json: + schema: + $ref: '#/components/schemas/PlatformSettings' + '401': + $ref: '#/components/responses/Unauthorized' + '429': + $ref: '#/components/responses/TooManyRequests' + patch: + operationId: platform.updateSettings + tags: + - Platform + summary: Change the platform's runtime switches and client feature flags (operations.manage) + description: Changes the settings of the caller's mode. If-Match is required (400 if_match_required without it). client_flags + is merged one level deep, and a flag sent as null is removed. announcement is replaced, and null clears it. Writes + platform.settings_updated with before and after. Other API instances pick the change up within 30 seconds. It stays + callable while read_only is on, so the freeze can always be lifted. + x-substratal-phase: phase3 + x-substratal-step-up: always + parameters: + - name: If-Match + in: header + required: true + description: The ETag from a prior read. Missing is 400 if_match_required; a mismatch is 409 version_conflict. + schema: + type: string + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/PlatformSettingsWrite' + responses: + '400': + $ref: '#/components/responses/BadRequest' + '200': + description: The updated settings, as an operations.view caller sees them + headers: + ETag: + $ref: '#/components/headers/ETag' + content: + application/json: + schema: + $ref: '#/components/schemas/PlatformSettings' + '403': + $ref: '#/components/responses/Forbidden' + '409': + $ref: '#/components/responses/Conflict' + '422': + $ref: '#/components/responses/Unprocessable' components: securitySchemes: bearerAuth: @@ -4172,6 +5526,13 @@ components: in: query schema: type: string + Include: + name: include + in: query + description: '`total` adds `page.total` and `page.total_capped`: the number of rows matching the current filters across + every page, counted up to 10,000 (Conventions → Pagination). Omitted unless requested.' + schema: + type: string IdempotencyKey: name: Idempotency-Key in: header @@ -4226,7 +5587,7 @@ components: $ref: '#/components/schemas/Error' Forbidden: description: Authenticated but not permitted (forbidden, destructive_operation_restricted, entitlement_required, role_escalation_forbidden, - …) + mfa_enrollment_required, reauthentication_required, …) content: application/json: schema: @@ -4304,6 +5665,71 @@ components: code: type: string additionalProperties: true + BulkItemError: + type: object + description: The error object the single call would have returned, without the outer error envelope. + required: + - code + - message + properties: + code: + type: string + example: user_protected + message: + type: string + details: + type: object + additionalProperties: true + BulkResults: + type: object + description: One result per requested item, in request order (Conventions → Bulk operations). + required: + - results + properties: + results: + type: array + items: + type: object + required: + - id + - status + properties: + id: + type: string + description: The item's id + as sent: null + status: + type: integer + description: 'The status the single call would have returned: 200 on success, otherwise the error''s 4xx or + 500' + error: + $ref: '#/components/schemas/BulkItemError' + BulkInviteResults: + type: object + description: One result per requested email, in request order (Conventions → Bulk operations). + required: + - results + properties: + results: + type: array + items: + type: object + required: + - email + - status + properties: + email: + type: string + description: The email + as sent: null + status: + type: integer + description: 'The status POST /users would have returned: 201 on success, otherwise the error''s 4xx or 500' + user_id: + type: string + description: The new User's id. Present only on 201. + error: + $ref: '#/components/schemas/BulkItemError' OAuthError: type: object required: @@ -4322,6 +5748,15 @@ components: type: string has_more: type: boolean + total: + type: integer + minimum: 0 + maximum: 10000 + description: Only with `include=total`. Rows matching the current filters across every page, ignoring `cursor`; + 10000 when capped. + total_capped: + type: boolean + description: Only with `include=total`. True when there are more than 10,000 matching rows. PageEnvelope: type: object required: @@ -4370,6 +5805,237 @@ components: type: string email_verified: type: boolean + Reauthentication: + type: object + required: + - token_type + - access_token + - expires_in + - mfa_verified_at + properties: + token_type: + type: string + access_token: + type: string + description: A new platform access token for the same session, carrying the updated mfa_verified_at claim. + expires_in: + type: integer + example: 900 + mfa_verified_at: + type: string + format: date-time + description: 'When this session last proved a second factor: now.' + PasskeyCreationOptions: + type: object + required: + - publicKey + - expires_in + properties: + publicKey: + type: object + description: PublicKeyCredentialCreationOptions in their JSON form (binary values base64url), ready for PublicKeyCredential.parseCreationOptionsFromJSON(). + required: + - rp + - user + - challenge + properties: + rp: + type: object + properties: + id: + type: string + example: substratalapps.com + name: + type: string + example: Substratal + user: + type: object + properties: + id: + type: string + name: + type: string + displayName: + type: string + challenge: + type: string + pubKeyCredParams: + type: array + items: + type: object + timeout: + type: integer + excludeCredentials: + type: array + items: + type: object + authenticatorSelection: + type: object + attestation: + type: string + expires_in: + type: integer + example: 300 + description: Seconds the challenge stays valid. + PasskeyRequestOptions: + type: object + required: + - publicKey + - expires_in + properties: + publicKey: + type: object + description: PublicKeyCredentialRequestOptions in their JSON form, ready for PublicKeyCredential.parseRequestOptionsFromJSON(). + required: + - challenge + properties: + challenge: + type: string + timeout: + type: integer + rpId: + type: string + example: substratalapps.com + allowCredentials: + type: array + items: + type: object + userVerification: + type: string + expires_in: + type: integer + example: 300 + PasskeyAttestation: + type: object + description: The PublicKeyCredential from navigator.credentials.create(), as JSON (toJSON()). + required: + - id + - rawId + - type + - response + properties: + id: + type: string + rawId: + type: string + type: + type: string + response: + type: object + required: + - clientDataJSON + - attestationObject + properties: + clientDataJSON: + type: string + attestationObject: + type: string + transports: + type: array + items: + type: string + authenticatorAttachment: + type: string + clientExtensionResults: + type: object + PasskeyAssertion: + type: object + description: The PublicKeyCredential from navigator.credentials.get(), as JSON (toJSON()). + required: + - id + - rawId + - type + - response + properties: + id: + type: string + rawId: + type: string + type: + type: string + response: + type: object + required: + - clientDataJSON + - authenticatorData + - signature + properties: + clientDataJSON: + type: string + authenticatorData: + type: string + signature: + type: string + userHandle: + type: string + authenticatorAttachment: + type: string + clientExtensionResults: + type: object + Passkey: + type: object + description: A registered passkey. Never includes the credential id or public key. + required: + - id + - name + - transports + - backup_eligible + - backup_state + - created_at + properties: + id: + type: string + example: wac_01JAG8M2N3P4Q5R6S7T8U9V0W1 + name: + type: string + maxLength: 64 + aaguid: + type: string + description: The authenticator model (a UUID), when it reported one. + transports: + type: array + items: + type: string + backup_eligible: + type: boolean + description: A synced passkey (it can be backed up). + backup_state: + type: boolean + description: Currently backed up. + created_at: + type: string + format: date-time + last_used_at: + type: string + format: date-time + PasskeyList: + type: object + required: + - data + properties: + data: + type: array + maxItems: 10 + items: + $ref: '#/components/schemas/Passkey' + PasskeyRegistration: + type: object + required: + - passkey + - mfa_enabled + properties: + passkey: + $ref: '#/components/schemas/Passkey' + mfa_enabled: + type: boolean + const: true + recovery_codes: + type: array + items: + type: string + minItems: 10 + maxItems: 10 + description: Only when this passkey is the User's first MFA method. Shown once. MfaChallenge: type: object required: @@ -4387,6 +6053,8 @@ components: type: array items: type: string + description: 'The second factors this User can complete the challenge with: totp when TOTP is on, passkey when they + have a passkey, and always recovery_code.' expires_in: type: integer example: 300 @@ -4433,6 +6101,12 @@ components: type: array items: type: string + plan: + type: string + description: The User's platform plan when the token was issued, by the same rule as `User.plan` (an Organization's + Standard subscription counts for the members its `member_scope` includes). Always present. Currently `free` or + `standard`; more values may be added later, so treat a missing or unknown value as `free`. The way a free-tier + Application gates paid features. test_mode: type: boolean iat: @@ -4505,6 +6179,12 @@ components: $ref: '#/components/schemas/UserStatus' mfa_enabled: type: boolean + description: TOTP confirmed, or at least one passkey (Auth → MFA). + mfa_enrollment_required: + type: boolean + description: Staff (holding a platform Role that grants a permission) without MFA, neither TOTP nor a passkey. Once + staff MFA is enforced, their sessions can only enroll, read themselves, change password, and log out (Auth → Staff + MFA). signup_application_id: type: string test_mode: @@ -4577,6 +6257,11 @@ components: last_used_at: type: string format: date-time + passkeys: + type: array + description: Passkey metadata. Never includes the credential id or public key. + items: + $ref: '#/components/schemas/Passkey' sessions: type: array items: @@ -4660,6 +6345,48 @@ components: updated_at: type: string format: date-time + ImageUploadRequest: + type: object + required: + - content_type + - content_length + properties: + content_type: + type: string + content_length: + type: integer + minimum: 1 + description: The file's size in bytes. At most 2097152 for an avatar, 1048576 for an icon. + ImageUpload: + type: object + required: + - id + - url + - fields + - content_type + - max_bytes + - expires_at + description: A presigned POST. Send multipart/form-data to url with every entry of fields, then the file as the last + field, named file. The upload is accepted only with that content_type and at most max_bytes, until expires_at. + properties: + id: + type: string + description: The upload id (upl_…) to complete. + url: + type: string + description: Where to POST the form. + fields: + type: object + additionalProperties: + type: string + description: Form fields to send unchanged, including key, Content-Type, policy, and signature. + content_type: + type: string + max_bytes: + type: integer + expires_at: + type: string + format: date-time AppProfile: type: object properties: @@ -4742,10 +6469,22 @@ components: maxLength: 255 ApplicationAccessTier: type: string - description: 'Which plan unlocks the Application: free for every User, standard for Users covered by a Standard subscription. - Set by applications.manage; defaults to standard.' + description: 'Who gets in without a grant. free: every User. standard: Users covered by a Standard subscription; first_party + (Substratal''s own) Applications only. restricted: only the people the developer grants Entitlements to, from their + own billing or none. A first-party Application defaults to standard and only applications.manage changes its tier. + Any other Application defaults to restricted, and its owner chooses free or restricted while it''s approved or pending_review + (409 application_not_available otherwise, at most 10 changes a day). standard on one that isn''t first-party is 422 + access_tier_reserved.' ApplicationSummary: type: object + required: + - id + - slug + - name + - visibility + - access_tier + - review_status + - holder_count properties: id: type: string @@ -4763,6 +6502,19 @@ components: $ref: '#/components/schemas/ApplicationAccessTier' review_status: $ref: '#/components/schemas/ApplicationReviewStatus' + review_requested_at: + type: string + format: date-time + readOnly: true + description: When the Application last entered pending_review. See Application. + owner_user_id: + type: string + owner_organization_id: + type: string + holder_count: + type: integer + minimum: 0 + description: Active Entitlements for the Application; a User grant and an Organization grant count once each ApplicationSummaryPage: allOf: - $ref: '#/components/schemas/PageEnvelope' @@ -4824,6 +6576,11 @@ components: $ref: '#/components/schemas/ApplicationVisibility' access_tier: $ref: '#/components/schemas/ApplicationAccessTier' + first_party: + type: boolean + default: false + description: Substratal's own Application. Only applications.manage sets it, and only a first-party Application + can be access_tier standard. Staff-created customer Applications (concierge onboarding) aren't first-party. owner_user_id: type: string owner_organization_id: @@ -4862,6 +6619,11 @@ components: description: true when a developer submitted it themselves, not staff. A self-registered Application must use the hosted sign-in flow (POST /auth/app-tokens returns 403 embedded_login_not_allowed), and only applications.manage can turn on receives_platform_notifications for it. + review_requested_at: + type: string + format: date-time + readOnly: true + description: When the Application last entered pending_review. See Application. test_mode: type: boolean created_at: @@ -5029,6 +6791,10 @@ components: $ref: '#/components/schemas/Actor' implicit: type: boolean + mfa_enrollment_required: + type: boolean + description: 'On POST /users/{id}/roles/{roleId} only: the User is now staff but has no MFA (neither TOTP nor a + passkey), so their platform Roles take effect once they enroll (Auth → Staff MFA).' UserRoleAssignmentPage: allOf: - $ref: '#/components/schemas/PageEnvelope' @@ -5047,6 +6813,7 @@ components: - user_status - entitlement_status - effective_permissions + - plan properties: user_id: type: string @@ -5081,6 +6848,10 @@ components: type: array items: type: string + plan: + type: string + description: The User's platform plan at `computed_at`, the same value an app token issued at that moment carries + in its `plan` claim. Currently `free` or `standard`; more values may be added later. computed_at: type: string format: date-time @@ -5161,7 +6932,8 @@ components: type: string SubscriptionStatus: type: string - description: Mirrors Stripe. active, trialing, and past_due cover their users with Standard; the rest don't. + description: Mirrors the payment processor. active, trialing, and past_due cover their users with Standard; the rest + don't. Tenant: type: object properties: @@ -5299,9 +7071,11 @@ components: last_synced_at: type: string format: date-time + interval: + $ref: '#/components/schemas/BillingInterval' unit_amount: type: integer - description: Cents per user per month (600). + description: The subscribed price, in cents per user per interval. currency: type: string const: usd @@ -5313,6 +7087,27 @@ components: updated_at: type: string format: date-time + SubscriptionListItem: + allOf: + - $ref: '#/components/schemas/Subscription' + - type: object + properties: + user_email: + type: string + format: email + description: 'Individual subscriptions: the User''s email, for display.' + organization_name: + type: string + description: 'Organization subscriptions: the Organization''s name, for display.' + SubscriptionPage: + allOf: + - $ref: '#/components/schemas/PageEnvelope' + - type: object + properties: + data: + type: array + items: + $ref: '#/components/schemas/SubscriptionListItem' UserSubscription: type: object properties: @@ -5337,6 +7132,26 @@ components: $ref: '#/components/schemas/Plan' subscription: $ref: '#/components/schemas/Subscription' + BillingInterval: + type: string + PlanPrice: + type: object + required: + - plan + - interval + - unit_amount + - currency + properties: + plan: + type: string + interval: + $ref: '#/components/schemas/BillingInterval' + unit_amount: + type: integer + description: Cents per user per interval. + currency: + type: string + const: usd CheckoutSessionCreate: type: object required: @@ -5347,6 +7162,9 @@ components: plan: type: string description: Only standard is self-service; business and enterprise return 422 plan_requires_sales. + interval: + $ref: '#/components/schemas/BillingInterval' + description: How often Standard is billed. Default month. success_url: type: string format: uri @@ -5377,6 +7195,64 @@ components: type: string AuditTargetType: type: string + PlatformAnnouncement: + type: object + required: + - text + - level + additionalProperties: false + properties: + text: + type: string + minLength: 1 + maxLength: 500 + level: + type: string + PlatformSettings: + type: object + description: signup_open and announcement are always present. client_flags needs an authenticated caller; read_only + and updated_at need operations.view. + required: + - signup_open + properties: + signup_open: + type: boolean + description: false closes POST /auth/signup (403 signup_closed). Invitations still work. + announcement: + description: A banner for clients to show, or null. + allOf: + - $ref: '#/components/schemas/PlatformAnnouncement' + client_flags: + type: object + description: Remote-configurable client feature flags, flag name to boolean. At most 100. + additionalProperties: + type: boolean + read_only: + type: boolean + description: 'true answers every non-GET from a caller without superadmin with 503 service_unavailable and Retry-After: + 300. Sign-in, refresh, logout, session revocation, and token issuance stay open.' + updated_at: + type: string + format: date-time + PlatformSettingsWrite: + type: object + properties: + signup_open: + type: boolean + read_only: + type: boolean + client_flags: + type: object + description: 'Merged one level deep: each flag sent replaces that flag, and a flag sent as null is removed. Names + match ^[a-z][a-z0-9_]{0,63}$; at most 100 after the merge.' + additionalProperties: + type: + - boolean + - 'null' + announcement: + description: Replaces the announcement; null clears it. + allOf: + - $ref: '#/components/schemas/PlatformAnnouncement' AuditExportRequest: type: object description: The same filters as GET /audit-events, as body fields, plus format. @@ -5406,6 +7282,9 @@ components: type: string tenant_id: type: string + request_id: + type: string + maxLength: 128 since: type: string format: date-time @@ -5449,6 +7328,210 @@ components: description: 'When the file and this record are deleted: 7 days after the request.' test_mode: type: boolean + UsageReport: + type: object + required: + - since + - until + - granularity + - group_by + - data + properties: + since: + type: string + format: date + until: + type: string + format: date + granularity: + type: string + group_by: + type: array + items: + type: string + data: + type: array + description: Oldest period first, then by the grouped dimensions. Periods and groups with no requests are omitted. + items: + $ref: '#/components/schemas/UsageRow' + UsageRow: + type: object + required: + - period + - requests + - errors_4xx + - errors_5xx + - latency_ms_avg + - latency_ms_max + properties: + period: + type: string + format: date + description: The bucket's first day (UTC). + application_id: + type: string + description: Only with group_by=application. null for requests that didn't resolve to exactly one Application. + api_key_id: + type: string + description: Only with group_by=api_key. null for requests made without an API Key. + operation: + type: string + description: Only with group_by=operation. The operationId. + requests: + type: integer + errors_4xx: + type: integer + errors_5xx: + type: integer + latency_ms_avg: + type: integer + description: Mean latency, rounded to the millisecond. + latency_ms_max: + type: integer + Stats: + type: object + required: + - generated_at + - applications + - entitlements + - webhook_subscriptions + - push_credentials + - tier_change_requests + properties: + tenant_id: + type: string + description: The Tenant the counts are confined to, or null for platform-wide. + generated_at: + type: string + format: date-time + description: When these counts were computed. At most a minute old. + users: + description: Users by status. null when tenant_id is set. + type: object + required: + - active + - invited + - suspended + - deleted + properties: + active: + type: integer + invited: + type: integer + suspended: + type: integer + deleted: + type: integer + applications: + type: object + required: + - by_review_status + - by_access_tier + properties: + by_review_status: + type: object + required: + - approved + - pending_review + - rejected + - suspended + - retired + properties: + approved: + type: integer + pending_review: + type: integer + rejected: + type: integer + suspended: + type: integer + retired: + type: integer + by_access_tier: + type: object + required: + - free + - standard + properties: + free: + type: integer + standard: + type: integer + entitlements: + type: object + description: Entitlements by status. + required: + - active + - disabled + - expired + - revoked + properties: + active: + type: integer + disabled: + type: integer + expired: + type: integer + revoked: + type: integer + subscriptions: + description: Covering subscriptions (active, trialing, or past_due) by subscriber type. null when tenant_id is set. + type: object + required: + - user + - organization + properties: + user: + type: integer + organization: + type: integer + organizations: + description: Organizations by status. null when tenant_id is set. + type: object + required: + - active + - suspended + properties: + active: + type: integer + suspended: + type: integer + webhook_subscriptions: + type: object + description: Webhook subscriptions by status. + required: + - healthy + - unhealthy + - disabled + properties: + healthy: + type: integer + unhealthy: + type: integer + disabled: + type: integer + push_credentials: + type: object + description: Applications' push credentials by status. + required: + - active + - failed + - disabled + properties: + active: + type: integer + failed: + type: integer + disabled: + type: integer + tier_change_requests: + type: object + required: + - open + properties: + open: + type: integer + description: Requests that are pending, scheduled, or in_progress. ScimToken: type: object properties: @@ -5625,6 +7708,25 @@ components: created_at: type: string format: date-time + WebhookDeliveryListItem: + allOf: + - $ref: '#/components/schemas/WebhookDelivery' + - type: object + properties: + subscription_id: + type: string + scope: + type: string + description: 'The subscription''s scope: an application_id, or ''platform''.' + WebhookDeliveryPage: + allOf: + - $ref: '#/components/schemas/PageEnvelope' + - type: object + properties: + data: + type: array + items: + $ref: '#/components/schemas/WebhookDeliveryListItem' PushProvider: type: string PushCredentialCreate: @@ -5705,6 +7807,7 @@ components: $ref: '#/components/schemas/PushProvider' status: type: string + description: 'disabled: the Application was retired.' team_id: type: string description: apns @@ -5740,6 +7843,59 @@ components: updated_at: type: string format: date-time + BFFKey: + type: object + required: + - id + - application_id + - name + - public_key + - created_at + properties: + id: + type: string + description: bfk_…, sent as X-Substratal-BFF-Key + application_id: + type: string + name: + type: string + public_key: + type: string + description: The Ed25519 public key, 32 bytes, base64url without padding + created_at: + type: string + format: date-time + last_used_at: + type: string + format: date-time + description: Updated at most every 5 minutes + revoked_at: + type: string + format: date-time + BFFKeyCreate: + type: object + required: + - name + - public_key + additionalProperties: false + properties: + name: + type: string + minLength: 1 + maxLength: 64 + public_key: + type: string + maxLength: 1024 + description: Raw 32-byte Ed25519 key (base64url or base64), or a PEM PUBLIC KEY block + BFFKeyList: + type: object + required: + - data + properties: + data: + type: array + items: + $ref: '#/components/schemas/BFFKey' PushCredentialList: type: object required: @@ -5750,6 +7906,15 @@ components: maxItems: 3 items: $ref: '#/components/schemas/PushCredential' + PushCredentialPage: + allOf: + - $ref: '#/components/schemas/PageEnvelope' + - type: object + properties: + data: + type: array + items: + $ref: '#/components/schemas/PushCredential' DeviceStatus: type: string DeviceInactiveReason: @@ -6147,6 +8312,12 @@ components: expires_at: type: string format: date-time + rate_limit_per_minute: + type: integer + minimum: 1 + maximum: 10000 + description: Replaces the default 100 requests/minute for this key. Null (the default) means the platform default. + Operations with their own ceiling keep it. Only platform api_keys.manage may send it; anyone else gets 403 forbidden. ApiKey: allOf: - $ref: '#/components/schemas/ApiKeyWrite' diff --git a/api-contract/CONTRACT.json b/api-contract/CONTRACT.json index b55cbd7..e8b40e9 100644 --- a/api-contract/CONTRACT.json +++ b/api-contract/CONTRACT.json @@ -1,10 +1,10 @@ { "source": "https://compositecode.github.io/substratalapps.com/openapi.yaml", - "sha256": "ae796abe3696c69b907e393ea0e8c4ec54b4b0acf05f4fa7fb24ddd96a52a1da", - "info_version": "1.0.0-draft.9", + "sha256": "24bac7fcbc8d6f45e2b7e998dc913cfb37f03a93bada36e72a072b9636c5a9de", + "info_version": "1.0.0-draft.36", "substratal_versions": [ "1" ], - "operations": 124, - "synced_at": "2026-10-23T15:49:50Z" + "operations": 157, + "synced_at": "2026-12-03T08:10:50Z" } diff --git a/api-contract/openapi.yaml b/api-contract/openapi.yaml index f36006d..5c27878 100644 --- a/api-contract/openapi.yaml +++ b/api-contract/openapi.yaml @@ -1,14 +1,14 @@ openapi: 3.1.0 info: title: Substratal Apps — Platform API - version: "1.0.0-draft.9" + version: "1.0.0-draft.36" summary: >- User accounts, auth, roles, per-app entitlements (the on/off access switch), profiles, settings, organizations, tenancy, subscription billing, and push notifications for applications built on Substratal Apps. Target contract for an API that is not yet implemented; the prose specification is authoritative. description: >- - Full documentation: https://compositecode.github.io/substratalapps.com/ — read + Full documentation: https://docs.substratalapps.com/ — read /api-reference/conventions/ first (IDs, pagination, PATCH semantics, ETag/If-Match, idempotency, error shape). @@ -29,6 +29,11 @@ info: restrict_destructive=true. For `conditional`, only requests matching `x-substratal-destructive-when` are rejected; the rest of the operation stays callable. + `x-substratal-step-up` (`always` | `conditional`) marks operations + that need a recent MFA check from a User session (Auth → Step-up): + without one within the last 10 minutes they return 403 + reauthentication_required. For `conditional`, only requests matching + `x-substratal-step-up-when` need it. Application and Role ids are derived (app_, role__), not random; every other id is a prefix plus a ULID. `x-substratal-phase` gives the roadmap phase an operation ships in. @@ -36,7 +41,7 @@ info: name: Unlicensed draft — internal specification, not yet released externalDocs: description: Substratal Apps Platform API documentation - url: https://compositecode.github.io/substratalapps.com/ + url: https://docs.substratalapps.com/ servers: - url: https://api.substratalapps.com description: Production @@ -56,11 +61,18 @@ tags: - name: Tenancy - name: Billing - name: Audit + - name: Usage & stats + description: >- + Request usage per Application, API Key, and operation, and the console home screen's live counts. - name: Webhooks - name: Notifications description: >- Push notifications (APNs, FCM, Web Push) and the notification inbox. - name: API Keys + - name: Platform + description: >- + Runtime operational switches (signup, read-only maintenance) and client + feature flags. - name: Meta paths: @@ -158,6 +170,10 @@ paths: - $ref: "#/components/parameters/ApiVersion" tags: [Auth] summary: Complete a login that returned an MFA challenge + description: >- + Send the mfa_token and exactly one of code (TOTP), recovery_code, or + passkey (an assertion for options from POST /auth/mfa/passkey-options). + A passkey sign-in adds hwk to the session's amr. security: [] x-substratal-phase: mvp requestBody: @@ -171,6 +187,7 @@ paths: mfa_token: { type: string } code: { type: string, pattern: "^[0-9]{6}$" } recovery_code: { type: string } + passkey: { $ref: "#/components/schemas/PasskeyAssertion" } responses: "400": { $ref: "#/components/responses/BadRequest" } "200": @@ -182,6 +199,41 @@ paths: "403": { $ref: "#/components/responses/Forbidden" } "429": { $ref: "#/components/responses/TooManyRequests" } + /auth/mfa/passkey-options: + post: + operationId: auth.mfaPasskeyOptions + parameters: + - $ref: "#/components/parameters/ApiVersion" + tags: [Auth] + summary: Get WebAuthn request options to complete an MFA challenge with a passkey + description: >- + Returns PublicKeyCredentialRequestOptions limited to the User's own + passkeys, with a fresh challenge valid for 5 minutes and usable once. + Pass publicKey to navigator.credentials.get() and send the result to + POST /auth/mfa/verify as passkey, with the same mfa_token. + 409 passkey_not_registered when the User has no passkey. + security: [] + x-substratal-phase: mvp + requestBody: + required: true + content: + application/json: + schema: + type: object + required: [mfa_token] + properties: + mfa_token: { type: string } + responses: + "400": { $ref: "#/components/responses/BadRequest" } + "200": + description: Request options + content: + application/json: + schema: { $ref: "#/components/schemas/PasskeyRequestOptions" } + "401": { $ref: "#/components/responses/Unauthorized" } + "409": { $ref: "#/components/responses/Conflict" } + "429": { $ref: "#/components/responses/TooManyRequests" } + /auth/token/refresh: post: operationId: auth.refreshToken @@ -232,6 +284,67 @@ paths: "400": { $ref: "#/components/responses/BadRequest" } "401": { $ref: "#/components/responses/Unauthorized" } + /auth/reauthenticate: + post: + operationId: auth.reauthenticate + parameters: + - $ref: "#/components/parameters/ApiVersion" + tags: [Auth] + summary: Prove a second factor again, for step-up (User token, MFA enabled) + description: >- + Records a fresh MFA check on the calling session (mfa_verified_at), so + operations marked x-substratal-step-up work for the next 10 minutes. + Send exactly one of code (a current TOTP code), recovery_code (a + single-use recovery code), or passkey (an assertion for options from + POST /auth/reauthenticate/passkey-options). The response is a new + access token carrying the updated mfa_verified_at claim; the refresh + token is unchanged. Wrong codes and failed assertions count toward a + lockout: after 5 in 15 minutes it is 429 too_many_attempts. + 409 mfa_not_enabled when the User has neither TOTP nor a passkey. + x-substratal-phase: mvp + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + code: { type: string, pattern: "^[0-9]{6}$" } + recovery_code: { type: string } + passkey: { $ref: "#/components/schemas/PasskeyAssertion" } + responses: + "400": { $ref: "#/components/responses/BadRequest" } + "200": + description: Re-authenticated + content: + application/json: + schema: { $ref: "#/components/schemas/Reauthentication" } + "401": { $ref: "#/components/responses/Unauthorized" } + "409": { $ref: "#/components/responses/Conflict" } + "429": { $ref: "#/components/responses/TooManyRequests" } + + /auth/reauthenticate/passkey-options: + post: + operationId: auth.reauthenticatePasskeyOptions + parameters: + - $ref: "#/components/parameters/ApiVersion" + tags: [Auth] + summary: Get WebAuthn request options to re-authenticate with a passkey (User token) + description: >- + Like POST /auth/mfa/passkey-options, for the calling User's session: + send the assertion to POST /auth/reauthenticate as passkey. + 409 passkey_not_registered when the User has no passkey. + x-substratal-phase: mvp + responses: + "400": { $ref: "#/components/responses/BadRequest" } + "200": + description: Request options + content: + application/json: + schema: { $ref: "#/components/schemas/PasskeyRequestOptions" } + "401": { $ref: "#/components/responses/Unauthorized" } + "409": { $ref: "#/components/responses/Conflict" } + /auth/app-tokens: post: operationId: auth.createAppToken @@ -522,7 +635,12 @@ paths: - $ref: "#/components/parameters/ApiVersion" tags: [Auth] summary: Begin TOTP enrollment (self only) + description: >- + A User who already has a passkey needs a recent MFA check (step-up), + like registering another passkey. x-substratal-phase: mvp + x-substratal-step-up: conditional + x-substratal-step-up-when: "the User already has an MFA method" responses: "400": { $ref: "#/components/responses/BadRequest" } "200": @@ -541,7 +659,10 @@ paths: parameters: - $ref: "#/components/parameters/ApiVersion" tags: [Auth] - summary: Support reset of a user's TOTP (requires users.manage) + summary: Support reset of a user's MFA, TOTP and passkeys (requires users.manage) + description: >- + Removes TOTP, every passkey, and the recovery codes, and revokes every + session. 409 mfa_not_enabled when the User has neither. x-substratal-phase: mvp x-substratal-destructive: always responses: @@ -559,7 +680,13 @@ paths: - $ref: "#/components/parameters/ApiVersion" tags: [Auth] summary: Confirm TOTP enrollment with a first code; returns recovery codes once + description: >- + recovery_codes is present only when TOTP is the User's first MFA + method. A User who already has a passkey keeps their existing codes, + and needs a recent MFA check (step-up). x-substratal-phase: mvp + x-substratal-step-up: conditional + x-substratal-step-up-when: "the User already has an MFA method" requestBody: required: true content: @@ -610,6 +737,148 @@ paths: "409": { $ref: "#/components/responses/Conflict" } "429": { $ref: "#/components/responses/TooManyRequests" } + /users/{id}/mfa/passkeys/registration-options: + parameters: + - $ref: "#/components/parameters/UserIdOrMe" + post: + operationId: auth.passkeyRegistrationOptions + parameters: + - $ref: "#/components/parameters/ApiVersion" + tags: [Auth] + summary: Begin registering a passkey (self only) + description: >- + Returns PublicKeyCredentialCreationOptions (user verification required, + resident key preferred, the User's existing passkeys excluded) with a + challenge valid for 5 minutes and usable once. Pass publicKey to + navigator.credentials.create() and send the result to + POST /users/{id}/mfa/passkeys. A User who already has an MFA method + needs a recent MFA check (step-up); one enrolling their first method + needs a session signed in with a password in the last 10 minutes + (403 recent_sign_in_required). 409 passkey_limit_reached at 10 + passkeys; 409 mfa_not_applicable without a password identity. + x-substratal-phase: mvp + x-substratal-step-up: conditional + x-substratal-step-up-when: "the User already has an MFA method" + responses: + "400": { $ref: "#/components/responses/BadRequest" } + "200": + description: Creation options + content: + application/json: + schema: { $ref: "#/components/schemas/PasskeyCreationOptions" } + "403": { $ref: "#/components/responses/Forbidden" } + "409": { $ref: "#/components/responses/Conflict" } + + /users/{id}/mfa/passkeys: + parameters: + - $ref: "#/components/parameters/UserIdOrMe" + get: + operationId: auth.listPasskeys + parameters: + - $ref: "#/components/parameters/ApiVersion" + tags: [Auth] + summary: List a User's passkeys (self or users.manage) + description: "Oldest first. Never includes key material." + x-substratal-phase: mvp + responses: + "400": { $ref: "#/components/responses/BadRequest" } + "200": + description: The User's passkeys + content: + application/json: + schema: { $ref: "#/components/schemas/PasskeyList" } + "403": { $ref: "#/components/responses/Forbidden" } + "404": { $ref: "#/components/responses/NotFound" } + post: + operationId: auth.registerPasskey + parameters: + - $ref: "#/components/parameters/ApiVersion" + tags: [Auth] + summary: Finish registering a passkey (self only) + description: >- + Verifies the attestation against the challenge from + registration-options, which must have been issued to this session, + and stores the credential. MFA is then enabled. When this is the + User's first MFA method the response also carries ten recovery codes, + shown once. Writes user.passkey_added. 400 passkey_invalid when the + attestation fails (wrong origin or RP ID, unknown, expired, or used + challenge, user verification missing); 409 passkey_limit_reached; + 409 passkey_already_registered. + x-substratal-phase: mvp + requestBody: + required: true + content: + application/json: + schema: + type: object + required: [credential] + properties: + credential: { $ref: "#/components/schemas/PasskeyAttestation" } + name: { type: string, description: "A label for the User, at most 64 characters. Default Passkey." } + responses: + "400": { $ref: "#/components/responses/BadRequest" } + "201": + description: Registered + content: + application/json: + schema: { $ref: "#/components/schemas/PasskeyRegistration" } + "403": { $ref: "#/components/responses/Forbidden" } + "409": { $ref: "#/components/responses/Conflict" } + "422": { $ref: "#/components/responses/Unprocessable" } + + /users/{id}/mfa/passkeys/{passkeyId}: + parameters: + - $ref: "#/components/parameters/UserIdOrMe" + - { name: passkeyId, in: path, required: true, schema: { type: string } } + patch: + operationId: auth.updatePasskey + tags: [Auth] + summary: Rename a passkey (self only) + x-substratal-phase: mvp + parameters: + - $ref: "#/components/parameters/ApiVersion" + - $ref: "#/components/parameters/IfMatch" + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + name: { type: string, description: "1 to 64 characters." } + responses: + "400": { $ref: "#/components/responses/BadRequest" } + "200": + description: The updated passkey + headers: + ETag: { $ref: "#/components/headers/ETag" } + content: + application/json: + schema: { $ref: "#/components/schemas/Passkey" } + "403": { $ref: "#/components/responses/Forbidden" } + "404": { $ref: "#/components/responses/NotFound" } + "409": { $ref: "#/components/responses/Conflict" } + "422": { $ref: "#/components/responses/Unprocessable" } + delete: + operationId: auth.deletePasskey + parameters: + - $ref: "#/components/parameters/ApiVersion" + tags: [Auth] + summary: Remove a passkey (self only) + description: >- + Needs a recent MFA check (step-up). Writes user.passkey_removed. + Removing the User's last MFA method (no TOTP, no other passkey) also + deletes the recovery codes, writes user.mfa_disabled, and alerts the + User, as turning TOTP off does. + x-substratal-phase: mvp + x-substratal-destructive: always + x-substratal-step-up: always + responses: + "400": { $ref: "#/components/responses/BadRequest" } + "204": { description: Removed } + "403": { $ref: "#/components/responses/Forbidden" } + "404": { $ref: "#/components/responses/NotFound" } + /users/{id}/sessions: parameters: - $ref: "#/components/parameters/UserIdOrMe" @@ -710,6 +979,7 @@ paths: - $ref: "#/components/parameters/ApiVersion" - $ref: "#/components/parameters/Limit" - $ref: "#/components/parameters/Cursor" + - $ref: "#/components/parameters/Include" - { name: status, in: query, description: "deleted is allowed for users.manage only", schema: { type: string, enum: [active, invited, suspended, deleted] } } - { name: email, in: query, schema: { type: string, format: email } } - { name: q, in: query, schema: { type: string, minLength: 3 } } @@ -766,6 +1036,84 @@ paths: "409": { $ref: "#/components/responses/Conflict" } "422": { $ref: "#/components/responses/Unprocessable" } + /users/bulk-invite: + post: + operationId: users.bulkInvite + tags: [Users] + summary: Invite up to 25 users in one call (users.manage) + description: >- + Requires users.manage. Each email is POST /users with status invited and an invitation email, + processed independently: one failing email doesn't stop the others, and each success writes its + own user.created Audit Event. Each email counts against POST /users's rate limit (20/min), so + emails past it get a per-item 429. The response is 200 with one result per email, in request + order; an item's status is what POST /users would have returned (201, 409 email_taken, + 422 validation_failed, 429 rate_limited). application_id, if given, becomes each new User's + signup_application_id and brands the invitation email. See /api-reference/conventions/#bulk-operations. + x-substratal-phase: mvp + parameters: + - $ref: "#/components/parameters/ApiVersion" + - $ref: "#/components/parameters/IdempotencyKey" + requestBody: + required: true + content: + application/json: + schema: + type: object + required: [emails] + properties: + emails: { type: array, minItems: 1, maxItems: 25, items: { type: string } } + application_id: { type: string } + responses: + "400": { $ref: "#/components/responses/BadRequest" } + "200": + description: One result per email, in request order + content: + application/json: + schema: { $ref: "#/components/schemas/BulkInviteResults" } + "403": { $ref: "#/components/responses/Forbidden" } + "404": { $ref: "#/components/responses/NotFound" } + "409": { $ref: "#/components/responses/Conflict" } + "422": { $ref: "#/components/responses/Unprocessable" } + + /users/bulk-suspend: + post: + operationId: users.bulkSuspend + tags: [Users] + summary: Suspend up to 25 users in one call (users.manage) + description: >- + Requires users.manage. Each id is POST /users/{id}/suspend with the shared reason, processed + independently, each with its own user.suspended Audit Event and webhooks. The protected + superadmin is a per-item 409 user_protected. Like POST /users/{id}/suspend it needs a recent + MFA check (403 reauthentication_required for the whole batch). Each id counts against + POST /users/{id}/suspend's rate limit. The response is 200 with one result per id, in request order; an item's status is + what POST /users/{id}/suspend would have returned. See /api-reference/conventions/#bulk-operations. + x-substratal-phase: mvp + x-substratal-destructive: always + x-substratal-step-up: always + parameters: + - $ref: "#/components/parameters/ApiVersion" + - $ref: "#/components/parameters/IdempotencyKey" + requestBody: + required: true + content: + application/json: + schema: + type: object + required: [user_ids] + properties: + user_ids: { type: array, minItems: 1, maxItems: 25, items: { type: string } } + reason: { type: string, maxLength: 2000 } + responses: + "400": { $ref: "#/components/responses/BadRequest" } + "200": + description: One result per id, in request order + content: + application/json: + schema: { $ref: "#/components/schemas/BulkResults" } + "403": { $ref: "#/components/responses/Forbidden" } + "409": { $ref: "#/components/responses/Conflict" } + "422": { $ref: "#/components/responses/Unprocessable" } + /users/{id}: parameters: - $ref: "#/components/parameters/UserIdOrMe" @@ -793,6 +1141,8 @@ paths: x-substratal-phase: mvp x-substratal-destructive: conditional x-substratal-destructive-when: "status becomes suspended" + x-substratal-step-up: conditional + x-substratal-step-up-when: "status becomes suspended" parameters: - $ref: "#/components/parameters/ApiVersion" - $ref: "#/components/parameters/IfMatch" @@ -823,6 +1173,7 @@ paths: summary: Soft-delete a user (self or users.manage) x-substratal-phase: mvp x-substratal-destructive: always + x-substratal-step-up: always responses: "400": { $ref: "#/components/responses/BadRequest" } "204": { description: Deleted } @@ -840,6 +1191,7 @@ paths: summary: Suspend a user (users.manage) x-substratal-phase: mvp x-substratal-destructive: always + x-substratal-step-up: always requestBody: content: application/json: @@ -903,6 +1255,7 @@ paths: summary: Request right-to-erasure (soft-delete now, hard-delete cascade in 7 days) x-substratal-phase: mvp x-substratal-destructive: always + x-substratal-step-up: always requestBody: content: application/json: @@ -921,6 +1274,23 @@ paths: /users/{id}/erasure-requests/current: parameters: - $ref: "#/components/parameters/UserIdOrMe" + get: + operationId: users.getErasure + parameters: + - $ref: "#/components/parameters/ApiVersion" + tags: [Users] + summary: Read the User's pending erasure request + description: "Self, or users.manage. Returns the erasure request while it's scheduled; 404 erasure_not_scheduled when none is pending (never requested, cancelled, or completed). A soft-deleted User 404s (user_not_found) for anyone without users.manage, as on cancel." + x-substratal-phase: mvp + responses: + "400": { $ref: "#/components/responses/BadRequest" } + "200": + description: The scheduled erasure request + content: + application/json: + schema: { $ref: "#/components/schemas/ErasureRequest" } + "403": { $ref: "#/components/responses/Forbidden" } + "404": { $ref: "#/components/responses/NotFound" } delete: operationId: users.cancelErasure parameters: @@ -978,6 +1348,94 @@ paths: "409": { $ref: "#/components/responses/Conflict" } "422": { $ref: "#/components/responses/Unprocessable" } + /users/{id}/avatar/uploads: + parameters: + - $ref: "#/components/parameters/UserIdOrMe" + post: + operationId: profiles.createAvatarUpload + tags: [Profiles] + summary: Start an avatar upload (self or users.manage) + description: >- + Returns a presigned POST: send the image straight to url as multipart/form-data, with every + entry of fields and then the file as the last field, named file, within 5 minutes. The API + never sees the bytes. Then call POST /users/{id}/avatar/uploads/{uploadId}/complete. PNG, + JPEG, or WebP, at most 2 MB (a larger content_length is 422 validation_failed). 10 upload + starts per caller per hour, shared with Application icons. + x-substratal-phase: mvp + parameters: + - $ref: "#/components/parameters/ApiVersion" + - $ref: "#/components/parameters/IdempotencyKeyOptional" + requestBody: + required: true + content: + application/json: + schema: { $ref: "#/components/schemas/ImageUploadRequest" } + responses: + "400": { $ref: "#/components/responses/BadRequest" } + "201": + description: Where and how to upload + content: + application/json: + schema: { $ref: "#/components/schemas/ImageUpload" } + "403": { $ref: "#/components/responses/Forbidden" } + "404": { $ref: "#/components/responses/NotFound" } + "422": { $ref: "#/components/responses/Unprocessable" } + "429": { $ref: "#/components/responses/TooManyRequests" } + "503": { $ref: "#/components/responses/ServiceUnavailable" } + + /users/{id}/avatar/uploads/{uploadId}/complete: + parameters: + - $ref: "#/components/parameters/UserIdOrMe" + - { name: uploadId, in: path, required: true, schema: { type: string } } + post: + operationId: profiles.completeAvatarUpload + tags: [Profiles] + summary: Check an uploaded avatar and make it the Profile's avatar_url (self or users.manage) + description: >- + Checks the uploaded file's magic bytes against the declared content_type, its size, and its + dimensions (at most 2048 × 2048), stores it at a content-addressed + https://assets.substratalapps.com/avatars/… URL, sets avatar_url, and deletes the previous + hosted avatar. A file that fails a check is deleted, and the call is 422 invalid_image with + details.reason. An upload that was never sent, or was already completed, is 404 + upload_not_found. Writes profile.avatar_changed when someone other than the User does it. + x-substratal-phase: mvp + parameters: + - $ref: "#/components/parameters/ApiVersion" + responses: + "400": { $ref: "#/components/responses/BadRequest" } + "200": + description: The updated Profile + headers: + ETag: { $ref: "#/components/headers/ETag" } + content: + application/json: + schema: { $ref: "#/components/schemas/Profile" } + "403": { $ref: "#/components/responses/Forbidden" } + "404": { $ref: "#/components/responses/NotFound" } + "422": { $ref: "#/components/responses/Unprocessable" } + "503": { $ref: "#/components/responses/ServiceUnavailable" } + + /users/{id}/avatar: + parameters: + - $ref: "#/components/parameters/UserIdOrMe" + delete: + operationId: profiles.deleteAvatar + tags: [Profiles] + summary: Remove the avatar (self or users.manage) + description: >- + Sets avatar_url to null and deletes the hosted image, if it is one; an external https URL is + just cleared. PATCH /users/{id}/profile with avatar_url null does the same. Writes + profile.avatar_changed when someone other than the User does it. + x-substratal-phase: mvp + x-substratal-destructive: always + parameters: + - $ref: "#/components/parameters/ApiVersion" + responses: + "400": { $ref: "#/components/responses/BadRequest" } + "204": { description: Removed } + "403": { $ref: "#/components/responses/Forbidden" } + "404": { $ref: "#/components/responses/NotFound" } + /users/{id}/settings: parameters: - $ref: "#/components/parameters/UserIdOrMe" @@ -1124,11 +1582,18 @@ paths: operationId: applications.list tags: [Applications] summary: List the catalog (filtered by visibility rules) + description: >- + Newest first by created_at, ties broken by id. With applications.manage, + review_status=pending_review is the review queue and defaults to oldest-waiting first, by + review_requested_at (falling back to created_at). sort sets the order explicitly by + created_at: created_at for oldest first, -created_at for newest first, in the queue too. A + cursor is only valid under the sort it was issued with. x-substratal-phase: mvp parameters: - $ref: "#/components/parameters/ApiVersion" - $ref: "#/components/parameters/Limit" - $ref: "#/components/parameters/Cursor" + - $ref: "#/components/parameters/Include" - { name: visibility, in: query, schema: { $ref: "#/components/schemas/ApplicationVisibility" } } - { name: review_status, in: query, schema: { $ref: "#/components/schemas/ApplicationReviewStatus" } } - { name: access_tier, in: query, schema: { $ref: "#/components/schemas/ApplicationAccessTier" } } @@ -1136,8 +1601,12 @@ paths: - { name: tenant_id, in: query, schema: { type: string } } - { name: owner_user_id, in: query, schema: { type: string } } - { name: owner_organization_id, in: query, schema: { type: string } } + - { name: q, in: query, description: "Case-insensitive prefix match on name or slug", schema: { type: string } } + - { name: include_inactive, in: query, description: "Include retired Applications (also included by review_status=retired)", schema: { type: boolean, default: false } } + - { name: sort, in: query, description: "created_at (oldest first) or -created_at (newest first). Ties are broken by id in the same direction.", schema: { type: string, enum: [created_at, -created_at] } } responses: "400": { $ref: "#/components/responses/BadRequest" } + "422": { $ref: "#/components/responses/Unprocessable" } "200": description: A page of Applications (trimmed view) content: @@ -1151,7 +1620,8 @@ paths: applications.manage creates any Application, approved by default (concierge onboarding). Any other User with a verified email may submit their own: it's owned by the caller (or an Organization they're an org_admin of), starts in pending_review, and can't set visibility, - access_tier, review_status, or review_notes (403 moderation_field_forbidden). Unverified + review_status, or review_notes (403 moderation_field_forbidden). Its access_tier is free or + restricted (the default); standard is 422 access_tier_reserved. Unverified email is 403 email_not_verified; API Keys without applications.manage are 403 forbidden. Self-service submissions are limited to 10 per User per day. x-substratal-phase: mvp @@ -1205,7 +1675,7 @@ paths: summary: Update a catalog entry (owner — configuration; applications.manage — anything) x-substratal-phase: mvp x-substratal-destructive: conditional - x-substratal-destructive-when: "review_status becomes rejected or suspended, or available_app_roles/permissions shrink" + x-substratal-destructive-when: "review_status becomes rejected, suspended, or retired, or available_app_roles/permissions shrink" parameters: - $ref: "#/components/parameters/ApiVersion" - $ref: "#/components/parameters/IfMatch" @@ -1223,6 +1693,115 @@ paths: "403": { $ref: "#/components/responses/Forbidden" } "409": { $ref: "#/components/responses/Conflict" } "422": { $ref: "#/components/responses/Unprocessable" } + "429": { $ref: "#/components/responses/TooManyRequests" } + delete: + operationId: applications.delete + tags: [Applications] + summary: Delete an unreferenced test-mode Application (applications.manage) + description: >- + Only a test-mode Application that nothing references can be deleted; a live one is + 409 application_not_deletable (retire it with review_status: retired instead). Anything + still referencing it (Entitlements, API Keys, webhooks, devices, notifications, settings or + profile rows, push credentials, role assignments, refresh tokens, Users who signed up + through it) is 409 application_in_use, naming each kind in `references`. Its own Roles go + with it; audit history is kept. Writes application.deleted. + x-substratal-phase: mvp + x-substratal-destructive: always + parameters: + - $ref: "#/components/parameters/ApiVersion" + responses: + "400": { $ref: "#/components/responses/BadRequest" } + "204": { description: Deleted } + "403": { $ref: "#/components/responses/Forbidden" } + "404": { $ref: "#/components/responses/NotFound" } + "409": { $ref: "#/components/responses/Conflict" } + + /applications/{id}/icon/uploads: + parameters: + - { name: id, in: path, required: true, schema: { type: string } } + post: + operationId: applications.createIconUpload + tags: [Applications] + summary: Start an icon upload (the owner or applications.manage) + description: >- + Returns a presigned POST, as for avatars: send the image straight to url with every entry of + fields and then the file as the last field, named file, within 5 minutes, then call + POST /applications/{id}/icon/uploads/{uploadId}/complete. PNG, JPEG, or WebP, square, at most + 1 MB (a larger content_length is 422 validation_failed). 10 upload starts per caller per + hour, shared with avatars. + x-substratal-phase: mvp + parameters: + - $ref: "#/components/parameters/ApiVersion" + - $ref: "#/components/parameters/IdempotencyKeyOptional" + requestBody: + required: true + content: + application/json: + schema: { $ref: "#/components/schemas/ImageUploadRequest" } + responses: + "400": { $ref: "#/components/responses/BadRequest" } + "201": + description: Where and how to upload + content: + application/json: + schema: { $ref: "#/components/schemas/ImageUpload" } + "403": { $ref: "#/components/responses/Forbidden" } + "404": { $ref: "#/components/responses/NotFound" } + "422": { $ref: "#/components/responses/Unprocessable" } + "429": { $ref: "#/components/responses/TooManyRequests" } + "503": { $ref: "#/components/responses/ServiceUnavailable" } + + /applications/{id}/icon/uploads/{uploadId}/complete: + parameters: + - { name: id, in: path, required: true, schema: { type: string } } + - { name: uploadId, in: path, required: true, schema: { type: string } } + post: + operationId: applications.completeIconUpload + tags: [Applications] + summary: Check an uploaded icon and make it the Application's icon_url (the owner or applications.manage) + description: >- + Checks the uploaded file's magic bytes against the declared content_type, its size, and its + dimensions (square, at most 2048 × 2048), stores it at a content-addressed + https://assets.substratalapps.com/apps/… URL, sets icon_url, and deletes the previous hosted + icon. A file that fails a check is deleted, and the call is 422 invalid_image with + details.reason. An upload that was never sent, or was already completed, is 404 + upload_not_found. Writes application.icon_changed. + x-substratal-phase: mvp + parameters: + - $ref: "#/components/parameters/ApiVersion" + responses: + "400": { $ref: "#/components/responses/BadRequest" } + "200": + description: The updated Application + headers: + ETag: { $ref: "#/components/headers/ETag" } + content: + application/json: + schema: { $ref: "#/components/schemas/Application" } + "403": { $ref: "#/components/responses/Forbidden" } + "404": { $ref: "#/components/responses/NotFound" } + "422": { $ref: "#/components/responses/Unprocessable" } + "503": { $ref: "#/components/responses/ServiceUnavailable" } + + /applications/{id}/icon: + parameters: + - { name: id, in: path, required: true, schema: { type: string } } + delete: + operationId: applications.deleteIcon + tags: [Applications] + summary: Remove the icon (the owner or applications.manage) + description: >- + Sets icon_url to null and deletes the hosted image, if it is one; an external https URL is + just cleared. Writes application.icon_changed. + x-substratal-phase: mvp + x-substratal-destructive: always + parameters: + - $ref: "#/components/parameters/ApiVersion" + responses: + "400": { $ref: "#/components/responses/BadRequest" } + "204": { description: Removed } + "403": { $ref: "#/components/responses/Forbidden" } + "404": { $ref: "#/components/responses/NotFound" } # ───────────────────────────── Entitlements ───────────────────────────── @@ -1238,6 +1817,7 @@ paths: - $ref: "#/components/parameters/ApiVersion" - $ref: "#/components/parameters/Limit" - $ref: "#/components/parameters/Cursor" + - $ref: "#/components/parameters/Include" - { name: application_id, in: query, schema: { type: string } } - { name: status, in: query, schema: { $ref: "#/components/schemas/EntitlementStatus" } } - { name: source, in: query, schema: { $ref: "#/components/schemas/EntitlementSource" } } @@ -1292,6 +1872,7 @@ paths: - $ref: "#/components/parameters/ApiVersion" - $ref: "#/components/parameters/Limit" - $ref: "#/components/parameters/Cursor" + - $ref: "#/components/parameters/Include" - { name: application_id, in: query, schema: { type: string } } - { name: status, in: query, schema: { $ref: "#/components/schemas/EntitlementStatus" } } - { name: user_id, in: query, schema: { type: string } } @@ -1379,6 +1960,54 @@ paths: "404": { $ref: "#/components/responses/NotFound" } "409": { $ref: "#/components/responses/Conflict" } + /entitlements/bulk-update: + post: + operationId: entitlements.bulkUpdate + tags: [Entitlements] + summary: Change the status of up to 25 Entitlements in one call + description: >- + Each item is PATCH /entitlements/{id} with its status and disabled_reason: the same access + rules and transition table, processed independently, each with its own Audit Event and webhooks. + Each item counts against PATCH /entitlements/{id}'s rate limit. The response is 200 with one + result per item, in request order; an item's status is what the PATCH would have returned. An + item that disables or revokes is refused (403 destructive_operation_restricted) for a + restrict_destructive key; the other items go ahead. See /api-reference/conventions/#bulk-operations. + x-substratal-phase: mvp + x-substratal-destructive: conditional + x-substratal-destructive-when: "an item's status becomes disabled or revoked" + parameters: + - $ref: "#/components/parameters/ApiVersion" + - $ref: "#/components/parameters/IdempotencyKey" + requestBody: + required: true + content: + application/json: + schema: + type: object + required: [items] + properties: + items: + type: array + minItems: 1 + maxItems: 25 + items: + type: object + required: [id, status] + properties: + id: { type: string } + status: { $ref: "#/components/schemas/EntitlementStatus" } + disabled_reason: { type: [string, "null"], maxLength: 255 } + responses: + "400": { $ref: "#/components/responses/BadRequest" } + "200": + description: One result per item, in request order + content: + application/json: + schema: { $ref: "#/components/schemas/BulkResults" } + "403": { $ref: "#/components/responses/Forbidden" } + "409": { $ref: "#/components/responses/Conflict" } + "422": { $ref: "#/components/responses/Unprocessable" } + # ─────────────────────────── Roles & Permissions ─────────────────────────── /permissions: @@ -1405,11 +2034,21 @@ paths: operationId: roles.list tags: [Roles & Permissions] summary: List Roles + description: >- + Any authenticated caller; each sees only the Roles visible to it. Platform Roles are + visible to Users holding any platform permission and to platform keys. An Application's + Roles are visible to platform roles.manage and applications.manage holders, the + Application's own key, and the Application's owner (its owner_user_id, or any active org_admin of its + owner_organization_id), with no platform permission needed. An owner sees only the Roles + of Applications they own: never another Application's, and never platform Roles unless + they also hold a platform permission. A scope the caller can't see returns an empty page, + not an error. x-substratal-phase: mvp parameters: - $ref: "#/components/parameters/ApiVersion" - $ref: "#/components/parameters/Limit" - $ref: "#/components/parameters/Cursor" + - $ref: "#/components/parameters/Include" - { name: scope, in: query, description: "'platform' or an application_id", schema: { type: string } } responses: "400": { $ref: "#/components/responses/BadRequest" } @@ -1465,6 +2104,18 @@ paths: operationId: roles.update tags: [Roles & Permissions] summary: Change a Role's permissions or description + description: >- + An app Role may be changed by platform roles.manage or applications.manage, the + Application's own key holding roles.manage, or the Application's owner (its owner_user_id, + or any active org_admin of its owner_organization_id) with no platform permission needed. + Assigning it still takes roles.manage, the owner, or the app's own key. Its permissions must be + keys its own Application declares; a platform key, another Application's key, or an + undeclared key returns 422 unknown_permission. A platform Role needs platform + roles.manage, and every permission it grants must be one the caller holds (403 + role_escalation_forbidden); seed Roles can't be changed (403 seed_role_immutable). A + Role the caller can't see (another Application's, or a platform Role for a caller with + no platform permission) returns 404 role_not_found; one it can see but not change + returns 403 forbidden. x-substratal-phase: mvp x-substratal-destructive: conditional x-substratal-destructive-when: "permissions shrink" @@ -1488,6 +2139,7 @@ paths: application/json: schema: { $ref: "#/components/schemas/Role" } "403": { $ref: "#/components/responses/Forbidden" } + "404": { $ref: "#/components/responses/NotFound" } "409": { $ref: "#/components/responses/Conflict" } "422": { $ref: "#/components/responses/Unprocessable" } delete: @@ -1535,7 +2187,13 @@ paths: - $ref: "#/components/parameters/ApiVersion" tags: [Roles & Permissions] summary: Assign a Role (idempotent — 200 if already held) + description: >- + Assigning a platform Role that grants a permission to a User without + MFA succeeds, but the Role takes effect only once they enroll TOTP; + the response's mfa_enrollment_required says so (Auth → Staff MFA). x-substratal-phase: mvp + x-substratal-step-up: conditional + x-substratal-step-up-when: "the Role is a platform Role" responses: "400": { $ref: "#/components/responses/BadRequest" } "200": @@ -1558,6 +2216,8 @@ paths: summary: Remove a Role assignment (idempotent) x-substratal-phase: mvp x-substratal-destructive: always + x-substratal-step-up: conditional + x-substratal-step-up-when: "the Role is a platform Role" responses: "400": { $ref: "#/components/responses/BadRequest" } "204": { description: Removed } @@ -1596,6 +2256,7 @@ paths: - $ref: "#/components/parameters/ApiVersion" - $ref: "#/components/parameters/Limit" - $ref: "#/components/parameters/Cursor" + - $ref: "#/components/parameters/Include" - { name: status, in: query, schema: { type: string, enum: [active, suspended] } } - { name: q, in: query, schema: { type: string } } responses: @@ -1691,6 +2352,7 @@ paths: - $ref: "#/components/parameters/ApiVersion" - $ref: "#/components/parameters/Limit" - $ref: "#/components/parameters/Cursor" + - $ref: "#/components/parameters/Include" - { name: role, in: query, schema: { $ref: "#/components/schemas/OrganizationMemberRole" } } - { name: membership_status, in: query, schema: { $ref: "#/components/schemas/OrganizationMembershipStatus" } } - { name: q, in: query, schema: { type: string } } @@ -2053,6 +2715,64 @@ paths: # ───────────────────────────── Billing ───────────────────────────── + /billing/prices: + get: + operationId: billing.listPrices + tags: [Billing] + summary: Standard's prices, monthly and yearly (User token) + description: >- + Any signed-in User. Each price is in cents per user per interval, the amount Checkout + charges. 503 billing_unavailable when billing isn't configured or the prices can't be read. + x-substratal-phase: phase2 + parameters: + - $ref: "#/components/parameters/ApiVersion" + responses: + "200": + description: Standard's prices + content: + application/json: + schema: + type: object + required: [data] + properties: + data: { type: array, items: { $ref: "#/components/schemas/PlanPrice" } } + "400": { $ref: "#/components/responses/BadRequest" } + "503": { $ref: "#/components/responses/ServiceUnavailable" } + + /subscriptions: + get: + operationId: billing.listSubscriptions + tags: [Billing] + summary: List every subscriber's subscription (billing.manage) + description: >- + Requires billing.manage. Every User's and Organization's subscription in the caller's mode, + most recently updated first, with the subscriber's email or name for display. Revenue and + invoices stay with the payment processor. + x-substratal-phase: phase2 + parameters: + - $ref: "#/components/parameters/ApiVersion" + - $ref: "#/components/parameters/Limit" + - $ref: "#/components/parameters/Cursor" + - $ref: "#/components/parameters/Include" + - name: status + in: query + description: "Subscriptions in any of these statuses. Repeatable." + style: form + explode: true + schema: { type: array, items: { $ref: "#/components/schemas/SubscriptionStatus" }, maxItems: 8 } + - { name: subscriber_type, in: query, schema: { type: string, enum: [user, organization] } } + - { name: cancel_at_period_end, in: query, schema: { type: boolean } } + - { name: current_period_end_before, in: query, description: "Subscriptions whose current period ends before this time.", schema: { type: string, format: date-time } } + responses: + "400": { $ref: "#/components/responses/BadRequest" } + "200": + description: A page of subscriptions + content: + application/json: + schema: { $ref: "#/components/schemas/SubscriptionPage" } + "403": { $ref: "#/components/responses/Forbidden" } + "422": { $ref: "#/components/responses/Unprocessable" } + /users/{id}/subscription: parameters: - $ref: "#/components/parameters/UserIdOrMe" @@ -2077,7 +2797,7 @@ paths: post: operationId: billing.createUserCheckoutSession tags: [Billing] - summary: Start a Stripe Checkout to subscribe yourself to Standard (User token) + summary: Start a Checkout to subscribe yourself to Standard (User token) x-substratal-phase: phase2 parameters: - $ref: "#/components/parameters/ApiVersion" @@ -2098,13 +2818,38 @@ paths: "422": { $ref: "#/components/responses/Unprocessable" } "503": { $ref: "#/components/responses/ServiceUnavailable" } + /users/me/billing/checkout-sessions/{session_id}/confirm: + parameters: + - { name: session_id, in: path, required: true, schema: { type: string }, description: "The Checkout Session id from success_url's session_id parameter." } + post: + operationId: billing.confirmUserCheckoutSession + tags: [Billing] + summary: Sync your subscription from a returning Checkout, without waiting for the webhook (User token) + description: >- + Call it when the person lands on success_url. It reads the Checkout Session and, if it's + complete, applies the subscription at once (the same sync the billing webhook runs), then + returns what GET /users/me/subscription would. An open or expired session changes nothing. + Idempotent. 404 checkout_session_not_found if the session isn't this User's. + x-substratal-phase: phase2 + parameters: + - $ref: "#/components/parameters/ApiVersion" + responses: + "200": + description: The User's plan and individual subscription, after the sync + content: + application/json: + schema: { $ref: "#/components/schemas/UserSubscription" } + "400": { $ref: "#/components/responses/BadRequest" } + "404": { $ref: "#/components/responses/NotFound" } + "503": { $ref: "#/components/responses/ServiceUnavailable" } + /users/me/billing/portal-sessions: post: operationId: billing.createUserPortalSession parameters: - $ref: "#/components/parameters/ApiVersion" tags: [Billing] - summary: Open the Stripe Customer Portal for your own subscription (User token) + summary: Open the billing portal for your own subscription (User token) x-substratal-phase: phase2 requestBody: required: true @@ -2179,7 +2924,7 @@ paths: post: operationId: billing.createOrganizationCheckoutSession tags: [Billing] - summary: Start a Stripe Checkout to subscribe the Organization to Standard (org admin, User token) + summary: Start a Checkout to subscribe the Organization to Standard (org admin, User token) x-substratal-phase: phase2 parameters: - $ref: "#/components/parameters/ApiVersion" @@ -2208,6 +2953,33 @@ paths: "422": { $ref: "#/components/responses/Unprocessable" } "503": { $ref: "#/components/responses/ServiceUnavailable" } + /organizations/{id}/billing/checkout-sessions/{session_id}/confirm: + parameters: + - { name: id, in: path, required: true, schema: { type: string } } + - { name: session_id, in: path, required: true, schema: { type: string }, description: "The Checkout Session id from success_url's session_id parameter." } + post: + operationId: billing.confirmOrganizationCheckoutSession + tags: [Billing] + summary: Sync the Organization's subscription from a returning Checkout (org admin, User token) + description: >- + The Organization form of billing.confirmUserCheckoutSession: returns what + GET /organizations/{id}/subscription would, after the sync. + x-substratal-phase: phase2 + parameters: + - $ref: "#/components/parameters/ApiVersion" + responses: + "200": + description: The Organization's plan and subscription, after the sync + headers: + ETag: { $ref: "#/components/headers/ETag" } + content: + application/json: + schema: { $ref: "#/components/schemas/OrganizationSubscription" } + "400": { $ref: "#/components/responses/BadRequest" } + "403": { $ref: "#/components/responses/Forbidden" } + "404": { $ref: "#/components/responses/NotFound" } + "503": { $ref: "#/components/responses/ServiceUnavailable" } + /organizations/{id}/billing/portal-sessions: parameters: - { name: id, in: path, required: true, schema: { type: string } } @@ -2216,7 +2988,7 @@ paths: parameters: - $ref: "#/components/parameters/ApiVersion" tags: [Billing] - summary: Open the Stripe Customer Portal for the Organization's subscription (org admin or billing.manage, User token) + summary: Open the billing portal for the Organization's subscription (org admin or billing.manage, User token) x-substratal-phase: phase2 requestBody: required: true @@ -2247,6 +3019,7 @@ paths: - $ref: "#/components/parameters/ApiVersion" - $ref: "#/components/parameters/Limit" - $ref: "#/components/parameters/Cursor" + - $ref: "#/components/parameters/Include" - { name: target_user_id, in: query, schema: { type: string } } - { name: target_type, in: query, schema: { $ref: "#/components/schemas/AuditTargetType" } } - { name: target_id, in: query, schema: { type: string } } @@ -2260,6 +3033,10 @@ paths: - { name: application_id, in: query, schema: { type: string } } - { name: organization_id, in: query, schema: { type: string } } - { name: tenant_id, in: query, schema: { type: string } } + - name: request_id + in: query + description: "Events written by one request: the X-Request-Id it sent or was given. Exact match." + schema: { type: string, maxLength: 128 } - { name: since, in: query, schema: { type: string, format: date-time } } - { name: until, in: query, schema: { type: string, format: date-time } } responses: @@ -2274,6 +3051,7 @@ paths: application/json: schema: { $ref: "#/components/schemas/AuditEventPage" } "403": { $ref: "#/components/responses/Forbidden" } + "422": { $ref: "#/components/responses/Unprocessable" } /audit-events/{id}: parameters: @@ -2344,6 +3122,78 @@ paths: schema: { $ref: "#/components/schemas/AuditExport" } "404": { $ref: "#/components/responses/NotFound" } + # ───────────────────────────── Usage & stats ───────────────────────────── + + /usage: + get: + operationId: usage.get + tags: [Usage & stats] + summary: Request counts, errors, and latency per day, week, or month + description: >- + From a daily rollup of the request log, refreshed hourly: the current UTC day covers up to + the last complete hour. Buckets are UTC; week is ISO (Monday start); period is the bucket's + first day, so the buckets at either end of the range may be partial. Rows are in the + caller's mode. Platform operations.view sees every row. An app-confined API Key sees only + its own Application's rows, and an Application's owner sees only that Application's rows by + passing application_id; both are forced. Anyone else gets 403. + x-substratal-phase: phase3 + parameters: + - $ref: "#/components/parameters/ApiVersion" + - name: since + in: query + description: "First day included (UTC). Default: 30 days before until." + schema: { type: string, format: date } + - name: until + in: query + description: "First day not included (UTC). Default: tomorrow, so today is included. At most 13 months after since." + schema: { type: string, format: date } + - name: granularity + in: query + schema: { type: string, enum: [day, week, month], default: day } + - name: group_by + in: query + description: "Split rows by these dimensions. Repeat for several. Without it, one row per period." + style: form + explode: true + schema: { type: array, items: { type: string, enum: [application, api_key, operation] } } + - { name: application_id, in: query, schema: { type: string } } + - { name: api_key_id, in: query, schema: { type: string } } + - { name: operation, in: query, description: "An operationId, such as users.list.", schema: { type: string } } + responses: + "400": { $ref: "#/components/responses/BadRequest" } + "200": + description: The usage report + content: + application/json: + schema: { $ref: "#/components/schemas/UsageReport" } + "403": { $ref: "#/components/responses/Forbidden" } + "422": { $ref: "#/components/responses/Unprocessable" } + + /stats: + get: + operationId: stats.get + tags: [Usage & stats] + summary: Current counts for the console's home screen, in one call + description: >- + Live counts, grouped by status, computed at most once a minute per server instance + (generated_at says when). Every known status is present, with 0 when nothing has it. + Counts are in the caller's mode. Platform-wide with operations.view or users.list. With + tenant_id, the counts are that Tenant's only, and its owner may call it too; users, + subscriptions, and organizations are then null, since they don't belong to a Tenant. + x-substratal-phase: phase3 + parameters: + - $ref: "#/components/parameters/ApiVersion" + - { name: tenant_id, in: query, schema: { type: string } } + responses: + "400": { $ref: "#/components/responses/BadRequest" } + "200": + description: The counts + content: + application/json: + schema: { $ref: "#/components/schemas/Stats" } + "403": { $ref: "#/components/responses/Forbidden" } + "404": { $ref: "#/components/responses/NotFound" } + # ───────────────────────────── Webhooks ───────────────────────────── /webhooks: @@ -2356,7 +3206,20 @@ paths: - $ref: "#/components/parameters/ApiVersion" - $ref: "#/components/parameters/Limit" - $ref: "#/components/parameters/Cursor" + - $ref: "#/components/parameters/Include" - { name: application_id, in: query, schema: { type: string } } + - name: status + in: query + description: "Subscriptions in any of these statuses. Repeatable." + style: form + explode: true + schema: { type: array, items: { type: string, enum: [healthy, unhealthy, disabled] }, maxItems: 3 } + - name: scope + in: query + description: >- + "platform" returns only platform-scoped subscriptions. Callers without webhooks.manage see none, so + they get an empty page. Can't be combined with application_id (400 invalid_request). + schema: { type: string, enum: [platform] } responses: "400": { $ref: "#/components/responses/BadRequest" } "200": @@ -2498,8 +3361,10 @@ paths: application/json: schema: type: object + required: [delivery_id, event_id] properties: - delivery_id: { type: string } + delivery_id: { type: string, description: "The new delivery's id (`dlv_…`)." } + event_id: { type: string, description: "The webhook.test event's id (`wev_…`), the envelope's `id`." } /webhooks/{id}/deliveries: parameters: @@ -2513,6 +3378,7 @@ paths: - $ref: "#/components/parameters/ApiVersion" - $ref: "#/components/parameters/Limit" - $ref: "#/components/parameters/Cursor" + - $ref: "#/components/parameters/Include" - { name: event_id, in: query, schema: { type: string } } - { name: status, in: query, schema: { type: string, enum: [pending, succeeded, failed] } } - { name: since, in: query, schema: { type: string, format: date-time } } @@ -2529,6 +3395,59 @@ paths: properties: data: { type: array, items: { $ref: "#/components/schemas/WebhookDelivery" } } + /webhook-deliveries: + get: + operationId: webhooks.listAllDeliveries + tags: [Webhooks] + summary: Delivery attempts across every subscription visible to the caller (30-day log) + description: >- + Scoped like GET /webhooks: webhooks.manage sees every subscription's deliveries, an Application's + owner and its app keys see only that Application's. A caller with no visible subscriptions gets an + empty page. Newest first. + x-substratal-phase: phase2 + parameters: + - $ref: "#/components/parameters/ApiVersion" + - $ref: "#/components/parameters/Limit" + - $ref: "#/components/parameters/Cursor" + - $ref: "#/components/parameters/Include" + - { name: status, in: query, schema: { type: string, enum: [pending, succeeded, failed] } } + - { name: since, in: query, description: "Deliveries created at or after this time.", schema: { type: string, format: date-time } } + - { name: until, in: query, description: "Deliveries created before this time.", schema: { type: string, format: date-time } } + - { name: application_id, in: query, schema: { type: string } } + - { name: subscription_id, in: query, schema: { type: string } } + - { name: event_type, in: query, schema: { $ref: "#/components/schemas/WebhookEvent" } } + responses: + "400": { $ref: "#/components/responses/BadRequest" } + "200": + description: A page of deliveries + content: + application/json: + schema: { $ref: "#/components/schemas/WebhookDeliveryPage" } + "422": { $ref: "#/components/responses/Unprocessable" } + + /webhooks/{id}/deliveries/{deliveryId}: + parameters: + - { name: id, in: path, required: true, schema: { type: string } } + - { name: deliveryId, in: path, required: true, schema: { type: string } } + get: + operationId: webhooks.getDelivery + parameters: + - $ref: "#/components/parameters/ApiVersion" + tags: [Webhooks] + summary: Fetch one delivery attempt (30-day log) + description: >- + Visible to whoever can read GET /webhooks/{id}/deliveries. 404 delivery_not_found when the + delivery isn't on that subscription or is older than the 30-day log. + x-substratal-phase: phase2 + responses: + "400": { $ref: "#/components/responses/BadRequest" } + "200": + description: The delivery + content: + application/json: + schema: { $ref: "#/components/schemas/WebhookDelivery" } + "404": { $ref: "#/components/responses/NotFound" } + /webhooks/{id}/deliveries/{deliveryId}/redeliver: parameters: - { name: id, in: path, required: true, schema: { type: string } } @@ -2547,6 +3466,35 @@ paths: # ───────────────────────────── Notifications ───────────────────────────── + /push-credentials: + get: + operationId: pushCredentials.listAll + tags: [Notifications] + summary: List push credentials across Applications (applications.manage, an owner's own, or an app key's own) + description: >- + applications.manage sees every Application's credentials. A User without it sees only the + credentials of Applications they own (owner_user_id, or an active org_admin of the owning + Organization); owning none is an empty list. An app-scoped key sees only its own Application's + credentials, with no extra permission, the same rows as GET /applications/{id}/push-credentials. + A platform key without applications.manage gets 403. Never returns key material. Newest first. + x-substratal-phase: phase2 + parameters: + - $ref: "#/components/parameters/ApiVersion" + - $ref: "#/components/parameters/Limit" + - $ref: "#/components/parameters/Cursor" + - $ref: "#/components/parameters/Include" + - { name: status, in: query, schema: { type: string, enum: [active, failed, disabled] } } + - { name: provider, in: query, schema: { $ref: "#/components/schemas/PushProvider" } } + responses: + "400": { $ref: "#/components/responses/BadRequest" } + "200": + description: A page of push credentials + content: + application/json: + schema: { $ref: "#/components/schemas/PushCredentialPage" } + "403": { $ref: "#/components/responses/Forbidden" } + "422": { $ref: "#/components/responses/Unprocessable" } + /applications/{id}/push-credentials: parameters: - { name: id, in: path, required: true, schema: { type: string } } @@ -2605,55 +3553,133 @@ paths: operationId: pushCredentials.get parameters: - $ref: "#/components/parameters/ApiVersion" - tags: [Notifications] - summary: Fetch one provider's configuration - x-substratal-phase: phase2 + tags: [Notifications] + summary: Fetch one provider's configuration + x-substratal-phase: phase2 + responses: + "400": { $ref: "#/components/responses/BadRequest" } + "200": + description: The credential + headers: + ETag: { $ref: "#/components/headers/ETag" } + content: + application/json: + schema: { $ref: "#/components/schemas/PushCredential" } + "404": { $ref: "#/components/responses/NotFound" } + patch: + operationId: pushCredentials.update + tags: [Notifications] + summary: Replace key material, change non-secret fields, or re-enable a failed credential (User token only) + description: "Writable fields are the provider's own create fields, plus status (only failed → active). Any change to key material also returns a failed credential to active. The VAPID key pair can't be rotated in place: delete and recreate the web_push credential." + x-substratal-phase: phase2 + parameters: + - $ref: "#/components/parameters/ApiVersion" + - $ref: "#/components/parameters/IfMatch" + requestBody: + required: true + content: + application/json: + schema: { $ref: "#/components/schemas/PushCredentialUpdate" } + responses: + "200": + description: The updated credential + content: + application/json: + schema: { $ref: "#/components/schemas/PushCredential" } + "400": { $ref: "#/components/responses/BadRequest" } + "404": { $ref: "#/components/responses/NotFound" } + "409": { $ref: "#/components/responses/Conflict" } + "422": { $ref: "#/components/responses/Unprocessable" } + delete: + operationId: pushCredentials.delete + parameters: + - $ref: "#/components/parameters/ApiVersion" + tags: [Notifications] + summary: Remove a push provider (User token only) + description: "Pending deliveries to that provider are skipped. Removing web_push deactivates every web_push device of the Application (inactive_reason credential_removed), because browser subscriptions are bound to the VAPID key." + x-substratal-phase: phase2 + x-substratal-destructive: always + responses: + "204": { description: Removed } + "400": { $ref: "#/components/responses/BadRequest" } + "404": { $ref: "#/components/responses/NotFound" } + + /applications/{id}/bff-keys: + parameters: + - { name: id, in: path, required: true, schema: { type: string } } + get: + operationId: bffKeys.list + tags: [Applications] + summary: List a first-party Application's BFF signing keys (applications.manage, the owner, or the app's own key) + description: >- + The Ed25519 public keys the Application's backend (its BFF) signs forwarded client IPs and user agents + with (NFR → Authentication → First-party BFF forwarding). Only public keys are stored, so nothing here + is secret. Revoked keys are listed too, newest first. At most 2 active keys at a time, so the list + isn't paginated. + x-substratal-phase: phase2 + parameters: + - $ref: "#/components/parameters/ApiVersion" responses: "400": { $ref: "#/components/responses/BadRequest" } "200": - description: The credential - headers: - ETag: { $ref: "#/components/headers/ETag" } + description: Every key, active and revoked content: application/json: - schema: { $ref: "#/components/schemas/PushCredential" } + schema: { $ref: "#/components/schemas/BFFKeyList" } "404": { $ref: "#/components/responses/NotFound" } - patch: - operationId: pushCredentials.update - tags: [Notifications] - summary: Replace key material, change non-secret fields, or re-enable a failed credential (User token only) - description: "Writable fields are the provider's own create fields, plus status (only failed → active). Any change to key material also returns a failed credential to active. The VAPID key pair can't be rotated in place: delete and recreate the web_push credential." + post: + operationId: bffKeys.create + tags: [Applications] + summary: Register a BFF signing key for a first-party Application (applications.manage, User token only) + description: >- + Registers the public half of an Ed25519 key pair the Application's backend generated; the private key + never leaves that backend. public_key is the raw 32-byte key in base64url or base64, or a PEM + "PUBLIC KEY" (SPKI) block. Only a first_party Application can have keys (409 + application_not_first_party), and not a retired one (409 application_retired). At most 2 active keys, + to rotate without downtime (409 bff_key_limit_reached); the same public key twice is 409 bff_key_exists. + Writes application.bff_key_added. x-substratal-phase: phase2 + x-substratal-step-up: always parameters: - $ref: "#/components/parameters/ApiVersion" - - $ref: "#/components/parameters/IfMatch" + - $ref: "#/components/parameters/IdempotencyKeyOptional" requestBody: required: true content: application/json: - schema: { $ref: "#/components/schemas/PushCredentialUpdate" } + schema: { $ref: "#/components/schemas/BFFKeyCreate" } responses: - "200": - description: The updated credential + "201": + description: Key registered content: application/json: - schema: { $ref: "#/components/schemas/PushCredential" } + schema: { $ref: "#/components/schemas/BFFKey" } "400": { $ref: "#/components/responses/BadRequest" } + "403": { $ref: "#/components/responses/Forbidden" } "404": { $ref: "#/components/responses/NotFound" } "409": { $ref: "#/components/responses/Conflict" } "422": { $ref: "#/components/responses/Unprocessable" } + + /applications/{id}/bff-keys/{keyId}: + parameters: + - { name: id, in: path, required: true, schema: { type: string } } + - { name: keyId, in: path, required: true, schema: { type: string } } delete: - operationId: pushCredentials.delete - parameters: - - $ref: "#/components/parameters/ApiVersion" - tags: [Notifications] - summary: Remove a push provider (User token only) - description: "Pending deliveries to that provider are skipped. Removing web_push deactivates every web_push device of the Application (inactive_reason credential_removed), because browser subscriptions are bound to the VAPID key." + operationId: bffKeys.revoke + tags: [Applications] + summary: Revoke a BFF signing key (applications.manage, User token only) + description: >- + Forwards signed with the key stop being trusted within a minute on every server. The key stays listed + with revoked_at set. Revoking a revoked key is a no-op 204. Writes application.bff_key_revoked. x-substratal-phase: phase2 x-substratal-destructive: always + x-substratal-step-up: always + parameters: + - $ref: "#/components/parameters/ApiVersion" responses: - "204": { description: Removed } + "204": { description: Revoked } "400": { $ref: "#/components/responses/BadRequest" } + "403": { $ref: "#/components/responses/Forbidden" } "404": { $ref: "#/components/responses/NotFound" } /users/{id}/devices: @@ -2974,9 +4000,11 @@ paths: - $ref: "#/components/parameters/ApiVersion" - $ref: "#/components/parameters/Limit" - $ref: "#/components/parameters/Cursor" + - $ref: "#/components/parameters/Include" - { name: scope, in: query, schema: { type: string } } - { name: mode, in: query, schema: { type: string, enum: [live, test] } } - { name: intended_use, in: query, schema: { type: string, enum: [service, agent] } } + - { name: q, in: query, description: "Case-insensitive prefix match on name", schema: { type: string } } - { name: include_inactive, in: query, description: "Include revoked and expired keys", schema: { type: boolean, default: false } } responses: "400": { $ref: "#/components/responses/BadRequest" } @@ -2992,6 +4020,8 @@ paths: tags: [API Keys] summary: Create a key (api_keys.manage, or the Application's owner for an app-scoped key) x-substratal-phase: mvp + x-substratal-step-up: conditional + x-substratal-step-up-when: "scope is platform" requestBody: required: true content: @@ -3027,10 +4057,12 @@ paths: "404": { $ref: "#/components/responses/NotFound" } patch: operationId: apiKeys.update + x-substratal-step-up: conditional + x-substratal-step-up-when: "rate_limit_per_minute is sent" parameters: - $ref: "#/components/parameters/ApiVersion" tags: [API Keys] - summary: Change name, permissions, or restrict_destructive + summary: Change name, permissions, restrict_destructive, or rate_limit_per_minute (api_keys.manage only) x-substratal-phase: mvp x-substratal-destructive: conditional x-substratal-destructive-when: "restrict_destructive set to false" @@ -3044,6 +4076,11 @@ paths: name: { type: string, maxLength: 100 } permissions: { type: array, items: { type: string } } restrict_destructive: { type: boolean } + rate_limit_per_minute: + type: [integer, "null"] + minimum: 1 + maximum: 10000 + description: Platform api_keys.manage only (403 forbidden otherwise). Null restores the platform default. responses: "400": { $ref: "#/components/responses/BadRequest" } "200": @@ -3086,6 +4123,79 @@ paths: schema: { $ref: "#/components/schemas/ApiKeyWithSecret" } "404": { $ref: "#/components/responses/NotFound" } + # ───────────────────────────── Platform ───────────────────────────── + + /platform/settings: + get: + operationId: platform.getSettings + tags: [Platform] + summary: Read the platform's runtime switches and client feature flags + description: >- + Authentication is optional. Without a Bearer token: signup_open and + announcement, for live mode, or for test mode with test_mode=true. + With one: the caller's own mode, plus client_flags. With + operations.view, also read_only and updated_at, read fresh; everyone + else may get a copy up to 30 seconds old. ETag is the row's version. + security: + - {} + - bearerAuth: [] + x-substratal-phase: phase3 + parameters: + - $ref: "#/components/parameters/ApiVersion" + - name: test_mode + in: query + required: false + description: "Unauthenticated callers only: read test mode's settings. An authenticated caller always reads its own mode." + schema: { type: boolean, default: false } + responses: + "400": { $ref: "#/components/responses/BadRequest" } + "200": + description: The settings visible to this caller + headers: + ETag: { $ref: "#/components/headers/ETag" } + content: + application/json: + schema: { $ref: "#/components/schemas/PlatformSettings" } + "401": { $ref: "#/components/responses/Unauthorized" } + "429": { $ref: "#/components/responses/TooManyRequests" } + patch: + operationId: platform.updateSettings + tags: [Platform] + summary: Change the platform's runtime switches and client feature flags (operations.manage) + description: >- + Changes the settings of the caller's mode. If-Match is required (400 + if_match_required without it). client_flags is merged one level deep, + and a flag sent as null is removed. announcement is replaced, and null + clears it. Writes platform.settings_updated with before and after. + Other API instances pick the change up within 30 seconds. It stays + callable while read_only is on, so the freeze can always be lifted. + x-substratal-phase: phase3 + x-substratal-step-up: always + parameters: + - $ref: "#/components/parameters/ApiVersion" + - name: If-Match + in: header + required: true + description: The ETag from a prior read. Missing is 400 if_match_required; a mismatch is 409 version_conflict. + schema: { type: string } + requestBody: + required: true + content: + application/json: + schema: { $ref: "#/components/schemas/PlatformSettingsWrite" } + responses: + "400": { $ref: "#/components/responses/BadRequest" } + "200": + description: The updated settings, as an operations.view caller sees them + headers: + ETag: { $ref: "#/components/headers/ETag" } + content: + application/json: + schema: { $ref: "#/components/schemas/PlatformSettings" } + "403": { $ref: "#/components/responses/Forbidden" } + "409": { $ref: "#/components/responses/Conflict" } + "422": { $ref: "#/components/responses/Unprocessable" } + components: securitySchemes: bearerAuth: @@ -3120,6 +4230,14 @@ components: name: cursor in: query schema: { type: string } + Include: + name: include + in: query + description: >- + `total` adds `page.total` and `page.total_capped`: the number of rows + matching the current filters across every page, counted up to 10,000 + (Conventions → Pagination). Omitted unless requested. + schema: { type: string, enum: [total] } IdempotencyKey: name: Idempotency-Key in: header @@ -3161,7 +4279,7 @@ components: application/json: schema: { $ref: "#/components/schemas/Error" } Forbidden: - description: "Authenticated but not permitted (forbidden, destructive_operation_restricted, entitlement_required, role_escalation_forbidden, …)" + description: "Authenticated but not permitted (forbidden, destructive_operation_restricted, entitlement_required, role_escalation_forbidden, mfa_enrollment_required, reauthentication_required, …)" content: application/json: schema: { $ref: "#/components/schemas/Error" } @@ -3219,6 +4337,46 @@ components: code: { type: string } additionalProperties: true + BulkItemError: + type: object + description: The error object the single call would have returned, without the outer error envelope. + required: [code, message] + properties: + code: { type: string, example: user_protected } + message: { type: string } + details: { type: object, additionalProperties: true } + + BulkResults: + type: object + description: One result per requested item, in request order (Conventions → Bulk operations). + required: [results] + properties: + results: + type: array + items: + type: object + required: [id, status] + properties: + id: { type: string, description: The item's id, as sent } + status: { type: integer, description: "The status the single call would have returned: 200 on success, otherwise the error's 4xx or 500" } + error: { $ref: "#/components/schemas/BulkItemError" } + + BulkInviteResults: + type: object + description: One result per requested email, in request order (Conventions → Bulk operations). + required: [results] + properties: + results: + type: array + items: + type: object + required: [email, status] + properties: + email: { type: string, description: The email, as sent } + status: { type: integer, description: "The status POST /users would have returned: 201 on success, otherwise the error's 4xx or 500" } + user_id: { type: string, description: The new User's id. Present only on 201. } + error: { $ref: "#/components/schemas/BulkItemError" } + OAuthError: type: object required: [error] @@ -3232,6 +4390,16 @@ components: properties: next_cursor: { type: [string, "null"] } has_more: { type: boolean } + total: + type: integer + minimum: 0 + maximum: 10000 + description: >- + Only with `include=total`. Rows matching the current filters across + every page, ignoring `cursor`; 10000 when capped. + total_capped: + type: boolean + description: Only with `include=total`. True when there are more than 10,000 matching rows. PageEnvelope: type: object @@ -3264,13 +4432,132 @@ components: user_id: { type: string } email_verified: { type: boolean } + Reauthentication: + type: object + required: [token_type, access_token, expires_in, mfa_verified_at] + properties: + token_type: { type: string, enum: [Bearer] } + access_token: { type: string, description: "A new platform access token for the same session, carrying the updated mfa_verified_at claim." } + expires_in: { type: integer, example: 900 } + mfa_verified_at: { type: string, format: date-time, description: "When this session last proved a second factor: now." } + + PasskeyCreationOptions: + type: object + required: [publicKey, expires_in] + properties: + publicKey: + type: object + description: >- + PublicKeyCredentialCreationOptions in their JSON form (binary + values base64url), ready for + PublicKeyCredential.parseCreationOptionsFromJSON(). + required: [rp, user, challenge] + properties: + rp: { type: object, properties: { id: { type: string, example: substratalapps.com }, name: { type: string, example: Substratal } } } + user: { type: object, properties: { id: { type: string }, name: { type: string }, displayName: { type: string } } } + challenge: { type: string } + pubKeyCredParams: { type: array, items: { type: object } } + timeout: { type: integer } + excludeCredentials: { type: array, items: { type: object } } + authenticatorSelection: { type: object } + attestation: { type: string } + expires_in: { type: integer, example: 300, description: "Seconds the challenge stays valid." } + + PasskeyRequestOptions: + type: object + required: [publicKey, expires_in] + properties: + publicKey: + type: object + description: >- + PublicKeyCredentialRequestOptions in their JSON form, ready for + PublicKeyCredential.parseRequestOptionsFromJSON(). + required: [challenge] + properties: + challenge: { type: string } + timeout: { type: integer } + rpId: { type: string, example: substratalapps.com } + allowCredentials: { type: array, items: { type: object } } + userVerification: { type: string } + expires_in: { type: integer, example: 300 } + + PasskeyAttestation: + type: object + description: "The PublicKeyCredential from navigator.credentials.create(), as JSON (toJSON())." + required: [id, rawId, type, response] + properties: + id: { type: string } + rawId: { type: string } + type: { type: string, enum: [public-key] } + response: + type: object + required: [clientDataJSON, attestationObject] + properties: + clientDataJSON: { type: string } + attestationObject: { type: string } + transports: { type: array, items: { type: string } } + authenticatorAttachment: { type: string } + clientExtensionResults: { type: object } + + PasskeyAssertion: + type: object + description: "The PublicKeyCredential from navigator.credentials.get(), as JSON (toJSON())." + required: [id, rawId, type, response] + properties: + id: { type: string } + rawId: { type: string } + type: { type: string, enum: [public-key] } + response: + type: object + required: [clientDataJSON, authenticatorData, signature] + properties: + clientDataJSON: { type: string } + authenticatorData: { type: string } + signature: { type: string } + userHandle: { type: [string, "null"] } + authenticatorAttachment: { type: string } + clientExtensionResults: { type: object } + + Passkey: + type: object + description: "A registered passkey. Never includes the credential id or public key." + required: [id, name, transports, backup_eligible, backup_state, created_at, last_used_at] + properties: + id: { type: string, example: wac_01JAG8M2N3P4Q5R6S7T8U9V0W1 } + name: { type: string, maxLength: 64 } + aaguid: { type: [string, "null"], description: "The authenticator model (a UUID), when it reported one." } + transports: { type: array, items: { type: string } } + backup_eligible: { type: boolean, description: "A synced passkey (it can be backed up)." } + backup_state: { type: boolean, description: "Currently backed up." } + created_at: { type: string, format: date-time } + last_used_at: { type: [string, "null"], format: date-time } + + PasskeyList: + type: object + required: [data] + properties: + data: { type: array, maxItems: 10, items: { $ref: "#/components/schemas/Passkey" } } + + PasskeyRegistration: + type: object + required: [passkey, mfa_enabled] + properties: + passkey: { $ref: "#/components/schemas/Passkey" } + mfa_enabled: { type: boolean, const: true } + recovery_codes: + type: array + items: { type: string } + minItems: 10 + maxItems: 10 + description: "Only when this passkey is the User's first MFA method. Shown once." + MfaChallenge: type: object required: [mfa_required, mfa_token, methods, expires_in] properties: mfa_required: { type: boolean, const: true } mfa_token: { type: string } - methods: { type: array, items: { type: string, enum: [totp, recovery_code] } } + methods: { type: array, items: { type: string, enum: [totp, passkey, recovery_code] }, description: "The second factors this User can complete the challenge with: totp when TOTP is on, passkey when they have a passkey, and always recovery_code." } expires_in: { type: integer, example: 300 } AppToken: @@ -3295,6 +4582,13 @@ components: email_verified: { type: boolean } entitlement_status: { $ref: "#/components/schemas/ResolvedEntitlementStatus" } effective_permissions: { type: array, items: { type: string } } + plan: + type: string + description: >- + The User's platform plan when the token was issued, by the same rule as `User.plan` (an Organization's + Standard subscription counts for the members its `member_scope` includes). Always present. Currently + `free` or `standard`; more values may be added later, so treat a missing or unknown value as `free`. + The way a free-tier Application gates paid features. test_mode: { type: boolean } iat: { type: integer } exp: { type: integer } @@ -3336,7 +4630,8 @@ components: email_verified: { type: boolean } pending_email: { type: [string, "null"], format: email } status: { $ref: "#/components/schemas/UserStatus" } - mfa_enabled: { type: boolean } + mfa_enabled: { type: boolean, description: "TOTP confirmed, or at least one passkey (Auth → MFA)." } + mfa_enrollment_required: { type: boolean, description: "Staff (holding a platform Role that grants a permission) without MFA, neither TOTP nor a passkey. Once staff MFA is enforced, their sessions can only enroll, read themselves, change password, and log out (Auth → Staff MFA)." } signup_application_id: { type: [string, "null"] } test_mode: { type: boolean } created_at: { type: string, format: date-time } @@ -3378,6 +4673,10 @@ components: method: { type: string, enum: [password, sso] } mfa_enabled: { type: boolean } last_used_at: { type: [string, "null"], format: date-time } + passkeys: + type: array + description: "Passkey metadata. Never includes the credential id or public key." + items: { $ref: "#/components/schemas/Passkey" } sessions: { type: array, items: { $ref: "#/components/schemas/Session" } } organizations: type: array @@ -3431,6 +4730,31 @@ components: locale: { type: string, readOnly: true, example: en-US, description: "Mirror of the global Settings locale; write it there." } updated_at: { type: string, format: date-time } + ImageUploadRequest: + type: object + required: [content_type, content_length] + properties: + content_type: { type: string, enum: [image/png, image/jpeg, image/webp] } + content_length: { type: integer, minimum: 1, description: "The file's size in bytes. At most 2097152 for an avatar, 1048576 for an icon." } + + ImageUpload: + type: object + required: [id, url, fields, content_type, max_bytes, expires_at] + description: >- + A presigned POST. Send multipart/form-data to url with every entry of fields, then the + file as the last field, named file. The upload is accepted only with that content_type and + at most max_bytes, until expires_at. + properties: + id: { type: string, description: "The upload id (upl_…) to complete." } + url: { type: string, description: "Where to POST the form." } + fields: + type: object + additionalProperties: { type: string } + description: "Form fields to send unchanged, including key, Content-Type, policy, and signature." + content_type: { type: string, enum: [image/png, image/jpeg, image/webp] } + max_bytes: { type: integer } + expires_at: { type: string, format: date-time } + AppProfile: type: object properties: @@ -3479,7 +4803,7 @@ components: ApplicationReviewStatus: type: string - enum: [approved, pending_review, rejected, suspended] + enum: [approved, pending_review, rejected, suspended, retired] ApplicationPermission: type: object @@ -3490,11 +4814,19 @@ components: ApplicationAccessTier: type: string - enum: [free, standard] - description: "Which plan unlocks the Application: free for every User, standard for Users covered by a Standard subscription. Set by applications.manage; defaults to standard." + enum: [free, standard, restricted] + description: >- + Who gets in without a grant. free: every User. standard: Users covered by a Standard + subscription; first_party (Substratal's own) Applications only. restricted: only the people + the developer grants Entitlements to, from their own billing or none. A first-party + Application defaults to standard and only applications.manage changes its tier. Any other + Application defaults to restricted, and its owner chooses free or restricted while it's + approved or pending_review (409 application_not_available otherwise, at most 10 changes a + day). standard on one that isn't first-party is 422 access_tier_reserved. ApplicationSummary: type: object + required: [id, slug, name, description, icon_url, visibility, access_tier, review_status, review_requested_at, owner_user_id, owner_organization_id, holder_count] properties: id: { type: string } slug: { type: string } @@ -3504,6 +4836,10 @@ components: visibility: { $ref: "#/components/schemas/ApplicationVisibility" } access_tier: { $ref: "#/components/schemas/ApplicationAccessTier" } review_status: { $ref: "#/components/schemas/ApplicationReviewStatus" } + review_requested_at: { type: [string, "null"], format: date-time, readOnly: true, description: "When the Application last entered pending_review. See Application." } + owner_user_id: { type: [string, "null"] } + owner_organization_id: { type: [string, "null"] } + holder_count: { type: integer, minimum: 0, description: "Active Entitlements for the Application; a User grant and an Organization grant count once each" } ApplicationSummaryPage: allOf: @@ -3529,6 +4865,7 @@ components: default_app_role: { type: [string, "null"] } visibility: { $ref: "#/components/schemas/ApplicationVisibility" } access_tier: { $ref: "#/components/schemas/ApplicationAccessTier" } + first_party: { type: boolean, default: false, description: "Substratal's own Application. Only applications.manage sets it, and only a first-party Application can be access_tier standard. Staff-created customer Applications (concierge onboarding) aren't first-party." } owner_user_id: { type: [string, "null"] } owner_organization_id: { type: [string, "null"] } review_status: { $ref: "#/components/schemas/ApplicationReviewStatus" } @@ -3548,6 +4885,7 @@ components: properties: stale_override_counts: { type: object, additionalProperties: { type: integer } } self_registered: { type: boolean, readOnly: true, description: "true when a developer submitted it themselves, not staff. A self-registered Application must use the hosted sign-in flow (POST /auth/app-tokens returns 403 embedded_login_not_allowed), and only applications.manage can turn on receives_platform_notifications for it." } + review_requested_at: { type: [string, "null"], format: date-time, readOnly: true, description: "When the Application last entered pending_review. See Application." } test_mode: { type: boolean } created_at: { type: string, format: date-time } updated_at: { type: string, format: date-time } @@ -3658,6 +4996,7 @@ components: assigned_at: { type: [string, "null"], format: date-time } assigned_by: { oneOf: [ { $ref: "#/components/schemas/Actor" }, { type: "null" } ] } implicit: { type: boolean } + mfa_enrollment_required: { type: boolean, description: "On POST /users/{id}/roles/{roleId} only: the User is now staff but has no MFA (neither TOTP nor a passkey), so their platform Roles take effect once they enroll (Auth → Staff MFA)." } UserRoleAssignmentPage: allOf: @@ -3668,7 +5007,7 @@ components: EffectivePermissions: type: object - required: [user_id, application_id, allowed, user_status, entitlement_status, effective_permissions] + required: [user_id, application_id, allowed, user_status, entitlement_status, effective_permissions, plan] properties: user_id: { type: string } application_id: { type: string } @@ -3687,6 +5026,11 @@ components: member_decision: { type: [string, "null"], enum: [included, excluded, null] } roles: { type: array, items: { type: string } } effective_permissions: { type: array, items: { type: string } } + plan: + type: string + description: >- + The User's platform plan at `computed_at`, the same value an app token issued at that moment carries in + its `plan` claim. Currently `free` or `standard`; more values may be added later. computed_at: { type: string, format: date-time } # ── Organizations ── @@ -3753,7 +5097,7 @@ components: SubscriptionStatus: type: string enum: [active, trialing, past_due, canceled, unpaid, incomplete, incomplete_expired, paused] - description: "Mirrors Stripe. active, trialing, and past_due cover their users with Standard; the rest don't." + description: "Mirrors the payment processor. active, trialing, and past_due cover their users with Standard; the rest don't." Tenant: type: object @@ -3838,12 +5182,28 @@ components: current: { type: integer } last_synced: { type: [integer, "null"] } last_synced_at: { type: [string, "null"], format: date-time } - unit_amount: { type: integer, description: "Cents per user per month (600)." } + interval: { $ref: "#/components/schemas/BillingInterval" } + unit_amount: { type: integer, description: "The subscribed price, in cents per user per interval." } currency: { type: string, const: usd } test_mode: { type: boolean } created_at: { type: string, format: date-time } updated_at: { type: string, format: date-time } + SubscriptionListItem: + allOf: + - $ref: "#/components/schemas/Subscription" + - type: object + properties: + user_email: { type: [string, "null"], format: email, description: "Individual subscriptions: the User's email, for display." } + organization_name: { type: [string, "null"], description: "Organization subscriptions: the Organization's name, for display." } + + SubscriptionPage: + allOf: + - $ref: "#/components/schemas/PageEnvelope" + - type: object + properties: + data: { type: array, items: { $ref: "#/components/schemas/SubscriptionListItem" } } + UserSubscription: type: object properties: @@ -3859,11 +5219,23 @@ components: plan: { $ref: "#/components/schemas/Plan" } subscription: { oneOf: [ { $ref: "#/components/schemas/Subscription" }, { type: "null" } ] } + BillingInterval: { type: string, enum: [month, year] } + + PlanPrice: + type: object + required: [plan, interval, unit_amount, currency] + properties: + plan: { type: string, enum: [standard] } + interval: { $ref: "#/components/schemas/BillingInterval" } + unit_amount: { type: integer, description: "Cents per user per interval." } + currency: { type: string, const: usd } + CheckoutSessionCreate: type: object required: [plan, success_url, cancel_url] properties: plan: { type: string, enum: [standard, business, enterprise], description: "Only standard is self-service; business and enterprise return 422 plan_requires_sales." } + interval: { $ref: "#/components/schemas/BillingInterval", description: "How often Standard is billed. Default month." } success_url: { type: string, format: uri } cancel_url: { type: string, format: uri } @@ -3901,6 +5273,10 @@ components: - user.mfa_reset - user.sessions_revoked - audit.exported + - application.retired + - application.deleted + - profile.avatar_changed + - application.icon_changed - entitlement.granted - entitlement.disabled - entitlement.revoked @@ -3945,10 +5321,59 @@ components: - push_credential.updated - push_credential.deleted - device.deleted + - platform.settings_updated + - user.passkey_added + - user.passkey_removed + - application.bff_key_added + - application.bff_key_revoked AuditTargetType: type: string - enum: [user, entitlement, role, role_assignment, application, organization, subscription, tenant, tier_change_request, api_key, webhook, push_credential, device, audit_export] + enum: [user, entitlement, role, role_assignment, application, organization, subscription, tenant, tier_change_request, api_key, webhook, push_credential, device, audit_export, platform_settings] + + PlatformAnnouncement: + type: object + required: [text, level] + additionalProperties: false + properties: + text: { type: string, minLength: 1, maxLength: 500 } + level: { type: string, enum: [info, warning, critical] } + + PlatformSettings: + type: object + description: >- + signup_open and announcement are always present. client_flags needs + an authenticated caller; read_only and updated_at need + operations.view. + required: [signup_open, announcement] + properties: + signup_open: { type: boolean, description: "false closes POST /auth/signup (403 signup_closed). Invitations still work." } + announcement: + description: A banner for clients to show, or null. + oneOf: + - $ref: "#/components/schemas/PlatformAnnouncement" + - type: "null" + client_flags: + type: object + description: Remote-configurable client feature flags, flag name to boolean. At most 100. + additionalProperties: { type: boolean } + read_only: { type: boolean, description: "true answers every non-GET from a caller without superadmin with 503 service_unavailable and Retry-After: 300. Sign-in, refresh, logout, session revocation, and token issuance stay open." } + updated_at: { type: string, format: date-time } + + PlatformSettingsWrite: + type: object + properties: + signup_open: { type: boolean } + read_only: { type: boolean } + client_flags: + type: object + description: "Merged one level deep: each flag sent replaces that flag, and a flag sent as null is removed. Names match ^[a-z][a-z0-9_]{0,63}$; at most 100 after the merge." + additionalProperties: { type: [boolean, "null"] } + announcement: + description: Replaces the announcement; null clears it. + oneOf: + - $ref: "#/components/schemas/PlatformAnnouncement" + - type: "null" AuditExportRequest: type: object @@ -3964,6 +5389,7 @@ components: application_id: { type: string } organization_id: { type: string } tenant_id: { type: string } + request_id: { type: string, maxLength: 128 } since: { type: string, format: date-time } until: { type: string, format: date-time } @@ -3983,6 +5409,119 @@ components: expires_at: { type: string, format: date-time, description: "When the file and this record are deleted: 7 days after the request." } test_mode: { type: boolean } + UsageReport: + type: object + required: [since, until, granularity, group_by, data] + properties: + since: { type: string, format: date } + until: { type: string, format: date } + granularity: { type: string, enum: [day, week, month] } + group_by: { type: array, items: { type: string, enum: [application, api_key, operation] } } + data: + type: array + description: "Oldest period first, then by the grouped dimensions. Periods and groups with no requests are omitted." + items: { $ref: "#/components/schemas/UsageRow" } + + UsageRow: + type: object + required: [period, requests, errors_4xx, errors_5xx, latency_ms_avg, latency_ms_max] + properties: + period: { type: string, format: date, description: "The bucket's first day (UTC)." } + application_id: { type: [string, "null"], description: "Only with group_by=application. null for requests that didn't resolve to exactly one Application." } + api_key_id: { type: [string, "null"], description: "Only with group_by=api_key. null for requests made without an API Key." } + operation: { type: string, description: "Only with group_by=operation. The operationId." } + requests: { type: integer } + errors_4xx: { type: integer } + errors_5xx: { type: integer } + latency_ms_avg: { type: integer, description: "Mean latency, rounded to the millisecond." } + latency_ms_max: { type: integer } + + Stats: + type: object + required: [tenant_id, generated_at, users, applications, entitlements, subscriptions, organizations, + webhook_subscriptions, push_credentials, tier_change_requests] + properties: + tenant_id: { type: [string, "null"], description: "The Tenant the counts are confined to, or null for platform-wide." } + generated_at: { type: string, format: date-time, description: "When these counts were computed. At most a minute old." } + users: + description: "Users by status. null when tenant_id is set." + oneOf: + - type: "null" + - type: object + required: [active, invited, suspended, deleted] + properties: + active: { type: integer } + invited: { type: integer } + suspended: { type: integer } + deleted: { type: integer } + applications: + type: object + required: [by_review_status, by_access_tier] + properties: + by_review_status: + type: object + required: [approved, pending_review, rejected, suspended, retired] + properties: + approved: { type: integer } + pending_review: { type: integer } + rejected: { type: integer } + suspended: { type: integer } + retired: { type: integer } + by_access_tier: + type: object + required: [free, standard] + properties: + free: { type: integer } + standard: { type: integer } + entitlements: + type: object + description: Entitlements by status. + required: [active, disabled, expired, revoked] + properties: + active: { type: integer } + disabled: { type: integer } + expired: { type: integer } + revoked: { type: integer } + subscriptions: + description: "Covering subscriptions (active, trialing, or past_due) by subscriber type. null when tenant_id is set." + oneOf: + - type: "null" + - type: object + required: [user, organization] + properties: + user: { type: integer } + organization: { type: integer } + organizations: + description: "Organizations by status. null when tenant_id is set." + oneOf: + - type: "null" + - type: object + required: [active, suspended] + properties: + active: { type: integer } + suspended: { type: integer } + webhook_subscriptions: + type: object + description: Webhook subscriptions by status. + required: [healthy, unhealthy, disabled] + properties: + healthy: { type: integer } + unhealthy: { type: integer } + disabled: { type: integer } + push_credentials: + type: object + description: Applications' push credentials by status. + required: [active, failed, disabled] + properties: + active: { type: integer } + failed: { type: integer } + disabled: { type: integer } + tier_change_requests: + type: object + required: [open] + properties: + open: { type: integer, description: "Requests that are pending, scheduled, or in_progress." } + ScimToken: type: object properties: @@ -4037,10 +5576,12 @@ components: - entitlement.deleted - role.assigned - role.removed + - user.updated - user.suspended - user.reactivated - user.deleted - user.expired + - profile.updated - organization.member_added - organization.member_removed - application.review_status_changed @@ -4069,6 +5610,7 @@ components: - user_deleted - test_user_expired - test_user_extended + - application_retired WebhookEventEnvelope: type: object @@ -4127,6 +5669,21 @@ components: next_retry_at: { type: [string, "null"], format: date-time } created_at: { type: string, format: date-time } + WebhookDeliveryListItem: + allOf: + - $ref: "#/components/schemas/WebhookDelivery" + - type: object + properties: + subscription_id: { type: string } + scope: { type: string, description: "The subscription's scope: an application_id, or 'platform'." } + + WebhookDeliveryPage: + allOf: + - $ref: "#/components/schemas/PageEnvelope" + - type: object + properties: + data: { type: array, items: { $ref: "#/components/schemas/WebhookDeliveryListItem" } } + # ── Notifications ── PushProvider: type: string @@ -4163,7 +5720,7 @@ components: id: { type: string, description: "pcr_…" } application_id: { type: string } provider: { $ref: "#/components/schemas/PushProvider" } - status: { type: string, enum: [active, failed] } + status: { type: string, enum: [active, failed, disabled], description: "disabled: the Application was retired." } team_id: { type: string, description: "apns" } key_id: { type: string, description: "apns" } topic: { type: string, description: "apns" } @@ -4177,19 +5734,52 @@ components: created_at: { type: string, format: date-time } updated_at: { type: string, format: date-time } + BFFKey: + type: object + required: [id, application_id, name, public_key, created_at, last_used_at, revoked_at] + properties: + id: { type: string, description: "bfk_…, sent as X-Substratal-BFF-Key" } + application_id: { type: string } + name: { type: string } + public_key: { type: string, description: "The Ed25519 public key, 32 bytes, base64url without padding" } + created_at: { type: string, format: date-time } + last_used_at: { type: [string, "null"], format: date-time, description: "Updated at most every 5 minutes" } + revoked_at: { type: [string, "null"], format: date-time } + + BFFKeyCreate: + type: object + required: [name, public_key] + additionalProperties: false + properties: + name: { type: string, minLength: 1, maxLength: 64 } + public_key: { type: string, maxLength: 1024, description: "Raw 32-byte Ed25519 key (base64url or base64), or a PEM PUBLIC KEY block" } + + BFFKeyList: + type: object + required: [data] + properties: + data: { type: array, items: { $ref: "#/components/schemas/BFFKey" } } + PushCredentialList: type: object required: [data] properties: data: { type: array, maxItems: 3, items: { $ref: "#/components/schemas/PushCredential" } } + PushCredentialPage: + allOf: + - $ref: "#/components/schemas/PageEnvelope" + - type: object + properties: + data: { type: array, items: { $ref: "#/components/schemas/PushCredential" } } + DeviceStatus: type: string enum: [active, inactive] DeviceInactiveReason: type: string - enum: [unregistered, session_revoked, user_suspended, user_deleted, test_user_expired, stale, limit, credential_removed] + enum: [unregistered, session_revoked, user_suspended, user_deleted, test_user_expired, stale, limit, credential_removed, application_retired] WebPushSubscription: type: object @@ -4413,6 +6003,15 @@ components: type: boolean description: "When true, every operation marked x-substratal-destructive is rejected with 403 destructive_operation_restricted." expires_at: { type: [string, "null"], format: date-time } + rate_limit_per_minute: + type: [integer, "null"] + minimum: 1 + maximum: 10000 + description: >- + Replaces the default 100 requests/minute for this key. Null (the + default) means the platform default. Operations with their own + ceiling keep it. Only platform api_keys.manage may send it; anyone + else gets 403 forbidden. ApiKey: allOf: