( ticket: string | null, secret: string | null | undefined )
| 58 | |
| 59 | export type PreviewClaims = z.infer<typeof previewClaimsSchema>; |
| 60 | |
| 61 | /** A preview token must expire; `jwt.verify` accepts a token without `exp`. */ |
| 62 | const previewTokenPayloadSchema = z.intersection( |
| 63 | previewClaimsSchema, |
| 64 | z.object({ exp: z.number() }) |
| 65 | ); |
| 66 | |
| 67 | export type SecretBinding = string | { get(): Promise<string> }; |
| 68 | |
| 69 | export async function resolveSecret( |
| 70 | secret: SecretBinding | null | undefined |
| 71 | ): Promise<string | null> { |
| 72 | if (!secret) { |
| 73 | return null; |
| 74 | } |
| 75 | if (typeof secret === 'string') { |
| 76 | return secret; |
| 77 | } |
| 78 | |
| 79 | try { |
| 80 | return await secret.get(); |
| 81 | } catch { |
| 82 | return null; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | export function validateStreamTicket( |
| 87 | ticket: string | null, |
| 88 | secret: string | null | undefined, |
| 89 | expectedAudience: string |
| 90 | ): { success: true; payload: StreamTicketPayload } | { success: false; error: string } { |
| 91 | if (!ticket) { |
| 92 | return { success: false, error: 'Missing stream ticket' }; |
| 93 | } |
no outgoing calls
no test coverage detected