Encode an integer page identifier as an opaque base64 string. This function exists to ensure that page IDs are opaque tokens that do not reveal the underlying pagination strategy to API consumers. The encoding format may change in the future, so consumers should treat page_id as an
(value: int)
| 10 | |
| 11 | |
| 12 | def encode_page_id(value: int) -> str: |
| 13 | """Encode an integer page identifier as an opaque base64 string. |
| 14 | |
| 15 | This function exists to ensure that page IDs are opaque tokens that do not |
| 16 | reveal the underlying pagination strategy to API consumers. The encoding |
| 17 | format may change in the future, so consumers should treat page_id as an |
| 18 | opaque string and not attempt to parse or construct it themselves. |
| 19 | |
| 20 | Args: |
| 21 | value: The integer value to encode. |
| 22 | |
| 23 | Returns: |
| 24 | Base64-encoded string (URL-safe, without padding). |
| 25 | """ |
| 26 | return base64.urlsafe_b64encode(str(value).encode()).decode().rstrip('=') |
| 27 | |
| 28 | |
| 29 | def decode_page_id(page_id: str | None) -> int | None: |
no outgoing calls