MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / parseV2Moved

Function parseV2Moved

apps/cloud/src/auth/v2-moved.ts:38–55  ·  view source on GitHub ↗
(
  metadata: Readonly<Record<string, unknown>>,
  v2Origin: URL,
)

Source from the content-addressed store, hash-verified

36/** The move recorded in an organization's metadata, or `null` when there is
37 * none or it is malformed. */
38export 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. */
58export interface V2MovedSource {

Callers 2

v2-moved.test.tsFile · 0.90
v2MovedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected