Skip to content

chore: Separate out utils package into sub-files #466

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 1 commit into from
May 21, 2024
Merged
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
4 changes: 2 additions & 2 deletions apps/mail-bridge/postal-db/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
getUniqueDKIMSelector,
randomAlphaNumeric
} from './generators';
import { and, eq, sql } from 'drizzle-orm/sql';
import { and, eq, sql } from 'drizzle-orm';
import {
lookupCNAME,
lookupMX,
Expand All @@ -27,7 +27,7 @@ import {
parseSpfIncludes,
parseDmarc,
buildDmarcRecord
} from '@u22n/utils';
} from '@u22n/utils/dns';
import { env } from '../env';

export type CreateOrgInput = {
Expand Down
2 changes: 1 addition & 1 deletion apps/mail-bridge/postal-routes/inbound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
typeIdValidator,
validateTypeId,
type TypeId
} from '@u22n/utils';
} from '@u22n/utils/typeid';
import { Hono } from 'hono';
import { z } from 'zod';
import { db } from '@u22n/database';
Expand Down
2 changes: 1 addition & 1 deletion apps/mail-bridge/trpc/routers/domainRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { z } from 'zod';
import { router, protectedProcedure } from '../trpc';
import { and, eq } from '@u22n/database/orm';
import { postalServers } from '@u22n/database/schema';
import { typeIdValidator } from '@u22n/utils';
import { typeIdValidator } from '@u22n/utils/typeid';
import { postalDB } from '../../postal-db';
import { httpEndpoints, organizations, servers } from '../../postal-db/schema';
import {
Expand Down
2 changes: 1 addition & 1 deletion apps/mail-bridge/trpc/routers/orgRouter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { z } from 'zod';
import { router, protectedProcedure } from '../trpc';
import { eq } from '@u22n/database/orm';
import { typeIdGenerator, typeIdValidator } from '@u22n/utils';
import { typeIdGenerator, typeIdValidator } from '@u22n/utils/typeid';
import {
addMailServer,
createOrg,
Expand Down
2 changes: 1 addition & 1 deletion apps/mail-bridge/trpc/routers/sendMailRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
orgs,
convoParticipants
} from '@u22n/database/schema';
import { typeIdValidator } from '@u22n/utils';
import { typeIdValidator } from '@u22n/utils/typeid';
import { and, eq, inArray } from '@u22n/database/orm';
import { tiptapHtml, tiptapVue3 } from '@u22n/tiptap';
import { tipTapExtensions } from '@u22n/tiptap/extensions';
Expand Down
2 changes: 1 addition & 1 deletion apps/mail-bridge/utils/contactParsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
contacts,
emailIdentities
} from '@u22n/database/schema';
import { typeIdGenerator } from '@u22n/utils';
import { typeIdGenerator } from '@u22n/utils/typeid';

export async function parseAddressIds(input: {
addresses: EmailAddress[];
Expand Down
3 changes: 1 addition & 2 deletions apps/mail-bridge/utils/realtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { db } from '@u22n/database';
import { eq, inArray } from '@u22n/database/orm';
import { convoEntries, convoParticipants, convos } from '@u22n/database/schema';
import RealtimeServer from '@u22n/realtime/server';

import type { TypeId } from '@u22n/utils';
import type { TypeId } from '@u22n/utils/typeid';
import { env } from '../env';

export const realtime = new RealtimeServer({
Expand Down
1 change: 0 additions & 1 deletion apps/platform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"@u22n/utils": "workspace:^",
"@unkey/ratelimit": "^0.1.3",
"hono": "^4.3.8",
"itty-time": "^1.0.6",
"lucia": "^3.1.1",
"oslo": "^1.1.3",
"superjson": "^2.2.1",
Expand Down
2 changes: 1 addition & 1 deletion apps/platform/storage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { env } from './env';
import { ms } from 'itty-time';
import { ms } from '@u22n/utils/ms';
import redisDriver from 'unstorage/drivers/redis';
import { createStorage, type StorageValue } from 'unstorage';
import type { DatabaseSession } from 'lucia';
Expand Down
10 changes: 3 additions & 7 deletions apps/platform/trpc/routers/authRouter/passkeyRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ import type {
RegistrationResponseJSON,
AuthenticationResponseJSON
} from '@simplewebauthn/types';
import {
nanoIdToken,
typeIdGenerator,
typeIdValidator,
zodSchemas
} from '@u22n/utils';
import { typeIdGenerator, typeIdValidator } from '@u22n/utils/typeid';
import { nanoIdToken, zodSchemas } from '@u22n/utils/zodSchemas';
import { ms } from '@u22n/utils/ms';
import {
verifyRegistrationResponse,
generateRegistrationOptions,
Expand All @@ -23,7 +20,6 @@ import { createAuthenticator } from '~platform/utils/auth/passkeyUtils';
import { validateUsername } from './signupRouter';
import { createLuciaSessionCookie } from '~platform/utils/session';
import { env } from '~platform/env';
import { ms } from 'itty-time';
import { getCookie, setCookie } from 'hono/cookie';

export const passkeyRouter = router({
Expand Down
9 changes: 3 additions & 6 deletions apps/platform/trpc/routers/authRouter/passwordRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ import {
} from '~platform/trpc/trpc';
import { eq } from '@u22n/database/orm';
import { accounts } from '@u22n/database/schema';
import {
nanoIdToken,
typeIdGenerator,
zodSchemas,
strongPasswordSchema
} from '@u22n/utils';
import { nanoIdToken, zodSchemas } from '@u22n/utils/zodSchemas';
import { strongPasswordSchema } from '@u22n/utils/password';
import { typeIdGenerator } from '@u22n/utils/typeid';
import { TRPCError } from '@trpc/server';
import { lucia } from '~platform/utils/auth';
import { validateUsername } from './signupRouter';
Expand Down
11 changes: 4 additions & 7 deletions apps/platform/trpc/routers/authRouter/recoveryRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@ import { Argon2id } from 'oslo/password';
import { router, publicRateLimitedProcedure } from '~platform/trpc/trpc';
import { eq } from '@u22n/database/orm';
import { accounts } from '@u22n/database/schema';
import {
nanoIdToken,
strongPasswordSchema,
typeIdValidator,
zodSchemas
} from '@u22n/utils';
import { nanoIdToken, zodSchemas } from '@u22n/utils/zodSchemas';
import { strongPasswordSchema } from '@u22n/utils/password';
import { typeIdValidator } from '@u22n/utils/typeid';
import { ms } from '@u22n/utils/ms';
import { TRPCError } from '@trpc/server';
import { createLuciaSessionCookie } from '~platform/utils/session';
import { decodeHex, encodeHex } from 'oslo/encoding';
import { TOTPController, createTOTPKeyURI } from 'oslo/otp';
import { deleteCookie, getCookie, setCookie } from 'hono/cookie';
import { env } from '~platform/env';
import { storage } from '~platform/storage';
import { ms } from 'itty-time';

export const recoveryRouter = router({
/**
Expand Down
3 changes: 2 additions & 1 deletion apps/platform/trpc/routers/authRouter/signupRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import type { DBType } from '@u22n/database';
import { eq } from '@u22n/database/orm';
import { accounts } from '@u22n/database/schema';
import { blockedUsernames, reservedUsernames } from '~platform/utils/signup';
import { zodSchemas, calculatePasswordStrength } from '@u22n/utils';
import { calculatePasswordStrength } from '@u22n/utils/password';
import { zodSchemas } from '@u22n/utils/zodSchemas';

export async function validateUsername(
db: DBType,
Expand Down
2 changes: 1 addition & 1 deletion apps/platform/trpc/routers/authRouter/twoFactorRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { accounts } from '@u22n/database/schema';
import { decodeHex, encodeHex } from 'oslo/encoding';
import { TOTPController, createTOTPKeyURI } from 'oslo/otp';
import { TRPCError } from '@trpc/server';
import { nanoIdToken, zodSchemas } from '@u22n/utils';
import { nanoIdToken, zodSchemas } from '@u22n/utils/zodSchemas';
import { Argon2id } from 'oslo/password';
import { getCookie, setCookie } from 'hono/cookie';
import { storage } from '~platform/storage';
Expand Down
6 changes: 5 additions & 1 deletion apps/platform/trpc/routers/convoRouter/convoRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ import {
convoEntryPrivateVisibilityParticipants,
convoEntryRawHtmlEmails
} from '@u22n/database/schema';
import { typeIdValidator, type TypeId, typeIdGenerator } from '@u22n/utils';
import {
typeIdValidator,
type TypeId,
typeIdGenerator
} from '@u22n/utils/typeid';
import { TRPCError } from '@trpc/server';
import { tipTapExtensions } from '@u22n/tiptap/extensions';
import { tiptapCore, type tiptapVue3 } from '@u22n/tiptap';
Expand Down
2 changes: 1 addition & 1 deletion apps/platform/trpc/routers/convoRouter/entryRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { z } from 'zod';
import { router, orgProcedure } from '~platform/trpc/trpc';
import { and, desc, eq, lt, or } from '@u22n/database/orm';
import { convos, convoEntries } from '@u22n/database/schema';
import { typeIdValidator } from '@u22n/utils';
import { typeIdValidator } from '@u22n/utils/typeid';
import { TRPCError } from '@trpc/server';

export const convoEntryRouter = router({
Expand Down
4 changes: 2 additions & 2 deletions apps/platform/trpc/routers/orgRouter/mail/domainsRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import {
postalServers,
orgPostalConfigs
} from '@u22n/database/schema';
import { typeIdGenerator, typeIdValidator } from '@u22n/utils';
import { typeIdGenerator, typeIdValidator } from '@u22n/utils/typeid';
import { lookupNS } from '@u22n/utils/dns';
import { TRPCError } from '@trpc/server';
import { isAccountAdminOfOrg } from '~platform/utils/account';
import { mailBridgeTrpcClient } from '~platform/utils/tRPCServerClients';
import { lookupNS } from '@u22n/utils';

export const domainsRouter = router({
createNewDomain: orgProcedure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
emailIdentitiesAuthorizedOrgMembers,
emailIdentityExternal
} from '@u22n/database/schema';
import { nanoIdToken, typeIdGenerator, typeIdValidator } from '@u22n/utils';
import { typeIdGenerator, typeIdValidator } from '@u22n/utils/typeid';
import { nanoIdToken } from '@u22n/utils/zodSchemas';
import { TRPCError } from '@trpc/server';
import { env } from '~platform/env';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import {
import {
typeIdGenerator,
typeIdValidator,
type TypeId,
nanoIdToken
} from '@u22n/utils';
type TypeId
} from '@u22n/utils/typeid';
import { nanoIdToken } from '@u22n/utils/zodSchemas';
import { isAccountAdminOfOrg } from '~platform/utils/account';
import { TRPCError } from '@trpc/server';
import { emailIdentityExternalRouter } from './emailIdentityExternalRouter';
Expand Down
2 changes: 1 addition & 1 deletion apps/platform/trpc/routers/orgRouter/orgCrudRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
orgMemberProfiles,
accounts
} from '@u22n/database/schema';
import { typeIdGenerator } from '@u22n/utils';
import { typeIdGenerator } from '@u22n/utils/typeid';
import { TRPCError } from '@trpc/server';
import { blockedUsernames, reservedUsernames } from '~platform/utils/signup';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { z } from 'zod';
import { router, orgProcedure } from '~platform/trpc/trpc';
import { eq } from '@u22n/database/orm';
import { orgs } from '@u22n/database/schema';
import { typeIdValidator } from '@u22n/utils';
import { typeIdValidator } from '@u22n/utils/typeid';
import { isAccountAdminOfOrg } from '~platform/utils/account';
import { TRPCError } from '@trpc/server';

Expand Down
8 changes: 2 additions & 6 deletions apps/platform/trpc/routers/orgRouter/users/invitesRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@ import {
orgMemberProfiles,
accounts
} from '@u22n/database/schema';
import {
nanoIdToken,
typeIdGenerator,
typeIdValidator,
zodSchemas
} from '@u22n/utils';
import { typeIdGenerator, typeIdValidator } from '@u22n/utils/typeid';
import { nanoIdToken, zodSchemas } from '@u22n/utils/zodSchemas';
import { refreshOrgShortCodeCache } from '~platform/utils/orgShortCode';
import { isAccountAdminOfOrg } from '~platform/utils/account';
import { TRPCError } from '@trpc/server';
Expand Down
2 changes: 1 addition & 1 deletion apps/platform/trpc/routers/orgRouter/users/teamsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
teams,
orgMembers
} from '@u22n/database/schema';
import { typeIdGenerator, type TypeId } from '@u22n/utils';
import { typeIdGenerator, type TypeId } from '@u22n/utils/typeid';

export async function addOrgMemberToTeamHandler({
orgId,
Expand Down
4 changes: 2 additions & 2 deletions apps/platform/trpc/routers/orgRouter/users/teamsRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { z } from 'zod';
import { router, orgProcedure } from '~platform/trpc/trpc';
import { eq, and } from '@u22n/database/orm';
import { teams } from '@u22n/database/schema';
import { typeIdGenerator, typeIdValidator } from '@u22n/utils';
import { uiColors } from '@u22n/utils';
import { typeIdGenerator, typeIdValidator } from '@u22n/utils/typeid';
import { uiColors } from '@u22n/utils/colors';
import { isAccountAdminOfOrg } from '../../../../utils/account';
import { TRPCError } from '@trpc/server';
import { addOrgMemberToTeamHandler } from './teamsHandler';
Expand Down
3 changes: 2 additions & 1 deletion apps/platform/trpc/routers/userRouter/addressRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
emailRoutingRulesDestinations
} from '@u22n/database/schema';
import { orgMembers } from '@u22n/database/schema';
import { nanoIdToken, typeIdGenerator, typeIdValidator } from '@u22n/utils';
import { typeIdGenerator, typeIdValidator } from '@u22n/utils/typeid';
import { nanoIdToken } from '@u22n/utils/zodSchemas';
import { env } from '~platform/env';

export const addressRouter = router({
Expand Down
2 changes: 1 addition & 1 deletion apps/platform/trpc/routers/userRouter/profileRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { z } from 'zod';
import { router, accountProcedure } from '~platform/trpc/trpc';
import { and, eq } from '@u22n/database/orm';
import { orgMemberProfiles, orgs, orgMembers } from '@u22n/database/schema';
import { typeIdValidator } from '@u22n/utils';
import { typeIdValidator } from '@u22n/utils/typeid';
import { TRPCError } from '@trpc/server';

export const profileRouter = router({
Expand Down
13 changes: 6 additions & 7 deletions apps/platform/trpc/routers/userRouter/securityRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { z } from 'zod';
import { router, accountProcedure } from '~platform/trpc/trpc';
import { and, eq } from '@u22n/database/orm';
import { accounts, authenticators, sessions } from '@u22n/database/schema';
import { typeIdValidator } from '@u22n/utils/typeid';
import { nanoIdToken, zodSchemas } from '@u22n/utils/zodSchemas';
import {
nanoIdToken,
typeIdValidator,
zodSchemas,
calculatePasswordStrength,
strongPasswordSchema
} from '@u22n/utils';
strongPasswordSchema,
calculatePasswordStrength
} from '@u22n/utils/password';
import { datePlus } from '@u22n/utils/ms';
import { TRPCError } from '@trpc/server';
import { deleteCookie, getCookie, setCookie } from 'hono/cookie';
import type {
Expand All @@ -28,7 +28,6 @@ import { TOTPController, createTOTPKeyURI } from 'oslo/otp';
import { lucia } from '~platform/utils/auth';
import { storage } from '~platform/storage';
import { env } from '~platform/env';
import { datePlus } from 'itty-time';

const authStorage = storage.auth;

Expand Down
2 changes: 1 addition & 1 deletion apps/platform/utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
TimeSpan
} from 'lucia';
import { UnInboxDBAdapter } from './auth/adapter';
import type { TypeId } from '@u22n/utils';
import type { TypeId } from '@u22n/utils/typeid';
import { env } from '~platform/env';

const adapter = new UnInboxDBAdapter();
Expand Down
2 changes: 1 addition & 1 deletion apps/platform/utils/auth/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { db } from '@u22n/database';
import { eq, inArray, lte } from '@u22n/database/orm';
import { sessions, accounts } from '@u22n/database/schema';
import { storage } from '~platform/storage';
import { typeIdGenerator } from '@u22n/utils';
import { typeIdGenerator } from '@u22n/utils/typeid';

const sessionStorage = storage.session;

Expand Down
2 changes: 1 addition & 1 deletion apps/platform/utils/auth/passkeyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { db } from '@u22n/database';
import { accounts, authenticators } from '@u22n/database/schema';
import type { AuthenticatorTransportFuture } from '@simplewebauthn/types';
import { isoBase64URL } from '@simplewebauthn/server/helpers';
import { typeIdGenerator } from '@u22n/utils';
import { typeIdGenerator } from '@u22n/utils/typeid';

export type CredentialDeviceType = 'singleDevice' | 'multiDevice';
export interface Authenticator {
Expand Down
2 changes: 1 addition & 1 deletion apps/platform/utils/realtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { db } from '@u22n/database';
import { eq, inArray } from '@u22n/database/orm';
import { convoEntries, convoParticipants, convos } from '@u22n/database/schema';
import RealtimeServer from '@u22n/realtime/server';
import type { TypeId } from '@u22n/utils';
import type { TypeId } from '@u22n/utils/typeid';
import { env } from '~platform/env';

export const realtime = new RealtimeServer({
Expand Down
2 changes: 1 addition & 1 deletion apps/platform/utils/session.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UAParser } from 'ua-parser-js';
import { lucia } from './auth';
import type { TypeId } from '@u22n/utils';
import type { TypeId } from '@u22n/utils/typeid';
import type { Context } from 'hono';
import { setCookie } from 'hono/cookie';
import { db } from '@u22n/database';
Expand Down
2 changes: 1 addition & 1 deletion apps/storage/api/avatar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Ctx } from '../ctx';
import { checkSignedIn } from '../middlewares';
import { zValidator } from '@hono/zod-validator';
import { z } from 'zod';
import { typeIdValidator, type TypeId } from '@u22n/utils';
import { typeIdValidator, type TypeId } from '@u22n/utils/typeid';
import {
orgMemberProfiles,
orgMembers,
Expand Down
2 changes: 1 addition & 1 deletion apps/storage/api/internalPresign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Hono } from 'hono';
import type { Ctx } from '../ctx';
import { checkAuthorizedService } from '../middlewares';
import { zValidator } from '@hono/zod-validator';
import { typeIdGenerator } from '@u22n/utils';
import { typeIdGenerator } from '@u22n/utils/typeid';
import { PutObjectCommand } from '@aws-sdk/client-s3';
import { env } from '../env';
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
Expand Down
Loading