( metadata: Readonly<Record<string, unknown>>, v2Origin: URL, )
| 36 | /** The move recorded in an organization's metadata, or `null` when there is |
| 37 | * none or it is malformed. */ |
| 38 | export const parseV2Moved = ( |
| 39 | metadata: Readonly<Record<string, unknown>>, |
| 40 | v2Origin: URL, |
| 41 | ): V2Moved | null => { |
| 42 | const slug = metadata[V2_MOVED_SLUG_KEY]; |
| 43 | const movedAt = metadata[V2_MOVED_AT_KEY]; |
| 44 | if (typeof slug !== "string" || slug.length > V2_SLUG_MAX_LENGTH || !V2_SLUG.test(slug)) { |
| 45 | return null; |
| 46 | } |
| 47 | if (typeof movedAt !== "string" || !ISO_TIMESTAMP.test(movedAt)) return null; |
| 48 | const time = Date.parse(movedAt); |
| 49 | if (!Number.isFinite(time)) return null; |
| 50 | return { |
| 51 | v2Url: new URL(`/org/${slug}`, v2Origin).href, |
| 52 | v2Slug: slug, |
| 53 | movedAt: new Date(time).toISOString(), |
| 54 | }; |
| 55 | }; |
| 56 | |
| 57 | /** The read the check makes. */ |
| 58 | export interface V2MovedSource { |
no outgoing calls
no test coverage detected