{
  "openapi": "3.1.0",
  "info": {
    "title": "ShiftForest reviewed login recovery RPC API",
    "version": "1.0.0",
    "description": "Human-session account recovery. These RPC endpoints are hosted by the configured Supabase project, not the v1/v2 API-key gateway. Workspace headers scope administrator calls. Recipient calls use the actual Auth subject. No automatic sending; share the resulting app /account/login-recovery?recovery=UUID link through a verified channel. Owners must transfer ownership first; enterprise users use their IdP; an account already bound to another worker in this workspace cannot accept. Personal creator-bound keys, PIN, owned terminals, push subscriptions and pending staff deliveries are revoked; independent integration principals and unrelated workspaces are preserved. A verified replacement account must exist before acceptance."
  },
  "servers": [
    {
      "url": "https://{project}.supabase.co",
      "variables": {
        "project": {
          "default": "YOUR_PROJECT_REF"
        }
      }
    }
  ],
  "security": [
    {
      "publishableKey": [],
      "userSession": []
    }
  ],
  "components": {
    "securitySchemes": {
      "publishableKey": {
        "type": "apiKey",
        "in": "header",
        "name": "apikey"
      },
      "userSession": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "Supabase user access token"
      }
    }
  },
  "paths": {
    "/rest/v1/rpc/get_member_login_recovery_context": {
      "post": {
        "operationId": "get_member_login_recovery_context",
        "description": "Review a bound worker and replacement email. Administrator human session required.",
        "parameters": [
          {
            "name": "X-ShiftForest-Workspace",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Selected workspace for administrator calls. Does not grant authority."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "p_user": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "p_email": {
                    "type": "string",
                    "format": "email",
                    "maxLength": 254
                  }
                },
                "required": [
                  "p_user",
                  "p_email"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful RPC result; cancellation returns null.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "user_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "name": {
                      "type": "string"
                    },
                    "role": {
                      "type": "string",
                      "enum": [
                        "admin",
                        "manager",
                        "employee"
                      ]
                    },
                    "login_enabled": {
                      "type": "boolean"
                    },
                    "replacement_email": {
                      "type": "string",
                      "format": "email"
                    },
                    "revision": {
                      "type": "integer"
                    },
                    "pending": {
                      "oneOf": [
                        {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "string",
                              "format": "uuid"
                            },
                            "state": {
                              "const": "pending"
                            },
                            "expires_at": {
                              "type": "string",
                              "format": "date-time"
                            },
                            "replacement_email": {
                              "type": "string",
                              "format": "email"
                            }
                          },
                          "required": [
                            "id",
                            "state",
                            "expires_at",
                            "replacement_email"
                          ]
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "access": {
                      "type": "object",
                      "properties": {
                        "active_keys": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "enabled_terminals": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "open_attendance": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "future_shifts": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "pending_requests": {
                          "type": "integer",
                          "minimum": 0
                        }
                      }
                    },
                    "review_token": {
                      "type": "string",
                      "pattern": "^[a-f0-9]{64}$"
                    }
                  },
                  "required": [
                    "user_id",
                    "name",
                    "role",
                    "login_enabled",
                    "replacement_email",
                    "revision",
                    "pending",
                    "access",
                    "review_token"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "401": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "403": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "409": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "429": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "503": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "404": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          }
        }
      }
    },
    "/rest/v1/rpc/request_member_login_recovery_checked": {
      "post": {
        "operationId": "request_member_login_recovery_checked",
        "description": "Suspend old workspace login and create a 24-hour offer. Administrator with recent MFA. Retain identical command ID, payload and review token for an ambiguous retry; changed commands conflict. No email is sent.",
        "parameters": [
          {
            "name": "X-ShiftForest-Workspace",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Selected workspace for administrator calls. Does not grant authority."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "p_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "p_user": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "p_email": {
                    "type": "string",
                    "format": "email",
                    "maxLength": 254
                  },
                  "p_review_token": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$"
                  },
                  "p_reason": {
                    "type": "string",
                    "minLength": 10,
                    "maxLength": 1000
                  }
                },
                "required": [
                  "p_id",
                  "p_user",
                  "p_email",
                  "p_review_token",
                  "p_reason"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful RPC result; cancellation returns null.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "state": {
                      "type": "string",
                      "enum": [
                        "pending",
                        "accepted",
                        "cancelled"
                      ]
                    },
                    "expires_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  },
                  "required": [
                    "id",
                    "state",
                    "expires_at"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "401": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "403": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "409": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "429": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "503": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "404": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          }
        }
      }
    },
    "/rest/v1/rpc/cancel_member_login_recovery_checked": {
      "post": {
        "operationId": "cancel_member_login_recovery_checked",
        "description": "Cancel a pending offer. Administrator with recent MFA; cancellation never restores login or credentials.",
        "parameters": [
          {
            "name": "X-ShiftForest-Workspace",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Selected workspace for administrator calls. Does not grant authority."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "p_id": {
                    "type": "string",
                    "format": "uuid"
                  }
                },
                "required": [
                  "p_id"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful RPC result; cancellation returns null.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "null"
                }
              }
            }
          },
          "400": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "401": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "403": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "409": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "429": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "503": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "404": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          }
        }
      }
    },
    "/rest/v1/rpc/get_my_member_login_recovery": {
      "post": {
        "operationId": "get_my_member_login_recovery",
        "description": "Preview only an offer for this available, verified replacement Auth account. Returns null when unavailable, or accepted=true for an already accepted current binding.",
        "parameters": [
          {
            "name": "X-ShiftForest-Workspace",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Selected workspace for administrator calls. Does not grant authority."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "p_id": {
                    "type": "string",
                    "format": "uuid"
                  }
                },
                "required": [
                  "p_id"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful RPC result; cancellation returns null.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "company_id": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "company_name": {
                          "type": "string"
                        },
                        "member_name": {
                          "type": "string"
                        },
                        "role": {
                          "type": "string",
                          "enum": [
                            "admin",
                            "manager",
                            "employee"
                          ]
                        },
                        "expires_at": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "revision": {
                          "type": "integer"
                        }
                      },
                      "required": [
                        "id",
                        "company_id",
                        "company_name",
                        "member_name",
                        "role",
                        "expires_at",
                        "revision"
                      ]
                    },
                    {
                      "type": "object",
                      "properties": {
                        "accepted": {
                          "const": true
                        },
                        "company_id": {
                          "type": "string",
                          "format": "uuid"
                        }
                      },
                      "required": [
                        "accepted",
                        "company_id"
                      ]
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "401": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "403": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "409": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "429": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "503": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "404": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          }
        }
      }
    },
    "/rest/v1/rpc/accept_member_login_recovery_checked": {
      "post": {
        "operationId": "accept_member_login_recovery_checked",
        "description": "Explicit recipient acceptance. Rechecks verified email, current issuer authority, membership, reviewed workforce revision and expiry. Preserves workforce history; never merges or deletes Auth accounts. Identical successful retries do not repeat the transfer or re-enable offboarded access.",
        "parameters": [
          {
            "name": "X-ShiftForest-Workspace",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Selected workspace for administrator calls. Does not grant authority."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "p_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "p_revision": {
                    "type": "integer",
                    "format": "int64",
                    "minimum": 1
                  }
                },
                "required": [
                  "p_id",
                  "p_revision"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful RPC result; cancellation returns null.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "accepted": {
                      "const": true
                    },
                    "company_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "accepted",
                    "company_id"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "401": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "403": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "409": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "429": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "503": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          },
          "404": {
            "description": "Request rejected. Read the PostgREST message/code; do not automatically retry a changed review.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "details": {},
                    "hint": {}
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
