Skip to content

Commit 170d81e

Browse files
committed
Update linkry types for group owner
1 parent e4374a4 commit 170d81e

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/api/functions/linkry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from "@aws-sdk/client-dynamodb";
66
import { unmarshall } from "@aws-sdk/util-dynamodb";
77
import { LinkryGroupUUIDToGroupNameMap } from "common/config.js";
8-
import { DelegatedLinkRecord, LinkRecord } from "common/types/linkry.js";
8+
import { LinkRecord } from "common/types/linkry.js";
99
import { FastifyRequest } from "fastify";
1010

1111
export async function fetchLinkEntry(
@@ -255,7 +255,7 @@ export async function getDelegatedLinks(
255255
...ownerRecord,
256256
access: groupIds,
257257
owner: ownerRecord.access.replace("OWNER#", ""),
258-
} as DelegatedLinkRecord;
258+
} as LinkRecord;
259259
} catch (error) {
260260
console.error(`Error processing delegated slug ${slug}:`, error);
261261
return null;

src/common/types/generic.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Organizations } from "@acm-uiuc/js-shared";
12
import * as z from "zod/v4";
23

34

@@ -23,3 +24,9 @@ export const illinoisNetId = z
2324
example: "rjjones",
2425
id: "IllinoisNetId",
2526
});
27+
28+
export const OrgUniqueId = z.enum(Object.keys(Organizations)).meta({
29+
description: "The unique org ID for a given ACM sub-organization. See https://github.com/acm-uiuc/js-shared/blob/main/src/orgs.ts#L15",
30+
examples: ["A01", "C01"],
31+
id: "OrgUniqueId"
32+
})

src/common/types/linkry.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import * as z from "zod/v4";
2+
import { OrgUniqueId } from "./generic.js";
23

34
export type ShortLinkEntry = {
45
slug: string;
56
access: string;
67
redir?: string;
78
};
89

9-
export const LINKRY_MAX_SLUG_LENGTH = 1000;
10+
export const LINKRY_MAX_SLUG_LENGTH = 100;
1011

1112
export const getRequest = z.object({
1213
slug: z.string().min(1).max(LINKRY_MAX_SLUG_LENGTH).optional()
@@ -19,7 +20,10 @@ export const linkryAccessList = z.array(z.string().min(1)).meta({
1920

2021

2122
export const createRequest = z.object({
22-
slug: linkrySlug,
23+
slug: linkrySlug.refine((url) => !url.includes('#'), {
24+
message: "Slug must not contain a hashtag"
25+
}),
26+
orgId: z.optional(OrgUniqueId),
2327
access: linkryAccessList,
2428
redirect: z.url().min(1).meta({ description: "Full URL to redirect to when the short URL is visited.", example: "https://google.com" })
2529
});
@@ -33,14 +37,8 @@ export const linkRecord = z.object({
3337
owner: z.string().min(1)
3438
});
3539

36-
export const delegatedLinkRecord = linkRecord.extend({
37-
owner: z.string().min(1)
38-
});
39-
4040
export type LinkRecord = z.infer<typeof linkRecord>;
4141

42-
export type DelegatedLinkRecord = z.infer<typeof delegatedLinkRecord>;
43-
4442
export const getLinksResponse = z.object({
4543
ownedLinks: z.array(linkRecord),
4644
delegatedLinks: z.array(linkRecord)

0 commit comments

Comments
 (0)