-
Notifications
You must be signed in to change notification settings - Fork 59
[#340] Make @forge/utils package #381
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
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
9c9199a
feat(utils): create package
alexanderpaolini c8456d5
feat(utils): migrate over discord from api
alexanderpaolini 8b191a6
feat(utils): remove discord from api utils
alexanderpaolini b943dfb
feat(utils): migrate over discord stuff for seed script
alexanderpaolini a387a2c
feat(utils): migrate over auth to use api as well
alexanderpaolini fb45249
feat(utils): move over discord from api package
alexanderpaolini c06e62d
feat(utils): migrate the rest of discord utils
alexanderpaolini 35841f4
feat(utils): move over permissons
alexanderpaolini ae29578
feat(utils): move over date utils
alexanderpaolini 9f98fd4
Merge branch 'main' into utils/create-utils-package
alexanderpaolini 96c5766
chore(utils): lint and format
alexanderpaolini 4039f62
Merge branch 'utils/create-utils-package' of https://github.com/Knigh…
alexanderpaolini 033d76d
feat(repo): fix pnpm-locl
alexanderpaolini b9d4ec1
chore(utils): test change
alexanderpaolini afd5aaa
feat: move sendEmail util to forge/emails
DGoel1602 509245d
chore: format
DGoel1602 374ed20
chore(utils): make console an eslint error
alexanderpaolini 0a7fb71
chore(*): upgrade .nvmrc
alexanderpaolini 98a6c58
chore(*): format:fix
alexanderpaolini d21cf7c
migrate api utils
DVidal1205 28c6979
Merge main into utils/create-utils-package
DVidal1205 0ea5c1f
migrate blade utils
DVidal1205 14439cb
migrate gemiknights utils
DVidal1205 29d67cd
migrate form client utils
DVidal1205 013acb7
chore: format
DVidal1205 39c381e
chore: format (again)
DVidal1205 8e37f80
chore: remove scripts
DVidal1205 8801f76
chore: format
DVidal1205 af2dd92
chore: format and client/server separation
DVidal1205 87e8e1f
chore: lint and type
DVidal1205 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 20.16 | ||
| v25.6.1 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| # Utils Package Migration Status | ||
|
|
||
| ## Overview | ||
| This document tracks the progress of migrating utility functions from various locations into the centralized `@forge/utils` package. | ||
|
|
||
| ## What Has Been Done ✅ | ||
|
|
||
| ### 1. Created `@forge/utils` Package | ||
| - Created new package at `packages/utils/` | ||
| - Set up package.json with proper dependencies | ||
| - Configured TypeScript, ESLint, and build setup | ||
|
|
||
| ### 2. Migrated Functions to `@forge/utils` | ||
|
|
||
| #### Discord Utilities (`packages/utils/src/discord.ts`) | ||
| - ✅ `api` - Discord REST API client | ||
| - ✅ `addRoleToMember` | ||
| - ✅ `removeRoleFromMember` | ||
| - ✅ `addMemberToServer` | ||
| - ✅ `handleDiscordOAuthCallback` | ||
| - ✅ `resolveDiscordUserId` | ||
| - ✅ `isDiscordAdmin` | ||
| - ✅ `isDiscordMember` | ||
| - ✅ `isDiscordVIP` | ||
| - ✅ `log` - Discord logging function | ||
|
|
||
| #### Permissions (`packages/utils/src/permissions.ts`) | ||
| - ✅ `hasPermission` | ||
| - ✅ `controlPerms` (with `or` and `and` methods) | ||
| - ✅ `isJudgeAdmin` | ||
| - ✅ `getJudgeSessionFromCookie` | ||
| - ✅ `getPermsAsList` | ||
|
|
||
| #### Time Utilities (`packages/utils/src/time.ts`) | ||
| - ✅ `formatHourTime` | ||
| - ✅ `formatDateRange` | ||
|
|
||
| #### Other Utilities | ||
| - ✅ `logger` (`packages/utils/src/logger.ts`) - Console logger wrapper | ||
| - ✅ `stripe` (`packages/utils/src/stripe.ts`) - Stripe client | ||
| - ✅ `env` (`packages/utils/src/env.ts`) - Environment variables | ||
|
|
||
| ### 3. Updated Imports Across Codebase | ||
| - ✅ All API package routers now import from `@forge/utils` | ||
| - ✅ Auth package updated to use `@forge/utils` | ||
| - ✅ Email package updated to use `@forge/utils` | ||
| - ✅ DB scripts updated to use `@forge/utils` | ||
| - ✅ No remaining imports from old `../utils` path in API package | ||
|
|
||
| ### 4. Email Package Migration | ||
| - ✅ Moved `sendEmail` function to `@forge/email` package | ||
| - ✅ Updated email package to use `@forge/utils` logger | ||
|
|
||
| ## What's Left To Do ⚠️ | ||
|
|
||
| ### 1. Duplicate Functions (High Priority) | ||
|
|
||
| #### `formatDateRange` - NAMING CONFLICT ⚠️ | ||
| - **Location 1**: `apps/blade/src/lib/utils.ts:29` | ||
| - Formats date ranges: "Jan 1 - Jan 15, 2024" (dates only) | ||
| - Uses `toLocaleDateString` with month/day/year | ||
| - **Location 2**: `packages/utils/src/time.ts:36` | ||
| - Formats time ranges: "9:00am - 5:00pm" (times only) | ||
| - Uses `formatHourTime` helper | ||
| - **Status**: These are DIFFERENT functions with the same name! | ||
| - **Action Required**: | ||
| - Rename one of them to avoid confusion | ||
| - Recommended: Rename utils version to `formatTimeRange` (more accurate) | ||
| - Or: Rename blade version to `formatDateRangeOnly` or similar | ||
| - These serve different purposes and both should exist | ||
|
|
||
| #### `getPermsAsList` | ||
| - **Location 1**: `apps/blade/src/lib/utils.ts:120` | ||
| - **Location 2**: `packages/utils/src/permissions.ts:95` | ||
| - **Status**: Function exists in both places | ||
| - **Used in**: | ||
| - `apps/blade/src/app/_components/admin/roles/roleedit.tsx` | ||
| - `apps/blade/src/app/_components/admin/roles/roletable.tsx` | ||
| - `apps/blade/src/app/_components/navigation/session-navbar.tsx` | ||
| - **Action Required**: | ||
| - Update all imports in blade app to use `@forge/utils` | ||
| - Remove duplicate definition from `apps/blade/src/lib/utils.ts` | ||
|
|
||
| ### 2. Remaining Functions in Old `packages/api/src/utils.ts` | ||
|
|
||
| The following functions are still in the old utils file and may need to be migrated or kept: | ||
|
|
||
| - `gmail` - Google Gmail API client (may stay in API package) | ||
| - `calendar` - Google Calendar API client (may stay in API package) | ||
| - `generateJsonSchema` - Form schema generation (form-specific, may stay) | ||
| - `regenerateMediaUrls` - Form media URL regeneration (form-specific, may stay) | ||
| - `CreateFormSchema` - Form schema type (form-specific, may stay) | ||
| - `createForm` - Form creation function (form-specific, may stay) | ||
|
|
||
| **Decision Needed**: These are form-specific utilities. Should they: | ||
| 1. Stay in API package (recommended - they're domain-specific) | ||
| 2. Move to a separate `@forge/forms` package | ||
| 3. Move to `@forge/utils` (not recommended - too domain-specific) | ||
|
|
||
| ### 3. Other App-Specific Utils | ||
|
|
||
| #### `apps/blade/src/lib/utils.ts` | ||
| Contains app-specific utilities that should likely stay: | ||
| - `formatDateTime` - Blade-specific date formatting | ||
| - `getFormattedDate` - Blade-specific date formatting | ||
| - `getTagColor` - Event tag color mapping (Blade-specific) | ||
| - `getClassTeam` - Hackathon class team mapping (Blade-specific) | ||
| - `extractProcedures` - tRPC procedure extraction (Blade-specific) | ||
|
|
||
| **Status**: These are app-specific and should remain in the blade app. | ||
|
|
||
| ## Migration Statistics | ||
|
|
||
| - **Old utils.ts exports**: 6 items (mostly form-specific) | ||
| - **New @forge/utils exports**: 21 items | ||
| - **Files importing from old utils**: 0 ✅ | ||
| - **Files importing from new utils**: 23 ✅ | ||
| - **Duplicate utility functions**: 2 ⚠️ | ||
|
|
||
| ## Next Steps | ||
|
|
||
| 1. **Immediate Actions**: | ||
| - [ ] **Resolve naming conflict**: Rename `formatDateRange` in `@forge/utils` to `formatTimeRange` (or rename blade version) | ||
| - [ ] Update `apps/blade/src/lib/utils.ts` to import `getPermsAsList` from `@forge/utils` | ||
| - [ ] Update all blade app files using `getPermsAsList` to import from `@forge/utils` | ||
| - [ ] Remove duplicate `getPermsAsList` definition from `apps/blade/src/lib/utils.ts` | ||
|
|
||
| 2. **Verification**: | ||
| - [ ] Test all affected components after migration | ||
| - [ ] Run static analysis again to confirm no duplicates remain | ||
| - [ ] Verify both date/time formatting functions work correctly after renaming | ||
|
|
||
| 3. **Documentation**: | ||
| - [ ] Update any documentation referencing old utils paths | ||
| - [ ] Document which utilities belong in `@forge/utils` vs app-specific utils | ||
|
|
||
| ## Running Analysis | ||
|
|
||
| To re-run the analysis scripts: | ||
|
|
||
| ```bash | ||
| # Find duplicate functions and code blocks | ||
| npx tsx scripts/analyze-duplicates.ts | ||
|
|
||
| # Find utils migration status | ||
| npx tsx scripts/analyze-utils-migration.ts | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.