From 69926cdaf6c8f0feb5097151368167cb211145b7 Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Thu, 1 Oct 2026 15:12:21 -0400 Subject: [PATCH 01/22] FE-3140 refactor(billing): move the billing telemetry event contract to account-core The typed billing event union, its payload allowlist, the payload builders and the billing event-name constants now live in @comfyorg/account-core/billing so billing web can import them. src/platform/telemetry/types.ts re-exports the moved names until the cloud imports are migrated. --- .../account-core/src/core/billing/index.ts | 1 + .../telemetry/billingTelemetryEvent.ts | 38 ++ .../billing/telemetry/capabilityReadEvent.ts | 5 + .../telemetry/downgradeToPersonalEvent.ts | 18 + .../src/core/billing/telemetry/eventNames.ts | 37 ++ .../src/core/billing/telemetry/index.ts | 27 ++ .../core/billing/telemetry/operationEvent.ts | 31 ++ .../src/core/billing/telemetry/payload.ts | 82 ++++ .../billing/telemetry/resubscribeEvent.ts | 13 + .../src/core/billing/telemetry/stages.ts | 75 ++++ .../telemetry/subscriptionCheckoutEvent.ts | 40 ++ .../src/core/billing/telemetry/topupEvent.ts | 35 ++ .../src/core/billing/telemetry/vocabulary.ts | 37 ++ .../core/billing/telemetry/webHandoffEvent.ts | 12 + .../subscription/constants/tierPricing.ts | 3 +- .../utils/subscriptionTierRank.ts | 4 +- src/platform/telemetry/types.ts | 358 ++---------------- 17 files changed, 480 insertions(+), 336 deletions(-) create mode 100644 packages/account-core/src/core/billing/telemetry/billingTelemetryEvent.ts create mode 100644 packages/account-core/src/core/billing/telemetry/capabilityReadEvent.ts create mode 100644 packages/account-core/src/core/billing/telemetry/downgradeToPersonalEvent.ts create mode 100644 packages/account-core/src/core/billing/telemetry/eventNames.ts create mode 100644 packages/account-core/src/core/billing/telemetry/index.ts create mode 100644 packages/account-core/src/core/billing/telemetry/operationEvent.ts create mode 100644 packages/account-core/src/core/billing/telemetry/payload.ts create mode 100644 packages/account-core/src/core/billing/telemetry/resubscribeEvent.ts create mode 100644 packages/account-core/src/core/billing/telemetry/stages.ts create mode 100644 packages/account-core/src/core/billing/telemetry/subscriptionCheckoutEvent.ts create mode 100644 packages/account-core/src/core/billing/telemetry/topupEvent.ts create mode 100644 packages/account-core/src/core/billing/telemetry/vocabulary.ts create mode 100644 packages/account-core/src/core/billing/telemetry/webHandoffEvent.ts diff --git a/packages/account-core/src/core/billing/index.ts b/packages/account-core/src/core/billing/index.ts index 0844f0221f3..6dc157ef75a 100644 --- a/packages/account-core/src/core/billing/index.ts +++ b/packages/account-core/src/core/billing/index.ts @@ -168,6 +168,7 @@ export { operationRoute } from './operationLifecycle.js' export { BILLING_OPERATION_TELEMETRY_EVENT } from '../../telemetry.js' +export * from './telemetry/index.js' export type { EmbeddedChallengeOutcome, EmbeddedChallengePort diff --git a/packages/account-core/src/core/billing/telemetry/billingTelemetryEvent.ts b/packages/account-core/src/core/billing/telemetry/billingTelemetryEvent.ts new file mode 100644 index 00000000000..502ead9bde0 --- /dev/null +++ b/packages/account-core/src/core/billing/telemetry/billingTelemetryEvent.ts @@ -0,0 +1,38 @@ +import type { CapabilityReadBillingEvent } from './capabilityReadEvent.js' +import type { DowngradeToPersonalBillingEvent } from './downgradeToPersonalEvent.js' +import type { BillingOperationBillingEvent } from './operationEvent.js' +import type { ResubscribeBillingEvent } from './resubscribeEvent.js' +import type { SubscriptionCheckoutBillingEvent } from './subscriptionCheckoutEvent.js' +import type { TopupBillingEvent } from './topupEvent.js' +import type { WebHandoffBillingEvent } from './webHandoffEvent.js' + +export type BillingSurface = 'cloud_app' | 'billing_web' + +export type BillingClient = 'sdk' | 'legacy' + +export type BillingTelemetryEvent = { + /** The rail of the code that emitted the event; absent when the emitter does not know it. */ + billing_client?: BillingClient +} & ( + | CapabilityReadBillingEvent + | SubscriptionCheckoutBillingEvent + | BillingOperationBillingEvent + | ResubscribeBillingEvent + | TopupBillingEvent + | DowngradeToPersonalBillingEvent + | WebHandoffBillingEvent +) + +type BillingTelemetryEventNameFor = + T extends BillingTelemetryEvent + ? `billing.${T['operation']}.${T['stage']}` + : never + +export type BillingTelemetryEventName = + BillingTelemetryEventNameFor + +export function getBillingTelemetryEventName( + event: BillingTelemetryEvent +): BillingTelemetryEventName { + return `billing.${event.operation}.${event.stage}` as BillingTelemetryEventName +} diff --git a/packages/account-core/src/core/billing/telemetry/capabilityReadEvent.ts b/packages/account-core/src/core/billing/telemetry/capabilityReadEvent.ts new file mode 100644 index 00000000000..23ad64b480e --- /dev/null +++ b/packages/account-core/src/core/billing/telemetry/capabilityReadEvent.ts @@ -0,0 +1,5 @@ +import type { BillingFailed, BillingSucceeded } from './stages.js' + +export type CapabilityReadBillingEvent = { + operation: 'capability_read' +} & (BillingSucceeded | Pick) diff --git a/packages/account-core/src/core/billing/telemetry/downgradeToPersonalEvent.ts b/packages/account-core/src/core/billing/telemetry/downgradeToPersonalEvent.ts new file mode 100644 index 00000000000..c4ca1c2a428 --- /dev/null +++ b/packages/account-core/src/core/billing/telemetry/downgradeToPersonalEvent.ts @@ -0,0 +1,18 @@ +import type { + BillingFailed, + BillingStarted, + BillingSucceeded +} from './stages.js' +import type { BillingTierKey } from './vocabulary.js' + +export type DowngradeToPersonalBillingEvent = { + operation: 'downgrade_to_personal' + member_removal_count: number + member_removal_failures: number + target_tier?: BillingTierKey + /** + * Client-observed end-to-end wall time from this attempt's canonical + * `started` event through to this terminal event. + */ + duration_ms?: number +} & (BillingStarted | BillingSucceeded | BillingFailed) diff --git a/packages/account-core/src/core/billing/telemetry/eventNames.ts b/packages/account-core/src/core/billing/telemetry/eventNames.ts new file mode 100644 index 00000000000..76796131a9a --- /dev/null +++ b/packages/account-core/src/core/billing/telemetry/eventNames.ts @@ -0,0 +1,37 @@ +import type { BillingTelemetryEventName } from './billingTelemetryEvent.js' + +export const BILLING_TELEMETRY_EVENTS = { + BILLING_SUBSCRIPTION_CHECKOUT_RECEIVED: + 'billing.subscription_checkout.checkout_received', + BILLING_TOPUP_CHECKOUT_RECEIVED: 'billing.topup.checkout_received', + BILLING_SUBSCRIPTION_CHECKOUT_REQUEST_SENT: + 'billing.subscription_checkout.request_sent', + BILLING_TOPUP_REQUEST_SENT: 'billing.topup.request_sent', + BILLING_SUBSCRIPTION_CHECKOUT_INTENT: 'billing.subscription_checkout.intent', + BILLING_TOPUP_INTENT: 'billing.topup.intent', + BILLING_SUBSCRIPTION_CHECKOUT_STARTED: + 'billing.subscription_checkout.started', + BILLING_SUBSCRIPTION_CHECKOUT_SUCCEEDED: + 'billing.subscription_checkout.succeeded', + BILLING_SUBSCRIPTION_CHECKOUT_FAILED: 'billing.subscription_checkout.failed', + BILLING_SUBSCRIPTION_CHECKOUT_TIMEOUT: + 'billing.subscription_checkout.timeout', + BILLING_OPERATION_STARTED: 'billing.operation.started', + BILLING_CAPABILITY_READ_SUCCEEDED: 'billing.capability_read.succeeded', + BILLING_CAPABILITY_READ_FAILED: 'billing.capability_read.failed', + BILLING_OPERATION_SUCCEEDED: 'billing.operation.succeeded', + BILLING_OPERATION_FAILED: 'billing.operation.failed', + BILLING_OPERATION_TIMEOUT: 'billing.operation.timeout', + BILLING_RESUBSCRIBE_STARTED: 'billing.resubscribe.started', + BILLING_RESUBSCRIBE_SUCCEEDED: 'billing.resubscribe.succeeded', + BILLING_RESUBSCRIBE_FAILED: 'billing.resubscribe.failed', + BILLING_TOPUP_STARTED: 'billing.topup.started', + BILLING_TOPUP_SUCCEEDED: 'billing.topup.succeeded', + BILLING_TOPUP_FAILED: 'billing.topup.failed', + BILLING_DOWNGRADE_TO_PERSONAL_STARTED: + 'billing.downgrade_to_personal.started', + BILLING_DOWNGRADE_TO_PERSONAL_SUCCEEDED: + 'billing.downgrade_to_personal.succeeded', + BILLING_DOWNGRADE_TO_PERSONAL_FAILED: 'billing.downgrade_to_personal.failed', + BILLING_WEB_HANDOFF_OPENED: 'billing.web_handoff.opened' +} as const satisfies Record diff --git a/packages/account-core/src/core/billing/telemetry/index.ts b/packages/account-core/src/core/billing/telemetry/index.ts new file mode 100644 index 00000000000..72f5976340e --- /dev/null +++ b/packages/account-core/src/core/billing/telemetry/index.ts @@ -0,0 +1,27 @@ +export type { + BillingTelemetryErrorCode, + BillingTelemetryFailureCategory, + BillingOperationTerminal, + BillingTelemetryFailure +} from './stages.js' +export type { + BillingClient, + BillingSurface, + BillingTelemetryEvent, + BillingTelemetryEventName +} from './billingTelemetryEvent.js' +export { getBillingTelemetryEventName } from './billingTelemetryEvent.js' +export { + getBillingTelemetryEventPayload, + getCloudAppBillingTelemetryEventPayload +} from './payload.js' +export { BILLING_TELEMETRY_EVENTS } from './eventNames.js' +export type { + BillingCycle, + BillingTierKey, + HostedBillingIntent, + PaymentIntentSource, + ResubscribeSource, + SubscriptionCheckoutTier, + SubscriptionCheckoutType +} from './vocabulary.js' diff --git a/packages/account-core/src/core/billing/telemetry/operationEvent.ts b/packages/account-core/src/core/billing/telemetry/operationEvent.ts new file mode 100644 index 00000000000..25ddf3b9baa --- /dev/null +++ b/packages/account-core/src/core/billing/telemetry/operationEvent.ts @@ -0,0 +1,31 @@ +import type { BillingPresentation } from '../operationState.js' +import type { BillingOperationTerminal, BillingStarted } from './stages.js' +import type { + BillingCycle, + PaymentIntentSource, + SubscriptionCheckoutTier, + SubscriptionCheckoutType +} from './vocabulary.js' + +export type BillingOperationBillingEvent = { + operation: 'operation' + /** Absent when the initiating call itself failed, before the backend returned one to poll. */ + billing_op_id?: string + operation_type: 'subscription' | 'topup' | 'cancel' + /** Set by the billing SDK rail, as is `resumed`; the poller never sets either. */ + presentation?: BillingPresentation + /** True when this tab reattached to an operation it did not issue. */ + resumed?: boolean + tier?: SubscriptionCheckoutTier + cycle?: BillingCycle + checkout_type?: SubscriptionCheckoutType + payment_intent_source?: PaymentIntentSource + /** + * Client-observed end-to-end wall time from this attempt's canonical + * `started` event through to this terminal event, including the + * initiating API call's latency (not just the poll-observation window). + * On `timeout` this is how long the client watched, not the operation's + * true duration. + */ + duration_ms?: number +} & (BillingStarted | BillingOperationTerminal) diff --git a/packages/account-core/src/core/billing/telemetry/payload.ts b/packages/account-core/src/core/billing/telemetry/payload.ts new file mode 100644 index 00000000000..3299bfd4cac --- /dev/null +++ b/packages/account-core/src/core/billing/telemetry/payload.ts @@ -0,0 +1,82 @@ +import type { + BillingSurface, + BillingTelemetryEvent +} from './billingTelemetryEvent.js' + +type BillingTelemetryPayload = Record + +type KeysOfUnion = T extends unknown ? keyof T : never + +type BillingPayloadField = Exclude< + KeysOfUnion, + 'operation' | 'stage' | 'outcome' +> + +const BILLING_PAYLOAD_FIELD_HANDLING = { + checkout_status: 'required', + correlation_id: 'required', + failure_category: 'required', + intent: 'required', + member_removal_count: 'required', + member_removal_failures: 'required', + operation_type: 'required', + result: 'required', + source: 'required', + billing_client: 'optional', + billing_op_id: 'optional', + checkout_attempt_id: 'optional', + checkout_type: 'optional', + cycle: 'optional', + decline_reason: 'optional', + duration_ms: 'optional', + error_code: 'optional', + payment_intent_source: 'optional', + presentation: 'optional', + recovery_outcome: 'optional', + resumed: 'optional', + target_tier: 'optional', + tier: 'optional' +} as const satisfies Record + +const OPTIONAL_BILLING_PAYLOAD_FIELDS = Object.entries( + BILLING_PAYLOAD_FIELD_HANDLING +).flatMap(([field, handling]) => (handling === 'optional' ? [field] : [])) + +const REQUIRED_BILLING_PAYLOAD_FIELDS = Object.entries( + BILLING_PAYLOAD_FIELD_HANDLING +).flatMap(([field, handling]) => (handling === 'required' ? [field] : [])) + +const optionalBillingPayloadFields: ReadonlySet = new Set( + OPTIONAL_BILLING_PAYLOAD_FIELDS +) +const requiredBillingPayloadFields: ReadonlySet = new Set( + REQUIRED_BILLING_PAYLOAD_FIELDS +) + +export function getBillingTelemetryEventPayload(event: BillingTelemetryEvent) { + const payload: BillingTelemetryPayload = { + operation: event.operation, + stage: event.stage, + outcome: event.outcome + } + + for (const [field, value] of Object.entries(event)) { + if (requiredBillingPayloadFields.has(field)) { + payload[field] = value + } else if (optionalBillingPayloadFields.has(field) && value !== undefined) { + payload[field] = value + } + } + + return payload +} + +/** Only the cloud build registers the sinks that call this; the desktop host sink claims no surface. */ +export function getCloudAppBillingTelemetryEventPayload( + event: BillingTelemetryEvent +): BillingTelemetryPayload & { billing_surface: BillingSurface } { + return { + ...getBillingTelemetryEventPayload(event), + billing_surface: 'cloud_app' + } +} diff --git a/packages/account-core/src/core/billing/telemetry/resubscribeEvent.ts b/packages/account-core/src/core/billing/telemetry/resubscribeEvent.ts new file mode 100644 index 00000000000..e52f5e0fe82 --- /dev/null +++ b/packages/account-core/src/core/billing/telemetry/resubscribeEvent.ts @@ -0,0 +1,13 @@ +import type { + BillingFailed, + BillingRecoveredSucceeded, + BillingStarted +} from './stages.js' +import type { PaymentIntentSource, ResubscribeSource } from './vocabulary.js' + +export type ResubscribeBillingEvent = { + operation: 'resubscribe' + source: ResubscribeSource + checkout_attempt_id?: string + payment_intent_source?: PaymentIntentSource +} & (BillingStarted | BillingRecoveredSucceeded | BillingFailed) diff --git a/packages/account-core/src/core/billing/telemetry/stages.ts b/packages/account-core/src/core/billing/telemetry/stages.ts new file mode 100644 index 00000000000..7294c43cc79 --- /dev/null +++ b/packages/account-core/src/core/billing/telemetry/stages.ts @@ -0,0 +1,75 @@ +import type { BillingDeclineReason } from '../operationState.js' + +export type BillingTelemetryFailureCategory = + | 'validation' + | 'network' + | 'api_rejected' + | 'provider_decline' + | 'redirect' + | 'poll_timeout' + | 'reconciliation_needed' + | 'stale_operation' + | 'rendering' + | 'unknown' + +export type BillingTelemetryErrorCode = + | 'downgrade_not_allowed' + | 'member_removal_failed' + | 'missing_checkout_response' + | 'missing_payment_method_url' + | 'payment_popup_blocked' + | 'reactivation_not_confirmed' + | 'reactivation_amount_changed' + +export interface BillingTelemetryFailure { + failure_category: BillingTelemetryFailureCategory + error_code?: BillingTelemetryErrorCode +} + +export type BillingIntent = { + stage: 'intent' + outcome: 'pending' +} + +export type BillingRequestSent = { + stage: 'request_sent' + outcome: 'pending' +} + +export type BillingCheckoutReceived = { + stage: 'checkout_received' + outcome: 'pending' + billing_op_id: string + checkout_status: Status +} + +export type BillingStarted = { + stage: 'started' + outcome: 'pending' +} + +export type BillingSucceeded = { + stage: 'succeeded' + outcome: 'success' +} + +export type BillingRecoveredSucceeded = BillingSucceeded & { + recovery_outcome?: 'late_success' +} + +export type BillingFailed = BillingTelemetryFailure & { + stage: 'failed' + outcome: 'failure' +} + +export type BillingTimedOut = { + stage: 'timeout' + outcome: 'failure' + failure_category: 'poll_timeout' +} + +/** The stage one attempt at a billing operation settled on. */ +export type BillingOperationTerminal = + | BillingSucceeded + | (BillingFailed & { decline_reason?: BillingDeclineReason }) + | BillingTimedOut diff --git a/packages/account-core/src/core/billing/telemetry/subscriptionCheckoutEvent.ts b/packages/account-core/src/core/billing/telemetry/subscriptionCheckoutEvent.ts new file mode 100644 index 00000000000..e7146cb9982 --- /dev/null +++ b/packages/account-core/src/core/billing/telemetry/subscriptionCheckoutEvent.ts @@ -0,0 +1,40 @@ +import type { SubscribeResponse } from '@comfyorg/ingest-types' + +import type { + BillingCheckoutReceived, + BillingFailed, + BillingIntent, + BillingRecoveredSucceeded, + BillingRequestSent, + BillingStarted, + BillingTimedOut +} from './stages.js' +import type { + BillingCycle, + PaymentIntentSource, + SubscriptionCheckoutTier, + SubscriptionCheckoutType +} from './vocabulary.js' + +export type SubscriptionCheckoutBillingEvent = { + operation: 'subscription_checkout' + billing_op_id?: string + checkout_attempt_id?: string + tier?: SubscriptionCheckoutTier + cycle?: BillingCycle + checkout_type?: SubscriptionCheckoutType + payment_intent_source?: PaymentIntentSource + /** + * Client-observed end-to-end wall time from this attempt's canonical + * `started` event through to this terminal event. + */ + duration_ms?: number +} & ( + | BillingIntent + | BillingCheckoutReceived + | BillingRequestSent + | BillingStarted + | BillingRecoveredSucceeded + | BillingFailed + | BillingTimedOut +) diff --git a/packages/account-core/src/core/billing/telemetry/topupEvent.ts b/packages/account-core/src/core/billing/telemetry/topupEvent.ts new file mode 100644 index 00000000000..06a0d884cc5 --- /dev/null +++ b/packages/account-core/src/core/billing/telemetry/topupEvent.ts @@ -0,0 +1,35 @@ +import type { CreateTopupResponse } from '@comfyorg/ingest-types' + +import type { + BillingCheckoutReceived, + BillingFailed, + BillingIntent, + BillingRequestSent, + BillingStarted, + BillingSucceeded +} from './stages.js' +import type { PaymentIntentSource } from './vocabulary.js' + +export type TopupBillingEvent = { + operation: 'topup' + billing_op_id?: string + /** + * Surface the top-up was opened from. Absent when the caller named none, + * exactly as on the subscription rail's events — absent is no claim, never + * an implied default. Named `payment_intent_source` to match its siblings + * above; the journey's own `entry_source` is a separate, smaller enum. + */ + payment_intent_source?: PaymentIntentSource + /** + * Client-observed end-to-end wall time from this attempt's canonical + * `started` event through to this terminal event. + */ + duration_ms?: number +} & ( + | BillingIntent + | BillingCheckoutReceived + | BillingRequestSent + | BillingStarted + | BillingSucceeded + | BillingFailed +) diff --git a/packages/account-core/src/core/billing/telemetry/vocabulary.ts b/packages/account-core/src/core/billing/telemetry/vocabulary.ts new file mode 100644 index 00000000000..03985c29ade --- /dev/null +++ b/packages/account-core/src/core/billing/telemetry/vocabulary.ts @@ -0,0 +1,37 @@ +export type BillingTierKey = 'free' | 'standard' | 'creator' | 'pro' | 'founder' + +export type BillingCycle = 'monthly' | 'yearly' + +export type SubscriptionCheckoutType = 'new' | 'change' + +export type SubscriptionCheckoutTier = BillingTierKey | 'team' + +export type ResubscribeSource = 'pricing_dialog' | 'settings_billing_panel' + +/** Mirrors `BillingSource` in `@comfyorg/billing-contract`; a type test there fails when the two drift. */ +export type PaymentIntentSource = + | 'subscription_required' + | 'out_of_credits' + | 'top_up_blocked' + | 'deep_link' + | 'subscribe_to_run' + | 'subscribe_now_button' + | 'upgrade_to_add_credits' + | 'settings_billing_panel' + | 'avatar_menu_plans' + | 'team_members_panel' + | 'invite_member_upsell' + | 'upload_model_upgrade' + | 'team_upgrade_resume' + | 'free_tier_quota' + | 'agent_paywall' + +/** Mirrors `BillingIntent` in `@comfyorg/billing-contract`; a type test there fails when the two drift. */ +export type HostedBillingIntent = + | 'pricing' + | 'checkout' + | 'top-up' + | 'subscription' + | 'payment-methods' + | 'invoices' + | 'result' diff --git a/packages/account-core/src/core/billing/telemetry/webHandoffEvent.ts b/packages/account-core/src/core/billing/telemetry/webHandoffEvent.ts new file mode 100644 index 00000000000..2da2fd3a7e2 --- /dev/null +++ b/packages/account-core/src/core/billing/telemetry/webHandoffEvent.ts @@ -0,0 +1,12 @@ +import type { HostedBillingIntent, PaymentIntentSource } from './vocabulary.js' + +export type WebHandoffBillingEvent = { + operation: 'web_handoff' + stage: 'opened' + outcome: 'pending' + intent: HostedBillingIntent + result: 'opened' | 'blocked' + payment_intent_source?: PaymentIntentSource + /** The cloud journey id the entry link carries as `correlation_id`. */ + correlation_id: string +} diff --git a/src/platform/cloud/subscription/constants/tierPricing.ts b/src/platform/cloud/subscription/constants/tierPricing.ts index 0ceb6456d9f..2d9f8231fac 100644 --- a/src/platform/cloud/subscription/constants/tierPricing.ts +++ b/src/platform/cloud/subscription/constants/tierPricing.ts @@ -1,3 +1,4 @@ +import type { BillingTierKey } from '@comfyorg/account-core/billing' import { TIER_CATALOG } from '@comfyorg/account-ui/billing/catalog' import type { SubscriptionTier as IngestSubscriptionTier } from '@comfyorg/ingest-types' @@ -8,7 +9,7 @@ export type { IngestSubscriptionTier } export type RegistrySubscriptionTier = components['schemas']['SubscriptionTier'] -export type TierKey = 'free' | 'standard' | 'creator' | 'pro' | 'founder' +export type TierKey = BillingTierKey // Self-serve personal-plan tiers only. TEAM and ENTERPRISE are workspace-level // and sales-managed respectively, and intentionally have no catalog key (see diff --git a/src/platform/cloud/subscription/utils/subscriptionTierRank.ts b/src/platform/cloud/subscription/utils/subscriptionTierRank.ts index 355efaf1bcd..499a2f92976 100644 --- a/src/platform/cloud/subscription/utils/subscriptionTierRank.ts +++ b/src/platform/cloud/subscription/utils/subscriptionTierRank.ts @@ -1,6 +1,8 @@ +import type { BillingCycle } from '@comfyorg/account-core/billing' + import type { TierKey } from '@/platform/cloud/subscription/constants/tierPricing' -export type BillingCycle = 'monthly' | 'yearly' +export type { BillingCycle } type RankedTierKey = Exclude type RankedPlanKey = `${BillingCycle}-${RankedTierKey}` diff --git a/src/platform/telemetry/types.ts b/src/platform/telemetry/types.ts index b0aa19c72ec..af5bfa1e606 100644 --- a/src/platform/telemetry/types.ts +++ b/src/platform/telemetry/types.ts @@ -17,18 +17,16 @@ import { SESSION_TELEMETRY_EVENT } from '@comfyorg/account-core/telemetry' import type { - BillingDeclineReason, - BillingPresentation + BillingTelemetryErrorCode as BillingErrorCode, + BillingTelemetryEvent, + BillingTelemetryFailureCategory as BillingFailureCategory, + ResubscribeSource, + SubscriptionCheckoutTier, + SubscriptionCheckoutType } from '@comfyorg/account-core/billing' -import type { - BillingIntent as HostedBillingIntent, - BillingSource -} from '@comfyorg/billing-contract' -import type { - AgentRunMode, - CreateTopupResponse, - SubscribeResponse -} from '@comfyorg/ingest-types' +import { BILLING_TELEMETRY_EVENTS } from '@comfyorg/account-core/billing' +import type { BillingSource } from '@comfyorg/billing-contract' +import type { AgentRunMode } from '@comfyorg/ingest-types' import type { AuthErrorMetadata, AuthFlowAction, @@ -44,8 +42,19 @@ export type { AuthMethod } export type PaymentIntentSource = BillingSource -export type SubscriptionCheckoutType = 'new' | 'change' -export type SubscriptionCheckoutTier = TierKey | 'team' +export type { + BillingOperationTerminal, + BillingTelemetryEvent, + BillingTelemetryEventName, + BillingTelemetryFailure as BillingFailure, + SubscriptionCheckoutTier, + SubscriptionCheckoutType +} from '@comfyorg/account-core/billing' +export { + getBillingTelemetryEventName, + getBillingTelemetryEventPayload, + getCloudAppBillingTelemetryEventPayload +} from '@comfyorg/account-core/billing' /** * Authentication metadata for sign-up tracking @@ -1196,7 +1205,7 @@ export interface SubscriptionCancellationMetadata { } export interface ResubscribeClickMetadata { - source: 'pricing_dialog' | 'settings_billing_panel' + source: ResubscribeSource /** Why the pricing dialog was opened, when the click came from one. */ payment_intent_source?: PaymentIntentSource } @@ -1263,293 +1272,6 @@ export interface WorkspaceInviteFailedMetadata extends Record { failed_count: number } -type BillingFailureCategory = - | 'validation' - | 'network' - | 'api_rejected' - | 'provider_decline' - | 'redirect' - | 'poll_timeout' - | 'reconciliation_needed' - | 'stale_operation' - | 'rendering' - | 'unknown' - -type BillingErrorCode = - | 'downgrade_not_allowed' - | 'member_removal_failed' - | 'missing_checkout_response' - | 'missing_payment_method_url' - | 'payment_popup_blocked' - | 'reactivation_not_confirmed' - | 'reactivation_amount_changed' - -export interface BillingFailure { - failure_category: BillingFailureCategory - error_code?: BillingErrorCode -} - -type BillingIntent = { - stage: 'intent' - outcome: 'pending' -} - -type BillingRequestSent = { - stage: 'request_sent' - outcome: 'pending' -} - -type BillingCheckoutReceived = { - stage: 'checkout_received' - outcome: 'pending' - billing_op_id: string - checkout_status: Status -} - -type BillingStarted = { - stage: 'started' - outcome: 'pending' -} - -type BillingSucceeded = { - stage: 'succeeded' - outcome: 'success' -} - -type BillingRecoveredSucceeded = BillingSucceeded & { - recovery_outcome?: 'late_success' -} - -type BillingFailed = BillingFailure & { - stage: 'failed' - outcome: 'failure' -} - -type BillingTimedOut = { - stage: 'timeout' - outcome: 'failure' - failure_category: 'poll_timeout' -} - -/** The stage one attempt at a billing operation settled on. */ -export type BillingOperationTerminal = - | BillingSucceeded - | (BillingFailed & { decline_reason?: BillingDeclineReason }) - | BillingTimedOut - -type SubscriptionCheckoutBillingEvent = { - operation: 'subscription_checkout' - billing_op_id?: string - checkout_attempt_id?: string - tier?: SubscriptionCheckoutTier - cycle?: BillingCycle - checkout_type?: SubscriptionCheckoutType - payment_intent_source?: PaymentIntentSource - /** - * Client-observed end-to-end wall time from this attempt's canonical - * `started` event through to this terminal event. - */ - duration_ms?: number -} & ( - | BillingIntent - | BillingCheckoutReceived - | BillingRequestSent - | BillingStarted - | BillingRecoveredSucceeded - | BillingFailed - | BillingTimedOut -) - -type BillingOperationBillingEvent = { - operation: 'operation' - /** Absent when the initiating call itself failed, before the backend returned one to poll. */ - billing_op_id?: string - operation_type: 'subscription' | 'topup' | 'cancel' - /** Set by the billing SDK rail, as is `resumed`; the poller never sets either. */ - presentation?: BillingPresentation - /** True when this tab reattached to an operation it did not issue. */ - resumed?: boolean - tier?: SubscriptionCheckoutTier - cycle?: BillingCycle - checkout_type?: SubscriptionCheckoutType - payment_intent_source?: PaymentIntentSource - /** - * Client-observed end-to-end wall time from this attempt's canonical - * `started` event through to this terminal event, including the - * initiating API call's latency (not just the poll-observation window). - * On `timeout` this is how long the client watched, not the operation's - * true duration. - */ - duration_ms?: number -} & (BillingStarted | BillingOperationTerminal) - -type ResubscribeBillingEvent = { - operation: 'resubscribe' - source: ResubscribeClickMetadata['source'] - checkout_attempt_id?: string - payment_intent_source?: PaymentIntentSource -} & (BillingStarted | BillingRecoveredSucceeded | BillingFailed) - -type TopupBillingEvent = { - operation: 'topup' - billing_op_id?: string - /** - * Surface the top-up was opened from. Absent when the caller named none, - * exactly as on the subscription rail's events — absent is no claim, never - * an implied default. Named `payment_intent_source` to match its siblings - * above; the journey's own `entry_source` is a separate, smaller enum. - */ - payment_intent_source?: PaymentIntentSource - /** - * Client-observed end-to-end wall time from this attempt's canonical - * `started` event through to this terminal event. - */ - duration_ms?: number -} & ( - | BillingIntent - | BillingCheckoutReceived - | BillingRequestSent - | BillingStarted - | BillingSucceeded - | BillingFailed -) - -type DowngradeToPersonalBillingEvent = { - operation: 'downgrade_to_personal' - member_removal_count: number - member_removal_failures: number - target_tier?: TierKey - /** - * Client-observed end-to-end wall time from this attempt's canonical - * `started` event through to this terminal event. - */ - duration_ms?: number -} & (BillingStarted | BillingSucceeded | BillingFailed) - -type CapabilityReadBillingEvent = { - operation: 'capability_read' -} & (BillingSucceeded | Pick) - -type WebHandoffBillingEvent = { - operation: 'web_handoff' - stage: 'opened' - outcome: 'pending' - intent: HostedBillingIntent - result: 'opened' | 'blocked' - payment_intent_source?: PaymentIntentSource - /** The cloud journey id the entry link carries as `correlation_id`. */ - correlation_id: string -} - -type BillingSurface = 'cloud_app' | 'billing_web' - -type BillingClient = 'sdk' | 'legacy' - -export type BillingTelemetryEvent = { - /** The rail of the code that emitted the event; absent when the emitter does not know it. */ - billing_client?: BillingClient -} & ( - | CapabilityReadBillingEvent - | SubscriptionCheckoutBillingEvent - | BillingOperationBillingEvent - | ResubscribeBillingEvent - | TopupBillingEvent - | DowngradeToPersonalBillingEvent - | WebHandoffBillingEvent -) - -type BillingTelemetryEventNameFor = - T extends BillingTelemetryEvent - ? `billing.${T['operation']}.${T['stage']}` - : never - -export type BillingTelemetryEventName = - BillingTelemetryEventNameFor - -export function getBillingTelemetryEventName( - event: BillingTelemetryEvent -): BillingTelemetryEventName { - return `billing.${event.operation}.${event.stage}` as BillingTelemetryEventName -} - -type BillingTelemetryPayload = Record - -type KeysOfUnion = T extends unknown ? keyof T : never - -type BillingPayloadField = Exclude< - KeysOfUnion, - 'operation' | 'stage' | 'outcome' -> - -const BILLING_PAYLOAD_FIELD_HANDLING = { - checkout_status: 'required', - correlation_id: 'required', - failure_category: 'required', - intent: 'required', - member_removal_count: 'required', - member_removal_failures: 'required', - operation_type: 'required', - result: 'required', - source: 'required', - billing_client: 'optional', - billing_op_id: 'optional', - checkout_attempt_id: 'optional', - checkout_type: 'optional', - cycle: 'optional', - decline_reason: 'optional', - duration_ms: 'optional', - error_code: 'optional', - payment_intent_source: 'optional', - presentation: 'optional', - recovery_outcome: 'optional', - resumed: 'optional', - target_tier: 'optional', - tier: 'optional' -} as const satisfies Record - -const OPTIONAL_BILLING_PAYLOAD_FIELDS = Object.entries( - BILLING_PAYLOAD_FIELD_HANDLING -).flatMap(([field, handling]) => (handling === 'optional' ? [field] : [])) - -const REQUIRED_BILLING_PAYLOAD_FIELDS = Object.entries( - BILLING_PAYLOAD_FIELD_HANDLING -).flatMap(([field, handling]) => (handling === 'required' ? [field] : [])) - -const optionalBillingPayloadFields: ReadonlySet = new Set( - OPTIONAL_BILLING_PAYLOAD_FIELDS -) -const requiredBillingPayloadFields: ReadonlySet = new Set( - REQUIRED_BILLING_PAYLOAD_FIELDS -) - -export function getBillingTelemetryEventPayload(event: BillingTelemetryEvent) { - const payload: BillingTelemetryPayload = { - operation: event.operation, - stage: event.stage, - outcome: event.outcome - } - - for (const [field, value] of Object.entries(event)) { - if (requiredBillingPayloadFields.has(field)) { - payload[field] = value - } else if (optionalBillingPayloadFields.has(field) && value !== undefined) { - payload[field] = value - } - } - - return payload -} - -/** Only the cloud build registers the sinks that call this; the desktop host sink claims no surface. */ -export function getCloudAppBillingTelemetryEventPayload( - event: BillingTelemetryEvent -): BillingTelemetryPayload & { billing_surface: BillingSurface } { - return { - ...getBillingTelemetryEventPayload(event), - billing_surface: 'cloud_app' - } -} - /** * Checkout-journey lifecycle events for the embedded-checkout rollout. * @@ -1953,39 +1675,7 @@ export const TelemetryEvents = { AGENT_PAYWALL_CTA_CLICKED: 'app:agent_paywall_cta_clicked', // Canonical Billing Lifecycle - BILLING_SUBSCRIPTION_CHECKOUT_RECEIVED: - 'billing.subscription_checkout.checkout_received', - BILLING_TOPUP_CHECKOUT_RECEIVED: 'billing.topup.checkout_received', - BILLING_SUBSCRIPTION_CHECKOUT_REQUEST_SENT: - 'billing.subscription_checkout.request_sent', - BILLING_TOPUP_REQUEST_SENT: 'billing.topup.request_sent', - BILLING_SUBSCRIPTION_CHECKOUT_INTENT: 'billing.subscription_checkout.intent', - BILLING_TOPUP_INTENT: 'billing.topup.intent', - BILLING_SUBSCRIPTION_CHECKOUT_STARTED: - 'billing.subscription_checkout.started', - BILLING_SUBSCRIPTION_CHECKOUT_SUCCEEDED: - 'billing.subscription_checkout.succeeded', - BILLING_SUBSCRIPTION_CHECKOUT_FAILED: 'billing.subscription_checkout.failed', - BILLING_SUBSCRIPTION_CHECKOUT_TIMEOUT: - 'billing.subscription_checkout.timeout', - BILLING_OPERATION_STARTED: 'billing.operation.started', - BILLING_CAPABILITY_READ_SUCCEEDED: 'billing.capability_read.succeeded', - BILLING_CAPABILITY_READ_FAILED: 'billing.capability_read.failed', - BILLING_OPERATION_SUCCEEDED: 'billing.operation.succeeded', - BILLING_OPERATION_FAILED: 'billing.operation.failed', - BILLING_OPERATION_TIMEOUT: 'billing.operation.timeout', - BILLING_RESUBSCRIBE_STARTED: 'billing.resubscribe.started', - BILLING_RESUBSCRIBE_SUCCEEDED: 'billing.resubscribe.succeeded', - BILLING_RESUBSCRIBE_FAILED: 'billing.resubscribe.failed', - BILLING_TOPUP_STARTED: 'billing.topup.started', - BILLING_TOPUP_SUCCEEDED: 'billing.topup.succeeded', - BILLING_TOPUP_FAILED: 'billing.topup.failed', - BILLING_DOWNGRADE_TO_PERSONAL_STARTED: - 'billing.downgrade_to_personal.started', - BILLING_DOWNGRADE_TO_PERSONAL_SUCCEEDED: - 'billing.downgrade_to_personal.succeeded', - BILLING_DOWNGRADE_TO_PERSONAL_FAILED: 'billing.downgrade_to_personal.failed', - BILLING_WEB_HANDOFF_OPENED: 'billing.web_handoff.opened', + ...BILLING_TELEMETRY_EVENTS, // Onboarding Survey USER_SURVEY_OPENED: 'app:user_survey_opened', From be72e3ef8003ee46cdcc356296a4fb25e98908b4 Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Thu, 1 Oct 2026 15:13:19 -0400 Subject: [PATCH 02/22] FE-3140 refactor(billing): move the checkout journey event contract to account-core The journey phases, their wire names and payload builder share their failure vocabulary with the billing event union, so billing web needs them from the same package to type the billing.checkout events. --- .../core/billing/telemetry/checkoutJourney.ts | 178 ++++++++++++++++ .../src/core/billing/telemetry/index.ts | 24 ++- src/platform/telemetry/types.ts | 192 ++---------------- 3 files changed, 215 insertions(+), 179 deletions(-) create mode 100644 packages/account-core/src/core/billing/telemetry/checkoutJourney.ts diff --git a/packages/account-core/src/core/billing/telemetry/checkoutJourney.ts b/packages/account-core/src/core/billing/telemetry/checkoutJourney.ts new file mode 100644 index 00000000000..67b050fbbd8 --- /dev/null +++ b/packages/account-core/src/core/billing/telemetry/checkoutJourney.ts @@ -0,0 +1,178 @@ +import type { + BillingTelemetryErrorCode, + BillingTelemetryFailureCategory +} from './stages.js' + +/** + * Checkout-journey lifecycle events for the embedded-checkout rollout. + * + * These intermediate stages are kept deliberately separate from the terminal + * billing taxonomy above (`billing..`): entry, preview, and + * Payment Element observations are client observations of progress, never + * business success/failure/timeout. They share one frozen journey context so + * the two rollout arms can be compared on the same denominator. + */ +export const CHECKOUT_JOURNEY_SCHEMA_VERSION = 1 + +export type CheckoutJourneyArm = 'control' | 'treatment' +export type CheckoutAssignmentStatus = 'resolved' | 'unavailable' +export type CheckoutUiMode = 'embedded' | 'hosted' | 'unknown' +export type CheckoutEntryFlow = + | 'initial_subscription' + | 'paid_upgrade' + | 'topup' + | 'other' + | 'unknown' +export type CheckoutEntrySource = + | 'pricing' + | 'deep_link' + | 'recovery' + | 'settings_billing' + | 'other' + | 'unknown' + | 'agent_paywall' +type CheckoutElementPhase = 'init' | 'mount' | 'update' +/** Which Stripe element in the shared group the observation came from. */ +type CheckoutElementKind = 'payment' | 'address' +type CheckoutSubmitPhase = 'validation' | 'token_creation' + +/** + * The frozen arm assignment. A resolved assignment always carries an arm; an + * unavailable one never does, so an unknown assignment cannot masquerade as a + * resolved `control`. Encoded as a discriminated union so the invariant is a + * compile-time guarantee rather than a convention. + */ +type CheckoutJourneyAssignment = + | { assignment_status: 'resolved'; assigned_arm: CheckoutJourneyArm } + | { assignment_status: 'unavailable'; assigned_arm?: never } + +/** + * Non-sensitive entry context frozen at journey creation and replayed on every + * journey event. + */ +export type CheckoutJourneyContext = { + checkout_journey_id: string + /** UTC ISO-8601 timestamp captured at common intent, preserved across reload. */ + checkout_entered_at: string + ui_mode?: CheckoutUiMode + entry_flow: CheckoutEntryFlow + entry_source: CheckoutEntrySource + billing_op_id?: string +} & CheckoutJourneyAssignment + +type CheckoutJourneyEntered = { phase: 'entered' } +type CheckoutJourneyPreviewReady = { + phase: 'preview_ready' + preview_revision?: string +} +type CheckoutJourneyPreviewFailed = { + phase: 'preview_failed' + failure_category: BillingTelemetryFailureCategory + error_code?: BillingTelemetryErrorCode + preview_revision?: string +} +type CheckoutJourneyPaymentElementReady = { + phase: 'payment_element_ready' + element: CheckoutElementKind +} +type CheckoutJourneyPaymentElementFailed = { + phase: 'payment_element_failed' + element: CheckoutElementKind + element_phase: CheckoutElementPhase + error_code?: string +} +type CheckoutJourneyPaymentSubmitAttempted = { + phase: 'payment_submit_attempted' +} +type CheckoutJourneyPaymentSubmitFailed = { + phase: 'payment_submit_failed' + submit_phase: CheckoutSubmitPhase + error_code?: string +} +type CheckoutJourneySubmitted = { phase: 'submitted' } +type CheckoutJourneyOperationLinked = { + phase: 'operation_linked' + billing_op_id: string +} + +export type CheckoutJourneyPhaseEvent = + | CheckoutJourneyEntered + | CheckoutJourneyPreviewReady + | CheckoutJourneyPreviewFailed + | CheckoutJourneyPaymentElementReady + | CheckoutJourneyPaymentElementFailed + | CheckoutJourneyPaymentSubmitAttempted + | CheckoutJourneyPaymentSubmitFailed + | CheckoutJourneySubmitted + | CheckoutJourneyOperationLinked + +type CheckoutJourneyPhase = CheckoutJourneyPhaseEvent['phase'] + +export type CheckoutJourneyTelemetryEvent = CheckoutJourneyContext & + CheckoutJourneyPhaseEvent + +export type CheckoutJourneyTelemetryEventName = + `billing.checkout.${CheckoutJourneyPhase}` + +/** + * The wire name for every phase. Typed as a total `Record` over the phase + * union, so a phase added to the union without a name here fails to compile — + * and so the runtime list below can never drift from the emitted names. + */ +export const CHECKOUT_JOURNEY_EVENT_NAME_BY_PHASE: Record< + CheckoutJourneyPhase, + CheckoutJourneyTelemetryEventName +> = { + entered: 'billing.checkout.entered', + preview_ready: 'billing.checkout.preview_ready', + preview_failed: 'billing.checkout.preview_failed', + payment_element_ready: 'billing.checkout.payment_element_ready', + payment_element_failed: 'billing.checkout.payment_element_failed', + payment_submit_attempted: 'billing.checkout.payment_submit_attempted', + payment_submit_failed: 'billing.checkout.payment_submit_failed', + submitted: 'billing.checkout.submitted', + operation_linked: 'billing.checkout.operation_linked' +} + +export function getCheckoutJourneyTelemetryEventName( + event: CheckoutJourneyTelemetryEvent +): CheckoutJourneyTelemetryEventName { + return CHECKOUT_JOURNEY_EVENT_NAME_BY_PHASE[event.phase] +} + +export function getCheckoutJourneyTelemetryEventPayload( + event: CheckoutJourneyTelemetryEvent +) { + return { + schema_version: CHECKOUT_JOURNEY_SCHEMA_VERSION, + phase: event.phase, + checkout_journey_id: event.checkout_journey_id, + checkout_entered_at: event.checkout_entered_at, + assignment_status: event.assignment_status, + entry_flow: event.entry_flow, + entry_source: event.entry_source, + ...(event.assigned_arm !== undefined && { + assigned_arm: event.assigned_arm + }), + ...(event.ui_mode !== undefined && { ui_mode: event.ui_mode }), + ...(event.billing_op_id !== undefined && { + billing_op_id: event.billing_op_id + }), + ...('preview_revision' in event && + event.preview_revision !== undefined && { + preview_revision: event.preview_revision + }), + ...('failure_category' in event && { + failure_category: event.failure_category + }), + ...('error_code' in event && + event.error_code !== undefined && { error_code: event.error_code }), + ...('element' in event && { element: event.element }), + ...('element_phase' in event && { element_phase: event.element_phase }), + ...('submit_phase' in event && { submit_phase: event.submit_phase }) + } +} + +export type CheckoutJourneyTelemetryEventPayload = ReturnType< + typeof getCheckoutJourneyTelemetryEventPayload +> diff --git a/packages/account-core/src/core/billing/telemetry/index.ts b/packages/account-core/src/core/billing/telemetry/index.ts index 72f5976340e..515e3191bb4 100644 --- a/packages/account-core/src/core/billing/telemetry/index.ts +++ b/packages/account-core/src/core/billing/telemetry/index.ts @@ -1,8 +1,8 @@ export type { - BillingTelemetryErrorCode, - BillingTelemetryFailureCategory, BillingOperationTerminal, - BillingTelemetryFailure + BillingTelemetryErrorCode, + BillingTelemetryFailure, + BillingTelemetryFailureCategory } from './stages.js' export type { BillingClient, @@ -16,6 +16,24 @@ export { getCloudAppBillingTelemetryEventPayload } from './payload.js' export { BILLING_TELEMETRY_EVENTS } from './eventNames.js' +export type { + CheckoutAssignmentStatus, + CheckoutEntryFlow, + CheckoutEntrySource, + CheckoutJourneyArm, + CheckoutJourneyContext, + CheckoutJourneyPhaseEvent, + CheckoutJourneyTelemetryEvent, + CheckoutJourneyTelemetryEventName, + CheckoutJourneyTelemetryEventPayload, + CheckoutUiMode +} from './checkoutJourney.js' +export { + CHECKOUT_JOURNEY_EVENT_NAME_BY_PHASE, + CHECKOUT_JOURNEY_SCHEMA_VERSION, + getCheckoutJourneyTelemetryEventName, + getCheckoutJourneyTelemetryEventPayload +} from './checkoutJourney.js' export type { BillingCycle, BillingTierKey, diff --git a/src/platform/telemetry/types.ts b/src/platform/telemetry/types.ts index af5bfa1e606..4f20983e11a 100644 --- a/src/platform/telemetry/types.ts +++ b/src/platform/telemetry/types.ts @@ -17,9 +17,10 @@ import { SESSION_TELEMETRY_EVENT } from '@comfyorg/account-core/telemetry' import type { - BillingTelemetryErrorCode as BillingErrorCode, BillingTelemetryEvent, - BillingTelemetryFailureCategory as BillingFailureCategory, + CheckoutJourneyTelemetryEvent, + CheckoutJourneyTelemetryEventName, + CheckoutJourneyTelemetryEventPayload, ResubscribeSource, SubscriptionCheckoutTier, SubscriptionCheckoutType @@ -47,12 +48,25 @@ export type { BillingTelemetryEvent, BillingTelemetryEventName, BillingTelemetryFailure as BillingFailure, + CheckoutAssignmentStatus, + CheckoutEntryFlow, + CheckoutEntrySource, + CheckoutJourneyArm, + CheckoutJourneyContext, + CheckoutJourneyPhaseEvent, + CheckoutJourneyTelemetryEvent, + CheckoutJourneyTelemetryEventName, + CheckoutUiMode, SubscriptionCheckoutTier, SubscriptionCheckoutType } from '@comfyorg/account-core/billing' export { + CHECKOUT_JOURNEY_EVENT_NAME_BY_PHASE, + CHECKOUT_JOURNEY_SCHEMA_VERSION, getBillingTelemetryEventName, getBillingTelemetryEventPayload, + getCheckoutJourneyTelemetryEventName, + getCheckoutJourneyTelemetryEventPayload, getCloudAppBillingTelemetryEventPayload } from '@comfyorg/account-core/billing' @@ -1272,180 +1286,6 @@ export interface WorkspaceInviteFailedMetadata extends Record { failed_count: number } -/** - * Checkout-journey lifecycle events for the embedded-checkout rollout. - * - * These intermediate stages are kept deliberately separate from the terminal - * billing taxonomy above (`billing..`): entry, preview, and - * Payment Element observations are client observations of progress, never - * business success/failure/timeout. They share one frozen journey context so - * the two rollout arms can be compared on the same denominator. - */ -export const CHECKOUT_JOURNEY_SCHEMA_VERSION = 1 - -export type CheckoutJourneyArm = 'control' | 'treatment' -export type CheckoutAssignmentStatus = 'resolved' | 'unavailable' -export type CheckoutUiMode = 'embedded' | 'hosted' | 'unknown' -export type CheckoutEntryFlow = - | 'initial_subscription' - | 'paid_upgrade' - | 'topup' - | 'other' - | 'unknown' -export type CheckoutEntrySource = - | 'pricing' - | 'deep_link' - | 'recovery' - | 'settings_billing' - | 'other' - | 'unknown' - | 'agent_paywall' -type CheckoutElementPhase = 'init' | 'mount' | 'update' -/** Which Stripe element in the shared group the observation came from. */ -type CheckoutElementKind = 'payment' | 'address' -type CheckoutSubmitPhase = 'validation' | 'token_creation' - -/** - * The frozen arm assignment. A resolved assignment always carries an arm; an - * unavailable one never does, so an unknown assignment cannot masquerade as a - * resolved `control`. Encoded as a discriminated union so the invariant is a - * compile-time guarantee rather than a convention. - */ -type CheckoutJourneyAssignment = - | { assignment_status: 'resolved'; assigned_arm: CheckoutJourneyArm } - | { assignment_status: 'unavailable'; assigned_arm?: never } - -/** - * Non-sensitive entry context frozen at journey creation and replayed on every - * journey event. - */ -export type CheckoutJourneyContext = { - checkout_journey_id: string - /** UTC ISO-8601 timestamp captured at common intent, preserved across reload. */ - checkout_entered_at: string - ui_mode?: CheckoutUiMode - entry_flow: CheckoutEntryFlow - entry_source: CheckoutEntrySource - billing_op_id?: string -} & CheckoutJourneyAssignment - -type CheckoutJourneyEntered = { phase: 'entered' } -type CheckoutJourneyPreviewReady = { - phase: 'preview_ready' - preview_revision?: string -} -type CheckoutJourneyPreviewFailed = { - phase: 'preview_failed' - failure_category: BillingFailureCategory - error_code?: BillingErrorCode - preview_revision?: string -} -type CheckoutJourneyPaymentElementReady = { - phase: 'payment_element_ready' - element: CheckoutElementKind -} -type CheckoutJourneyPaymentElementFailed = { - phase: 'payment_element_failed' - element: CheckoutElementKind - element_phase: CheckoutElementPhase - error_code?: string -} -type CheckoutJourneyPaymentSubmitAttempted = { - phase: 'payment_submit_attempted' -} -type CheckoutJourneyPaymentSubmitFailed = { - phase: 'payment_submit_failed' - submit_phase: CheckoutSubmitPhase - error_code?: string -} -type CheckoutJourneySubmitted = { phase: 'submitted' } -type CheckoutJourneyOperationLinked = { - phase: 'operation_linked' - billing_op_id: string -} - -export type CheckoutJourneyPhaseEvent = - | CheckoutJourneyEntered - | CheckoutJourneyPreviewReady - | CheckoutJourneyPreviewFailed - | CheckoutJourneyPaymentElementReady - | CheckoutJourneyPaymentElementFailed - | CheckoutJourneyPaymentSubmitAttempted - | CheckoutJourneyPaymentSubmitFailed - | CheckoutJourneySubmitted - | CheckoutJourneyOperationLinked - -type CheckoutJourneyPhase = CheckoutJourneyPhaseEvent['phase'] - -export type CheckoutJourneyTelemetryEvent = CheckoutJourneyContext & - CheckoutJourneyPhaseEvent - -export type CheckoutJourneyTelemetryEventName = - `billing.checkout.${CheckoutJourneyPhase}` - -/** - * The wire name for every phase. Typed as a total `Record` over the phase - * union, so a phase added to the union without a name here fails to compile — - * and so the runtime list below can never drift from the emitted names. - */ -export const CHECKOUT_JOURNEY_EVENT_NAME_BY_PHASE: Record< - CheckoutJourneyPhase, - CheckoutJourneyTelemetryEventName -> = { - entered: 'billing.checkout.entered', - preview_ready: 'billing.checkout.preview_ready', - preview_failed: 'billing.checkout.preview_failed', - payment_element_ready: 'billing.checkout.payment_element_ready', - payment_element_failed: 'billing.checkout.payment_element_failed', - payment_submit_attempted: 'billing.checkout.payment_submit_attempted', - payment_submit_failed: 'billing.checkout.payment_submit_failed', - submitted: 'billing.checkout.submitted', - operation_linked: 'billing.checkout.operation_linked' -} - -export function getCheckoutJourneyTelemetryEventName( - event: CheckoutJourneyTelemetryEvent -): CheckoutJourneyTelemetryEventName { - return CHECKOUT_JOURNEY_EVENT_NAME_BY_PHASE[event.phase] -} - -export function getCheckoutJourneyTelemetryEventPayload( - event: CheckoutJourneyTelemetryEvent -) { - return { - schema_version: CHECKOUT_JOURNEY_SCHEMA_VERSION, - phase: event.phase, - checkout_journey_id: event.checkout_journey_id, - checkout_entered_at: event.checkout_entered_at, - assignment_status: event.assignment_status, - entry_flow: event.entry_flow, - entry_source: event.entry_source, - ...(event.assigned_arm !== undefined && { - assigned_arm: event.assigned_arm - }), - ...(event.ui_mode !== undefined && { ui_mode: event.ui_mode }), - ...(event.billing_op_id !== undefined && { - billing_op_id: event.billing_op_id - }), - ...('preview_revision' in event && - event.preview_revision !== undefined && { - preview_revision: event.preview_revision - }), - ...('failure_category' in event && { - failure_category: event.failure_category - }), - ...('error_code' in event && - event.error_code !== undefined && { error_code: event.error_code }), - ...('element' in event && { element: event.element }), - ...('element_phase' in event && { element_phase: event.element_phase }), - ...('submit_phase' in event && { submit_phase: event.submit_phase }) - } -} - -type CheckoutJourneyTelemetryEventPayload = ReturnType< - typeof getCheckoutJourneyTelemetryEventPayload -> - export interface FetchTimeoutMetadata { route: string method: string From 995108663c2fa147d18e02261eae0ee1fc64996b Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Thu, 1 Oct 2026 15:16:43 -0400 Subject: [PATCH 03/22] FE-3140 refactor(billing): import the billing event contract from account-core Migrates every cloud import of the moved contract to @comfyorg/account-core/billing and deletes the re-exports from src/platform/telemetry/types.ts. TelemetryEvents spreads the shared billing event names, TierKey and BillingCycle derive from the shared vocabulary, and the telemetry failure type is now BillingTelemetryFailure. --- .../utils/subscriptionCheckoutTracker.ts | 2 +- .../telemetry/TelemetryRegistry.test.ts | 6 +++-- src/platform/telemetry/TelemetryRegistry.ts | 6 +++-- .../telemetry/billingTelemetryEvent.test.ts | 11 ++++---- .../telemetry/checkoutJourneyEvent.test.ts | 7 +++-- .../cloud/DatadogRumTelemetryProvider.test.ts | 2 +- .../cloud/DatadogRumTelemetryProvider.ts | 20 +++++++------- .../cloud/MixpanelTelemetryProvider.ts | 7 ++--- .../cloud/PostHogTelemetryProvider.test.ts | 2 +- .../cloud/PostHogTelemetryProvider.ts | 18 ++++++++----- .../providers/host/HostTelemetrySink.ts | 13 +++++---- src/platform/telemetry/types.ts | 27 ------------------- .../telemetry/utils/billingFailureCategory.ts | 10 +++---- .../telemetry/webHandoffEvent.test.ts | 5 ++-- .../workspace/api/workspaceApiError.ts | 4 +-- .../billing/sdk/billingSdkTelemetry.ts | 7 ++--- .../billing/sdk/topupOperationView.ts | 8 +++--- ...TopUpCreditsDialogContentWorkspace.test.ts | 6 +++-- .../TopUpCreditsDialogContentWorkspace.vue | 10 +++---- .../composables/useDowngradeToPersonal.ts | 4 +-- .../composables/useSubscriptionCheckout.ts | 12 ++++----- .../workspace/stores/billingOperationStore.ts | 16 +++++------ .../workspace/utils/checkoutJourney.test.ts | 3 +-- .../workspace/utils/checkoutJourney.ts | 12 ++++----- .../utils/workspaceCheckoutTelemetry.ts | 7 ++--- 25 files changed, 101 insertions(+), 124 deletions(-) diff --git a/src/platform/cloud/subscription/utils/subscriptionCheckoutTracker.ts b/src/platform/cloud/subscription/utils/subscriptionCheckoutTracker.ts index 90770a985b1..91ac78679c4 100644 --- a/src/platform/cloud/subscription/utils/subscriptionCheckoutTracker.ts +++ b/src/platform/cloud/subscription/utils/subscriptionCheckoutTracker.ts @@ -1,3 +1,4 @@ +import type { SubscriptionCheckoutType } from '@comfyorg/account-core/billing' import type { SubscriptionDuration } from '@comfyorg/ingest-types' import { getTierPrice, @@ -12,7 +13,6 @@ import type { BeginCheckoutMetadata, PaymentIntentSource, ResubscribeClickMetadata, - SubscriptionCheckoutType, SubscriptionSuccessMetadata } from '@/platform/telemetry/types' diff --git a/src/platform/telemetry/TelemetryRegistry.test.ts b/src/platform/telemetry/TelemetryRegistry.test.ts index b3d1c39d059..3f31ccac4ca 100644 --- a/src/platform/telemetry/TelemetryRegistry.test.ts +++ b/src/platform/telemetry/TelemetryRegistry.test.ts @@ -1,3 +1,7 @@ +import type { + BillingTelemetryEvent, + CheckoutJourneyTelemetryEvent +} from '@comfyorg/account-core/billing' import { describe, expect, it, vi } from 'vitest' import { TelemetryRegistry } from './TelemetryRegistry' @@ -15,8 +19,6 @@ import type { AgentPaywallShownMetadata, AgentStarterPromptClickedMetadata, AgentWorkflowAppliedMetadata, - BillingTelemetryEvent, - CheckoutJourneyTelemetryEvent, TelemetryProvider } from './types' diff --git a/src/platform/telemetry/TelemetryRegistry.ts b/src/platform/telemetry/TelemetryRegistry.ts index 553c8f975fd..0e1bf1a7d50 100644 --- a/src/platform/telemetry/TelemetryRegistry.ts +++ b/src/platform/telemetry/TelemetryRegistry.ts @@ -1,3 +1,7 @@ +import type { + BillingTelemetryEvent, + CheckoutJourneyTelemetryEvent +} from '@comfyorg/account-core/billing' import type { AddCreditsClickMetadata, AgentAttachButtonClickedMetadata, @@ -27,9 +31,7 @@ import type { AuthErrorMetadata, AuthMetadata, BeginCheckoutMetadata, - BillingTelemetryEvent, BootstrapCompleteMetadata, - CheckoutJourneyTelemetryEvent, DefaultViewSetMetadata, EnterLinearMetadata, ExecutionErrorMetadata, diff --git a/src/platform/telemetry/billingTelemetryEvent.test.ts b/src/platform/telemetry/billingTelemetryEvent.test.ts index e1d411758f1..7a2664bfcc5 100644 --- a/src/platform/telemetry/billingTelemetryEvent.test.ts +++ b/src/platform/telemetry/billingTelemetryEvent.test.ts @@ -1,14 +1,13 @@ +import { + getBillingTelemetryEventPayload, + getCloudAppBillingTelemetryEventPayload +} from '@comfyorg/account-core/billing' +import type { BillingTelemetryEvent } from '@comfyorg/account-core/billing' import { pick } from 'es-toolkit' import { describe, expect, expectTypeOf, it } from 'vitest' import { toBillingTelemetryEvent } from '@/platform/workspace/billing/sdk/billingSdkTelemetry' -import type { BillingTelemetryEvent } from './types' -import { - getBillingTelemetryEventPayload, - getCloudAppBillingTelemetryEventPayload -} from './types' - type LateSuccessEvent = Extract< BillingTelemetryEvent, { recovery_outcome?: 'late_success' } diff --git a/src/platform/telemetry/checkoutJourneyEvent.test.ts b/src/platform/telemetry/checkoutJourneyEvent.test.ts index e696b73d966..2672fd07839 100644 --- a/src/platform/telemetry/checkoutJourneyEvent.test.ts +++ b/src/platform/telemetry/checkoutJourneyEvent.test.ts @@ -1,12 +1,11 @@ -import { describe, expect, it } from 'vitest' - import { CHECKOUT_JOURNEY_EVENT_NAME_BY_PHASE, CHECKOUT_JOURNEY_SCHEMA_VERSION, getCheckoutJourneyTelemetryEventName, getCheckoutJourneyTelemetryEventPayload -} from './types' -import type { CheckoutJourneyTelemetryEvent } from './types' +} from '@comfyorg/account-core/billing' +import type { CheckoutJourneyTelemetryEvent } from '@comfyorg/account-core/billing' +import { describe, expect, it } from 'vitest' const baseContext = { checkout_journey_id: 'journey-1', diff --git a/src/platform/telemetry/providers/cloud/DatadogRumTelemetryProvider.test.ts b/src/platform/telemetry/providers/cloud/DatadogRumTelemetryProvider.test.ts index 76ac0a782b0..a673125e649 100644 --- a/src/platform/telemetry/providers/cloud/DatadogRumTelemetryProvider.test.ts +++ b/src/platform/telemetry/providers/cloud/DatadogRumTelemetryProvider.test.ts @@ -1,9 +1,9 @@ +import type { BillingTelemetryEvent } from '@comfyorg/account-core/billing' import { computed } from 'vue' import { beforeEach, describe, expect, it, vi } from 'vitest' import { useCurrentUser } from '@/composables/auth/useCurrentUser' -import type { BillingTelemetryEvent } from '../../types' import { TelemetryEvents } from '../../types' import { DatadogRumTelemetryProvider } from './DatadogRumTelemetryProvider' diff --git a/src/platform/telemetry/providers/cloud/DatadogRumTelemetryProvider.ts b/src/platform/telemetry/providers/cloud/DatadogRumTelemetryProvider.ts index 9b08aabc557..5ea0bcf2691 100644 --- a/src/platform/telemetry/providers/cloud/DatadogRumTelemetryProvider.ts +++ b/src/platform/telemetry/providers/cloud/DatadogRumTelemetryProvider.ts @@ -1,3 +1,13 @@ +import { + getBillingTelemetryEventName, + getCheckoutJourneyTelemetryEventName, + getCheckoutJourneyTelemetryEventPayload, + getCloudAppBillingTelemetryEventPayload +} from '@comfyorg/account-core/billing' +import type { + BillingTelemetryEvent, + CheckoutJourneyTelemetryEvent +} from '@comfyorg/account-core/billing' // eslint-disable-next-line no-restricted-imports -- the telemetry layer owns the sinks that reportError() fans out to import { datadogRum } from '@datadog/browser-rum' @@ -5,8 +15,6 @@ import { useCurrentUser } from '@/composables/auth/useCurrentUser' import type { AuthMetadata, - BillingTelemetryEvent, - CheckoutJourneyTelemetryEvent, ExecutionOutcomeMetadata, FetchTimeoutMetadata, ImageLoadFailureMetadata, @@ -14,13 +22,7 @@ import type { UnifiedAuthRefreshMetadata, UnifiedAuthRetryMetadata } from '../../types' -import { - getBillingTelemetryEventName, - getCheckoutJourneyTelemetryEventName, - getCheckoutJourneyTelemetryEventPayload, - getCloudAppBillingTelemetryEventPayload, - TelemetryEvents -} from '../../types' +import { TelemetryEvents } from '../../types' export class DatadogRumTelemetryProvider implements TelemetryProvider { private isWatchingLogout = false diff --git a/src/platform/telemetry/providers/cloud/MixpanelTelemetryProvider.ts b/src/platform/telemetry/providers/cloud/MixpanelTelemetryProvider.ts index ee884400b94..347715c641a 100644 --- a/src/platform/telemetry/providers/cloud/MixpanelTelemetryProvider.ts +++ b/src/platform/telemetry/providers/cloud/MixpanelTelemetryProvider.ts @@ -1,3 +1,4 @@ +import { CHECKOUT_JOURNEY_EVENT_NAME_BY_PHASE } from '@comfyorg/account-core/billing' import type { OverridedMixpanel } from 'mixpanel-browser' import { omit } from 'es-toolkit' import { watch } from 'vue' @@ -43,11 +44,7 @@ import type { } from '../../types' import { remoteConfig } from '@/platform/remoteConfig/remoteConfig' import type { RemoteConfig } from '@/platform/remoteConfig/types' -import { - CHECKOUT_JOURNEY_EVENT_NAME_BY_PHASE, - OnboardingTourEvents, - TelemetryEvents -} from '../../types' +import { OnboardingTourEvents, TelemetryEvents } from '../../types' import { normalizeSurveyResponses } from '../../utils/surveyNormalization' const DEFAULT_DISABLED_EVENTS = [ diff --git a/src/platform/telemetry/providers/cloud/PostHogTelemetryProvider.test.ts b/src/platform/telemetry/providers/cloud/PostHogTelemetryProvider.test.ts index 416ce68adfe..f851b2a5246 100644 --- a/src/platform/telemetry/providers/cloud/PostHogTelemetryProvider.test.ts +++ b/src/platform/telemetry/providers/cloud/PostHogTelemetryProvider.test.ts @@ -1,3 +1,4 @@ +import type { BillingTelemetryEvent } from '@comfyorg/account-core/billing' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import type { Ref } from 'vue' import { computed, nextTick, ref } from 'vue' @@ -9,7 +10,6 @@ import { remoteConfig } from '@/platform/remoteConfig/remoteConfig' import type { RemoteConfig } from '@/platform/remoteConfig/types' import type { - BillingTelemetryEvent, BootstrapCompleteMetadata, OnboardingTourStage, RunButtonProperties diff --git a/src/platform/telemetry/providers/cloud/PostHogTelemetryProvider.ts b/src/platform/telemetry/providers/cloud/PostHogTelemetryProvider.ts index 0936d98d314..f4330febf19 100644 --- a/src/platform/telemetry/providers/cloud/PostHogTelemetryProvider.ts +++ b/src/platform/telemetry/providers/cloud/PostHogTelemetryProvider.ts @@ -1,3 +1,14 @@ +import { + CHECKOUT_JOURNEY_EVENT_NAME_BY_PHASE, + getBillingTelemetryEventName, + getCheckoutJourneyTelemetryEventName, + getCheckoutJourneyTelemetryEventPayload, + getCloudAppBillingTelemetryEventPayload +} from '@comfyorg/account-core/billing' +import type { + BillingTelemetryEvent, + CheckoutJourneyTelemetryEvent +} from '@comfyorg/account-core/billing' import type { PostHog } from 'posthog-js' import { watch } from 'vue' import type { WatchStopHandle } from 'vue' @@ -48,9 +59,7 @@ import type { UnifiedAuthRefreshMetadata, UnifiedAuthRetryMetadata, BeginCheckoutMetadata, - BillingTelemetryEvent, BootstrapCompleteMetadata, - CheckoutJourneyTelemetryEvent, DefaultViewSetMetadata, EnterLinearMetadata, ExecutionErrorMetadata, @@ -99,11 +108,6 @@ import type { } from '../../types' import { CANCELLATION_STAGE_EVENTS, - CHECKOUT_JOURNEY_EVENT_NAME_BY_PHASE, - getBillingTelemetryEventName, - getCheckoutJourneyTelemetryEventName, - getCheckoutJourneyTelemetryEventPayload, - getCloudAppBillingTelemetryEventPayload, OnboardingTourEvents, TelemetryEvents } from '../../types' diff --git a/src/platform/telemetry/providers/host/HostTelemetrySink.ts b/src/platform/telemetry/providers/host/HostTelemetrySink.ts index 63db7b34e63..762ca534ed5 100644 --- a/src/platform/telemetry/providers/host/HostTelemetrySink.ts +++ b/src/platform/telemetry/providers/host/HostTelemetrySink.ts @@ -1,3 +1,8 @@ +import { + getBillingTelemetryEventName, + getBillingTelemetryEventPayload +} from '@comfyorg/account-core/billing' +import type { BillingTelemetryEvent } from '@comfyorg/account-core/billing' import type { ComfyDesktop2TelemetryBridge, ComfyDesktop2TelemetryValue @@ -29,7 +34,6 @@ import type { AgentWorkflowAppliedMetadata, AuthMetadata, BeginCheckoutMetadata, - BillingTelemetryEvent, DefaultViewSetMetadata, EnterLinearMetadata, ExecutionErrorMetadata, @@ -68,12 +72,7 @@ import type { WorkflowImportMetadata, WorkflowSavedMetadata } from '../../types' -import { - CANCELLATION_STAGE_EVENTS, - TelemetryEvents, - getBillingTelemetryEventName, - getBillingTelemetryEventPayload -} from '../../types' +import { CANCELLATION_STAGE_EVENTS, TelemetryEvents } from '../../types' import { normalizeSurveyResponses } from '../../utils/surveyNormalization' type HostTelemetryProperties = Parameters< diff --git a/src/platform/telemetry/types.ts b/src/platform/telemetry/types.ts index 4f20983e11a..e6d069412f8 100644 --- a/src/platform/telemetry/types.ts +++ b/src/platform/telemetry/types.ts @@ -43,33 +43,6 @@ export type { AuthMethod } export type PaymentIntentSource = BillingSource -export type { - BillingOperationTerminal, - BillingTelemetryEvent, - BillingTelemetryEventName, - BillingTelemetryFailure as BillingFailure, - CheckoutAssignmentStatus, - CheckoutEntryFlow, - CheckoutEntrySource, - CheckoutJourneyArm, - CheckoutJourneyContext, - CheckoutJourneyPhaseEvent, - CheckoutJourneyTelemetryEvent, - CheckoutJourneyTelemetryEventName, - CheckoutUiMode, - SubscriptionCheckoutTier, - SubscriptionCheckoutType -} from '@comfyorg/account-core/billing' -export { - CHECKOUT_JOURNEY_EVENT_NAME_BY_PHASE, - CHECKOUT_JOURNEY_SCHEMA_VERSION, - getBillingTelemetryEventName, - getBillingTelemetryEventPayload, - getCheckoutJourneyTelemetryEventName, - getCheckoutJourneyTelemetryEventPayload, - getCloudAppBillingTelemetryEventPayload -} from '@comfyorg/account-core/billing' - /** * Authentication metadata for sign-up tracking */ diff --git a/src/platform/telemetry/utils/billingFailureCategory.ts b/src/platform/telemetry/utils/billingFailureCategory.ts index a4517b9a02e..f1aa6f35f8d 100644 --- a/src/platform/telemetry/utils/billingFailureCategory.ts +++ b/src/platform/telemetry/utils/billingFailureCategory.ts @@ -1,12 +1,12 @@ +import type { BillingTelemetryFailure } from '@comfyorg/account-core/billing' + import { WorkspaceApiError } from '@/platform/workspace/api/workspaceApi' import { AuthStoreError } from '@/stores/authStore' -import type { BillingFailure } from '../types' - export class BillingFailureError extends Error { constructor( message: string, - public readonly failure: BillingFailure + public readonly failure: BillingTelemetryFailure ) { super(message) this.name = 'BillingFailureError' @@ -23,7 +23,7 @@ export class PaymentPopupBlockedError extends BillingFailureError { } } -export function describeBillingFailure(err: unknown): BillingFailure { +export function describeBillingFailure(err: unknown): BillingTelemetryFailure { return err instanceof BillingFailureError ? err.failure : { failure_category: categorizeBillingApiError(err) } @@ -37,7 +37,7 @@ export function describeBillingFailure(err: unknown): BillingFailure { */ export function categorizeBillingApiError( err: unknown -): BillingFailure['failure_category'] { +): BillingTelemetryFailure['failure_category'] { if (err instanceof BillingFailureError) return err.failure.failure_category if (err instanceof WorkspaceApiError) { if (err.failureCategory) return err.failureCategory diff --git a/src/platform/telemetry/webHandoffEvent.test.ts b/src/platform/telemetry/webHandoffEvent.test.ts index e02697219bc..6bc13d18f64 100644 --- a/src/platform/telemetry/webHandoffEvent.test.ts +++ b/src/platform/telemetry/webHandoffEvent.test.ts @@ -1,9 +1,8 @@ -import { describe, expect, it } from 'vitest' - import { getBillingTelemetryEventPayload, getCloudAppBillingTelemetryEventPayload -} from './types' +} from '@comfyorg/account-core/billing' +import { describe, expect, it } from 'vitest' describe('the web handoff event payload', () => { it.for([ diff --git a/src/platform/workspace/api/workspaceApiError.ts b/src/platform/workspace/api/workspaceApiError.ts index 89bdeb8524e..894e6d05182 100644 --- a/src/platform/workspace/api/workspaceApiError.ts +++ b/src/platform/workspace/api/workspaceApiError.ts @@ -1,4 +1,4 @@ -import type { BillingFailure } from '@/platform/telemetry/types' +import type { BillingTelemetryFailure } from '@comfyorg/account-core/billing' /** * A leaf module, so a subclass can be declared wherever the class is needed @@ -10,7 +10,7 @@ export class WorkspaceApiError extends Error { public readonly status?: number, public readonly code?: string, /** For a failure `status` cannot classify, such as a billing SDK refusal. */ - public readonly failureCategory?: BillingFailure['failure_category'] + public readonly failureCategory?: BillingTelemetryFailure['failure_category'] ) { super(message) this.name = 'WorkspaceApiError' diff --git a/src/platform/workspace/billing/sdk/billingSdkTelemetry.ts b/src/platform/workspace/billing/sdk/billingSdkTelemetry.ts index b224549971b..646f3581adc 100644 --- a/src/platform/workspace/billing/sdk/billingSdkTelemetry.ts +++ b/src/platform/workspace/billing/sdk/billingSdkTelemetry.ts @@ -1,8 +1,9 @@ -import type { BillingOperationTelemetryEvent } from '@comfyorg/account-core/billing' +import type { + BillingOperationTelemetryEvent, + BillingTelemetryEvent +} from '@comfyorg/account-core/billing' import { BILLING_OPERATION_TELEMETRY_EVENT } from '@comfyorg/account-core/billing' -import type { BillingTelemetryEvent } from '@/platform/telemetry/types' - /** * The lifecycle's event onto the poller's `billing.operation.*` stages, so * both rails count in one funnel; only this rail sets `presentation` and diff --git a/src/platform/workspace/billing/sdk/topupOperationView.ts b/src/platform/workspace/billing/sdk/topupOperationView.ts index f4af702f226..3a96a41db05 100644 --- a/src/platform/workspace/billing/sdk/topupOperationView.ts +++ b/src/platform/workspace/billing/sdk/topupOperationView.ts @@ -7,6 +7,8 @@ import type { BillingDeclineReason, BillingOperationState, + BillingOperationTerminal, + BillingTelemetryFailure, TopupFailure, TopupResult } from '@comfyorg/account-core/billing' @@ -16,10 +18,6 @@ import { } from '@comfyorg/account-core/billing' import { t } from '@/i18n' -import type { - BillingFailure, - BillingOperationTerminal -} from '@/platform/telemetry/types' import type { BillingAuthenticationState, BillingOperationPhase, @@ -108,7 +106,7 @@ function topupFailureError(failure: TopupFailure): WorkspaceApiError { function topupFailureCategory( failure: TopupFailure -): BillingFailure['failure_category'] { +): BillingTelemetryFailure['failure_category'] { switch (failure.code) { case 'REQUEST_FAILED': return failure.httpStatus === undefined ? 'network' : 'api_rejected' diff --git a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts index 59db9854e7d..6b55d5ebfbd 100644 --- a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts +++ b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts @@ -1,7 +1,9 @@ -import type { TopupResult } from '@comfyorg/account-core/billing' +import type { + BillingTelemetryEvent, + TopupResult +} from '@comfyorg/account-core/billing' import { useFeatureFlags } from '@/composables/useFeatureFlags' -import type { BillingTelemetryEvent } from '@/platform/telemetry/types' import { failedTopup, fakeBillingSdk, diff --git a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.vue b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.vue index 5a8bd901904..f2c417a4f65 100644 --- a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.vue +++ b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.vue @@ -298,6 +298,10 @@