@@ -6,15 +6,22 @@ import type {
66 RuntimeEnvironment ,
77 User ,
88} from "@trigger.dev/database" ;
9+ import { tryCatch } from "@trigger.dev/core" ;
910import { customAlphabet } from "nanoid" ;
1011import { generate } from "random-words" ;
1112import slug from "slug" ;
1213import { $replica , prisma , type PrismaClientOrTransaction } from "~/db.server" ;
1314import { env } from "~/env.server" ;
1415import { featuresForUrl } from "~/features.server" ;
1516import { createApiKeyForEnv , createPkApiKeyForEnv , envSlug } from "./api-key.server" ;
16- import { getDefaultEnvironmentConcurrencyLimit } from "~/services/platform.v3.server" ;
17+ import {
18+ getDefaultEnvironmentConcurrencyLimit ,
19+ isBillingConfigured ,
20+ setBillingAlert ,
21+ } from "~/services/platform.v3.server" ;
22+ import { buildDefaultBillingAlerts } from "~/services/billingAlertsDefaults.server" ;
1723import { enqueueAttioWorkspaceSync } from "~/services/attio.server" ;
24+ import { logger } from "~/services/logger.server" ;
1825import {
1926 applyBillingLimitPauseAfterEnvCreate ,
2027 getInitialEnvPauseStateForBillingLimit ,
@@ -122,9 +129,26 @@ export async function createOrganization(
122129 adminUserId : userId ,
123130 } ) ;
124131
132+ void seedDefaultBillingAlerts ( organization . id ) ;
133+
125134 return { ...organization } ;
126135}
127136
137+ /** Seed default billing alerts for a new org. Never blocks/fails org creation. */
138+ async function seedDefaultBillingAlerts ( organizationId : string ) : Promise < void > {
139+ if ( ! isBillingConfigured ( ) ) {
140+ return ;
141+ }
142+
143+ const [ error ] = await tryCatch ( setBillingAlert ( organizationId , buildDefaultBillingAlerts ( ) ) ) ;
144+ if ( error ) {
145+ logger . warn ( "Failed to seed default billing alerts for new org" , {
146+ organizationId,
147+ error : error instanceof Error ? error . message : error ,
148+ } ) ;
149+ }
150+ }
151+
128152export async function createEnvironment ( {
129153 organization,
130154 project,
0 commit comments