Skip to content
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
1 change: 1 addition & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"hono": "4.11.7",
"hono-openapi": "^1.1.2",
"hono-rate-limiter": "0.5.3",
"qte": "0.1.0",
"std-env": "3.10.0",
"superjson": "2.2.6"
},
Expand Down
7 changes: 4 additions & 3 deletions apps/api/src/shared/auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { createAuth, databaseAdapter } from "@init/auth/server"
import { admin, organization } from "@init/auth/server/plugins"
import { database } from "@init/db/client"
import { APP_ID, APP_NAME, SESSION_EXPIRES_IN, SESSION_UPDATE_AGE } from "@init/utils/constants"
import { APP_ID, APP_NAME } from "@init/utils/constants"
import { seconds } from "qte"
import env from "#shared/env.ts"

export const auth = createAuth({
Expand All @@ -20,8 +21,8 @@ export const auth = createAuth({
plugins: [admin(), organization()],
secret: env.AUTH_SECRET,
session: {
expiresIn: SESSION_EXPIRES_IN,
updateAge: SESSION_UPDATE_AGE,
expiresIn: seconds("30d"),
updateAge: seconds("15d"),
},
socialProviders: {
github: {
Expand Down
6 changes: 3 additions & 3 deletions apps/api/src/shared/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { DeepMerge } from "@init/utils/type"
import { findIp } from "@arcjet/ip"
import { kv } from "@init/kv/client"
import { type DurationInput, milliseconds } from "@init/utils/duration"
import { rateLimiter } from "hono-rate-limiter"
import { createMiddleware } from "hono/factory"
import { HTTPException } from "hono/http-exception"
import { type TimeExpression, ms } from "qte"
import type { Session } from "#shared/auth.ts"
import type { AppContext } from "#shared/types.ts"

Expand Down Expand Up @@ -32,12 +32,12 @@ export const requireSession = createMiddleware<
/**
* Adds basic rate limiting protection with a fixed window to the request.
*/
export function withRateLimiting(interval: DurationInput, limit: number) {
export function withRateLimiting(interval: TimeExpression, limit: number) {
return rateLimiter<AppContext>({
keyGenerator: (c) => c.var.session?.user.id ?? findIp(c.req.raw) ?? "unknown",
limit,
standardHeaders: "draft-7",
windowMs: milliseconds(interval),
windowMs: ms(interval),
})
}

Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/expo-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/// <reference types="expo/types" />

// NOTE: This file should not be edited and should be in your git ignore
// NOTE: This file should not be edited and should be in your git ignore
7 changes: 6 additions & 1 deletion bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@tanstack/react-query": "^5.90.20",
"convex": "1.31.6",
"convex-helpers": "0.1.111",
"qte": "0.1.0",
"std-env": "3.10.0"
},
"devDependencies": {
Expand Down
7 changes: 4 additions & 3 deletions packages/backend/src/functions/shared/auth/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import type { AuthOptions } from "@init/auth/server"
import { createClient } from "@convex-dev/better-auth"
import { convex } from "@convex-dev/better-auth/plugins"
import { admin, anonymous, organization } from "@init/auth/server/plugins"
import { APP_ID, APP_NAME, SESSION_EXPIRES_IN, SESSION_UPDATE_AGE } from "@init/utils/constants"
import { APP_ID, APP_NAME } from "@init/utils/constants"
import { seconds } from "qte"
import type { DataModel } from "#functions/_generated/dataModel.js"
import { components } from "#functions/_generated/api.js"
import authConfig from "#functions/auth.config.ts"
Expand All @@ -30,7 +31,7 @@ export const authOptions = (ctx: GenericCtx<DataModel>) =>
},
plugins: [anonymous(), admin(), organization(), convex({ authConfig })],
session: {
expiresIn: SESSION_EXPIRES_IN,
updateAge: SESSION_UPDATE_AGE,
expiresIn: seconds("30d"),
updateAge: seconds("15d"),
},
}) satisfies AuthOptions
1 change: 1 addition & 0 deletions packages/email/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@react-email/components": "1.0.6",
"@react-email/render": "2.0.4",
"date-fns": "4.1.0",
"qte": "0.1.0",
"resend": "6.7.0"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions packages/email/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import type { ReactNode } from "react"
import { resend } from "@init/env/presets"
import { SendEmailError, BatchSendEmailError } from "@init/error"
import { getLogger, LoggerCategory } from "@init/observability/logger"
import { type DurationInput, milliseconds } from "@init/utils/duration"
import { singleton } from "@init/utils/singleton"
import { render } from "@react-email/render"
import { addMilliseconds } from "date-fns"
import { type TimeExpression, ms } from "qte"
import { Resend } from "resend"

type EmailSendParams = {
emails: string[]
subject: string
sendAt?: Date | DurationInput
sendAt?: Date | TimeExpression
from?: string
}

Expand Down Expand Up @@ -47,7 +47,7 @@ export async function sendEmail(body: ReactNode, params: EmailSendParams) {
? undefined
: sendAt instanceof Date
? sendAt.toISOString()
: addMilliseconds(new Date(), milliseconds(sendAt)).toISOString(),
: addMilliseconds(new Date(), ms(sendAt)).toISOString(),
subject,
to: emails,
})
Expand Down Expand Up @@ -97,7 +97,7 @@ export async function batchEmails(payload: Array<EmailSendParams & { body: React
? undefined
: sendAt instanceof Date
? sendAt.toISOString()
: addMilliseconds(new Date(), milliseconds(sendAt)).toISOString(),
: addMilliseconds(new Date(), ms(sendAt)).toISOString(),
subject,
to: emails,
}))
Expand Down
2 changes: 1 addition & 1 deletion packages/kv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
},
"dependencies": {
"@init/env": "workspace:*",
"@init/error": "workspace:*",
"@init/utils": "workspace:*",
"qte": "0.1.0",
"superjson": "2.2.6"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions packages/kv/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { type DurationInput, seconds } from "@init/utils/duration"
import { singleton } from "@init/utils/singleton"
import { type RedisClient, redis } from "bun"
import { seconds, type TimeExpression } from "qte"
import SuperJSON from "superjson"

type ClientConfig = {
/**
* Default time to live in seconds
*/
ttl?: DurationInput
ttl?: TimeExpression
}

export type KeyPart = string | number
Expand Down Expand Up @@ -49,7 +49,7 @@ class KeyValueClient {
* @param value - The value to set. Will be serialized using SuperJSON.
* @param expiresIn - The time to live in seconds
*/
async set(key: string | KeyPart[], value: unknown, expiresIn?: DurationInput): Promise<void> {
async set(key: string | KeyPart[], value: unknown, expiresIn?: TimeExpression): Promise<void> {
const normalizedKey = this.normalizeKey(key)

await this.client.set(normalizedKey, SuperJSON.stringify(value))
Expand Down
Loading