import base64


def decode(data: str) -> bytes:
    """Decode base64url (RFC 4648) encoded text

    :param data: Base64-encoded data
    :returns: Raw data
    :raises TypeError: if ``data`` is not a string
    :raises ValueError: if base64-decoding fails (e.g. if `data` contains non-base64 characters)

    >>> decode('dGVzdA')
    b'test'
    """

    if not isinstance(data, str):
        raise TypeError("Can only decode() strings.")
    return base64.b64decode(data + "===")