LCOV - code coverage report
Current view: top level - packages/billing-contract/src - returnTargets.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 25.0 % 8 2
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : /**
       2              :  * Where billing is allowed to send a customer back to. A closed registry, not
       3              :  * a caller-supplied URL: `return_to=<identifier>` names a target, and the
       4              :  * absolute destination is chosen here per environment, so a crafted entry URL
       5              :  * cannot turn the hosted app into an open redirect.
       6              :  *
       7              :  * Every destination below is one this repository already states. A family a
       8              :  * target has no confirmed origin for stays absent rather than being derived
       9              :  * from a sibling's hostname, because an unresolvable target fails closed while
      10              :  * a guessed one sends a customer somewhere nobody serves.
      11              :  *
      12              :  * Localhost and desktop return targets are out of scope: a developer running a
      13              :  * product locally returns to the deployed destination of whichever environment
      14              :  * their backend belongs to.
      15              :  */
      16              : import type { BillingEnvironment } from './contract'
      17              : import { parseUrl } from './url'
      18              : 
      19         2356 : export const RETURN_TARGETS = [
      20              :   'comfyui_workspace',
      21              :   'comfyui_credits',
      22              :   'platform_account',
      23              :   'platform_billing'
      24              : ] as const
      25              : 
      26              : export type ReturnTarget = (typeof RETURN_TARGETS)[number]
      27              : 
      28              : type ReturnTargetDestinations = Readonly<
      29              :   Partial<Record<BillingEnvironment, string>>
      30              : >
      31              : 
      32         2356 : const RETURN_TARGET_DESTINATIONS: Readonly<
      33              :   Record<ReturnTarget, ReturnTargetDestinations>
      34              : > = {
      35              :   comfyui_workspace: {
      36              :     production: 'https://cloud.comfy.org/',
      37              :     staging: 'https://stagingcloud.comfy.org/',
      38              :     test: 'https://testcloud.comfy.org/'
      39              :   },
      40              :   // The cloud app's credits settings page, the same URL the Workshop builds as
      41              :   // `WORKSHOP_CREDITS_URL`.
      42              :   comfyui_credits: {
      43              :     production: 'https://cloud.comfy.org/?settings=plan-credits',
      44              :     staging: 'https://stagingcloud.comfy.org/?settings=plan-credits',
      45              :     test: 'https://testcloud.comfy.org/?settings=plan-credits'
      46              :   },
      47              :   // Platform lives in its own repository and names no account route here, so
      48              :   // its origin root is the destination until that app names one.
      49              :   platform_account: {
      50              :     production: 'https://platform.comfy.org/',
      51              :     staging: 'https://stagingplatform.comfy.org/',
      52              :     test: 'https://testplatform.comfy.org/'
      53              :   },
      54              :   // Platform's own billing page, `pages/profile/billing.vue` in that app.
      55              :   platform_billing: {
      56              :     production: 'https://platform.comfy.org/profile/billing',
      57              :     staging: 'https://stagingplatform.comfy.org/profile/billing',
      58              :     test: 'https://testplatform.comfy.org/profile/billing'
      59              :   }
      60              : }
      61              : 
      62            0 : export function isReturnTarget(value: string): value is ReturnTarget {
      63            0 :   return RETURN_TARGETS.some((target) => target === value)
      64              : }
      65              : 
      66              : /**
      67              :  * Undefined for an identifier outside the registry, and for a registered
      68              :  * target that has no destination in the requested environment. Each call
      69              :  * returns a fresh `URL` so a caller can append to it without editing the
      70              :  * registry.
      71              :  */
      72            0 : export function resolveReturnTarget(
      73              :   target: string,
      74              :   environment: BillingEnvironment
      75              : ): URL | undefined {
      76            0 :   if (!isReturnTarget(target)) return undefined
      77              : 
      78            0 :   const destination = RETURN_TARGET_DESTINATIONS[target][environment]
      79            0 :   return destination === undefined ? undefined : parseUrl(destination)
      80              : }
        

Generated by: LCOV version 2.0-1