| 1 | /** Credentials for media requests that cannot set bearer or DPoP headers. */ |
| 2 | export interface DeviceHubAccess { |
| 3 | /** Absolute environment URL ending in `/api/device-hub`. */ |
| 4 | readonly httpBase: string; |
| 5 | /** Same base with the `ws(s)` scheme. */ |
| 6 | readonly wsBase: string; |
| 7 | /** Empty for cookie sessions; includes a short-lived ticket for bearer and DPoP sessions. */ |
| 8 | readonly query: Readonly<Record<string, string>>; |
| 9 | /** Whether requests must include session cookies. */ |
| 10 | readonly credentials: boolean; |
| 11 | } |
| 12 | |
| 13 | export const withDeviceHubQuery = (url: string, access: DeviceHubAccess): string => { |
| 14 | const entries = Object.entries(access.query); |
| 15 | if (entries.length === 0) return url; |
| 16 | const separator = url.includes("?") ? "&" : "?"; |
| 17 | return `${url}${separator}${new URLSearchParams(entries).toString()}`; |
| 18 | }; |