@@ -7,15 +7,13 @@ import type {
77 CloudRunSource ,
88 ExecutionMode ,
99 PrAuthorshipMode ,
10- SeatData ,
1110 StoredLogEntry ,
1211 TaskRunArtifactMetadata ,
1312} from "@posthog/shared" ;
1413import {
1514 DISMISSAL_REASON_OPTIONS ,
1615 type DismissalReasonOptionValue ,
1716 resolveCloudInitialPermissionMode ,
18- SEAT_PRODUCT_KEY ,
1917} from "@posthog/shared" ;
2018import type {
2119 AgentAnalyticsData ,
@@ -119,22 +117,6 @@ export function setPosthogApiClientAppVersion(version: string): void {
119117 clientAppVersion = version ;
120118}
121119
122- export class SeatSubscriptionRequiredError extends Error {
123- redirectUrl : string ;
124- constructor ( redirectUrl : string ) {
125- super ( "Billing subscription required" ) ;
126- this . name = "SeatSubscriptionRequiredError" ;
127- this . redirectUrl = redirectUrl ;
128- }
129- }
130-
131- export class SeatPaymentFailedError extends Error {
132- constructor ( message ?: string ) {
133- super ( message ?? "Payment failed" ) ;
134- this . name = "SeatPaymentFailedError" ;
135- }
136- }
137-
138120export class SandboxCustomImagesDisabledError extends Error {
139121 constructor ( message ?: string ) {
140122 super ( message ?? "Custom sandbox images are not enabled" ) ;
@@ -4452,113 +4434,6 @@ export class PostHogAPIClient {
44524434 return data . results ?? [ ] ;
44534435 }
44544436
4455- async getMySeat (
4456- options : { best ?: boolean } = { best : true } ,
4457- ) : Promise < SeatData | null > {
4458- try {
4459- const url = new URL ( `${ this . api . baseUrl } /api/seats/me/` ) ;
4460- url . searchParams . set ( "product_key" , SEAT_PRODUCT_KEY ) ;
4461- if ( options . best ) {
4462- url . searchParams . set ( "best" , "true" ) ;
4463- }
4464- const response = await this . api . fetcher . fetch ( {
4465- method : "get" ,
4466- url,
4467- path : "/api/seats/me/" ,
4468- } ) ;
4469- return ( await response . json ( ) ) as SeatData ;
4470- } catch ( error ) {
4471- if ( this . isFetcherStatusError ( error , 404 ) ) {
4472- return null ;
4473- }
4474- throw error ;
4475- }
4476- }
4477-
4478- async createSeat ( planKey : string ) : Promise < SeatData > {
4479- try {
4480- const user = await this . getCurrentUser ( ) ;
4481- const distinctId = user . distinct_id ;
4482- if ( ! distinctId ) {
4483- throw new Error ( "Cannot create seat: user has no distinct_id" ) ;
4484- }
4485- const url = new URL ( `${ this . api . baseUrl } /api/seats/` ) ;
4486- const response = await this . api . fetcher . fetch ( {
4487- method : "post" ,
4488- url,
4489- path : "/api/seats/" ,
4490- overrides : {
4491- body : JSON . stringify ( {
4492- product_key : SEAT_PRODUCT_KEY ,
4493- plan_key : planKey ,
4494- user_distinct_id : distinctId ,
4495- } ) ,
4496- } ,
4497- } ) ;
4498- return ( await response . json ( ) ) as SeatData ;
4499- } catch ( error ) {
4500- this . throwSeatError ( error ) ;
4501- }
4502- }
4503-
4504- async upgradeSeat ( planKey : string ) : Promise < SeatData > {
4505- try {
4506- const url = new URL ( `${ this . api . baseUrl } /api/seats/me/` ) ;
4507- const response = await this . api . fetcher . fetch ( {
4508- method : "patch" ,
4509- url,
4510- path : "/api/seats/me/" ,
4511- overrides : {
4512- body : JSON . stringify ( {
4513- product_key : SEAT_PRODUCT_KEY ,
4514- plan_key : planKey ,
4515- } ) ,
4516- } ,
4517- } ) ;
4518- return ( await response . json ( ) ) as SeatData ;
4519- } catch ( error ) {
4520- this . throwSeatError ( error ) ;
4521- }
4522- }
4523-
4524- async cancelSeat ( ) : Promise < void > {
4525- try {
4526- const url = new URL ( `${ this . api . baseUrl } /api/seats/me/` ) ;
4527- url . searchParams . set ( "product_key" , SEAT_PRODUCT_KEY ) ;
4528- await this . api . fetcher . fetch ( {
4529- method : "delete" ,
4530- url,
4531- path : "/api/seats/me/" ,
4532- } ) ;
4533- } catch ( error ) {
4534- if ( this . isFetcherStatusError ( error , 204 ) ) {
4535- return ;
4536- }
4537- this . throwSeatError ( error ) ;
4538- }
4539- }
4540-
4541- async reactivateSeat ( ) : Promise < SeatData > {
4542- try {
4543- const url = new URL ( `${ this . api . baseUrl } /api/seats/me/reactivate/` ) ;
4544- const response = await this . api . fetcher . fetch ( {
4545- method : "post" ,
4546- url,
4547- path : "/api/seats/me/reactivate/" ,
4548- overrides : {
4549- body : JSON . stringify ( { product_key : SEAT_PRODUCT_KEY } ) ,
4550- } ,
4551- } ) ;
4552- return ( await response . json ( ) ) as SeatData ;
4553- } catch ( error ) {
4554- this . throwSeatError ( error ) ;
4555- }
4556- }
4557-
4558- private isFetcherStatusError ( error : unknown , status : number ) : boolean {
4559- return error instanceof Error && error . message . includes ( `[${ status } ]` ) ;
4560- }
4561-
45624437 private parseFetcherError ( error : unknown ) : {
45634438 status : number ;
45644439 body : Record < string , unknown > ;
@@ -4607,26 +4482,6 @@ export class PostHogAPIClient {
46074482 }
46084483 }
46094484
4610- private throwSeatError ( error : unknown ) : never {
4611- const parsed = this . parseFetcherError ( error ) ;
4612-
4613- if ( parsed ) {
4614- if (
4615- parsed . status === 400 &&
4616- typeof parsed . body . redirect_url === "string"
4617- ) {
4618- throw new SeatSubscriptionRequiredError ( parsed . body . redirect_url ) ;
4619- }
4620- if ( parsed . status === 402 ) {
4621- const message =
4622- typeof parsed . body . error === "string" ? parsed . body . error : undefined ;
4623- throw new SeatPaymentFailedError ( message ) ;
4624- }
4625- }
4626-
4627- throw error ;
4628- }
4629-
46304485 /**
46314486 * Check if a feature flag is enabled for the current project.
46324487 * Returns true if the flag exists and is active, false otherwise.
0 commit comments