Skip to content

Use a shared NPM package for org constants #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@acm-uiuc:registry=https://registry.npmjs.org
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
"test:e2e": "playwright test",
"test:e2e-ui": "playwright test --ui"
},
"dependencies": {},
"dependencies": {
"@acm-uiuc/js-shared": "^2.1.0"
},
"devDependencies": {
"@eslint/compat": "^1.2.8",
"@eslint/eslintrc": "^3.3.1",
Expand Down Expand Up @@ -87,4 +89,4 @@
"resolutions": {
"pdfjs-dist": "^4.8.69"
}
}
}
6 changes: 3 additions & 3 deletions src/api/routes/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "zod-openapi/extend";
import { FastifyPluginAsync, FastifyRequest } from "fastify";
import { AppRoles } from "../../common/roles.js";
import { z } from "zod";
import { OrganizationList } from "../../common/orgs.js";
import { AllOrganizationList } from "@acm-uiuc/js-shared";
import {
DeleteItemCommand,
GetItemCommand,
Expand Down Expand Up @@ -111,7 +111,7 @@ const baseSchema = z.object({
description: "Google Maps link for easy navigation to the event location.",
example: "https://maps.app.goo.gl/dwbBBBkfjkgj8gvA8",
}),
host: z.enum(OrganizationList as [string, ...string[]]),
host: z.enum(AllOrganizationList as [string, ...string[]]),
featured: z.boolean().default(false).openapi({
description:
"Whether or not the event should be shown on the ACM @ UIUC website home page (and added to Discord, as available).",
Expand Down Expand Up @@ -165,7 +165,7 @@ const eventsPlugin: FastifyPluginAsyncZodOpenApi = async (
"If true, only get events which are marked as featured.",
}),
host: z
.enum(OrganizationList as [string, ...string[]])
.enum(AllOrganizationList as [string, ...string[]])
.optional()
.openapi({
description: "Retrieve events only for a specific host.",
Expand Down
8 changes: 4 additions & 4 deletions src/api/routes/ics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import ical, {
} from "ical-generator";
import moment from "moment";
import { getVtimezoneComponent } from "@touch4it/ical-timezones";
import { OrganizationList } from "../../common/orgs.js";
import { AllOrganizationList } from "@acm-uiuc/js-shared";
import { CLIENT_HTTP_CACHE_POLICY, EventRepeatOptions } from "./events.js";
import rateLimiter from "api/plugins/rateLimiter.js";
import { getCacheCounter } from "api/functions/cache.js";
Expand Down Expand Up @@ -43,7 +43,7 @@ function generateHostName(host: string) {

const icalPlugin: FastifyPluginAsync = async (fastify, _options) => {
fastify.register(rateLimiter, {
limit: OrganizationList.length,
limit: AllOrganizationList.length,
duration: 30,
rateLimitIdentifier: "ical",
});
Expand All @@ -53,7 +53,7 @@ const icalPlugin: FastifyPluginAsync = async (fastify, _options) => {
schema: withTags(["iCalendar Integration"], {
params: z.object({
host: z
.optional(z.enum(OrganizationList as [string, ...string[]]))
.optional(z.enum(AllOrganizationList as [string, ...string[]]))
.openapi({ description: "Host to get calendar for." }),
}),
summary:
Expand Down Expand Up @@ -87,7 +87,7 @@ const icalPlugin: FastifyPluginAsync = async (fastify, _options) => {
reply.header("etag", etag);
}
if (host) {
if (!OrganizationList.includes(host)) {
if (!AllOrganizationList.includes(host)) {
throw new ValidationError({
message: `Invalid host parameter "${host}" in path.`,
});
Expand Down
4 changes: 2 additions & 2 deletions src/api/routes/organizations.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FastifyPluginAsync } from "fastify";
import { OrganizationList } from "../../common/orgs.js";
import { AllOrganizationList } from "@acm-uiuc/js-shared";
import fastifyCaching from "@fastify/caching";
import rateLimiter from "api/plugins/rateLimiter.js";
import { withTags } from "api/components/index.js";
Expand All @@ -23,7 +23,7 @@ const organizationsPlugin: FastifyPluginAsync = async (fastify, _options) => {
}),
},
async (_request, reply) => {
reply.send(OrganizationList);
reply.send(AllOrganizationList);
},
);
};
Expand Down
30 changes: 0 additions & 30 deletions src/common/orgs.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/common/policies/events.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { z } from "zod";
import { string, z } from "zod";
import { createPolicy } from "./evaluator.js";
import { OrganizationList } from "../orgs.js";
import { AllOrganizationList } from "@acm-uiuc/js-shared";
import { FastifyRequest } from "fastify";

export const hostRestrictionPolicy = createPolicy(
"EventsHostRestrictionPolicy",
z.object({ host: z.array(z.enum(OrganizationList)) }),
z.object({ host: z.array(z.enum(AllOrganizationList)) }),
(request: FastifyRequest & { username?: string }, params) => {
if (!request.url.startsWith("/api/v1/events")) {
return {
Expand Down
4 changes: 2 additions & 2 deletions src/common/types/roomRequest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from "zod";
import { OrganizationList } from "../orgs.js";
import { AllOrganizationList } from "@acm-uiuc/js-shared";

export const eventThemeOptions = [
"Arts & Music",
Expand Down Expand Up @@ -146,7 +146,7 @@ export const roomRequestPostResponse = z.object({
});

export const roomRequestBaseSchema = z.object({
host: z.enum(OrganizationList),
host: z.enum(AllOrganizationList),
title: z.string().min(2, "Title must have at least 2 characters"),
semester: z
.string()
Expand Down
2 changes: 1 addition & 1 deletion src/ui/pages/events/ManageEvent.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { useNavigate, useParams } from "react-router-dom";
import { z } from "zod";
import { AuthGuard } from "@ui/components/AuthGuard";
import { useApi } from "@ui/util/api";
import { OrganizationList as orgList } from "@common/orgs";
import { AllOrganizationList as orgList } from "@acm-uiuc/js-shared";
import { AppRoles } from "@common/roles";
import { EVENT_CACHED_DURATION } from "@common/config";
import { IconPlus, IconTrash } from "@tabler/icons-react";
Expand Down
7 changes: 5 additions & 2 deletions src/ui/pages/roomRequest/NewRoomRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from "@mantine/core";
import { useForm, zodResolver } from "@mantine/form";
import { DateInput, DateTimePicker } from "@mantine/dates";
import { OrganizationList } from "@common/orgs";
import { AllOrganizationList } from "@acm-uiuc/js-shared";
import {
eventThemeOptions,
spaceTypeOptions,
Expand Down Expand Up @@ -401,7 +401,10 @@ const NewRoomRequest: React.FC<NewRoomRequestProps> = ({
placeholder="Select host organization"
withAsterisk
searchable
data={OrganizationList.map((org) => ({ value: org, label: org }))}
data={AllOrganizationList.map((org) => ({
value: org,
label: org,
}))}
{...form.getInputProps("host")}
/>
<TextInput
Expand Down
5 changes: 2 additions & 3 deletions tests/live/ical.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { expect, test } from "vitest";
import { describe } from "node:test";
import { OrganizationList } from "../../src/common/orgs.js";
import { AllOrganizationList } from "@acm-uiuc/js-shared";
import ical from "node-ical";
const baseEndpoint = `https://core.aws.qa.acmuiuc.org`;

Expand All @@ -8,7 +7,7 @@

const fetchWithRateLimit = async (url: string) => {
const response = await fetch(url);
expect(response.status).toBe(200);

Check failure on line 10 in tests/live/ical.test.ts

View workflow job for this annotation

GitHub Actions / Deploy to DEV and Run Tests

tests/live/ical.test.ts > Get calendars with rate limit handling

AssertionError: expected 400 to be 200 // Object.is equality - Expected + Received - 200 + 400 ❯ fetchWithRateLimit tests/live/ical.test.ts:10:27 ❯ tests/live/ical.test.ts:31:22

// Check rate limit headers
const remaining = parseInt(
Expand All @@ -28,7 +27,7 @@
};

test("Get calendars with rate limit handling", { timeout: 45000 }, async () => {
for (const org of OrganizationList) {
for (const org of AllOrganizationList) {
const response = await fetchWithRateLimit(
`${baseEndpoint}/api/v1/ical/${org}`,
);
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
# yarn lockfile v1


"@acm-uiuc/js-shared@^2.1.0":
version "2.1.0"
resolved "https://registry.yarnpkg.com/@acm-uiuc/js-shared/-/js-shared-2.1.0.tgz#c70f6d41a18daa4c2eb5f8be5de9e7a323e8f84c"
integrity sha512-d8JX9lXaVoEnA5oVDniaoHj0JLayA78uCFAWhmpF6BxxDpQPm7sLd6aeUfhdfrkvkWFq4AYBMTiSwYXKQsVbuA==

"@adobe/css-tools@^4.4.0":
version "4.4.1"
resolved "https://registry.yarnpkg.com/@adobe/css-tools/-/css-tools-4.4.1.tgz#2447a230bfe072c1659e6815129c03cf170710e3"
Expand Down
Loading