@whop/cli 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/api/groups.json","../src/auth/commands.ts","../src/commerce/products.ts","../src/commerce/client.ts","../src/commerce/crud.ts","../src/commerce/output.ts","../src/commerce/plans.ts","../src/commerce/billing.ts","../src/commerce/checkout.ts","../src/journey/quickstart.ts","../src/lib/colors.ts","../src/commands.ts","../package.json","../src/lib/renderer.ts","../src/cli.ts","../src/api/api-structure.json","../src/api/tag-descriptions.json","../src/lib/grouped-help.ts","../src/lib/colorize-output.ts","../src/index.ts"],"sourcesContent":["[\n [\n \"accounts\",\n \"Accounts\"\n ],\n [\n \"users\",\n \"Users\"\n ],\n [\n \"stats\",\n \"Stats\"\n ],\n [\n \"ledgers\",\n \"Ledgers\"\n ],\n [\n \"payouts\",\n \"Payouts\"\n ],\n [\n \"cards\",\n \"Cards\"\n ],\n [\n \"transfers\",\n \"Transfers\"\n ],\n [\n \"deposits\",\n \"Deposits\"\n ],\n [\n \"swaps\",\n \"Swaps\"\n ],\n [\n \"verifications\",\n \"Verifications\"\n ],\n [\n \"products\",\n \"Products\"\n ],\n [\n \"plans\",\n \"Plans\"\n ],\n [\n \"checkout-configurations\",\n \"Checkout Configurations\"\n ],\n [\n \"referrals\",\n \"Referrals\"\n ],\n [\n \"ads\",\n \"Ads\"\n ],\n [\n \"ad-campaigns\",\n \"Ad Campaigns\"\n ],\n [\n \"ad-groups\",\n \"Ad Groups\"\n ],\n [\n \"audiences\",\n \"Audiences\"\n ],\n [\n \"social-accounts\",\n \"Social Accounts\"\n ]\n]\n","import { Cli, z } from \"incur\";\nimport { validateApiKey, apiBaseUrl } from \"./client\";\nimport { readConfig } from \"./config\";\nimport { getSecret } from \"./keyring\";\nimport { OAuthError, performOAuthLogin } from \"./oauth\";\nimport {\n\tderiveProfileName,\n\tgetActiveProfile,\n\tgetValidAccessToken,\n\tlistProfiles,\n\tremoveProfile,\n\tswitchProfile,\n\tupsertProfile,\n} from \"./profiles\";\nimport {\n\tchooseAuthMethod,\n\tPromptCancelledError,\n\tpromptApiKey,\n\tselectProfile,\n\tstartSpinner,\n} from \"./prompts\";\nimport { AuthMethod, Identity, Profile } from \"./types\";\n\n/**\n * Auth commands: `whop auth login | logout | switch | status | list`.\n *\n * The login/logout business logic is context-free (`performLogin`,\n * `removeProfile`) and the incur run handlers are thin adapters. `loginAdapter`\n * and `logoutAdapter` are shared so the top-level `whop login` / `whop logout`\n * (registered in `index.ts`) behave identically without duplicating logic —\n * incur aliases can't cross from a group into a top-level command.\n */\n\n// --- CTA / error shapes accepted by the run context (kept minimal & structural) ---\ntype CtaCommand =\n\t| string\n\t| {\n\t\t\tcommand: string;\n\t\t\tdescription?: string | undefined;\n\t\t\toptions?: Record<string, unknown> | undefined;\n\t\t\targs?: Record<string, unknown> | undefined;\n\t };\ntype CtaInput = { description?: string | undefined; commands: CtaCommand[] };\ntype ErrorInput = {\n\tcode: string;\n\tmessage: string;\n\tcta?: CtaInput | undefined;\n\texitCode?: number | undefined;\n\tretryable?: boolean | undefined;\n};\n\n// --- Shared schemas ---\nexport const loginOptions = z.object({\n\tapiKey: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\"API key for non-interactive login (skips the prompt)\"),\n\tprofile: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\"Name for this profile (defaults to the account route)\"),\n\tcompanyId: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\n\t\t\t\"Business account to act on behalf of (biz_xxx) — for OAuth users who manage more than one\",\n\t\t),\n});\n\nexport const loginEnv = z.object({\n\tWHOP_API_KEY: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\"API key for non-interactive login\"),\n\tWHOP_API_BASE_URL: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\"Override the Whop API base URL\"),\n\tWHOP_CONFIG_DIR: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\"Override the CLI config directory\"),\n});\n\nexport const loginOutput = z.object({\n\tprofile: z.string().describe(\"The profile name\"),\n\tactive: z.boolean().describe(\"Whether this profile is now the active one\"),\n\tmethod: AuthMethod.describe(\"The authentication method\"),\n\tidentity: Identity.describe(\"The authenticated account or user identity\"),\n});\nexport type LoginOutput = z.infer<typeof loginOutput>;\n\nexport const logoutOptions = z.object({\n\tprofile: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\"Profile to remove (defaults to the active profile)\"),\n});\nexport const logoutOutput = z.object({\n\tremoved: z.string().describe(\"The removed profile name\"),\n\tnewActive: z\n\t\t.string()\n\t\t.nullable()\n\t\t.describe(\"The profile that is now active, if any\"),\n});\nexport type LogoutOutput = z.infer<typeof logoutOutput>;\n\nconst statusOutput = z.object({\n\tloggedIn: z\n\t\t.boolean()\n\t\t.describe(\"Whether the active profile has a usable stored credential\"),\n\tprofile: z.string().nullable(),\n\tmethod: AuthMethod.nullable(),\n\tidentity: Identity.nullable().describe(\n\t\t\"The logged-in user (OAuth) or the account (API key)\",\n\t),\n\taccount: Identity.nullable().describe(\n\t\t\"The account auto-filled for scoped commands (account_id/company_id)\",\n\t),\n\thasSecret: z\n\t\t.boolean()\n\t\t.describe(\"Whether a secret was found in the OS keychain for this profile\"),\n});\n\nconst listOutput = z.object({\n\tactive: z.string().nullable(),\n\tprofiles: z.array(Profile),\n});\n\nconst switchArgs = z.object({\n\tname: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\"Profile to switch to (interactive picker if omitted)\"),\n});\nconst switchOutput = z.object({\n\tactive: z.string().describe(\"The newly active profile\"),\n});\n\nexport const loginExamples = [\n\t{ description: \"Interactive login\" },\n\t{\n\t\toptions: { apiKey: \"whop_xxx\" },\n\t\tdescription: \"Non-interactive login (CI / agents)\",\n\t},\n\t{\n\t\toptions: { apiKey: \"whop_xxx\", profile: \"prod\" },\n\t\tdescription: \"Log in and name the profile\",\n\t},\n];\nexport const loginHint =\n\t\"Agents / CI: pass --api-key or set WHOP_API_KEY to skip the prompt.\";\n\n// --- Context-free login flows ---\ntype LoginResult =\n\t| { ok: true; output: LoginOutput; existed: boolean; underscoped: boolean }\n\t| { ok: false; code: string; message: string };\n\nexport async function performLogin(input: {\n\tagent: boolean;\n\tapiKey?: string | undefined;\n\tprofile?: string | undefined;\n\tcompanyId?: string | undefined;\n}): Promise<LoginResult> {\n\tlet method: AuthMethod = \"api_key\";\n\tif (!input.agent && !input.apiKey) method = await chooseAuthMethod();\n\n\t// Route to the OAuth browser flow.\n\tif (method === \"oauth\") {\n\t\ttry {\n\t\t\tconst { profileName, identity, existed } = await performOAuthLogin({\n\t\t\t\tprofile: input.profile,\n\t\t\t\tagent: input.agent,\n\t\t\t\tcompanyId: input.companyId,\n\t\t\t});\n\t\t\treturn {\n\t\t\t\tok: true,\n\t\t\t\texisted,\n\t\t\t\tunderscoped: false,\n\t\t\t\toutput: {\n\t\t\t\t\tprofile: profileName,\n\t\t\t\t\tactive: true,\n\t\t\t\t\tmethod: \"oauth\",\n\t\t\t\t\tidentity,\n\t\t\t\t},\n\t\t\t};\n\t\t} catch (err) {\n\t\t\tif (err instanceof OAuthError) {\n\t\t\t\treturn { ok: false, code: err.code, message: err.message };\n\t\t\t}\n\t\t\tthrow err;\n\t\t}\n\t}\n\n\t// Resolve the API key: flag/env > interactive prompt > error in agent mode.\n\tlet apiKey = input.apiKey;\n\tif (!apiKey) {\n\t\tif (input.agent) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\tcode: \"API_KEY_REQUIRED\",\n\t\t\t\tmessage: \"No API key provided and not running interactively.\",\n\t\t\t};\n\t\t}\n\t\tapiKey = await promptApiKey();\n\t}\n\t// Normalize: the SDK adds the `Bearer ` prefix itself, so strip one if pasted.\n\tconst key = apiKey.replace(/^Bearer\\s+/i, \"\").trim();\n\n\t// 3. Validate against the API.\n\tlet result: Awaited<ReturnType<typeof validateApiKey>>;\n\tif (input.agent) {\n\t\tresult = await validateApiKey(key, apiBaseUrl());\n\t} else {\n\t\tconst s = startSpinner(\"Validating API key…\");\n\t\tresult = await validateApiKey(key, apiBaseUrl());\n\t\tconst okay = result.status === \"valid\" || result.status === \"underscoped\";\n\t\ts.stop(okay ? \"API key validated.\" : \"API key check failed.\");\n\t}\n\tif (result.status === \"invalid\") {\n\t\treturn {\n\t\t\tok: false,\n\t\t\tcode: \"INVALID_API_KEY\",\n\t\t\tmessage: \"That API key was rejected (401 Unauthorized).\",\n\t\t};\n\t}\n\tif (result.status === \"error\") {\n\t\treturn { ok: false, code: \"VALIDATION_FAILED\", message: result.message };\n\t}\n\n\t// 4. Persist (secret → keychain, metadata → config) and activate.\n\tconst identity = result.identity;\n\tconst name = input.profile ?? deriveProfileName(identity);\n\tconst existed = listProfiles().some((profile) => profile.name === name);\n\tconst profile = upsertProfile({ name, method, secret: key, identity });\n\n\treturn {\n\t\tok: true,\n\t\texisted,\n\t\tunderscoped: result.status === \"underscoped\",\n\t\toutput: { profile: profile.name, active: true, method, identity },\n\t};\n}\n\n// --- Shared adapters (used by the group command and the top-level alias) ---\ntype LoginAdapterCtx = {\n\tagent: boolean;\n\toptions: {\n\t\tapiKey?: string | undefined;\n\t\tprofile?: string | undefined;\n\t\tcompanyId?: string | undefined;\n\t};\n\tenv: { WHOP_API_KEY?: string | undefined };\n\tok: (data: LoginOutput, meta?: { cta?: CtaInput | undefined }) => never;\n\terror: (options: ErrorInput) => never;\n};\n\nexport async function loginAdapter(c: LoginAdapterCtx): Promise<never> {\n\tlet result: LoginResult;\n\ttry {\n\t\tresult = await performLogin({\n\t\t\tagent: c.agent,\n\t\t\tapiKey: c.options.apiKey ?? c.env.WHOP_API_KEY,\n\t\t\tprofile: c.options.profile,\n\t\t\tcompanyId: c.options.companyId,\n\t\t});\n\t} catch (error) {\n\t\tif (error instanceof PromptCancelledError) {\n\t\t\treturn c.error({\n\t\t\t\tcode: \"CANCELLED\",\n\t\t\t\tmessage: \"Login cancelled.\",\n\t\t\t\texitCode: 130,\n\t\t\t});\n\t\t}\n\t\tthrow error;\n\t}\n\n\tif (!result.ok) {\n\t\tlet cta: CtaInput | undefined;\n\t\tif (result.code === \"API_KEY_REQUIRED\") {\n\t\t\tcta = {\n\t\t\t\tdescription: \"Provide a key non-interactively:\",\n\t\t\t\tcommands: [\n\t\t\t\t\t{\n\t\t\t\t\t\tcommand: \"auth login\",\n\t\t\t\t\t\toptions: { apiKey: true },\n\t\t\t\t\t\tdescription: \"Pass --api-key <key>\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t};\n\t\t} else if (\n\t\t\tresult.code === \"MULTIPLE_COMPANIES\" ||\n\t\t\tresult.code === \"COMPANY_NOT_FOUND\"\n\t\t) {\n\t\t\tcta = {\n\t\t\t\tdescription: \"Choose which business account to use:\",\n\t\t\t\tcommands: [\n\t\t\t\t\t{\n\t\t\t\t\t\tcommand: \"auth login\",\n\t\t\t\t\t\toptions: { companyId: true },\n\t\t\t\t\t\tdescription: \"Pass --company-id biz_xxx\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t};\n\t\t}\n\t\treturn c.error({\n\t\t\tcode: result.code,\n\t\t\tmessage: result.message,\n\t\t\tretryable: result.code !== \"INVALID_API_KEY\",\n\t\t\tcta,\n\t\t});\n\t}\n\n\t// First-run vs returning user: check whether they have any products yet.\n\t// Probe whenever we have an account so a returning\n\t// user with zero products still gets the \"start selling\" path. Use the\n\t// resolved account id (not the user id, which is what identity holds for\n\t// OAuth). On failure just fall back to the generic CTA — don't block login.\n\tlet firstRun = !result.existed;\n\tconst companyId = getActiveProfile()?.companyId ?? \"\";\n\tif (companyId) {\n\t\ttry {\n\t\t\tconst { createWhopFetch } = await import(\"../api/index.js\");\n\t\t\tconst fetch = createWhopFetch();\n\t\t\tconst res = await fetch(\n\t\t\t\tnew Request(\n\t\t\t\t\t`https://api.whop.com/products?company_id=${companyId}&first=1`,\n\t\t\t\t),\n\t\t\t);\n\t\t\tif (res.ok) {\n\t\t\t\tconst data = (await res.json()) as { data?: unknown[] };\n\t\t\t\tfirstRun = (data.data?.length ?? 0) === 0;\n\t\t\t}\n\t\t} catch {\n\t\t\t// Non-fatal — use generic CTA\n\t\t}\n\t}\n\n\t// No business account resolved (e.g. OAuth account with no business yet). Don't send\n\t// them to `quickstart` — it requires a biz_ id and would exit NO_COMPANY.\n\t// Mirror quickstart's guidance: create a business account, then re-authenticate.\n\tif (!companyId) {\n\t\treturn c.ok(result.output, {\n\t\t\tcta: {\n\t\t\t\tdescription:\n\t\t\t\t\t\"You're logged in, but no business account is linked to this account yet. Create a business account on Whop, then log in again:\",\n\t\t\t\tcommands: [\n\t\t\t\t\t{\n\t\t\t\t\t\tcommand: \"auth login\",\n\t\t\t\t\t\tdescription: \"Re-authenticate once you have a business account\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t});\n\t}\n\n\treturn c.ok(result.output, {\n\t\tcta: firstRun\n\t\t\t? {\n\t\t\t\t\tdescription: \"You're logged in. Start selling in one command:\",\n\t\t\t\t\tcommands: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"quickstart\",\n\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\"Create your product, set a price, get a checkout link\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}\n\t\t\t: {\n\t\t\t\t\tdescription: result.existed\n\t\t\t\t\t\t? \"Updated and switched to this profile:\"\n\t\t\t\t\t\t: \"Welcome back:\",\n\t\t\t\t\tcommands: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"quickstart\",\n\t\t\t\t\t\t\tdescription: \"See your status and what's next\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ command: \"auth status\", description: \"Show the active identity\" },\n\t\t\t\t\t],\n\t\t\t\t},\n\t});\n}\n\ntype LogoutAdapterCtx = {\n\toptions: { profile?: string | undefined };\n\tok: (data: LogoutOutput, meta?: { cta?: CtaInput | undefined }) => never;\n\terror: (options: ErrorInput) => never;\n};\n\nexport function logoutAdapter(c: LogoutAdapterCtx): never {\n\tconst target = c.options.profile ?? getActiveProfile()?.name;\n\tif (!target) {\n\t\treturn c.error({\n\t\t\tcode: \"NO_ACTIVE_PROFILE\",\n\t\t\tmessage: \"No active profile to log out from.\",\n\t\t\tretryable: false,\n\t\t\tcta: {\n\t\t\t\tdescription: \"Log in first:\",\n\t\t\t\tcommands: [{ command: \"auth login\", description: \"Log in to Whop\" }],\n\t\t\t},\n\t\t});\n\t}\n\tconst { removed, newActive } = removeProfile(target);\n\tif (!removed) {\n\t\treturn c.error({\n\t\t\tcode: \"PROFILE_NOT_FOUND\",\n\t\t\tmessage: `No profile named \"${target}\".`,\n\t\t\tretryable: false,\n\t\t});\n\t}\n\treturn c.ok(\n\t\t{ removed: target, newActive },\n\t\tnewActive\n\t\t\t? {\n\t\t\t\t\tcta: {\n\t\t\t\t\t\tdescription: `Now using \"${newActive}\".`,\n\t\t\t\t\t\tcommands: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcommand: \"auth status\",\n\t\t\t\t\t\t\t\tdescription: \"Show the active identity\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: undefined,\n\t);\n}\n\n// --- The `auth` command group ---\nexport function buildAuthGroup() {\n\tconst auth = Cli.create(\"auth\", {\n\t\tdescription: \"Manage Whop authentication\",\n\t});\n\n\tauth.command(\"login\", {\n\t\tdescription: \"Log in to Whop\",\n\t\taliases: [\"add\"],\n\t\toptions: loginOptions,\n\t\tenv: loginEnv,\n\t\toutput: loginOutput,\n\t\texamples: loginExamples,\n\t\thint: loginHint,\n\t\trun: (c) => loginAdapter(c),\n\t});\n\n\tauth.command(\"logout\", {\n\t\tdescription: \"Log out — remove a saved profile\",\n\t\taliases: [\"remove\", \"rm\"],\n\t\toptions: logoutOptions,\n\t\toutput: logoutOutput,\n\t\trun: (c) => logoutAdapter(c),\n\t});\n\n\tauth.command(\"switch\", {\n\t\tdescription: \"Switch the active profile\",\n\t\targs: switchArgs,\n\t\toutput: switchOutput,\n\t\trun: async (c) => {\n\t\t\tconst profiles = listProfiles();\n\t\t\tif (profiles.length === 0) {\n\t\t\t\treturn c.error({\n\t\t\t\t\tcode: \"NO_PROFILES\",\n\t\t\t\t\tmessage: \"No profiles yet — log in first.\",\n\t\t\t\t\tretryable: true,\n\t\t\t\t\tcta: {\n\t\t\t\t\t\tdescription: \"To authenticate:\",\n\t\t\t\t\t\tcommands: [\n\t\t\t\t\t\t\t{ command: \"auth login\", description: \"Log in to Whop\" },\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tlet name = c.args.name;\n\t\t\tif (!name) {\n\t\t\t\tif (c.agent) {\n\t\t\t\t\treturn c.error({\n\t\t\t\t\t\tcode: \"PROFILE_REQUIRED\",\n\t\t\t\t\t\tmessage: `Specify a profile name. Available: ${profiles.map((p) => p.name).join(\", \")}.`,\n\t\t\t\t\t\tretryable: true,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tname = await selectProfile(profiles);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (error instanceof PromptCancelledError) {\n\t\t\t\t\t\treturn c.error({\n\t\t\t\t\t\t\tcode: \"CANCELLED\",\n\t\t\t\t\t\t\tmessage: \"Switch cancelled.\",\n\t\t\t\t\t\t\texitCode: 130,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst profile = switchProfile(name);\n\t\t\tif (!profile) {\n\t\t\t\treturn c.error({\n\t\t\t\t\tcode: \"PROFILE_NOT_FOUND\",\n\t\t\t\t\tmessage: `No profile named \"${name}\". Available: ${profiles.map((p) => p.name).join(\", \")}.`,\n\t\t\t\t\tretryable: true,\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn c.ok(\n\t\t\t\t{ active: profile.name },\n\t\t\t\t{\n\t\t\t\t\tcta: {\n\t\t\t\t\t\tcommands: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcommand: \"auth status\",\n\t\t\t\t\t\t\t\tdescription: \"Show the active identity\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t},\n\t});\n\n\tauth.command(\"status\", {\n\t\tdescription: \"Show the active identity (whoami)\",\n\t\taliases: [\"whoami\"],\n\t\toutput: statusOutput,\n\t\trun: async (c) => {\n\t\t\tconst profile = getActiveProfile();\n\t\t\tif (!profile) {\n\t\t\t\treturn c.ok(\n\t\t\t\t\t{\n\t\t\t\t\t\tloggedIn: false,\n\t\t\t\t\t\tprofile: null,\n\t\t\t\t\t\tmethod: null,\n\t\t\t\t\t\tidentity: null,\n\t\t\t\t\t\taccount: null,\n\t\t\t\t\t\thasSecret: false,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tcta: {\n\t\t\t\t\t\t\tdescription: \"To authenticate:\",\n\t\t\t\t\t\t\tcommands: [\n\t\t\t\t\t\t\t\t{ command: \"auth login\", description: \"Log in to Whop\" },\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst hasSecret = getSecret(profile.name) !== null;\n\t\t\t// \"Logged in\" means we can actually obtain a Bearer token. For oauth\n\t\t\t// this may refresh the access token; a revoked/expired refresh token\n\t\t\t// resolves to null instead of throwing, so the reported state is honest.\n\t\t\tlet loggedIn = hasSecret;\n\t\t\tif (hasSecret) {\n\t\t\t\ttry {\n\t\t\t\t\tloggedIn = (await getValidAccessToken(profile)) !== null;\n\t\t\t\t} catch {\n\t\t\t\t\tloggedIn = false;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst account =\n\t\t\t\tprofile.accountId || profile.accountTitle || profile.accountRoute\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tid: profile.accountId,\n\t\t\t\t\t\t\ttitle: profile.accountTitle,\n\t\t\t\t\t\t\troute: profile.accountRoute,\n\t\t\t\t\t\t}\n\t\t\t\t\t: null;\n\t\t\treturn c.ok(\n\t\t\t\t{\n\t\t\t\t\tloggedIn,\n\t\t\t\t\tprofile: profile.name,\n\t\t\t\t\tmethod: profile.method,\n\t\t\t\t\tidentity:\n\t\t\t\t\t\tprofile.method === \"oauth\"\n\t\t\t\t\t\t\t? { id: profile.userId, email: profile.userEmail }\n\t\t\t\t\t\t\t: account,\n\t\t\t\t\taccount,\n\t\t\t\t\thasSecret,\n\t\t\t\t},\n\t\t\t\tloggedIn\n\t\t\t\t\t? undefined\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tcta: {\n\t\t\t\t\t\t\t\tdescription: hasSecret\n\t\t\t\t\t\t\t\t\t? \"Your session is no longer valid — log in again:\"\n\t\t\t\t\t\t\t\t\t: \"The stored secret is missing — log in again:\",\n\t\t\t\t\t\t\t\tcommands: [\n\t\t\t\t\t\t\t\t\t{ command: \"auth login\", description: \"Log in to Whop\" },\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t);\n\t\t},\n\t});\n\n\tauth.command(\"list\", {\n\t\tdescription: \"List saved authentication profiles\",\n\t\taliases: [\"ls\"],\n\t\toutput: listOutput,\n\t\trun: () => {\n\t\t\tconst { activeProfile, profiles } = readConfig();\n\t\t\tconst active =\n\t\t\t\tprofiles.find((p) => p.name === activeProfile)?.name ?? null;\n\t\t\treturn { active, profiles };\n\t\t},\n\t});\n\n\treturn auth;\n}\n","import { Cli, z } from \"incur\";\nimport { text, isCancel } from \"@clack/prompts\";\nimport { makeWhopRequest } from \"./client.js\";\nimport {\n\tbuildBody,\n\tregisterItemCommands,\n\tregisterListCommand,\n} from \"./crud.js\";\nimport { printCreateSuccess } from \"./output.js\";\n\nconst ProductSchema = z.object({\n\tid: z.string(),\n\ttitle: z.string(),\n\tvisibility: z.string().optional(),\n\troute: z.string().optional(),\n\theadline: z.string().nullable().optional(),\n\tdescription: z.string().nullable().optional(),\n\tmember_count: z.number().optional(),\n\tcreated_at: z.number().optional(),\n});\n\nconst createOptions = z.object({\n\ttitle: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\"Product display name (max 80 characters)\"),\n\tcompany_id: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\n\t\t\t\"Business account to create under (defaults to your active account)\",\n\t\t),\n\tvisibility: z\n\t\t.enum([\"visible\", \"hidden\", \"archived\"])\n\t\t.optional()\n\t\t.describe(\"Who can see this product\"),\n\theadline: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\"Short tagline shown on the store page\"),\n\tdescription: z.string().optional().describe(\"Full description\"),\n\troute: z.string().optional().describe(\"Custom URL slug (e.g. my-course)\"),\n\tredirect_purchase_url: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\"Redirect buyers here after purchase\"),\n});\n\nexport function buildProductsGroup() {\n\tconst products = Cli.create(\"products\", {\n\t\tdescription: \"Products — what you're selling on Whop\",\n\t});\n\n\tproducts.command(\"create\", {\n\t\tdescription: \"Create a product\",\n\t\thint: \"A product is the top-level container for what you sell. Add a pricing plan next.\",\n\t\toptions: createOptions,\n\t\toutput: ProductSchema,\n\t\toutputPolicy: \"agent-only\",\n\t\texamples: [\n\t\t\t{\n\t\t\t\toptions: { title: \"My Online Course\" },\n\t\t\t\tdescription: \"Create a product\",\n\t\t\t},\n\t\t\t{\n\t\t\t\toptions: { title: \"My Course\", visibility: \"hidden\" },\n\t\t\t\tdescription: \"Create a hidden product\",\n\t\t\t},\n\t\t],\n\t\trun: async (c) => {\n\t\t\tlet title = c.options.title;\n\t\t\tif (!title) {\n\t\t\t\tif (c.agent) {\n\t\t\t\t\treturn c.error({\n\t\t\t\t\t\tcode: \"TITLE_REQUIRED\",\n\t\t\t\t\t\tmessage: \"Pass --title to set the product name.\",\n\t\t\t\t\t\tretryable: true,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tconst t = await text({\n\t\t\t\t\tmessage: \"What are you selling?\",\n\t\t\t\t\tplaceholder:\n\t\t\t\t\t\t\"e.g. My Online Course, Trading Community, Fitness Program\",\n\t\t\t\t});\n\t\t\t\tif (isCancel(t))\n\t\t\t\t\treturn c.error({\n\t\t\t\t\t\tcode: \"CANCELLED\",\n\t\t\t\t\t\tmessage: \"Cancelled.\",\n\t\t\t\t\t\texitCode: 130,\n\t\t\t\t\t});\n\t\t\t\ttitle = t as string;\n\t\t\t}\n\n\t\t\tconst body = { ...buildBody(c.options), title };\n\n\t\t\tlet product: z.infer<typeof ProductSchema>;\n\t\t\ttry {\n\t\t\t\tproduct = await makeWhopRequest<z.infer<typeof ProductSchema>>(\n\t\t\t\t\t\"POST\",\n\t\t\t\t\t\"/products\",\n\t\t\t\t\tbody,\n\t\t\t\t);\n\t\t\t} catch (err) {\n\t\t\t\treturn c.error({\n\t\t\t\t\tcode: \"API_ERROR\",\n\t\t\t\t\tmessage:\n\t\t\t\t\t\terr instanceof Error ? err.message : \"Failed to create product\",\n\t\t\t\t\tretryable: true,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tprintCreateSuccess(c, {\n\t\t\t\ttitle: `Product \"${product.title}\" created`,\n\t\t\t\tid: product.id,\n\t\t\t\tnext: {\n\t\t\t\t\tcommand: `plans create --product_id ${product.id}`,\n\t\t\t\t\thint: \"Add pricing — required before you can take a checkout\",\n\t\t\t\t},\n\t\t\t});\n\n\t\t\treturn c.ok(product, {\n\t\t\t\tcta: {\n\t\t\t\t\tdescription: \"Add pricing to your product:\",\n\t\t\t\t\tcommands: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"plans create\",\n\t\t\t\t\t\t\toptions: { product_id: product.id },\n\t\t\t\t\t\t\tdescription: \"Create a pricing plan (required before checkout)\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t});\n\n\tregisterListCommand(products, {\n\t\tpath: \"/products\",\n\t\tdescription: \"List products\",\n\t});\n\n\tregisterItemCommands(products, {\n\t\tpath: \"/products\",\n\t\tnoun: \"product\",\n\t\tidLabel: \"Product ID (prod_xxx)\",\n\t\tschema: ProductSchema,\n\t\tupdateOptions: createOptions.partial(),\n\t});\n\n\treturn products;\n}\n","import { createWhopFetch } from \"../api/index.js\";\n\nconst PLACEHOLDER = \"https://api.whop.com\";\nconst whopFetch = createWhopFetch();\n\n/**\n * Thin wrapper around the API fetch proxy for hand-written commands. The proxy\n * strips the host and uses apiBaseUrl() internally, auto-fills the active\n * account, and normalizes errors to a top-level `message` — so we only need the\n * pathname (a query string in `path` is fine) and can surface `message` directly.\n */\nexport async function makeWhopRequest<T>(\n\tmethod: \"GET\" | \"POST\" | \"PATCH\" | \"DELETE\",\n\tpath: string,\n\tbody?: Record<string, unknown>,\n): Promise<T> {\n\tconst init: RequestInit = { method };\n\tif (body !== undefined) init.body = JSON.stringify(body);\n\tconst res = await whopFetch(new Request(`${PLACEHOLDER}${path}`, init));\n\n\tif (!res.ok) {\n\t\tconst payload = (await res.json().catch(() => null)) as {\n\t\t\tmessage?: string;\n\t\t} | null;\n\t\tthrow new Error(payload?.message ?? res.statusText);\n\t}\n\n\t// DELETE (and other 204s) can return an empty body, which `res.json()` would\n\t// reject — treat an empty body as a successful, content-less response.\n\tconst text = await res.text();\n\treturn (text ? JSON.parse(text) : { success: true }) as T;\n}\n","import { Cli, z } from \"incur\";\nimport { makeWhopRequest } from \"./client.js\";\n\n/** Copies defined option values into a request body, dropping `undefined`. */\nexport function buildBody(options: Record<string, unknown>): Record<string, unknown> {\n\tconst body: Record<string, unknown> = {};\n\tfor (const [key, value] of Object.entries(options)) {\n\t\tif (value !== undefined) body[key] = value;\n\t}\n\treturn body;\n}\n\ninterface ItemCommandConfig {\n\t/** Collection path, e.g. \"/products\". */\n\tpath: string;\n\t/** Singular resource noun for descriptions, e.g. \"product\". */\n\tnoun: string;\n\t/** Help text for the id argument, e.g. \"Product ID (prod_xxx)\". */\n\tidLabel: string;\n\t/** Output schema for get/update. */\n\tschema: z.ZodType;\n\t/** Options for `update`. Omit to skip the update command (e.g. checkout configs). */\n\tupdateOptions?: z.ZodObject<z.ZodRawShape>;\n\t/**\n\t * Normalizes the request body before `update` sends it (e.g. mapping friendly\n\t * enum values to the shape the API expects). Must match whatever the\n\t * hand-written `create` does so the same flags behave identically on both.\n\t */\n\ttransformBody?: (body: Record<string, unknown>) => Record<string, unknown>;\n}\n\n/**\n * Registers a `list` command. The active account is auto-filled by the fetch\n * proxy, so the only per-resource difference is the path and an optional filter.\n */\nexport function registerListCommand(\n\tgroup: ReturnType<typeof Cli.create>,\n\tconfig: {\n\t\tpath: string;\n\t\tdescription: string;\n\t\tfilter?: { option: string; param: string; describe: string };\n\t},\n): void {\n\tconst shape: Record<string, z.ZodType> = {\n\t\tfirst: z.coerce.number().optional().describe(\"Number of results\"),\n\t\tafter: z.string().optional().describe(\"Pagination cursor\"),\n\t};\n\tif (config.filter) {\n\t\tshape[config.filter.option] = z.string().optional().describe(config.filter.describe);\n\t}\n\tgroup.command(\"list\", {\n\t\tdescription: config.description,\n\t\toptions: z.object(shape),\n\t\trun: (c) => {\n\t\t\tconst options = c.options as Record<string, string | number | undefined>;\n\t\t\tconst params = new URLSearchParams();\n\t\t\tif (config.filter && options[config.filter.option]) {\n\t\t\t\tparams.set(config.filter.param, String(options[config.filter.option]));\n\t\t\t}\n\t\t\tif (options.first) params.set(\"first\", String(options.first));\n\t\t\tif (options.after) params.set(\"after\", String(options.after));\n\t\t\tconst qs = params.toString() ? `?${params}` : \"\";\n\t\t\treturn makeWhopRequest(\"GET\", `${config.path}${qs}`);\n\t\t},\n\t});\n}\n\n/**\n * Registers the by-id item commands (`get`, `update`, `delete`) that are\n * identical across commerce resources. `create` carries resource-specific logic\n * (CTAs, scope) and stays hand-written.\n */\nexport function registerItemCommands(\n\tgroup: ReturnType<typeof Cli.create>,\n\tconfig: ItemCommandConfig,\n): void {\n\tconst { path, noun, idLabel, schema, updateOptions, transformBody } = config;\n\tconst idArg = z.object({ id: z.string().describe(idLabel) });\n\n\tgroup.command(\"get\", {\n\t\tdescription: `Get a ${noun} by ID`,\n\t\targs: idArg,\n\t\toutput: schema,\n\t\trun: (c) => makeWhopRequest(`GET`, `${path}/${c.args.id}`),\n\t});\n\n\tif (updateOptions) {\n\t\tgroup.command(\"update\", {\n\t\t\tdescription: `Update a ${noun}`,\n\t\t\targs: idArg,\n\t\t\toptions: updateOptions,\n\t\t\toutput: schema,\n\t\t\trun: (c) => {\n\t\t\t\tconst body = buildBody(c.options);\n\t\t\t\treturn makeWhopRequest(\"PATCH\", `${path}/${c.args.id}`, transformBody ? transformBody(body) : body);\n\t\t\t},\n\t\t});\n\t}\n\n\tgroup.command(\"delete\", {\n\t\tdescription: `Delete a ${noun}`,\n\t\targs: idArg,\n\t\trun: (c) => makeWhopRequest(\"DELETE\", `${path}/${c.args.id}`),\n\t});\n}\n","import chalk from \"chalk\";\n\ninterface NextCommand {\n\tcommand: string;\n\thint?: string;\n}\n\n/**\n * Prints a clean, colored success summary for a `create` command — the human\n * counterpart to the structured envelope agents receive. Pairs with\n * `outputPolicy: \"agent-only\"` so humans see only this (with the checkout link\n * emphasized) and never the raw object dump.\n *\n * No-op in agent mode or when an explicit --format was requested.\n */\nexport function printCreateSuccess(\n\tc: { agent: boolean; formatExplicit: boolean },\n\topts: { title: string; id?: string; checkoutUrl?: string | null; next?: NextCommand },\n): void {\n\tif (c.agent || c.formatExplicit) return;\n\n\tconst lines: string[] = [\"\", chalk.green.bold(`✓ ${opts.title}`)];\n\tif (opts.id) lines.push(` ${chalk.dim(opts.id)}`);\n\n\tif (opts.checkoutUrl) {\n\t\tlines.push(\"\", chalk.bold(\"🎉 You can sell now. Share your checkout link:\"));\n\t\tlines.push(` ${chalk.cyan.underline(opts.checkoutUrl)}`);\n\t}\n\n\tif (opts.next) {\n\t\tlines.push(\"\", `${chalk.bold(\"Next\")} ${chalk.cyan.bold(`whop ${opts.next.command}`)}`);\n\t\tif (opts.next.hint) lines.push(` ${chalk.dim(`→ ${opts.next.hint}`)}`);\n\t}\n\n\tlines.push(\"\");\n\tconsole.log(lines.join(\"\\n\"));\n}\n","import { Cli, z } from \"incur\";\nimport { select, isCancel, spinner } from \"@clack/prompts\";\nimport { makeWhopRequest } from \"./client.js\";\nimport { getActiveProfile } from \"../auth/profiles.js\";\nimport { buildBody, registerItemCommands, registerListCommand } from \"./crud.js\";\nimport { BILLING_PERIOD_DAYS } from \"./billing.js\";\nimport { printCreateSuccess } from \"./output.js\";\n\nconst PlanSchema = z.object({\n\tid: z.string(),\n\ttitle: z.string().nullable().optional(),\n\tplan_type: z.string().optional(),\n\tbilling_period: z.string().nullable().optional(),\n\tinitial_price: z.number().nullable().optional(),\n\trenewal_price: z.number().nullable().optional(),\n\tcurrency: z.string().optional(),\n\tpurchase_url: z.string().nullable().optional(),\n\tvisibility: z.string().optional(),\n\tcreated_at: z.number().optional(),\n});\n\nconst createOptions = z.object({\n\tproduct_id: z.string().optional().describe(\"Product this plan belongs to (prod_xxx)\"),\n\ttitle: z.string().optional().describe(\"Display name for this plan\"),\n\tplan_type: z\n\t\t.enum([\"one_time\", \"renewal\", \"free\"])\n\t\t.optional()\n\t\t.describe(\"Billing model — one_time, renewal, or free\"),\n\tbilling_period: z\n\t\t.enum([\"daily\", \"weekly\", \"monthly\", \"quarterly\", \"annually\", \"every_two_years\"])\n\t\t.optional()\n\t\t.describe(\"How often to charge (for renewal plans)\"),\n\tinitial_price: z.coerce\n\t\t.number()\n\t\t.optional()\n\t\t.describe(\"Price in the plan's currency (e.g. 9.99 for $9.99)\"),\n\trenewal_price: z.coerce\n\t\t.number()\n\t\t.optional()\n\t\t.describe(\"Recurring price for renewal plans (defaults to initial_price)\"),\n\tcurrency: z.string().optional().describe(\"3-letter currency code (default: USD)\"),\n\ttrial_period_days: z.coerce.number().optional().describe(\"Free trial length in days\"),\n\tvisibility: z\n\t\t.enum([\"visible\", \"hidden\", \"archived\"])\n\t\t.optional()\n\t\t.describe(\"Who can see this plan\"),\n});\n\n// Maps friendly plan options to the shape the API expects. Shared by `create`\n// and `update` so the same flags behave identically on both.\nfunction normalizePlanBody(body: Record<string, unknown>): Record<string, unknown> {\n\tif (typeof body.billing_period === \"string\") {\n\t\tbody.billing_period = BILLING_PERIOD_DAYS[body.billing_period];\n\t}\n\tif (body.plan_type === \"renewal\" && body.renewal_price == null && body.initial_price != null) {\n\t\tbody.renewal_price = body.initial_price;\n\t}\n\treturn body;\n}\n\ninterface ProductListItem {\n\tid: string;\n\ttitle: string;\n}\n\ninterface ListResponse {\n\tdata: ProductListItem[];\n}\n\nasync function resolveProductId(\n\tprovidedId: string | undefined,\n\tisAgent: boolean,\n): Promise<\n\t| { ok: true; productId: string; autoResolved: boolean }\n\t| { ok: false; code: string; message: string; candidates?: ProductListItem[] }\n> {\n\tif (providedId) return { ok: true, productId: providedId, autoResolved: false };\n\n\t// Fetch products to auto-resolve a single one, or prompt/error on many.\n\tconst profile = getActiveProfile();\n\tconst params = new URLSearchParams({ first: \"100\" });\n\tif (profile?.companyId) params.set(\"company_id\", profile.companyId);\n\n\tlet data: ProductListItem[];\n\ttry {\n\t\tconst res = await makeWhopRequest<ListResponse>(\"GET\", `/products?${params}`);\n\t\tdata = res.data ?? [];\n\t} catch {\n\t\treturn { ok: false, code: \"API_ERROR\", message: \"Failed to fetch products\" };\n\t}\n\n\tif (data.length === 0) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\tcode: \"NO_PRODUCTS\",\n\t\t\tmessage: \"No products found. Create one first.\",\n\t\t};\n\t}\n\n\tif (data.length === 1) {\n\t\treturn { ok: true, productId: data[0].id, autoResolved: true };\n\t}\n\n\t// Multiple products\n\tif (isAgent) {\n\t\treturn { ok: false, code: \"PRODUCT_REQUIRED\", message: \"Multiple products found. Pass --product_id.\", candidates: data };\n\t}\n\n\t// Interactive picker in TTY\n\tconst chosen = await select<string>({\n\t\tmessage: \"Which product is this plan for?\",\n\t\toptions: data.map((p) => ({ value: p.id, label: p.title, hint: p.id })),\n\t});\n\tif (isCancel(chosen)) return { ok: false, code: \"CANCELLED\", message: \"Cancelled.\" };\n\treturn { ok: true, productId: chosen, autoResolved: false };\n}\n\nexport function buildPlansGroup() {\n\tconst plans = Cli.create(\"plans\", {\n\t\tdescription: \"Plans — pricing for your products\",\n\t});\n\n\tplans.command(\"create\", {\n\t\tdescription: \"Create a pricing plan\",\n\t\thint: \"A plan sets the price and billing interval. After creating a plan, your checkout link is ready to share.\",\n\t\toptions: createOptions,\n\t\toutput: PlanSchema,\n\t\toutputPolicy: \"agent-only\",\n\t\texamples: [\n\t\t\t{\n\t\t\t\toptions: { product_id: \"prod_xxx\", initial_price: 9.99, plan_type: \"one_time\" },\n\t\t\t\tdescription: \"One-time payment of $9.99\",\n\t\t\t},\n\t\t\t{\n\t\t\t\toptions: {\n\t\t\t\t\tproduct_id: \"prod_xxx\",\n\t\t\t\t\tinitial_price: 19.99,\n\t\t\t\t\tplan_type: \"renewal\",\n\t\t\t\t\tbilling_period: \"monthly\",\n\t\t\t\t},\n\t\t\t\tdescription: \"Monthly subscription at $19.99\",\n\t\t\t},\n\t\t],\n\t\trun: async (c) => {\n\t\t\tconst s = c.agent ? null : spinner();\n\t\t\tif (s) s.start(\"Resolving product…\");\n\n\t\t\tconst resolved = await resolveProductId(c.options.product_id, c.agent);\n\n\t\t\tif (s) s.stop(\"\");\n\n\t\t\tif (!resolved.ok) {\n\t\t\t\treturn c.error({\n\t\t\t\t\tcode: resolved.code,\n\t\t\t\t\tmessage: resolved.message,\n\t\t\t\t\tretryable: resolved.code !== \"CANCELLED\",\n\t\t\t\t\tcta:\n\t\t\t\t\t\tresolved.code === \"NO_PRODUCTS\"\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\tdescription: \"Create a product first:\",\n\t\t\t\t\t\t\t\t\tcommands: [{ command: \"products create\", description: \"Create a product\" }],\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t: resolved.candidates\n\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\tdescription: \"Available products:\",\n\t\t\t\t\t\t\t\t\t\tcommands: resolved.candidates.map((p) => ({\n\t\t\t\t\t\t\t\t\t\t\tcommand: \"plans create\",\n\t\t\t\t\t\t\t\t\t\t\toptions: { product_id: p.id },\n\t\t\t\t\t\t\t\t\t\t\tdescription: p.title,\n\t\t\t\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (resolved.autoResolved && !c.agent) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`Note: using product ${resolved.productId} — pass --product_id to override`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst body = normalizePlanBody({\n\t\t\t\t...buildBody(c.options),\n\t\t\t\tproduct_id: resolved.productId,\n\t\t\t});\n\n\t\t\tlet plan: z.infer<typeof PlanSchema>;\n\t\t\ttry {\n\t\t\t\tplan = await makeWhopRequest<z.infer<typeof PlanSchema>>(\"POST\", \"/plans\", body);\n\t\t\t} catch (err) {\n\t\t\t\treturn c.error({\n\t\t\t\t\tcode: \"API_ERROR\",\n\t\t\t\t\tmessage: err instanceof Error ? err.message : \"Failed to create plan\",\n\t\t\t\t\tretryable: true,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst purchaseUrl = plan.purchase_url;\n\t\t\tconst ctaDescription = purchaseUrl\n\t\t\t\t? `🎉 You can sell now. Share your checkout link: ${purchaseUrl}`\n\t\t\t\t: \"Plan created.\";\n\n\t\t\tprintCreateSuccess(c, {\n\t\t\t\ttitle: purchaseUrl ? \"Plan created — you can sell now\" : \"Plan created\",\n\t\t\t\tid: plan.id,\n\t\t\t\tcheckoutUrl: purchaseUrl,\n\t\t\t\tnext: {\n\t\t\t\t\tcommand: \"checkout-configurations create\",\n\t\t\t\t\thint: \"Optional: customize the checkout page (currency, redirect, payment mode)\",\n\t\t\t\t},\n\t\t\t});\n\n\t\t\treturn c.ok(plan, {\n\t\t\t\tcta: {\n\t\t\t\t\tdescription: ctaDescription,\n\t\t\t\t\tcommands: [\n\t\t\t\t\t\t{ command: \"quickstart\", description: \"See your setup status and what's next\" },\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"checkout-configurations create\",\n\t\t\t\t\t\t\toptions: { plan_id: plan.id },\n\t\t\t\t\t\t\tdescription: \"Optional: customize the checkout page\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t});\n\n\tregisterListCommand(plans, {\n\t\tpath: \"/plans\",\n\t\tdescription: \"List plans\",\n\t\tfilter: { option: \"product_id\", param: \"product_ids\", describe: \"Filter by product\" },\n\t});\n\n\tregisterItemCommands(plans, {\n\t\tpath: \"/plans\",\n\t\tnoun: \"plan\",\n\t\tidLabel: \"Plan ID (plan_xxx)\",\n\t\tschema: PlanSchema,\n\t\tupdateOptions: createOptions.omit({ product_id: true }).partial(),\n\t\ttransformBody: normalizePlanBody,\n\t});\n\n\treturn plans;\n}\n","/**\n * Friendly billing-interval names → days, the unit the API expects for a plan's\n * `billing_period` (e.g. 30 for monthly, 365 for annual). The CLI exposes the\n * names for readability and converts before sending.\n */\nexport const BILLING_PERIOD_DAYS: Record<string, number> = {\n\tdaily: 1,\n\tweekly: 7,\n\tmonthly: 30,\n\tquarterly: 90,\n\tannually: 365,\n\tevery_two_years: 730,\n};\n","import { Cli, z } from \"incur\";\nimport { makeWhopRequest } from \"./client.js\";\nimport { buildBody, registerItemCommands, registerListCommand } from \"./crud.js\";\nimport { printCreateSuccess } from \"./output.js\";\n\nconst CheckoutConfigSchema = z.object({\n\tid: z.string(),\n\tmode: z.enum([\"payment\", \"setup\"]).optional(),\n\tcurrency: z.string().nullable().optional(),\n\tpurchase_url: z.string().nullable().optional(),\n\tredirect_url: z.string().nullable().optional(),\n\tcompany_id: z.string().optional(),\n\tcreated_at: z.number().optional(),\n});\n\nconst createOptions = z.object({\n\tplan_id: z.string().optional().describe(\"Plan to attach this checkout to (plan_xxx)\"),\n\tmode: z\n\t\t.enum([\"payment\", \"setup\"])\n\t\t.optional()\n\t\t.describe(\"payment = charge immediately; setup = save payment method only\"),\n\tcurrency: z.string().optional().describe(\"3-letter currency code override\"),\n\tredirect_url: z.string().optional().describe(\"URL to redirect after successful checkout\"),\n\taffiliate_code: z.string().optional().describe(\"Affiliate code to apply\"),\n});\n\nexport function buildCheckoutGroup() {\n\tconst checkout = Cli.create(\"checkout-configurations\", {\n\t\tdescription: \"Checkout configurations — customize your checkout page\",\n\t});\n\n\tcheckout.command(\"create\", {\n\t\tdescription: \"Create a checkout configuration\",\n\t\thint: \"Customize the currency, redirect URL, and payment mode for a plan's checkout page.\",\n\t\toptions: createOptions,\n\t\toutput: CheckoutConfigSchema,\n\t\toutputPolicy: \"agent-only\",\n\t\texamples: [\n\t\t\t{\n\t\t\t\toptions: { plan_id: \"plan_xxx\" },\n\t\t\t\tdescription: \"Basic checkout configuration for a plan\",\n\t\t\t},\n\t\t\t{\n\t\t\t\toptions: { plan_id: \"plan_xxx\", redirect_url: \"https://mysite.com/thank-you\" },\n\t\t\t\tdescription: \"Redirect buyers to a custom thank-you page\",\n\t\t\t},\n\t\t],\n\t\trun: async (c) => {\n\t\t\tconst body = buildBody(c.options);\n\n\t\t\tlet config: z.infer<typeof CheckoutConfigSchema>;\n\t\t\ttry {\n\t\t\t\tconfig = await makeWhopRequest<z.infer<typeof CheckoutConfigSchema>>(\n\t\t\t\t\t\"POST\",\n\t\t\t\t\t\"/checkout_configurations\",\n\t\t\t\t\tbody,\n\t\t\t\t);\n\t\t\t} catch (err) {\n\t\t\t\treturn c.error({\n\t\t\t\t\tcode: \"API_ERROR\",\n\t\t\t\t\tmessage: err instanceof Error ? err.message : \"Failed to create checkout configuration\",\n\t\t\t\t\tretryable: true,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst purchaseUrl = config.purchase_url;\n\t\t\tprintCreateSuccess(c, {\n\t\t\t\ttitle: \"Checkout configured\",\n\t\t\t\tid: config.id,\n\t\t\t\tcheckoutUrl: purchaseUrl,\n\t\t\t\tnext: { command: \"quickstart\", hint: \"See your full setup status\" },\n\t\t\t});\n\t\t\treturn c.ok(config, {\n\t\t\t\tcta: {\n\t\t\t\t\tdescription: purchaseUrl\n\t\t\t\t\t\t? `Checkout configured. Share your link: ${purchaseUrl}`\n\t\t\t\t\t\t: \"Checkout configured.\",\n\t\t\t\t\tcommands: [\n\t\t\t\t\t\t{ command: \"quickstart\", description: \"See your full setup status\" },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t});\n\n\tregisterListCommand(checkout, {\n\t\tpath: \"/checkout_configurations\",\n\t\tdescription: \"List checkout configurations\",\n\t\tfilter: { option: \"plan_id\", param: \"plan_id\", describe: \"Filter by plan\" },\n\t});\n\n\tregisterItemCommands(checkout, {\n\t\tpath: \"/checkout_configurations\",\n\t\tnoun: \"checkout configuration\",\n\t\tidLabel: \"Checkout configuration ID\",\n\t\tschema: CheckoutConfigSchema,\n\t});\n\n\treturn checkout;\n}\n","import { z } from \"incur\";\nimport chalk from \"chalk\";\nimport { text, select, isCancel } from \"@clack/prompts\";\nimport { makeWhopRequest } from \"../commerce/client.js\";\nimport { resolveActiveCompanyId } from \"../api/index.js\";\nimport { BILLING_PERIOD_DAYS } from \"../commerce/billing.js\";\nimport { getActiveProfile } from \"../auth/profiles.js\";\nimport { c } from \"../lib/colors.js\";\n\ninterface ListItem {\n\tid: string;\n\ttitle?: string | null;\n\tpurchase_url?: string | null;\n}\ninterface ListResponse {\n\tdata: ListItem[];\n}\n\nconst StepSchema = z.object({\n\tid: z.string(),\n\tlabel: z.string(),\n\tcomplete: z.boolean(),\n\tcount: z.number().optional(),\n\tfirstId: z.string().optional(),\n\tfirstTitle: z.string().optional(),\n});\n\nconst NextStepSchema = z.object({\n\tcommand: z.string(),\n\toptions: z.record(z.string(), z.string()).optional(),\n\tdescription: z.string(),\n\thint: z.string().optional(),\n});\n\nexport const quickstartOptions = z.object({\n\ttitle: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\n\t\t\t\"Product name — providing this (or --price/--billing_period) makes quickstart create your product\",\n\t\t),\n\tprice: z.coerce\n\t\t.number()\n\t\t.optional()\n\t\t.describe(\"Price in the plan's currency (e.g. 9.99 for $9.99, 0 = free)\"),\n\tbilling_period: z\n\t\t.enum([\n\t\t\t\"monthly\",\n\t\t\t\"annually\",\n\t\t\t\"quarterly\",\n\t\t\t\"weekly\",\n\t\t\t\"daily\",\n\t\t\t\"every_two_years\",\n\t\t\t\"one_time\",\n\t\t])\n\t\t.optional()\n\t\t.describe(\"Billing interval — use 'one_time' for a single payment\"),\n\tcompany_id: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\n\t\t\t\"Business account to act on behalf of (biz_xxx); defaults to your active account\",\n\t\t),\n});\n\nexport const quickstartOutput = z.object({\n\taccount: z.string().nullable().describe(\"Authenticated account name\"),\n\tready: z\n\t\t.boolean()\n\t\t.describe(\"Whether you can take a sale now (a product with a plan exists)\"),\n\tcheckoutUrl: z\n\t\t.string()\n\t\t.nullable()\n\t\t.describe(\n\t\t\t\"The live checkout link to share — the journey's payoff, present once a plan exists\",\n\t\t),\n\tcreated: z\n\t\t.object({ productId: z.string().optional(), planId: z.string().optional() })\n\t\t.nullable()\n\t\t.describe(\n\t\t\t\"What this run created, if anything — null for a read-only status check\",\n\t\t),\n\tsteps: z.array(StepSchema).describe(\"The path to your first sale\"),\n\tnextStep: NextStepSchema.nullable().describe(\n\t\t\"The single command to run next, pre-filled — null when nothing is required\",\n\t),\n});\n\ntype Step = z.infer<typeof StepSchema>;\ntype NextStep = z.infer<typeof NextStepSchema>;\n\ntype CtaCommand = {\n\tcommand: string;\n\tdescription?: string;\n\toptions?: Record<string, string>;\n};\n\ntype RunCtx = {\n\tagent: boolean;\n\tformatExplicit: boolean;\n\toptions: z.infer<typeof quickstartOptions>;\n\tsetupAgents?: () => Promise<void>;\n\tok: (data: z.infer<typeof quickstartOutput>) => never;\n\terror: (opts: {\n\t\tcode: string;\n\t\tmessage: string;\n\t\tretryable?: boolean;\n\t\texitCode?: number;\n\t\tcta?: { description?: string; commands: CtaCommand[] };\n\t}) => never;\n};\n\ntype ErrorEnvelope = Parameters<RunCtx[\"error\"]>[0];\n\n// incur's `c.error` is a sentinel that only takes effect when returned from the\n// command `run`. Nested helpers can't force the caller to return, so they throw\n// this instead; runCreate's caller catches it and returns `c.error(envelope)`,\n// preserving code/retryable/cta (which a plain thrown Error would lose).\nclass QuickstartError extends Error {\n\tconstructor(readonly envelope: ErrorEnvelope) {\n\t\tsuper(envelope.message);\n\t}\n}\n\nexport async function runQuickstart(c: RunCtx): Promise<never> {\n\tconst profile = getActiveProfile();\n\t// Mirror the auth middleware: a saved profile OR a WHOP_API_KEY env var (the\n\t// agent / CI path) is enough — don't reject env-key auth the gate let through.\n\tif (!profile && !process.env.WHOP_API_KEY) {\n\t\treturn c.error({\n\t\t\tcode: \"NOT_AUTHENTICATED\",\n\t\t\tmessage: \"Not logged in.\",\n\t\t\tcta: {\n\t\t\t\tcommands: [{ command: \"auth login\", description: \"Log in to Whop\" }],\n\t\t\t},\n\t\t});\n\t}\n\n\tif (!c.agent && !c.formatExplicit && c.setupAgents) {\n\t\ttry {\n\t\t\tawait c.setupAgents();\n\t\t} catch (err) {\n\t\t\tconst message =\n\t\t\t\terr instanceof Error ? err.message : \"Couldn't set up Whop for agents.\";\n\t\t\tconsole.log(`\\n${chalk.yellow(\"!\")} Agent setup skipped: ${message}`);\n\t\t\tconsole.log(\n\t\t\t\tchalk.dim(\n\t\t\t\t\t\" You can retry later with `whop skills add` and `whop mcp add`.\",\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\n\tconst companyId =\n\t\tc.options.company_id ?? (await resolveActiveCompanyId()) ?? \"\";\n\tconst accountName =\n\t\tprofile?.accountTitle ??\n\t\tprofile?.accountRoute ??\n\t\tprofile?.name ??\n\t\t\"your account\";\n\n\tif (!companyId) {\n\t\treturn c.error({\n\t\t\tcode: \"NO_COMPANY\",\n\t\t\tmessage:\n\t\t\t\t\"No business account is linked to this login. Create a business account on Whop, then log in again.\",\n\t\t\tretryable: false,\n\t\t\tcta: {\n\t\t\t\tdescription: \"Create a business account, then re-authenticate:\",\n\t\t\t\tcommands: [\n\t\t\t\t\t{\n\t\t\t\t\t\tcommand: \"auth login\",\n\t\t\t\t\t\tdescription: \"Log in and pick a business account\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t});\n\t}\n\n\tconst [productsRes, plansRes, checkoutRes] = await Promise.allSettled([\n\t\tmakeWhopRequest<ListResponse>(\n\t\t\t\"GET\",\n\t\t\t`/products?company_id=${companyId}&first=100`,\n\t\t),\n\t\tmakeWhopRequest<ListResponse>(\n\t\t\t\"GET\",\n\t\t\t`/plans?account_id=${companyId}&first=100`,\n\t\t),\n\t\tmakeWhopRequest<ListResponse>(\n\t\t\t\"GET\",\n\t\t\t`/checkout_configurations?company_id=${companyId}&first=100`,\n\t\t),\n\t]);\n\n\t// Don't let a failed products/plans lookup masquerade as \"nothing exists\" —\n\t// that would show empty steps or, worse, prompt a duplicate create. Surface\n\t// the real error instead. A failed checkout lookup is non-critical.\n\tconst critical = [productsRes, plansRes].find((r) => r.status === \"rejected\");\n\tif (critical && critical.status === \"rejected\") {\n\t\tconst reason = critical.reason;\n\t\treturn c.error({\n\t\t\tcode: \"STATUS_CHECK_FAILED\",\n\t\t\tmessage: `Couldn't load your current setup: ${reason instanceof Error ? reason.message : \"API error\"}`,\n\t\t\tretryable: true,\n\t\t});\n\t}\n\n\tconst products =\n\t\tproductsRes.status === \"fulfilled\" ? (productsRes.value.data ?? []) : [];\n\tconst plans =\n\t\tplansRes.status === \"fulfilled\" ? (plansRes.value.data ?? []) : [];\n\tconst checkouts =\n\t\tcheckoutRes.status === \"fulfilled\" ? (checkoutRes.value.data ?? []) : [];\n\n\tconst ready = products.length > 0 && plans.length > 0;\n\tconst hasCreationFlags =\n\t\tc.options.title !== undefined ||\n\t\tc.options.price !== undefined ||\n\t\tc.options.billing_period !== undefined;\n\n\t// Mutate-gate: explicit creation flags always create (the user asked for it,\n\t// even on an already-set-up account). Without flags we only auto-guide a\n\t// create when something is missing AND we're interactive — so a ready account\n\t// in agent mode or with `--format`/`--json` stays a pure read-only status check.\n\tconst canMutateInteractively = !c.agent && !c.formatExplicit;\n\tconst shouldCreate = hasCreationFlags || (!ready && canMutateInteractively);\n\n\tif (shouldCreate) {\n\t\ttry {\n\t\t\treturn await runCreate(c, { companyId, accountName, products });\n\t\t} catch (err) {\n\t\t\tif (err instanceof QuickstartError) return c.error(err.envelope);\n\t\t\tthrow err;\n\t\t}\n\t}\n\n\tconst steps = buildSteps(products, plans);\n\tconst checkoutUrl = plans.find((p) => p.purchase_url)?.purchase_url ?? null;\n\tconst nextStep = resolveNextStep(products, plans, checkouts.length > 0);\n\n\tif (!c.agent && !c.formatExplicit) {\n\t\tprintSummary(accountName, steps, ready, checkoutUrl, nextStep);\n\t}\n\n\treturn c.ok({\n\t\taccount: accountName,\n\t\tready,\n\t\tcheckoutUrl,\n\t\tcreated: null,\n\t\tsteps,\n\t\tnextStep,\n\t});\n}\n\n/** Returns the provided value, errors in agent mode, or prompts interactively. */\nasync function resolveOrPrompt<T>(\n\tc: RunCtx,\n\tprovided: T | undefined,\n\tmissing: { code: string; message: string; example: string },\n\tprompt: () => Promise<T | symbol>,\n): Promise<T> {\n\tif (provided !== undefined) return provided;\n\tif (c.agent) {\n\t\tthrow new QuickstartError({\n\t\t\tcode: missing.code,\n\t\t\tmessage: `${missing.message} Example: ${missing.example}`,\n\t\t\tretryable: true,\n\t\t});\n\t}\n\tconst value = await prompt();\n\tif (isCancel(value))\n\t\tthrow new QuickstartError({\n\t\t\tcode: \"CANCELLED\",\n\t\t\tmessage: \"Setup cancelled.\",\n\t\t\texitCode: 130,\n\t\t});\n\treturn value as T;\n}\n\nconst FULL_EXAMPLE =\n\t'whop quickstart --title \"My Course\" --price 9.99 --billing_period monthly';\n\nasync function runCreate(\n\tc: RunCtx,\n\tstate: { companyId: string; accountName: string; products: ListItem[] },\n): Promise<never> {\n\tif (!c.agent) {\n\t\tconsole.log(`\\n${chalk.bold(\"Let's get you set up to sell.\")}\\n`);\n\t}\n\n\t// Create a new product when none exist or when an explicit --title is given\n\t// (the user named a product, so honor that intent even if they already have\n\t// others). Otherwise attach the new plan to an existing one.\n\t//\n\t// Gather every input up front, before any POST, so a partial invocation (e.g.\n\t// an agent passes --title but omits --price) fails cleanly without leaving an\n\t// orphaned product behind — and so a cancelled TTY prompt creates nothing.\n\tconst needsNewProduct =\n\t\tstate.products.length === 0 || c.options.title !== undefined;\n\tconst newTitle = needsNewProduct\n\t\t? await resolveOrPrompt(\n\t\t\t\tc,\n\t\t\t\tc.options.title,\n\t\t\t\t{\n\t\t\t\t\tcode: \"TITLE_REQUIRED\",\n\t\t\t\t\tmessage: \"Pass --title to name your product.\",\n\t\t\t\t\texample: FULL_EXAMPLE,\n\t\t\t\t},\n\t\t\t\t() =>\n\t\t\t\t\ttext({\n\t\t\t\t\t\tmessage: \"What are you selling?\",\n\t\t\t\t\t\tplaceholder: \"My Online Course\",\n\t\t\t\t\t}),\n\t\t\t)\n\t\t: undefined;\n\tconst existing = needsNewProduct\n\t\t? undefined\n\t\t: await resolveExistingProduct(c, state.products);\n\n\tconst price = await resolveOrPrompt(\n\t\tc,\n\t\tc.options.price,\n\t\t{\n\t\t\tcode: \"PRICE_REQUIRED\",\n\t\t\tmessage: \"Pass --price in dollars (9.99 = $9.99, 0 = free).\",\n\t\t\texample: FULL_EXAMPLE,\n\t\t},\n\t\tasync () => {\n\t\t\tconst p = await text({\n\t\t\t\tmessage: \"Price in dollars (9.99 = $9.99, 0 = free):\",\n\t\t\t\tplaceholder: \"9.99\",\n\t\t\t\tvalidate: (v) => (isNaN(Number(v)) ? \"Enter a number\" : undefined),\n\t\t\t});\n\t\t\treturn isCancel(p) ? p : Number(p);\n\t\t},\n\t);\n\n\tconst billingPeriod = await resolveOrPrompt(\n\t\tc,\n\t\tc.options.billing_period,\n\t\t{\n\t\t\tcode: \"BILLING_PERIOD_REQUIRED\",\n\t\t\tmessage: \"Pass --billing_period (one_time, monthly, annually, …).\",\n\t\t\texample: FULL_EXAMPLE,\n\t\t},\n\t\t() =>\n\t\t\tselect({\n\t\t\t\tmessage: \"How should customers be charged?\",\n\t\t\t\toptions: [\n\t\t\t\t\t{ value: \"one_time\", label: \"One-time payment\" },\n\t\t\t\t\t{ value: \"monthly\", label: \"Monthly subscription\" },\n\t\t\t\t\t{ value: \"annually\", label: \"Annual subscription\" },\n\t\t\t\t\t{ value: \"quarterly\", label: \"Quarterly\" },\n\t\t\t\t],\n\t\t\t}) as Promise<NonNullable<typeof c.options.billing_period> | symbol>,\n\t);\n\n\tlet productId: string;\n\tlet productTitle: string;\n\tlet productCreated = false;\n\tif (existing) {\n\t\tproductId = existing.id;\n\t\tproductTitle = existing.title ?? existing.id;\n\t} else {\n\t\tlet product: { id: string; title: string };\n\t\ttry {\n\t\t\tproduct = await makeWhopRequest<{ id: string; title: string }>(\n\t\t\t\t\"POST\",\n\t\t\t\t\"/products\",\n\t\t\t\t{\n\t\t\t\t\ttitle: newTitle,\n\t\t\t\t\tcompany_id: state.companyId,\n\t\t\t\t},\n\t\t\t);\n\t\t} catch (err) {\n\t\t\treturn c.error({\n\t\t\t\tcode: \"API_ERROR\",\n\t\t\t\tmessage: `Failed to create product: ${err instanceof Error ? err.message : \"unknown error\"}`,\n\t\t\t\tretryable: true,\n\t\t\t});\n\t\t}\n\t\tproductId = product.id;\n\t\tproductTitle = product.title;\n\t\tproductCreated = true;\n\t}\n\n\tconst isRenewal = billingPeriod !== \"one_time\";\n\tconst planBody: Record<string, unknown> = {\n\t\tproduct_id: productId,\n\t\taccount_id: state.companyId,\n\t\tinitial_price: price,\n\t\tplan_type: isRenewal ? \"renewal\" : \"one_time\",\n\t};\n\tif (isRenewal) {\n\t\tplanBody.billing_period = BILLING_PERIOD_DAYS[billingPeriod];\n\t\tplanBody.renewal_price = price;\n\t}\n\n\tlet plan: { id: string; purchase_url?: string | null };\n\ttry {\n\t\tplan = await makeWhopRequest<{ id: string; purchase_url?: string | null }>(\n\t\t\t\"POST\",\n\t\t\t\"/plans\",\n\t\t\tplanBody,\n\t\t);\n\t} catch (err) {\n\t\t// Product is ready but the plan failed — hand back a recovery command with\n\t\t// the product id already filled in. Only claim the product \"was created\"\n\t\t// when we actually created it this run (vs reused an existing one).\n\t\tconst detail = err instanceof Error ? err.message : \"unknown error\";\n\t\treturn c.error({\n\t\t\tcode: \"PLAN_FAILED\",\n\t\t\tmessage: productCreated\n\t\t\t\t? `Your product \"${productTitle}\" (${productId}) was created, but the plan failed: ${detail}`\n\t\t\t\t: `Couldn't add a plan to \"${productTitle}\" (${productId}): ${detail}`,\n\t\t\tretryable: false,\n\t\t\tcta: {\n\t\t\t\tdescription: \"Finish by adding a plan to your product:\",\n\t\t\t\tcommands: [\n\t\t\t\t\t{\n\t\t\t\t\t\tcommand: \"plans create\",\n\t\t\t\t\t\toptions: { product_id: productId },\n\t\t\t\t\t\tdescription: \"Add a pricing plan\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t});\n\t}\n\n\tconst checkoutUrl = plan.purchase_url ?? null;\n\tconst steps: Step[] = [\n\t\t{ id: \"auth\", label: \"Log in\", complete: true },\n\t\t{\n\t\t\tid: \"products\",\n\t\t\tlabel: \"Create a product\",\n\t\t\tcomplete: true,\n\t\t\tcount: 1,\n\t\t\tfirstId: productId,\n\t\t\tfirstTitle: productTitle,\n\t\t},\n\t\t{\n\t\t\tid: \"plans\",\n\t\t\tlabel: \"Add a pricing plan\",\n\t\t\tcomplete: true,\n\t\t\tcount: 1,\n\t\t\tfirstId: plan.id,\n\t\t},\n\t];\n\tconst nextStep = resolveNextStep(\n\t\t[{ id: productId }],\n\t\t[{ id: plan.id }],\n\t\tfalse,\n\t);\n\n\tif (!c.agent && !c.formatExplicit) {\n\t\tprintSummary(\n\t\t\tstate.accountName,\n\t\t\tsteps,\n\t\t\ttrue,\n\t\t\tcheckoutUrl,\n\t\t\tnextStep,\n\t\t\tproductTitle,\n\t\t);\n\t}\n\n\treturn c.ok({\n\t\taccount: state.accountName,\n\t\tready: true,\n\t\tcheckoutUrl,\n\t\tcreated: { productId, planId: plan.id },\n\t\tsteps,\n\t\tnextStep,\n\t});\n}\n\nasync function resolveExistingProduct(\n\tc: RunCtx,\n\tproducts: ListItem[],\n): Promise<ListItem> {\n\tif (products.length === 1) return products[0];\n\tif (c.agent) {\n\t\tthrow new QuickstartError({\n\t\t\tcode: \"PRODUCT_REQUIRED\",\n\t\t\tmessage: `You have ${products.length} products — add the plan to a specific one with plans create --product_id.`,\n\t\t\tretryable: true,\n\t\t\tcta: {\n\t\t\t\tdescription: \"Pick a product:\",\n\t\t\t\tcommands: products.map((p) => ({\n\t\t\t\t\tcommand: \"plans create\",\n\t\t\t\t\toptions: { product_id: p.id },\n\t\t\t\t\tdescription: p.title ?? p.id,\n\t\t\t\t})),\n\t\t\t},\n\t\t});\n\t}\n\tconst chosen = await select<string>({\n\t\tmessage: \"Which product is this plan for?\",\n\t\toptions: products.map((p) => ({\n\t\t\tvalue: p.id,\n\t\t\tlabel: p.title ?? p.id,\n\t\t\thint: p.id,\n\t\t})),\n\t});\n\tif (isCancel(chosen))\n\t\tthrow new QuickstartError({\n\t\t\tcode: \"CANCELLED\",\n\t\t\tmessage: \"Setup cancelled.\",\n\t\t\texitCode: 130,\n\t\t});\n\tconst match = products.find((p) => p.id === chosen);\n\tif (!match) {\n\t\tthrow new QuickstartError({\n\t\t\tcode: \"PRODUCT_NOT_FOUND\",\n\t\t\tmessage: `Selected product \"${chosen}\" is no longer available.`,\n\t\t\tretryable: true,\n\t\t});\n\t}\n\treturn match;\n}\n\nfunction buildSteps(products: ListItem[], plans: ListItem[]): Step[] {\n\treturn [\n\t\t{ id: \"auth\", label: \"Log in\", complete: true },\n\t\t{\n\t\t\tid: \"products\",\n\t\t\tlabel: \"Create a product\",\n\t\t\tcomplete: products.length > 0,\n\t\t\tcount: products.length,\n\t\t\tfirstId: products[0]?.id,\n\t\t\tfirstTitle: products[0]?.title ?? undefined,\n\t\t},\n\t\t{\n\t\t\tid: \"plans\",\n\t\t\tlabel: \"Add a pricing plan\",\n\t\t\tcomplete: plans.length > 0,\n\t\t\tcount: plans.length,\n\t\t\tfirstId: plans[0]?.id,\n\t\t},\n\t];\n}\n\nfunction resolveNextStep(\n\tproducts: Array<{ id: string }>,\n\tplans: Array<{ id: string }>,\n\thasCheckoutConfig: boolean,\n): NextStep | null {\n\tif (products.length === 0 || plans.length === 0) {\n\t\treturn {\n\t\t\tcommand: \"quickstart\",\n\t\t\tdescription:\n\t\t\t\t\"Create your product and pricing — ends with a checkout link\",\n\t\t\thint: \"Walks you through name, price, and billing. Pass --title/--price/--billing_period to skip the prompts.\",\n\t\t};\n\t}\n\tif (!hasCheckoutConfig) {\n\t\treturn {\n\t\t\tcommand: \"checkout-configurations create\",\n\t\t\toptions: plans[0]?.id ? { plan_id: plans[0].id } : undefined,\n\t\t\tdescription: \"Optional: customize your checkout page\",\n\t\t\thint: \"Your checkout link already works — this only tweaks currency, redirect, and payment mode\",\n\t\t};\n\t}\n\treturn null;\n}\n\nfunction printSummary(\n\taccount: string | null,\n\tsteps: Step[],\n\tready: boolean,\n\tcheckoutUrl: string | null,\n\tnextStep: NextStep | null,\n\tcreatedLabel?: string,\n): void {\n\tconst heading = createdLabel\n\t\t? `You're set up to sell \"${createdLabel}\"`\n\t\t: `Setup for \"${account ?? \"your account\"}\"`;\n\tconsole.log(`\\n${chalk.bold(heading)}\\n`);\n\n\tlet pendingMarked = false;\n\tfor (const step of steps) {\n\t\tif (step.complete) {\n\t\t\tlet label = step.label;\n\t\t\tif (step.count !== undefined) {\n\t\t\t\tlabel += chalk.dim(` (${step.count})`);\n\t\t\t\tif (step.firstTitle) label += chalk.dim(` — \"${step.firstTitle}\"`);\n\t\t\t}\n\t\t\tconsole.log(` ${c.success(\"✓\")} ${label}`);\n\t\t} else if (!pendingMarked) {\n\t\t\tpendingMarked = true;\n\t\t\tconsole.log(` ${chalk.cyan(\"●\")} ${chalk.bold(step.label)}`);\n\t\t} else {\n\t\t\tconsole.log(` ${chalk.dim(\"○\")} ${chalk.dim(step.label)}`);\n\t\t}\n\t}\n\n\tif (ready && checkoutUrl) {\n\t\tconsole.log(\n\t\t\t`\\n${chalk.green.bold(\"🎉 You're ready to sell.\")} Share your checkout link:`,\n\t\t);\n\t\tconsole.log(` ${chalk.cyan.underline(checkoutUrl)}`);\n\t}\n\n\tif (nextStep) {\n\t\tconst opts = nextStep.options\n\t\t\t? \" \" +\n\t\t\t\tObject.entries(nextStep.options)\n\t\t\t\t\t.map(([k, v]) => `--${k} ${v}`)\n\t\t\t\t\t.join(\" \")\n\t\t\t: \"\";\n\t\tconst label = ready ? \"Optional next\" : chalk.bold(\"Next step\");\n\t\tconsole.log(\n\t\t\t`\\n${label} ${chalk.cyan.bold(`whop ${nextStep.command}${opts}`)}`,\n\t\t);\n\t\tif (nextStep.hint) console.log(` ${chalk.dim(`→ ${nextStep.hint}`)}`);\n\t} else if (ready) {\n\t\tconsole.log(`\\n${c.success(\"✓ Your store is fully set up.\")}`);\n\t}\n\tconsole.log(\"\");\n}\n","import chalk from \"chalk\";\n\nexport const c = {\n heading: chalk.bold,\n command: chalk.bold,\n description: chalk.dim,\n flag: chalk.yellow,\n tableHeader: chalk.bold,\n separator: chalk.dim,\n number: chalk.dim,\n muted: chalk.dim,\n id: chalk.cyan,\n link: chalk.cyan.underline,\n success: chalk.green,\n error: chalk.red.bold,\n};\n","import groups from \"./api/groups.json\" with { type: \"json\" };\nimport {\n\tbuildAuthGroup,\n\tloginAdapter,\n\tloginEnv,\n\tloginExamples,\n\tloginHint,\n\tloginOptions,\n\tloginOutput,\n\tlogoutAdapter,\n\tlogoutOptions,\n\tlogoutOutput,\n} from \"./auth/commands\";\nimport {\n\tbuildCheckoutGroup,\n\tbuildPlansGroup,\n\tbuildProductsGroup,\n} from \"./commerce/index\";\nimport {\n\tquickstartOptions,\n\tquickstartOutput,\n\trunQuickstart,\n} from \"./journey/quickstart\";\n\ntype CliRegistration = {\n\tcommand: (...args: any[]) => unknown;\n\tserve: (\n\t\targv: string[],\n\t\toptions?: {\n\t\t\texit?: (code: number) => void;\n\t\t\tstdout?: (chunk: string) => void;\n\t\t},\n\t) => Promise<void>;\n};\n\ntype HandwrittenGroup = {\n\tname: string;\n\tdescription: string;\n\tsection: \"get-started\" | \"commerce\" | \"auth\";\n\tregister: (cli: CliRegistration) => unknown;\n};\n\nexport const HANDWRITTEN_GROUPS = [\n\t{\n\t\tname: \"quickstart\",\n\t\tdescription: \"Start here — check status and create your first product + checkout link\",\n\t\tsection: \"get-started\",\n\t\tregister: (cli: CliRegistration) =>\n\t\t\tcli.command(\"quickstart\", {\n\t\t\t\tdescription: \"Start selling — check your status and create what's missing\",\n\t\t\t\thint: \"In a terminal it guides you to your first sale. Agents: a read-only status check unless you pass --title/--price/--billing_period.\",\n\t\t\t\toptions: quickstartOptions,\n\t\t\t\toutput: quickstartOutput,\n\t\t\t\texamples: [\n\t\t\t\t\t{ description: \"Check status / get guided to your first sale\" },\n\t\t\t\t\t{\n\t\t\t\t\t\toptions: {\n\t\t\t\t\t\t\ttitle: \"My Course\",\n\t\t\t\t\t\t\tprice: 9.99,\n\t\t\t\t\t\t\tbilling_period: \"monthly\" as const,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdescription: \"Create a $9.99/mo product non-interactively\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\toutputPolicy: \"agent-only\",\n\t\t\t\trun: (c: Parameters<typeof runQuickstart>[0]) =>\n\t\t\t\t\trunQuickstart({ ...c, setupAgents: () => setupAgents(cli) }),\n\t\t\t}),\n\t},\n\t{\n\t\tname: \"products\",\n\t\tdescription: \"What you're selling\",\n\t\tsection: \"commerce\",\n\t\tregister: (cli: CliRegistration) => cli.command(buildProductsGroup()),\n\t},\n\t{\n\t\tname: \"plans\",\n\t\tdescription: \"Pricing for your products\",\n\t\tsection: \"commerce\",\n\t\tregister: (cli: CliRegistration) => cli.command(buildPlansGroup()),\n\t},\n\t{\n\t\tname: \"checkout-configurations\",\n\t\tdescription: \"Optional / advanced: customize the checkout page\",\n\t\tsection: \"commerce\",\n\t\tregister: (cli: CliRegistration) => cli.command(buildCheckoutGroup()),\n\t},\n\t{\n\t\tname: \"auth\",\n\t\tdescription: \"Manage authentication\",\n\t\tsection: \"auth\",\n\t\tregister: (cli: CliRegistration) => cli.command(buildAuthGroup()),\n\t},\n\t{\n\t\tname: \"login\",\n\t\tdescription: \"Sign in to Whop\",\n\t\tsection: \"auth\",\n\t\tregister: (cli: CliRegistration) =>\n\t\t\tcli.command(\"login\", {\n\t\t\t\tdescription: \"Log in to Whop (alias for `auth login`)\",\n\t\t\t\toptions: loginOptions,\n\t\t\t\tenv: loginEnv,\n\t\t\t\toutput: loginOutput,\n\t\t\t\texamples: loginExamples,\n\t\t\t\thint: loginHint,\n\t\t\t\trun: (c: Parameters<typeof loginAdapter>[0]) => loginAdapter(c),\n\t\t\t}),\n\t},\n\t{\n\t\tname: \"logout\",\n\t\tdescription: \"Sign out\",\n\t\tsection: \"auth\",\n\t\tregister: (cli: CliRegistration) =>\n\t\t\tcli.command(\"logout\", {\n\t\t\t\tdescription: \"Log out (alias for `auth logout`)\",\n\t\t\t\toptions: logoutOptions,\n\t\t\t\toutput: logoutOutput,\n\t\t\t\trun: (c: Parameters<typeof logoutAdapter>[0]) => logoutAdapter(c),\n\t\t\t}),\n\t},\n] satisfies HandwrittenGroup[];\n\nexport const HANDWRITTEN_GROUP_NAMES = new Set(\n\tHANDWRITTEN_GROUPS.map(({ name }) => name),\n);\n\nexport const API_GROUPS = groups\n\t.map(([name, tag]) => ({ name, tag }))\n\t.filter(({ name }) => !HANDWRITTEN_GROUP_NAMES.has(name));\n\nexport const COMMAND_GROUPS = [...API_GROUPS, ...HANDWRITTEN_GROUPS] as const;\n\nexport function registerHandwrittenGroups(cli: CliRegistration) {\n\tfor (const group of HANDWRITTEN_GROUPS) group.register(cli);\n}\n\nasync function setupAgents(cli: CliRegistration) {\n\tfor (const argv of [\n\t\t[\"skills\", \"add\"],\n\t\t[\"mcp\", \"add\"],\n\t]) {\n\t\tlet exitCode = 0;\n\t\tawait cli.serve(argv, {\n\t\t\texit: (code) => {\n\t\t\t\texitCode = code;\n\t\t\t},\n\t\t\tstdout: (chunk) => process.stdout.write(chunk),\n\t\t});\n\t\tif (exitCode !== 0) throw new Error(`whop ${argv.join(\" \")} failed.`);\n\t}\n}\n","{\n\t\"name\": \"@whop/cli\",\n\t\"version\": \"0.0.5\",\n\t\"description\": \"The Whop CLI — build and manage Whop apps from your terminal. Human and agent friendly.\",\n\t\"keywords\": [\n\t\t\"agent\",\n\t\t\"apps\",\n\t\t\"cli\",\n\t\t\"developer\",\n\t\t\"whop\"\n\t],\n\t\"homepage\": \"https://whop.com/developers/\",\n\t\"bugs\": \"https://github.com/whopio/whop-sdk-ts/issues\",\n\t\"license\": \"MIT\",\n\t\"repository\": {\n\t\t\"type\": \"git\",\n\t\t\"url\": \"git+https://github.com/whopio/whop-sdk-ts.git\",\n\t\t\"directory\": \"packages/cli\"\n\t},\n\t\"bin\": {\n\t\t\"whop\": \"dist/index.js\",\n\t\t\"whop-cli\": \"dist/index.js\"\n\t},\n\t\"files\": [\n\t\t\"dist\"\n\t],\n\t\"type\": \"module\",\n\t\"publishConfig\": {\n\t\t\"access\": \"public\"\n\t},\n\t\"scripts\": {\n\t\t\"build\": \"tsx scripts/sync-spec.ts && pnpm run clean && tsup\",\n\t\t\"clean\": \"rm -rf dist\",\n\t\t\"dev\": \"tsx scripts/sync-spec.ts && tsx src/index.ts\",\n\t\t\"start\": \"node dist/index.js\",\n\t\t\"check-types\": \"tsx scripts/sync-spec.ts && tsc --noEmit\",\n\t\t\"lint\": \"oxlint .\",\n\t\t\"lint:fix\": \"oxlint --fix --fix-suggestions && oxfmt\",\n\t\t\"ci:lint\": \"oxlint -f github .\",\n\t\t\"format\": \"oxfmt\",\n\t\t\"sync-spec\": \"tsx scripts/sync-spec.ts\",\n\t\t\"test\": \"tsx --test scripts/*.test.ts\"\n\t},\n\t\"dependencies\": {\n\t\t\"@clack/prompts\": \"^1.5.1\",\n\t\t\"@napi-rs/keyring\": \"^1.3.0\",\n\t\t\"@whop/sdk\": \"^0.0.40\",\n\t\t\"chalk\": \"5.4.1\"\n\t},\n\t\"devDependencies\": {\n\t\t\"@types/node\": \"25.3.5\",\n\t\t\"incur\": \"github:whopio/incur#ea62f88\",\n\t\t\"tsup\": \"8.5.0\",\n\t\t\"tsx\": \"4.19.4\",\n\t\t\"typescript\": \"5.9.3\"\n\t},\n\t\"engines\": {\n\t\t\"node\": \">=22\"\n\t},\n\t\"packageManager\": \"pnpm@10.23.0\"\n}\n","import { c } from \"./colors\";\n\nconst MAX_CELL_WIDTH = 40\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nfunction isObjectArray(value: unknown): value is Record<string, unknown>[] {\n return Array.isArray(value) && value.length > 0 && value.every(isPlainObject)\n}\n\nconst WHOP_TAG = /^[a-z]+_[A-Za-z0-9]+$/\n\n/** Plain truncated string — used for column width calculation (no ANSI codes). */\nfunction cellText(value: unknown): string {\n if (value == null) return ''\n const text = String(value)\n return text.length > MAX_CELL_WIDTH ? text.slice(0, MAX_CELL_WIDTH - 1) + '…' : text\n}\n\n/** Colored display string — used for rendering. */\nfunction formatCell(value: unknown): string {\n const text = cellText(value)\n if (typeof value === 'boolean') return value ? c.success(text) : c.error(text)\n if (typeof value === 'string' && WHOP_TAG.test(value)) return c.id(text)\n return text\n}\n\n/** Total printable width of one row: sum of column widths plus two-space separators between them. */\nfunction totalRowWidth(colWidths: number[]): number {\n const columnTotal = colWidths.reduce((sum, colWidth) => sum + colWidth, 0)\n return columnTotal + (colWidths.length - 1) * 2\n}\n\n/**\n * Renders an array of plain objects as an aligned terminal grid.\n * Drops columns from the right when the row would exceed the terminal width.\n */\nfunction renderRows(rows: Record<string, unknown>[]): string {\n // Only include keys that are scalar across every row — a column where some rows\n // have an object and others have null would render as \"[object Object]\".\n const isScalar = (value: unknown) => typeof value !== 'object' || value === null\n const scalarKeys = Object.keys(rows[0]!).filter((key) =>\n rows.every((row) => isScalar(row[key])),\n )\n\n if (scalarKeys.length === 0) return '(no displayable columns)'\n\n // Column width = max of the header label and the widest cell value across all rows.\n const allWidths = scalarKeys.map((key) =>\n Math.max(key.length, ...rows.map((row) => cellText(row[key]).length)),\n )\n\n // Drop the rightmost columns until the row fits within the terminal width.\n const termWidth = process.stdout.columns ?? 80\n let numVisible = allWidths.length\n while (numVisible > 1 && totalRowWidth(allWidths.slice(0, numVisible)) > termWidth) {\n numVisible--\n }\n\n const visibleKeys = scalarKeys.slice(0, numVisible)\n const visibleWidths = allWidths.slice(0, numVisible)\n\n const header = visibleKeys\n .map((key, i) => c.tableHeader(key.toUpperCase().padEnd(visibleWidths[i]!)))\n .join(' ')\n\n const separator = c.separator(visibleWidths.map((w) => '─'.repeat(w)).join('──'))\n\n const body = rows.map((row) =>\n visibleKeys\n .map((key, i) => {\n const value = row[key]\n const formatted = formatCell(value)\n const width = visibleWidths[i]!\n const pad = width - cellText(value).length\n // Right-align numbers, left-align everything else.\n return typeof value === 'number'\n ? c.number(' '.repeat(pad) + formatted)\n : formatted + ' '.repeat(pad)\n })\n .join(' '),\n )\n\n const hiddenCount = scalarKeys.length - numVisible\n const overflowHint =\n hiddenCount > 0\n ? `\\n${c.muted(`& ${hiddenCount} more columns — use --format json to see all`)}`\n : ''\n\n return [header, separator, ...body].join('\\n') + overflowHint\n}\n\n/**\n * Human-mode renderer passed to incur as `renderer`.\n * Handles top-level arrays and single-array wrapped responses (e.g. `{ accounts: [...], pagination: {...} }`).\n * Returns null for anything that can't be meaningfully rendered as a grid, falling back to incur's TOON formatter.\n */\nexport function render(data: unknown): string | null {\n if (isObjectArray(data)) return renderRows(data)\n\n if (isPlainObject(data)) {\n const arrayFields = Object.values(data).filter(isObjectArray)\n // Only render when there's exactly one array field — avoids guessing which to show.\n if (arrayFields.length === 1) {\n return renderRows(arrayFields[0] as Record<string, unknown>[])\n }\n }\n\n return null\n}\n","import { Cli } from \"incur\";\nimport { nativeSpec, filterSpecByTag, createWhopFetch } from \"./api\";\nimport { API_GROUPS, registerHandwrittenGroups } from \"./commands\";\nimport pkg from \"../package.json\" with { type: \"json\" };\nimport { render } from \"./lib/renderer\";\nimport { performLogin } from \"./auth/commands\";\nimport { getActiveProfile } from \"./auth/profiles\";\nimport { PromptCancelledError } from \"./auth/prompts\";\n\nconst cli = Cli.create(\"whop\", {\n\tversion: pkg.version,\n\tdescription: \"Build and manage Whop apps from your terminal.\",\n\trenderer: render,\n\tsync: {\n\t\tsuggestions: [\n\t\t\t\"start selling on Whop\",\n\t\t\t\"show my Whop business accounts\",\n\t\t\t\"create a Whop product and pricing plan\",\n\t\t],\n\t},\n\tmcp: {\n\t\tagents: [\"claude-desktop\"],\n\t},\n});\n\nconst spec = (tag: string) =>\n\tfilterSpecByTag(nativeSpec as Record<string, unknown>, tag);\nconst fetch = createWhopFetch();\n\nconst isAuthExempt = (cmd: string) =>\n\t!cmd ||\n\tcmd === \"login\" ||\n\tcmd === \"logout\" ||\n\tcmd === \"completions\" ||\n\tcmd.startsWith(\"auth\") ||\n\tcmd.startsWith(\"mcp\");\n\ncli.use(async (c, next) => {\n\tif (isAuthExempt(c.command)) return next();\n\tif (getActiveProfile()) return next();\n\tif (process.env.WHOP_API_KEY) return next();\n\n\tif (c.agent) {\n\t\treturn c.error({\n\t\t\tcode: \"NOT_AUTHENTICATED\",\n\t\t\tmessage: \"Not logged in. Set WHOP_API_KEY or run `whop login` first.\",\n\t\t\tcta: {\n\t\t\t\tcommands: [{ command: \"auth login\", description: \"Log in to Whop\" }],\n\t\t\t},\n\t\t});\n\t}\n\n\tlet result;\n\ttry {\n\t\tresult = await performLogin({ agent: false });\n\t} catch (err) {\n\t\tif (err instanceof PromptCancelledError) {\n\t\t\treturn c.error({\n\t\t\t\tcode: \"CANCELLED\",\n\t\t\t\tmessage: \"Login cancelled.\",\n\t\t\t\texitCode: 130,\n\t\t\t});\n\t\t}\n\t\tthrow err;\n\t}\n\n\tif (!result.ok) {\n\t\treturn c.error({\n\t\t\tcode: result.code,\n\t\t\tmessage: result.message,\n\t\t\tcta: {\n\t\t\t\tcommands: [{ command: \"auth login\", description: \"Log in to Whop\" }],\n\t\t\t},\n\t\t});\n\t}\n\n\treturn next();\n});\n\nregisterHandwrittenGroups(cli);\n\nfor (const { name, tag } of API_GROUPS) {\n\tcli.command(name, { fetch, openapi: spec(tag) });\n}\n\nexport default cli;\n","[\n {\n \"group\": \"Core Resources\",\n \"tags\": [\n \"Accounts\",\n \"Users\",\n \"Webhooks\",\n \"Stats\"\n ]\n },\n {\n \"group\": \"Money\",\n \"tags\": [\n \"Ledgers\",\n \"Payouts\",\n \"Cards\",\n \"Transfers\",\n \"Deposits\",\n \"Swaps\",\n \"Payout Methods\",\n \"Verifications\"\n ]\n },\n {\n \"group\": \"Commerce\",\n \"tags\": [\n \"Products\",\n \"Plans\",\n \"Checkout Configurations\",\n \"Referrals\"\n ]\n },\n {\n \"group\": \"Ads\",\n \"tags\": [\n \"Ads\",\n \"Ad Campaigns\",\n \"Ad Groups\",\n \"Audiences\"\n ]\n },\n {\n \"group\": \"Identity\",\n \"tags\": [\n \"Social Accounts\"\n ]\n }\n]\n","{\n \"Accounts\": \"Your Whop account\",\n \"Users\": \"Users on your platform\",\n \"Stats\": \"Platform-wide statistics\",\n \"Ledgers\": \"Transaction history\",\n \"Payouts\": \"Withdraw earnings\",\n \"Cards\": \"Issued virtual cards\",\n \"Transfers\": \"Move funds between accounts\",\n \"Deposits\": \"Add funds to your balance\",\n \"Swaps\": \"Convert between currencies\",\n \"Verifications\": \"Identity verification status\",\n \"Products\": \"Description of what you sell\",\n \"Plans\": \"Description of your pricing\",\n \"Checkout Configurations\": \"What your checkout page looks like\",\n \"Referrals\": \"Referral programs\",\n \"Ads\": \"Ad creatives\",\n \"Ad Campaigns\": \"Top-level campaign organization\",\n \"Ad Groups\": \"Sets of related ads\",\n \"Audiences\": \"Who sees your ads\",\n \"Social Accounts\": \"Linked social profiles\"\n}\n","import apiStructure from \"../api/api-structure.json\" with { type: \"json\" };\nimport tagDescriptions from \"../api/tag-descriptions.json\" with { type: \"json\" };\nimport { API_GROUPS, HANDWRITTEN_GROUPS } from \"../commands\";\nimport { c } from \"./colors\";\n\nconst descriptions: Record<string, string> = tagDescriptions;\nconst toCliName = (tag: string) => tag.toLowerCase().replace(/\\s+/g, \"-\");\n\nconst SECTION_LABELS = {\n\t\"get-started\": \"Get Started\",\n\tcommerce: \"Commerce\",\n\tauth: \"Auth\",\n} as const;\n\nconst INTEGRATIONS = [\n\t{ name: \"completions\", desc: \"Generate shell completion script\" },\n\t{ name: \"mcp add\", desc: \"Register as MCP server\" },\n\t{ name: \"skills\", desc: \"Sync skill files to agents (add, list)\" },\n];\n\nconst GLOBAL_FLAGS = [\n\t{\n\t\tflag: \"--filter-output <keys>\",\n\t\tdesc: \"Filter output by key paths (e.g. foo,bar.baz,a[0,3])\",\n\t},\n\t{ flag: \"--format <toon|json|yaml|md|jsonl>\", desc: \"Output format\" },\n\t{ flag: \"--full-output\", desc: \"Show full output envelope\" },\n\t{ flag: \"--help\", desc: \"Show help\" },\n\t{ flag: \"--llms, --llms-full\", desc: \"Print LLM-readable manifest\" },\n\t{ flag: \"--mcp\", desc: \"Start as MCP stdio server\" },\n\t{ flag: \"--schema\", desc: \"Show JSON Schema for command\" },\n\t{\n\t\tflag: \"--token-count\",\n\t\tdesc: \"Print token count of output (instead of output)\",\n\t},\n\t{ flag: \"--token-limit <n>\", desc: \"Limit output to n tokens\" },\n\t{ flag: \"--token-offset <n>\", desc: \"Skip first n tokens of output\" },\n\t{ flag: \"--version\", desc: \"Show version\" },\n];\n\ntype HelpCommand = {\n\tname: string;\n\tdescription: string;\n};\n\ntype HelpSection = {\n\tlabel: string;\n\tcommands: HelpCommand[];\n};\n\nconst handwrittenSection = (\n\tsection: (typeof HANDWRITTEN_GROUPS)[number][\"section\"],\n): HelpSection => ({\n\tlabel: SECTION_LABELS[section],\n\tcommands: HANDWRITTEN_GROUPS.filter((group) => group.section === section).map(\n\t\t({ name, description }) => ({ name, description }),\n\t),\n});\n\nexport function buildGroupedHelp(version: string, description: string): string {\n\tconst lines: string[] = [];\n\n\tconst presentCommands = new Set(API_GROUPS.map(({ name }) => name));\n\n\tconst apiSections = apiStructure\n\t\t.map(({ group, tags }) => ({\n\t\t\tlabel: group,\n\t\t\tcommands: (tags as string[])\n\t\t\t\t.filter((tag) => presentCommands.has(toCliName(tag)))\n\t\t\t\t.map((tag) => ({\n\t\t\t\t\tname: toCliName(tag),\n\t\t\t\t\tdescription: descriptions[tag] ?? \"\",\n\t\t\t\t})),\n\t\t}))\n\t\t.filter((section) => section.commands.length > 0);\n\n\tconst extraCommerce = apiSections\n\t\t.filter((section) => section.label.toLowerCase() === \"commerce\")\n\t\t.flatMap((section) => section.commands);\n\tconst commerceSection = handwrittenSection(\"commerce\");\n\tcommerceSection.commands = [...commerceSection.commands, ...extraCommerce];\n\n\tconst filteredApiSections = apiSections.filter(\n\t\t(section) => section.label.toLowerCase() !== \"commerce\",\n\t);\n\tconst allSections = [\n\t\thandwrittenSection(\"get-started\"),\n\t\tcommerceSection,\n\t\t...filteredApiSections,\n\t\thandwrittenSection(\"auth\"),\n\t].filter((section) => section.commands.length > 0);\n\tconst maxCmdLen = Math.max(\n\t\t...allSections.flatMap((section) =>\n\t\t\tsection.commands.map((command) => command.name.length),\n\t\t),\n\t);\n\n\tlines.push(`whop@${version} — ${description}`);\n\tlines.push(\"\");\n\tlines.push(\"Usage: whop <command>\");\n\n\tfor (const section of allSections) {\n\t\tlines.push(\"\");\n\t\tlines.push(c.heading(section.label.toUpperCase()));\n\t\tfor (const cmd of section.commands) {\n\t\t\tconst pad = \" \".repeat(maxCmdLen - cmd.name.length);\n\t\t\tlines.push(\n\t\t\t\t` ${c.command(cmd.name)}${pad} ${c.description(cmd.description)}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tconst maxIntLen = Math.max(...INTEGRATIONS.map((i) => i.name.length));\n\tlines.push(\"\");\n\tlines.push(\"Integrations:\");\n\tfor (const i of INTEGRATIONS) {\n\t\tlines.push(\n\t\t\t` ${c.command(i.name)}${\" \".repeat(maxIntLen - i.name.length)} ${c.description(i.desc)}`,\n\t\t);\n\t}\n\n\tconst maxFlagLen = Math.max(...GLOBAL_FLAGS.map((f) => f.flag.length));\n\tlines.push(\"\");\n\tlines.push(\"Global Options:\");\n\tfor (const f of GLOBAL_FLAGS) {\n\t\tlines.push(\n\t\t\t` ${c.flag(f.flag)}${\" \".repeat(maxFlagLen - f.flag.length)} ${c.description(f.desc)}`,\n\t\t);\n\t}\n\n\treturn lines.join(\"\\n\");\n}\n","import { c } from \"./colors\";\n\n/**\n * Themes incur's built-in help / error / CTA text so the whole CLI looks\n * consistent with our hand-rendered surfaces (root help, quickstart, tables).\n *\n * incur exposes a `renderer` hook only for command *data*, not for help or\n * errors, so we post-process the text it writes to stdout instead. This runs\n * only in human TTY mode (see `shouldColorize`) — structured output\n * (`--json`, `--format`, piped/agent) is passed through untouched, so machine\n * consumers never see ANSI codes.\n */\n\nconst SECTION_HEADERS = new Set([\n\t\"Usage\",\n\t\"Arguments\",\n\t\"Options\",\n\t\"Examples\",\n\t\"Environment Variables\",\n\t\"Global Options\",\n\t\"Integrations\",\n\t\"Commands\",\n\t\"Aliases\",\n]);\n\nconst FORMAT_FLAGS = [\"--json\", \"--format\", \"--full-output\", \"--schema\", \"--llms\", \"--llms-full\", \"--mcp\", \"--token-count\", \"--token-limit\", \"--token-offset\"];\n\n/** Color only when writing for a human: a TTY, with no structured-output flag. */\nexport function shouldColorize(argv: string[]): boolean {\n\tif (!process.stdout.isTTY) return false;\n\treturn !argv.some((a) => FORMAT_FLAGS.includes(a) || a.startsWith(\"--format=\"));\n}\n\n/** Highlights a flag token and any `<placeholder>` inside an option/flag row. */\nfunction paintFlag(flag: string): string {\n\treturn flag.replace(/(<[^>]+>)/g, (m) => c.muted(m)).replace(/(--[\\w-]+|-[\\w])/g, (m) => c.flag(m));\n}\n\n/** An indented command line (` whop products create # desc`) — in help examples or a CTA. */\nconst COMMAND_ROW = /^(\\s+)(whop\\s+\\S.*?)(\\s{2,}#\\s.*)?$/;\n\n/** Underlines any URL so links (checkout pages, dashboards) stand out. */\nfunction highlightUrls(text: string): string {\n\treturn text.replace(/https?:\\/\\/[^\\s)]+/g, (m) => c.link(m));\n}\n\nfunction colorizeLine(\n\tline: string,\n\tsection: string | null,\n\tnextLine: string | undefined,\n): { line: string; section: string | null } {\n\t// Error header, e.g. \"Error: msg\" or \"Error (HTTP_403): msg\".\n\tconst errMatch = line.match(/^(Error(?: \\([^)]+\\))?:)(.*)$/);\n\tif (errMatch) return { line: c.error(errMatch[1]) + highlightUrls(errMatch[2]), section };\n\tif (line.startsWith(\"Run `\")) return { line: c.heading(line), section };\n\n\t// Section header, e.g. \"Options:\" or \"Usage: whop products create\".\n\tconst header = line.match(/^([A-Z][A-Za-z ]+):(.*)$/);\n\tif (header && SECTION_HEADERS.has(header[1])) {\n\t\tconst rest = header[2].replace(/(whop[\\w\\s-]*)/g, (m) => c.command(m));\n\t\treturn { line: c.heading(`${header[1]}:`) + rest, section: header[1] };\n\t}\n\n\t// A `whop …` command line anywhere (help examples and CTAs alike).\n\tconst cmd = line.match(COMMAND_ROW);\n\tif (cmd) {\n\t\treturn { line: `${cmd[1]}${c.command(cmd[2])}${cmd[3] ? c.description(cmd[3]) : \"\"}`, section };\n\t}\n\n\t// A header-like line (\"Suggested command:\", a CTA description) immediately\n\t// followed by a command — bold it for emphasis.\n\tif (line.trim().endsWith(\":\") && nextLine !== undefined && COMMAND_ROW.test(nextLine)) {\n\t\treturn { line: c.heading(line), section };\n\t}\n\n\tif (line.trim() === \"\") return { line, section: null };\n\n\t// Rows inside a known section.\n\tif (section === \"Options\" || section === \"Global Options\" || section === \"Environment Variables\") {\n\t\tconst m = line.match(/^(\\s+)(\\S.*?)(\\s{2,})(.*)$/);\n\t\tif (m) return { line: `${m[1]}${paintFlag(m[2])}${m[3]}${c.description(m[4])}`, section };\n\t}\n\tif (section === \"Commands\" || section === \"Integrations\" || section === \"Aliases\") {\n\t\tconst m = line.match(/^(\\s+)(\\S+)(\\s{2,})(.*)$/);\n\t\tif (m) return { line: `${m[1]}${c.command(m[2])}${m[3]}${c.description(m[4])}`, section };\n\t}\n\tif (section === \"Arguments\") {\n\t\tconst m = line.match(/^(\\s+)(\\S+)(\\s{2,})(.*)$/);\n\t\tif (m) return { line: `${m[1]}${c.id(m[2])}${m[3]}${c.description(m[4])}`, section };\n\t}\n\n\t// Plain text (messages, CTA descriptions): make any link stand out.\n\treturn { line: highlightUrls(line), section };\n}\n\n/** Themes a chunk of incur help/error/CTA text. Safe to call per write. */\nexport function colorizeOutput(text: string): string {\n\tlet section: string | null = null;\n\tconst lines = text.split(\"\\n\");\n\treturn lines\n\t\t.map((line, i) => {\n\t\t\tconst result = colorizeLine(line, section, lines[i + 1]);\n\t\t\tsection = result.section;\n\t\t\treturn result.line;\n\t\t})\n\t\t.join(\"\\n\");\n}\n","import cli from \"./cli\";\nimport { getActiveProfile } from \"./auth/profiles\";\nimport { buildGroupedHelp } from \"./lib/grouped-help\";\nimport { colorizeOutput, shouldColorize } from \"./lib/colorize-output\";\nimport pkg from \"../package.json\" with { type: \"json\" };\n\nconst argv = process.argv.slice(2);\n\nasync function serve(argv: string[]) {\n\tif (shouldColorize(argv)) {\n\t\tawait cli.serve(argv, {\n\t\t\tstdout: (s) => process.stdout.write(colorizeOutput(s)),\n\t\t});\n\t} else {\n\t\tawait cli.serve(argv);\n\t}\n}\n\nif (argv.length === 0 && !getActiveProfile() && !process.env.WHOP_API_KEY) {\n\tawait serve([\"quickstart\"]);\n} else if (argv.length === 0 || (argv.length === 1 && argv[0] === \"--help\")) {\n\tprocess.stdout.write(\n\t\tbuildGroupedHelp(\n\t\t\tpkg.version,\n\t\t\tcli.description ?? \"Build and manage Whop apps from your terminal.\",\n\t\t) + \"\\n\",\n\t);\n\tprocess.exit(0);\n} else {\n\tawait serve(argv);\n}\n\nexport default cli;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,EACE;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AACF;;;ACzBO,IAAM,eAAe,iBAAE,OAAO;AA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MAAI,eAAeA,KAAI,GAAG;AACzB,UAAM,YAAI,MAAMA,OAAM;AAAA,MACrB,QAAQ,CAAC,MAAM,QAAQ,OAAO,MAAM,eAAe,CAAC,CAAC;AAAA,IACtD,CAAC;AAAA,EACF,OAAO;AACN,UAAM,YAAI,MAAMA,KAAI;AAAA,EACrB;AACD;AAEA,IAAI,KAAK,WAAW,KAAK,CAAC,iBAAiB,KAAK,CAAC,QAAQ,IAAI,cAAc;AAC1E,QAAM,MAAM,CAAC,YAAY,CAAC;AAC3B,WAAW,KAAK,WAAW,KAAM,KAAK,WAAW,KAAK,KAAK,CAAC,MAAM,UAAW;AAC5E,UAAQ,OAAO;AAAA,IACd;AAAA,MACC,gBAAI;AAAA,MACJ,YAAI,eAAe;AAAA,IACpB,IAAI;AAAA,EACL;AACA,UAAQ,KAAK,CAAC;AACf,OAAO;AACN,QAAM,MAAM,IAAI;AACjB;AAEA,IAAO,gBAAQ;","names":["identity","existed","profile","c","createWhopFetch","fetch","text","c","c","c","isCancel","createOptions","isCancel","c","createOptions","c","chalk","text","select","isCancel","chalk","c","chalk","isCancel","text","select","cli","c","argv","text","c","argv","text","argv"]}
1
+ {"version":3,"sources":["../src/api/groups.json","../src/auth/commands.ts","../src/commerce/products.ts","../src/commerce/client.ts","../src/commerce/crud.ts","../src/commerce/output.ts","../src/commerce/plans.ts","../src/commerce/billing.ts","../src/commerce/checkout.ts","../src/journey/quickstart.ts","../src/lib/colors.ts","../src/commands.ts","../package.json","../src/lib/renderer.ts","../src/cli.ts","../src/api/api-structure.json","../src/api/tag-descriptions.json","../src/lib/grouped-help.ts","../src/lib/colorize-output.ts","../src/index.ts"],"sourcesContent":["[\n [\n \"accounts\",\n \"Accounts\"\n ],\n [\n \"users\",\n \"Users\"\n ],\n [\n \"stats\",\n \"Stats\"\n ],\n [\n \"ledgers\",\n \"Ledgers\"\n ],\n [\n \"payouts\",\n \"Payouts\"\n ],\n [\n \"cards\",\n \"Cards\"\n ],\n [\n \"transfers\",\n \"Transfers\"\n ],\n [\n \"deposits\",\n \"Deposits\"\n ],\n [\n \"swaps\",\n \"Swaps\"\n ],\n [\n \"verifications\",\n \"Verifications\"\n ],\n [\n \"products\",\n \"Products\"\n ],\n [\n \"plans\",\n \"Plans\"\n ],\n [\n \"checkout-configurations\",\n \"Checkout Configurations\"\n ],\n [\n \"referrals\",\n \"Referrals\"\n ],\n [\n \"ads\",\n \"Ads\"\n ],\n [\n \"ad-campaigns\",\n \"Ad Campaigns\"\n ],\n [\n \"ad-groups\",\n \"Ad Groups\"\n ],\n [\n \"audiences\",\n \"Audiences\"\n ],\n [\n \"social-accounts\",\n \"Social Accounts\"\n ]\n]\n","import { Cli, z } from \"incur\";\nimport { validateApiKey, apiBaseUrl } from \"./client\";\nimport { readConfig } from \"./config\";\nimport { getSecret } from \"./keyring\";\nimport { OAuthError, performOAuthLogin } from \"./oauth\";\nimport {\n\tderiveProfileName,\n\tgetActiveProfile,\n\tgetValidAccessToken,\n\tlistProfiles,\n\tremoveAllProfiles,\n\tremoveProfile,\n\tswitchProfile,\n\tupsertProfile,\n} from \"./profiles\";\nimport {\n\tchooseAuthMethod,\n\tPromptCancelledError,\n\tpromptApiKey,\n\tselectProfile,\n\tstartSpinner,\n} from \"./prompts\";\nimport { AuthMethod, Identity, Profile } from \"./types\";\n\n/**\n * Auth commands: `whop auth login | logout | switch | status | list`.\n *\n * The login/logout business logic is context-free (`performLogin`,\n * `removeProfile`) and the incur run handlers are thin adapters. `loginAdapter`\n * and `logoutAdapter` are shared so the top-level `whop login` / `whop logout`\n * (registered in `index.ts`) behave identically without duplicating logic —\n * incur aliases can't cross from a group into a top-level command.\n */\n\n// --- CTA / error shapes accepted by the run context (kept minimal & structural) ---\ntype CtaCommand =\n\t| string\n\t| {\n\t\t\tcommand: string;\n\t\t\tdescription?: string | undefined;\n\t\t\toptions?: Record<string, unknown> | undefined;\n\t\t\targs?: Record<string, unknown> | undefined;\n\t };\ntype CtaInput = { description?: string | undefined; commands: CtaCommand[] };\ntype ErrorInput = {\n\tcode: string;\n\tmessage: string;\n\tcta?: CtaInput | undefined;\n\texitCode?: number | undefined;\n\tretryable?: boolean | undefined;\n};\n\n// --- Shared schemas ---\nexport const loginOptions = z.object({\n\tapiKey: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\"API key for non-interactive login (skips the prompt)\"),\n\tprofile: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\"Name for this profile (defaults to the account route)\"),\n\tcompanyId: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\n\t\t\t\"Business account to act on behalf of (biz_xxx) — for OAuth users who manage more than one\",\n\t\t),\n});\n\nexport const loginEnv = z.object({\n\tWHOP_API_KEY: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\"API key for non-interactive login\"),\n\tWHOP_API_BASE_URL: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\"Override the Whop API base URL\"),\n\tWHOP_CONFIG_DIR: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\"Override the CLI config directory\"),\n});\n\nexport const loginOutput = z.object({\n\tprofile: z.string().describe(\"The profile name\"),\n\tactive: z.boolean().describe(\"Whether this profile is now the active one\"),\n\tmethod: AuthMethod.describe(\"The authentication method\"),\n\tidentity: Identity.describe(\"The authenticated account or user identity\"),\n});\nexport type LoginOutput = z.infer<typeof loginOutput>;\n\nexport const logoutOptions = z.object({\n\tprofile: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\"Profile to remove (defaults to the active profile)\"),\n\tall: z\n\t\t.boolean()\n\t\t.optional()\n\t\t.describe(\"Remove every profile and its stored secret (full reset)\"),\n});\nexport const logoutOutput = z.object({\n\tremoved: z.array(z.string()).describe(\"The removed profile name(s)\"),\n\tnewActive: z\n\t\t.string()\n\t\t.nullable()\n\t\t.describe(\"The profile that is now active, if any\"),\n});\nexport type LogoutOutput = z.infer<typeof logoutOutput>;\n\nconst statusOutput = z.object({\n\tloggedIn: z\n\t\t.boolean()\n\t\t.describe(\"Whether the active profile has a usable stored credential\"),\n\tprofile: z.string().nullable(),\n\tmethod: AuthMethod.nullable(),\n\tidentity: Identity.nullable().describe(\n\t\t\"The logged-in user (OAuth) or the account (API key)\",\n\t),\n\taccount: Identity.nullable().describe(\n\t\t\"The account auto-filled for scoped commands (account_id/company_id)\",\n\t),\n\thasSecret: z\n\t\t.boolean()\n\t\t.describe(\"Whether a secret was found in the OS keychain for this profile\"),\n});\n\nconst listOutput = z.object({\n\tactive: z.string().nullable(),\n\tprofiles: z.array(Profile),\n});\n\nconst switchArgs = z.object({\n\tname: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\"Profile to switch to (interactive picker if omitted)\"),\n});\nconst switchOutput = z.object({\n\tactive: z.string().describe(\"The newly active profile\"),\n});\n\nexport const loginExamples = [\n\t{ description: \"Interactive login\" },\n\t{\n\t\toptions: { apiKey: \"whop_xxx\" },\n\t\tdescription: \"Non-interactive login (CI / agents)\",\n\t},\n\t{\n\t\toptions: { apiKey: \"whop_xxx\", profile: \"prod\" },\n\t\tdescription: \"Log in and name the profile\",\n\t},\n];\nexport const loginHint =\n\t\"Agents / CI: pass --api-key or set WHOP_API_KEY to skip the prompt.\";\n\n// --- Context-free login flows ---\ntype LoginResult =\n\t| { ok: true; output: LoginOutput; existed: boolean; underscoped: boolean }\n\t| { ok: false; code: string; message: string };\n\nexport async function performLogin(input: {\n\tagent: boolean;\n\tapiKey?: string | undefined;\n\tprofile?: string | undefined;\n\tcompanyId?: string | undefined;\n}): Promise<LoginResult> {\n\tlet method: AuthMethod = \"api_key\";\n\tif (!input.agent && !input.apiKey) method = await chooseAuthMethod();\n\n\t// Route to the OAuth browser flow.\n\tif (method === \"oauth\") {\n\t\ttry {\n\t\t\tconst { profileName, identity, existed } = await performOAuthLogin({\n\t\t\t\tprofile: input.profile,\n\t\t\t\tagent: input.agent,\n\t\t\t\tcompanyId: input.companyId,\n\t\t\t});\n\t\t\treturn {\n\t\t\t\tok: true,\n\t\t\t\texisted,\n\t\t\t\tunderscoped: false,\n\t\t\t\toutput: {\n\t\t\t\t\tprofile: profileName,\n\t\t\t\t\tactive: true,\n\t\t\t\t\tmethod: \"oauth\",\n\t\t\t\t\tidentity,\n\t\t\t\t},\n\t\t\t};\n\t\t} catch (err) {\n\t\t\tif (err instanceof OAuthError) {\n\t\t\t\treturn { ok: false, code: err.code, message: err.message };\n\t\t\t}\n\t\t\tthrow err;\n\t\t}\n\t}\n\n\t// Resolve the API key: flag/env > interactive prompt > error in agent mode.\n\tlet apiKey = input.apiKey;\n\tif (!apiKey) {\n\t\tif (input.agent) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\tcode: \"API_KEY_REQUIRED\",\n\t\t\t\tmessage: \"No API key provided and not running interactively.\",\n\t\t\t};\n\t\t}\n\t\tapiKey = await promptApiKey();\n\t}\n\t// Normalize: the SDK adds the `Bearer ` prefix itself, so strip one if pasted.\n\tconst key = apiKey.replace(/^Bearer\\s+/i, \"\").trim();\n\n\t// 3. Validate against the API.\n\tlet result: Awaited<ReturnType<typeof validateApiKey>>;\n\tif (input.agent) {\n\t\tresult = await validateApiKey(key, apiBaseUrl());\n\t} else {\n\t\tconst s = startSpinner(\"Validating API key…\");\n\t\tresult = await validateApiKey(key, apiBaseUrl());\n\t\tconst okay = result.status === \"valid\" || result.status === \"underscoped\";\n\t\ts.stop(okay ? \"API key validated.\" : \"API key check failed.\");\n\t}\n\tif (result.status === \"invalid\") {\n\t\treturn {\n\t\t\tok: false,\n\t\t\tcode: \"INVALID_API_KEY\",\n\t\t\tmessage: \"That API key was rejected (401 Unauthorized).\",\n\t\t};\n\t}\n\tif (result.status === \"error\") {\n\t\treturn { ok: false, code: \"VALIDATION_FAILED\", message: result.message };\n\t}\n\n\t// 4. Persist (secret → keychain, metadata → config) and activate.\n\tconst identity = result.identity;\n\tconst name = input.profile ?? deriveProfileName(identity);\n\tconst existed = listProfiles().some((profile) => profile.name === name);\n\tconst profile = upsertProfile({ name, method, secret: key, identity });\n\n\treturn {\n\t\tok: true,\n\t\texisted,\n\t\tunderscoped: result.status === \"underscoped\",\n\t\toutput: { profile: profile.name, active: true, method, identity },\n\t};\n}\n\n// --- Shared adapters (used by the group command and the top-level alias) ---\ntype LoginAdapterCtx = {\n\tagent: boolean;\n\toptions: {\n\t\tapiKey?: string | undefined;\n\t\tprofile?: string | undefined;\n\t\tcompanyId?: string | undefined;\n\t};\n\tenv: { WHOP_API_KEY?: string | undefined };\n\tok: (data: LoginOutput, meta?: { cta?: CtaInput | undefined }) => never;\n\terror: (options: ErrorInput) => never;\n};\n\nexport async function loginAdapter(c: LoginAdapterCtx): Promise<never> {\n\tlet result: LoginResult;\n\ttry {\n\t\tresult = await performLogin({\n\t\t\tagent: c.agent,\n\t\t\tapiKey: c.options.apiKey ?? c.env.WHOP_API_KEY,\n\t\t\tprofile: c.options.profile,\n\t\t\tcompanyId: c.options.companyId,\n\t\t});\n\t} catch (error) {\n\t\tif (error instanceof PromptCancelledError) {\n\t\t\treturn c.error({\n\t\t\t\tcode: \"CANCELLED\",\n\t\t\t\tmessage: \"Login cancelled.\",\n\t\t\t\texitCode: 130,\n\t\t\t});\n\t\t}\n\t\tthrow error;\n\t}\n\n\tif (!result.ok) {\n\t\tlet cta: CtaInput | undefined;\n\t\tif (result.code === \"API_KEY_REQUIRED\") {\n\t\t\tcta = {\n\t\t\t\tdescription: \"Provide a key non-interactively:\",\n\t\t\t\tcommands: [\n\t\t\t\t\t{\n\t\t\t\t\t\tcommand: \"auth login\",\n\t\t\t\t\t\toptions: { apiKey: true },\n\t\t\t\t\t\tdescription: \"Pass --api-key <key>\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t};\n\t\t} else if (\n\t\t\tresult.code === \"MULTIPLE_COMPANIES\" ||\n\t\t\tresult.code === \"COMPANY_NOT_FOUND\"\n\t\t) {\n\t\t\tcta = {\n\t\t\t\tdescription: \"Choose which business account to use:\",\n\t\t\t\tcommands: [\n\t\t\t\t\t{\n\t\t\t\t\t\tcommand: \"auth login\",\n\t\t\t\t\t\toptions: { companyId: true },\n\t\t\t\t\t\tdescription: \"Pass --company-id biz_xxx\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t};\n\t\t}\n\t\treturn c.error({\n\t\t\tcode: result.code,\n\t\t\tmessage: result.message,\n\t\t\tretryable: result.code !== \"INVALID_API_KEY\",\n\t\t\tcta,\n\t\t});\n\t}\n\n\t// First-run vs returning user: check whether they have any products yet.\n\t// Probe whenever we have an account so a returning\n\t// user with zero products still gets the \"start selling\" path. Use the\n\t// resolved account id (not the user id, which is what identity holds for\n\t// OAuth). On failure just fall back to the generic CTA — don't block login.\n\tlet firstRun = !result.existed;\n\tconst companyId = getActiveProfile()?.companyId ?? \"\";\n\tif (companyId) {\n\t\ttry {\n\t\t\tconst { createWhopFetch } = await import(\"../api/index.js\");\n\t\t\tconst fetch = createWhopFetch();\n\t\t\tconst res = await fetch(\n\t\t\t\tnew Request(\n\t\t\t\t\t`https://api.whop.com/products?company_id=${companyId}&first=1`,\n\t\t\t\t),\n\t\t\t);\n\t\t\tif (res.ok) {\n\t\t\t\tconst data = (await res.json()) as { data?: unknown[] };\n\t\t\t\tfirstRun = (data.data?.length ?? 0) === 0;\n\t\t\t}\n\t\t} catch {\n\t\t\t// Non-fatal — use generic CTA\n\t\t}\n\t}\n\n\t// No business account resolved (e.g. OAuth account with no business yet). Don't send\n\t// them to `quickstart` — it requires a biz_ id and would exit NO_COMPANY.\n\t// Mirror quickstart's guidance: create a business account, then re-authenticate.\n\tif (!companyId) {\n\t\treturn c.ok(result.output, {\n\t\t\tcta: {\n\t\t\t\tdescription:\n\t\t\t\t\t\"You're logged in, but no business account is linked to this account yet. Create a business account on Whop, then log in again:\",\n\t\t\t\tcommands: [\n\t\t\t\t\t{\n\t\t\t\t\t\tcommand: \"auth login\",\n\t\t\t\t\t\tdescription: \"Re-authenticate once you have a business account\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t});\n\t}\n\n\treturn c.ok(result.output, {\n\t\tcta: firstRun\n\t\t\t? {\n\t\t\t\t\tdescription: \"You're logged in. Start selling in one command:\",\n\t\t\t\t\tcommands: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"quickstart\",\n\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\"Create your product, set a price, get a checkout link\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}\n\t\t\t: {\n\t\t\t\t\tdescription: result.existed\n\t\t\t\t\t\t? \"Updated and switched to this profile:\"\n\t\t\t\t\t\t: \"Welcome back:\",\n\t\t\t\t\tcommands: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"quickstart\",\n\t\t\t\t\t\t\tdescription: \"See your status and what's next\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ command: \"auth status\", description: \"Show the active identity\" },\n\t\t\t\t\t],\n\t\t\t\t},\n\t});\n}\n\ntype LogoutAdapterCtx = {\n\toptions: { profile?: string | undefined; all?: boolean | undefined };\n\tok: (data: LogoutOutput, meta?: { cta?: CtaInput | undefined }) => never;\n\terror: (options: ErrorInput) => never;\n};\n\nexport function logoutAdapter(c: LogoutAdapterCtx): never {\n\tif (c.options.all) {\n\t\tif (c.options.profile) {\n\t\t\treturn c.error({\n\t\t\t\tcode: \"CONFLICTING_OPTIONS\",\n\t\t\t\tmessage: \"--all removes every profile — don't combine it with --profile.\",\n\t\t\t\tretryable: true,\n\t\t\t});\n\t\t}\n\t\tconst removed = removeAllProfiles();\n\t\tif (removed.length === 0) {\n\t\t\treturn c.error({\n\t\t\t\tcode: \"NO_PROFILES\",\n\t\t\t\tmessage: \"No profiles to remove.\",\n\t\t\t\tretryable: false,\n\t\t\t\tcta: {\n\t\t\t\t\tdescription: \"Log in first:\",\n\t\t\t\t\tcommands: [{ command: \"auth login\", description: \"Log in to Whop\" }],\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t\treturn c.ok(\n\t\t\t{ removed, newActive: null },\n\t\t\t{\n\t\t\t\tcta: {\n\t\t\t\t\tdescription: `Removed ${removed.length} profile${removed.length === 1 ? \"\" : \"s\"}. To authenticate again:`,\n\t\t\t\t\tcommands: [{ command: \"auth login\", description: \"Log in to Whop\" }],\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t}\n\n\tconst target = c.options.profile ?? getActiveProfile()?.name;\n\tif (!target) {\n\t\treturn c.error({\n\t\t\tcode: \"NO_ACTIVE_PROFILE\",\n\t\t\tmessage: \"No active profile to log out from.\",\n\t\t\tretryable: false,\n\t\t\tcta: {\n\t\t\t\tdescription: \"Log in first:\",\n\t\t\t\tcommands: [{ command: \"auth login\", description: \"Log in to Whop\" }],\n\t\t\t},\n\t\t});\n\t}\n\tconst { removed, newActive } = removeProfile(target);\n\tif (!removed) {\n\t\treturn c.error({\n\t\t\tcode: \"PROFILE_NOT_FOUND\",\n\t\t\tmessage: `No profile named \"${target}\".`,\n\t\t\tretryable: false,\n\t\t});\n\t}\n\treturn c.ok(\n\t\t{ removed: [target], newActive },\n\t\tnewActive\n\t\t\t? {\n\t\t\t\t\tcta: {\n\t\t\t\t\t\tdescription: `Now using \"${newActive}\".`,\n\t\t\t\t\t\tcommands: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcommand: \"auth status\",\n\t\t\t\t\t\t\t\tdescription: \"Show the active identity\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: undefined,\n\t);\n}\n\n// --- The `auth` command group ---\nexport function buildAuthGroup() {\n\tconst auth = Cli.create(\"auth\", {\n\t\tdescription: \"Manage Whop authentication\",\n\t});\n\n\tauth.command(\"login\", {\n\t\tdescription: \"Log in to Whop\",\n\t\taliases: [\"add\"],\n\t\toptions: loginOptions,\n\t\tenv: loginEnv,\n\t\toutput: loginOutput,\n\t\texamples: loginExamples,\n\t\thint: loginHint,\n\t\trun: (c) => loginAdapter(c),\n\t});\n\n\tauth.command(\"logout\", {\n\t\tdescription: \"Log out — remove a saved profile, or all with --all\",\n\t\taliases: [\"remove\", \"rm\"],\n\t\toptions: logoutOptions,\n\t\toutput: logoutOutput,\n\t\texamples: [\n\t\t\t{ description: \"Remove the active profile\" },\n\t\t\t{\n\t\t\t\toptions: { all: true },\n\t\t\t\tdescription: \"Remove every profile (full reset)\",\n\t\t\t},\n\t\t],\n\t\trun: (c) => logoutAdapter(c),\n\t});\n\n\tauth.command(\"switch\", {\n\t\tdescription: \"Switch the active profile\",\n\t\targs: switchArgs,\n\t\toutput: switchOutput,\n\t\trun: async (c) => {\n\t\t\tconst profiles = listProfiles();\n\t\t\tif (profiles.length === 0) {\n\t\t\t\treturn c.error({\n\t\t\t\t\tcode: \"NO_PROFILES\",\n\t\t\t\t\tmessage: \"No profiles yet — log in first.\",\n\t\t\t\t\tretryable: true,\n\t\t\t\t\tcta: {\n\t\t\t\t\t\tdescription: \"To authenticate:\",\n\t\t\t\t\t\tcommands: [\n\t\t\t\t\t\t\t{ command: \"auth login\", description: \"Log in to Whop\" },\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tlet name = c.args.name;\n\t\t\tif (!name) {\n\t\t\t\tif (c.agent) {\n\t\t\t\t\treturn c.error({\n\t\t\t\t\t\tcode: \"PROFILE_REQUIRED\",\n\t\t\t\t\t\tmessage: `Specify a profile name. Available: ${profiles.map((p) => p.name).join(\", \")}.`,\n\t\t\t\t\t\tretryable: true,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tname = await selectProfile(profiles);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (error instanceof PromptCancelledError) {\n\t\t\t\t\t\treturn c.error({\n\t\t\t\t\t\t\tcode: \"CANCELLED\",\n\t\t\t\t\t\t\tmessage: \"Switch cancelled.\",\n\t\t\t\t\t\t\texitCode: 130,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst profile = switchProfile(name);\n\t\t\tif (!profile) {\n\t\t\t\treturn c.error({\n\t\t\t\t\tcode: \"PROFILE_NOT_FOUND\",\n\t\t\t\t\tmessage: `No profile named \"${name}\". Available: ${profiles.map((p) => p.name).join(\", \")}.`,\n\t\t\t\t\tretryable: true,\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn c.ok(\n\t\t\t\t{ active: profile.name },\n\t\t\t\t{\n\t\t\t\t\tcta: {\n\t\t\t\t\t\tcommands: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcommand: \"auth status\",\n\t\t\t\t\t\t\t\tdescription: \"Show the active identity\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t},\n\t});\n\n\tauth.command(\"status\", {\n\t\tdescription: \"Show the active identity (whoami)\",\n\t\taliases: [\"whoami\"],\n\t\toutput: statusOutput,\n\t\trun: async (c) => {\n\t\t\tconst profile = getActiveProfile();\n\t\t\tif (!profile) {\n\t\t\t\treturn c.ok(\n\t\t\t\t\t{\n\t\t\t\t\t\tloggedIn: false,\n\t\t\t\t\t\tprofile: null,\n\t\t\t\t\t\tmethod: null,\n\t\t\t\t\t\tidentity: null,\n\t\t\t\t\t\taccount: null,\n\t\t\t\t\t\thasSecret: false,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tcta: {\n\t\t\t\t\t\t\tdescription: \"To authenticate:\",\n\t\t\t\t\t\t\tcommands: [\n\t\t\t\t\t\t\t\t{ command: \"auth login\", description: \"Log in to Whop\" },\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst hasSecret = getSecret(profile.name) !== null;\n\t\t\t// \"Logged in\" means we can actually obtain a Bearer token. For oauth\n\t\t\t// this may refresh the access token; a revoked/expired refresh token\n\t\t\t// resolves to null instead of throwing, so the reported state is honest.\n\t\t\tlet loggedIn = hasSecret;\n\t\t\tif (hasSecret) {\n\t\t\t\ttry {\n\t\t\t\t\tloggedIn = (await getValidAccessToken(profile)) !== null;\n\t\t\t\t} catch {\n\t\t\t\t\tloggedIn = false;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst account =\n\t\t\t\tprofile.accountId || profile.accountTitle || profile.accountRoute\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tid: profile.accountId,\n\t\t\t\t\t\t\ttitle: profile.accountTitle,\n\t\t\t\t\t\t\troute: profile.accountRoute,\n\t\t\t\t\t\t}\n\t\t\t\t\t: null;\n\t\t\treturn c.ok(\n\t\t\t\t{\n\t\t\t\t\tloggedIn,\n\t\t\t\t\tprofile: profile.name,\n\t\t\t\t\tmethod: profile.method,\n\t\t\t\t\tidentity:\n\t\t\t\t\t\tprofile.method === \"oauth\"\n\t\t\t\t\t\t\t? { id: profile.userId, email: profile.userEmail }\n\t\t\t\t\t\t\t: account,\n\t\t\t\t\taccount,\n\t\t\t\t\thasSecret,\n\t\t\t\t},\n\t\t\t\tloggedIn\n\t\t\t\t\t? undefined\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tcta: {\n\t\t\t\t\t\t\t\tdescription: hasSecret\n\t\t\t\t\t\t\t\t\t? \"Your session is no longer valid — log in again:\"\n\t\t\t\t\t\t\t\t\t: \"The stored secret is missing — log in again:\",\n\t\t\t\t\t\t\t\tcommands: [\n\t\t\t\t\t\t\t\t\t{ command: \"auth login\", description: \"Log in to Whop\" },\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t);\n\t\t},\n\t});\n\n\tauth.command(\"list\", {\n\t\tdescription: \"List saved authentication profiles\",\n\t\taliases: [\"ls\"],\n\t\toutput: listOutput,\n\t\trun: () => {\n\t\t\tconst { activeProfile, profiles } = readConfig();\n\t\t\tconst active =\n\t\t\t\tprofiles.find((p) => p.name === activeProfile)?.name ?? null;\n\t\t\treturn { active, profiles };\n\t\t},\n\t});\n\n\treturn auth;\n}\n","import { Cli, z } from \"incur\";\nimport { text, isCancel } from \"@clack/prompts\";\nimport { makeWhopRequest } from \"./client.js\";\nimport {\n\tbuildBody,\n\tregisterItemCommands,\n\tregisterListCommand,\n} from \"./crud.js\";\nimport { printCreateSuccess } from \"./output.js\";\n\nconst ProductSchema = z.object({\n\tid: z.string(),\n\ttitle: z.string(),\n\tvisibility: z.string().optional(),\n\troute: z.string().optional(),\n\theadline: z.string().nullable().optional(),\n\tdescription: z.string().nullable().optional(),\n\tmember_count: z.number().optional(),\n\tcreated_at: z.number().optional(),\n});\n\nconst createOptions = z.object({\n\ttitle: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\"Product display name (max 80 characters)\"),\n\tcompany_id: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\n\t\t\t\"Business account to create under (defaults to your active account)\",\n\t\t),\n\tvisibility: z\n\t\t.enum([\"visible\", \"hidden\", \"archived\"])\n\t\t.optional()\n\t\t.describe(\"Who can see this product\"),\n\theadline: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\"Short tagline shown on the store page\"),\n\tdescription: z.string().optional().describe(\"Full description\"),\n\troute: z.string().optional().describe(\"Custom URL slug (e.g. my-course)\"),\n\tredirect_purchase_url: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\"Redirect buyers here after purchase\"),\n});\n\nexport function buildProductsGroup() {\n\tconst products = Cli.create(\"products\", {\n\t\tdescription: \"Products — what you're selling on Whop\",\n\t});\n\n\tproducts.command(\"create\", {\n\t\tdescription: \"Create a product\",\n\t\thint: \"A product is the top-level container for what you sell. Add a pricing plan next.\",\n\t\toptions: createOptions,\n\t\toutput: ProductSchema,\n\t\toutputPolicy: \"agent-only\",\n\t\texamples: [\n\t\t\t{\n\t\t\t\toptions: { title: \"My Online Course\" },\n\t\t\t\tdescription: \"Create a product\",\n\t\t\t},\n\t\t\t{\n\t\t\t\toptions: { title: \"My Course\", visibility: \"hidden\" },\n\t\t\t\tdescription: \"Create a hidden product\",\n\t\t\t},\n\t\t],\n\t\trun: async (c) => {\n\t\t\tlet title = c.options.title;\n\t\t\tif (!title) {\n\t\t\t\tif (c.agent) {\n\t\t\t\t\treturn c.error({\n\t\t\t\t\t\tcode: \"TITLE_REQUIRED\",\n\t\t\t\t\t\tmessage: \"Pass --title to set the product name.\",\n\t\t\t\t\t\tretryable: true,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tconst t = await text({\n\t\t\t\t\tmessage: \"What are you selling?\",\n\t\t\t\t\tplaceholder:\n\t\t\t\t\t\t\"e.g. My Online Course, Trading Community, Fitness Program\",\n\t\t\t\t});\n\t\t\t\tif (isCancel(t))\n\t\t\t\t\treturn c.error({\n\t\t\t\t\t\tcode: \"CANCELLED\",\n\t\t\t\t\t\tmessage: \"Cancelled.\",\n\t\t\t\t\t\texitCode: 130,\n\t\t\t\t\t});\n\t\t\t\ttitle = t as string;\n\t\t\t}\n\n\t\t\tconst body = { ...buildBody(c.options), title };\n\n\t\t\tlet product: z.infer<typeof ProductSchema>;\n\t\t\ttry {\n\t\t\t\tproduct = await makeWhopRequest<z.infer<typeof ProductSchema>>(\n\t\t\t\t\t\"POST\",\n\t\t\t\t\t\"/products\",\n\t\t\t\t\tbody,\n\t\t\t\t);\n\t\t\t} catch (err) {\n\t\t\t\treturn c.error({\n\t\t\t\t\tcode: \"API_ERROR\",\n\t\t\t\t\tmessage:\n\t\t\t\t\t\terr instanceof Error ? err.message : \"Failed to create product\",\n\t\t\t\t\tretryable: true,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tprintCreateSuccess(c, {\n\t\t\t\ttitle: `Product \"${product.title}\" created`,\n\t\t\t\tid: product.id,\n\t\t\t\tnext: {\n\t\t\t\t\tcommand: `plans create --product_id ${product.id}`,\n\t\t\t\t\thint: \"Add pricing — required before you can take a checkout\",\n\t\t\t\t},\n\t\t\t});\n\n\t\t\treturn c.ok(product, {\n\t\t\t\tcta: {\n\t\t\t\t\tdescription: \"Add pricing to your product:\",\n\t\t\t\t\tcommands: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"plans create\",\n\t\t\t\t\t\t\toptions: { product_id: product.id },\n\t\t\t\t\t\t\tdescription: \"Create a pricing plan (required before checkout)\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t});\n\n\tregisterListCommand(products, {\n\t\tpath: \"/products\",\n\t\tdescription: \"List products\",\n\t});\n\n\tregisterItemCommands(products, {\n\t\tpath: \"/products\",\n\t\tnoun: \"product\",\n\t\tidLabel: \"Product ID (prod_xxx)\",\n\t\tschema: ProductSchema,\n\t\tupdateOptions: createOptions.partial(),\n\t});\n\n\treturn products;\n}\n","import { createWhopFetch } from \"../api/index.js\";\n\nconst PLACEHOLDER = \"https://api.whop.com\";\nconst whopFetch = createWhopFetch();\n\n/**\n * Thin wrapper around the API fetch proxy for hand-written commands. The proxy\n * strips the host and uses apiBaseUrl() internally, auto-fills the active\n * account, and normalizes errors to a top-level `message` — so we only need the\n * pathname (a query string in `path` is fine) and can surface `message` directly.\n */\nexport async function makeWhopRequest<T>(\n\tmethod: \"GET\" | \"POST\" | \"PATCH\" | \"DELETE\",\n\tpath: string,\n\tbody?: Record<string, unknown>,\n): Promise<T> {\n\tconst init: RequestInit = { method };\n\tif (body !== undefined) init.body = JSON.stringify(body);\n\tconst res = await whopFetch(new Request(`${PLACEHOLDER}${path}`, init));\n\n\tif (!res.ok) {\n\t\tconst payload = (await res.json().catch(() => null)) as {\n\t\t\tmessage?: string;\n\t\t} | null;\n\t\tthrow new Error(payload?.message ?? res.statusText);\n\t}\n\n\t// DELETE (and other 204s) can return an empty body, which `res.json()` would\n\t// reject — treat an empty body as a successful, content-less response.\n\tconst text = await res.text();\n\treturn (text ? JSON.parse(text) : { success: true }) as T;\n}\n","import { Cli, z } from \"incur\";\nimport { makeWhopRequest } from \"./client.js\";\n\n/** Copies defined option values into a request body, dropping `undefined`. */\nexport function buildBody(options: Record<string, unknown>): Record<string, unknown> {\n\tconst body: Record<string, unknown> = {};\n\tfor (const [key, value] of Object.entries(options)) {\n\t\tif (value !== undefined) body[key] = value;\n\t}\n\treturn body;\n}\n\ninterface ItemCommandConfig {\n\t/** Collection path, e.g. \"/products\". */\n\tpath: string;\n\t/** Singular resource noun for descriptions, e.g. \"product\". */\n\tnoun: string;\n\t/** Help text for the id argument, e.g. \"Product ID (prod_xxx)\". */\n\tidLabel: string;\n\t/** Output schema for get/update. */\n\tschema: z.ZodType;\n\t/** Options for `update`. Omit to skip the update command (e.g. checkout configs). */\n\tupdateOptions?: z.ZodObject<z.ZodRawShape>;\n\t/**\n\t * Normalizes the request body before `update` sends it (e.g. mapping friendly\n\t * enum values to the shape the API expects). Must match whatever the\n\t * hand-written `create` does so the same flags behave identically on both.\n\t */\n\ttransformBody?: (body: Record<string, unknown>) => Record<string, unknown>;\n}\n\n/**\n * Registers a `list` command. The active account is auto-filled by the fetch\n * proxy, so the only per-resource difference is the path and an optional filter.\n */\nexport function registerListCommand(\n\tgroup: ReturnType<typeof Cli.create>,\n\tconfig: {\n\t\tpath: string;\n\t\tdescription: string;\n\t\tfilter?: { option: string; param: string; describe: string };\n\t},\n): void {\n\tconst shape: Record<string, z.ZodType> = {\n\t\tfirst: z.coerce.number().optional().describe(\"Number of results\"),\n\t\tafter: z.string().optional().describe(\"Pagination cursor\"),\n\t};\n\tif (config.filter) {\n\t\tshape[config.filter.option] = z.string().optional().describe(config.filter.describe);\n\t}\n\tgroup.command(\"list\", {\n\t\tdescription: config.description,\n\t\toptions: z.object(shape),\n\t\trun: (c) => {\n\t\t\tconst options = c.options as Record<string, string | number | undefined>;\n\t\t\tconst params = new URLSearchParams();\n\t\t\tif (config.filter && options[config.filter.option]) {\n\t\t\t\tparams.set(config.filter.param, String(options[config.filter.option]));\n\t\t\t}\n\t\t\tif (options.first) params.set(\"first\", String(options.first));\n\t\t\tif (options.after) params.set(\"after\", String(options.after));\n\t\t\tconst qs = params.toString() ? `?${params}` : \"\";\n\t\t\treturn makeWhopRequest(\"GET\", `${config.path}${qs}`);\n\t\t},\n\t});\n}\n\n/**\n * Registers the by-id item commands (`get`, `update`, `delete`) that are\n * identical across commerce resources. `create` carries resource-specific logic\n * (CTAs, scope) and stays hand-written.\n */\nexport function registerItemCommands(\n\tgroup: ReturnType<typeof Cli.create>,\n\tconfig: ItemCommandConfig,\n): void {\n\tconst { path, noun, idLabel, schema, updateOptions, transformBody } = config;\n\tconst idArg = z.object({ id: z.string().describe(idLabel) });\n\n\tgroup.command(\"get\", {\n\t\tdescription: `Get a ${noun} by ID`,\n\t\targs: idArg,\n\t\toutput: schema,\n\t\trun: (c) => makeWhopRequest(`GET`, `${path}/${c.args.id}`),\n\t});\n\n\tif (updateOptions) {\n\t\tgroup.command(\"update\", {\n\t\t\tdescription: `Update a ${noun}`,\n\t\t\targs: idArg,\n\t\t\toptions: updateOptions,\n\t\t\toutput: schema,\n\t\t\trun: (c) => {\n\t\t\t\tconst body = buildBody(c.options);\n\t\t\t\treturn makeWhopRequest(\"PATCH\", `${path}/${c.args.id}`, transformBody ? transformBody(body) : body);\n\t\t\t},\n\t\t});\n\t}\n\n\tgroup.command(\"delete\", {\n\t\tdescription: `Delete a ${noun}`,\n\t\targs: idArg,\n\t\trun: (c) => makeWhopRequest(\"DELETE\", `${path}/${c.args.id}`),\n\t});\n}\n","import chalk from \"chalk\";\n\ninterface NextCommand {\n\tcommand: string;\n\thint?: string;\n}\n\n/**\n * Prints a clean, colored success summary for a `create` command — the human\n * counterpart to the structured envelope agents receive. Pairs with\n * `outputPolicy: \"agent-only\"` so humans see only this (with the checkout link\n * emphasized) and never the raw object dump.\n *\n * No-op in agent mode or when an explicit --format was requested.\n */\nexport function printCreateSuccess(\n\tc: { agent: boolean; formatExplicit: boolean },\n\topts: { title: string; id?: string; checkoutUrl?: string | null; next?: NextCommand },\n): void {\n\tif (c.agent || c.formatExplicit) return;\n\n\tconst lines: string[] = [\"\", chalk.green.bold(`✓ ${opts.title}`)];\n\tif (opts.id) lines.push(` ${chalk.dim(opts.id)}`);\n\n\tif (opts.checkoutUrl) {\n\t\tlines.push(\"\", chalk.bold(\"🎉 You can sell now. Share your checkout link:\"));\n\t\tlines.push(` ${chalk.cyan.underline(opts.checkoutUrl)}`);\n\t}\n\n\tif (opts.next) {\n\t\tlines.push(\"\", `${chalk.bold(\"Next\")} ${chalk.cyan.bold(`whop ${opts.next.command}`)}`);\n\t\tif (opts.next.hint) lines.push(` ${chalk.dim(`→ ${opts.next.hint}`)}`);\n\t}\n\n\tlines.push(\"\");\n\tconsole.log(lines.join(\"\\n\"));\n}\n","import { Cli, z } from \"incur\";\nimport { select, isCancel, spinner } from \"@clack/prompts\";\nimport { makeWhopRequest } from \"./client.js\";\nimport { getActiveProfile } from \"../auth/profiles.js\";\nimport { buildBody, registerItemCommands, registerListCommand } from \"./crud.js\";\nimport { BILLING_PERIOD_DAYS } from \"./billing.js\";\nimport { printCreateSuccess } from \"./output.js\";\n\nconst PlanSchema = z.object({\n\tid: z.string(),\n\ttitle: z.string().nullable().optional(),\n\tplan_type: z.string().optional(),\n\tbilling_period: z.string().nullable().optional(),\n\tinitial_price: z.number().nullable().optional(),\n\trenewal_price: z.number().nullable().optional(),\n\tcurrency: z.string().optional(),\n\tpurchase_url: z.string().nullable().optional(),\n\tvisibility: z.string().optional(),\n\tcreated_at: z.number().optional(),\n});\n\nconst createOptions = z.object({\n\tproduct_id: z.string().optional().describe(\"Product this plan belongs to (prod_xxx)\"),\n\ttitle: z.string().optional().describe(\"Display name for this plan\"),\n\tplan_type: z\n\t\t.enum([\"one_time\", \"renewal\", \"free\"])\n\t\t.optional()\n\t\t.describe(\"Billing model — one_time, renewal, or free\"),\n\tbilling_period: z\n\t\t.enum([\"daily\", \"weekly\", \"monthly\", \"quarterly\", \"annually\", \"every_two_years\"])\n\t\t.optional()\n\t\t.describe(\"How often to charge (for renewal plans)\"),\n\tinitial_price: z.coerce\n\t\t.number()\n\t\t.optional()\n\t\t.describe(\"Price in the plan's currency (e.g. 9.99 for $9.99)\"),\n\trenewal_price: z.coerce\n\t\t.number()\n\t\t.optional()\n\t\t.describe(\"Recurring price for renewal plans (defaults to initial_price)\"),\n\tcurrency: z.string().optional().describe(\"3-letter currency code (default: USD)\"),\n\ttrial_period_days: z.coerce.number().optional().describe(\"Free trial length in days\"),\n\tvisibility: z\n\t\t.enum([\"visible\", \"hidden\", \"archived\"])\n\t\t.optional()\n\t\t.describe(\"Who can see this plan\"),\n});\n\n// Maps friendly plan options to the shape the API expects. Shared by `create`\n// and `update` so the same flags behave identically on both.\nfunction normalizePlanBody(body: Record<string, unknown>): Record<string, unknown> {\n\tif (typeof body.billing_period === \"string\") {\n\t\tbody.billing_period = BILLING_PERIOD_DAYS[body.billing_period];\n\t}\n\tif (body.plan_type === \"renewal\" && body.renewal_price == null && body.initial_price != null) {\n\t\tbody.renewal_price = body.initial_price;\n\t}\n\treturn body;\n}\n\ninterface ProductListItem {\n\tid: string;\n\ttitle: string;\n}\n\ninterface ListResponse {\n\tdata: ProductListItem[];\n}\n\nasync function resolveProductId(\n\tprovidedId: string | undefined,\n\tisAgent: boolean,\n): Promise<\n\t| { ok: true; productId: string; autoResolved: boolean }\n\t| { ok: false; code: string; message: string; candidates?: ProductListItem[] }\n> {\n\tif (providedId) return { ok: true, productId: providedId, autoResolved: false };\n\n\t// Fetch products to auto-resolve a single one, or prompt/error on many.\n\tconst profile = getActiveProfile();\n\tconst params = new URLSearchParams({ first: \"100\" });\n\tif (profile?.companyId) params.set(\"company_id\", profile.companyId);\n\n\tlet data: ProductListItem[];\n\ttry {\n\t\tconst res = await makeWhopRequest<ListResponse>(\"GET\", `/products?${params}`);\n\t\tdata = res.data ?? [];\n\t} catch {\n\t\treturn { ok: false, code: \"API_ERROR\", message: \"Failed to fetch products\" };\n\t}\n\n\tif (data.length === 0) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\tcode: \"NO_PRODUCTS\",\n\t\t\tmessage: \"No products found. Create one first.\",\n\t\t};\n\t}\n\n\tif (data.length === 1) {\n\t\treturn { ok: true, productId: data[0].id, autoResolved: true };\n\t}\n\n\t// Multiple products\n\tif (isAgent) {\n\t\treturn { ok: false, code: \"PRODUCT_REQUIRED\", message: \"Multiple products found. Pass --product_id.\", candidates: data };\n\t}\n\n\t// Interactive picker in TTY\n\tconst chosen = await select<string>({\n\t\tmessage: \"Which product is this plan for?\",\n\t\toptions: data.map((p) => ({ value: p.id, label: p.title, hint: p.id })),\n\t});\n\tif (isCancel(chosen)) return { ok: false, code: \"CANCELLED\", message: \"Cancelled.\" };\n\treturn { ok: true, productId: chosen, autoResolved: false };\n}\n\nexport function buildPlansGroup() {\n\tconst plans = Cli.create(\"plans\", {\n\t\tdescription: \"Plans — pricing for your products\",\n\t});\n\n\tplans.command(\"create\", {\n\t\tdescription: \"Create a pricing plan\",\n\t\thint: \"A plan sets the price and billing interval. After creating a plan, your checkout link is ready to share.\",\n\t\toptions: createOptions,\n\t\toutput: PlanSchema,\n\t\toutputPolicy: \"agent-only\",\n\t\texamples: [\n\t\t\t{\n\t\t\t\toptions: { product_id: \"prod_xxx\", initial_price: 9.99, plan_type: \"one_time\" },\n\t\t\t\tdescription: \"One-time payment of $9.99\",\n\t\t\t},\n\t\t\t{\n\t\t\t\toptions: {\n\t\t\t\t\tproduct_id: \"prod_xxx\",\n\t\t\t\t\tinitial_price: 19.99,\n\t\t\t\t\tplan_type: \"renewal\",\n\t\t\t\t\tbilling_period: \"monthly\",\n\t\t\t\t},\n\t\t\t\tdescription: \"Monthly subscription at $19.99\",\n\t\t\t},\n\t\t],\n\t\trun: async (c) => {\n\t\t\tconst s = c.agent ? null : spinner();\n\t\t\tif (s) s.start(\"Resolving product…\");\n\n\t\t\tconst resolved = await resolveProductId(c.options.product_id, c.agent);\n\n\t\t\tif (s) s.stop(\"\");\n\n\t\t\tif (!resolved.ok) {\n\t\t\t\treturn c.error({\n\t\t\t\t\tcode: resolved.code,\n\t\t\t\t\tmessage: resolved.message,\n\t\t\t\t\tretryable: resolved.code !== \"CANCELLED\",\n\t\t\t\t\tcta:\n\t\t\t\t\t\tresolved.code === \"NO_PRODUCTS\"\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\tdescription: \"Create a product first:\",\n\t\t\t\t\t\t\t\t\tcommands: [{ command: \"products create\", description: \"Create a product\" }],\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t: resolved.candidates\n\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\tdescription: \"Available products:\",\n\t\t\t\t\t\t\t\t\t\tcommands: resolved.candidates.map((p) => ({\n\t\t\t\t\t\t\t\t\t\t\tcommand: \"plans create\",\n\t\t\t\t\t\t\t\t\t\t\toptions: { product_id: p.id },\n\t\t\t\t\t\t\t\t\t\t\tdescription: p.title,\n\t\t\t\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (resolved.autoResolved && !c.agent) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`Note: using product ${resolved.productId} — pass --product_id to override`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst body = normalizePlanBody({\n\t\t\t\t...buildBody(c.options),\n\t\t\t\tproduct_id: resolved.productId,\n\t\t\t});\n\n\t\t\tlet plan: z.infer<typeof PlanSchema>;\n\t\t\ttry {\n\t\t\t\tplan = await makeWhopRequest<z.infer<typeof PlanSchema>>(\"POST\", \"/plans\", body);\n\t\t\t} catch (err) {\n\t\t\t\treturn c.error({\n\t\t\t\t\tcode: \"API_ERROR\",\n\t\t\t\t\tmessage: err instanceof Error ? err.message : \"Failed to create plan\",\n\t\t\t\t\tretryable: true,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst purchaseUrl = plan.purchase_url;\n\t\t\tconst ctaDescription = purchaseUrl\n\t\t\t\t? `🎉 You can sell now. Share your checkout link: ${purchaseUrl}`\n\t\t\t\t: \"Plan created.\";\n\n\t\t\tprintCreateSuccess(c, {\n\t\t\t\ttitle: purchaseUrl ? \"Plan created — you can sell now\" : \"Plan created\",\n\t\t\t\tid: plan.id,\n\t\t\t\tcheckoutUrl: purchaseUrl,\n\t\t\t\tnext: {\n\t\t\t\t\tcommand: \"checkout-configurations create\",\n\t\t\t\t\thint: \"Optional: customize the checkout page (currency, redirect, payment mode)\",\n\t\t\t\t},\n\t\t\t});\n\n\t\t\treturn c.ok(plan, {\n\t\t\t\tcta: {\n\t\t\t\t\tdescription: ctaDescription,\n\t\t\t\t\tcommands: [\n\t\t\t\t\t\t{ command: \"quickstart\", description: \"See your setup status and what's next\" },\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"checkout-configurations create\",\n\t\t\t\t\t\t\toptions: { plan_id: plan.id },\n\t\t\t\t\t\t\tdescription: \"Optional: customize the checkout page\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t});\n\n\tregisterListCommand(plans, {\n\t\tpath: \"/plans\",\n\t\tdescription: \"List plans\",\n\t\tfilter: { option: \"product_id\", param: \"product_ids\", describe: \"Filter by product\" },\n\t});\n\n\tregisterItemCommands(plans, {\n\t\tpath: \"/plans\",\n\t\tnoun: \"plan\",\n\t\tidLabel: \"Plan ID (plan_xxx)\",\n\t\tschema: PlanSchema,\n\t\tupdateOptions: createOptions.omit({ product_id: true }).partial(),\n\t\ttransformBody: normalizePlanBody,\n\t});\n\n\treturn plans;\n}\n","/**\n * Friendly billing-interval names → days, the unit the API expects for a plan's\n * `billing_period` (e.g. 30 for monthly, 365 for annual). The CLI exposes the\n * names for readability and converts before sending.\n */\nexport const BILLING_PERIOD_DAYS: Record<string, number> = {\n\tdaily: 1,\n\tweekly: 7,\n\tmonthly: 30,\n\tquarterly: 90,\n\tannually: 365,\n\tevery_two_years: 730,\n};\n","import { Cli, z } from \"incur\";\nimport { makeWhopRequest } from \"./client.js\";\nimport { buildBody, registerItemCommands, registerListCommand } from \"./crud.js\";\nimport { printCreateSuccess } from \"./output.js\";\n\nconst CheckoutConfigSchema = z.object({\n\tid: z.string(),\n\tmode: z.enum([\"payment\", \"setup\"]).optional(),\n\tcurrency: z.string().nullable().optional(),\n\tpurchase_url: z.string().nullable().optional(),\n\tredirect_url: z.string().nullable().optional(),\n\tcompany_id: z.string().optional(),\n\tcreated_at: z.number().optional(),\n});\n\nconst createOptions = z.object({\n\tplan_id: z.string().optional().describe(\"Plan to attach this checkout to (plan_xxx)\"),\n\tmode: z\n\t\t.enum([\"payment\", \"setup\"])\n\t\t.optional()\n\t\t.describe(\"payment = charge immediately; setup = save payment method only\"),\n\tcurrency: z.string().optional().describe(\"3-letter currency code override\"),\n\tredirect_url: z.string().optional().describe(\"URL to redirect after successful checkout\"),\n\taffiliate_code: z.string().optional().describe(\"Affiliate code to apply\"),\n});\n\nexport function buildCheckoutGroup() {\n\tconst checkout = Cli.create(\"checkout-configurations\", {\n\t\tdescription: \"Checkout configurations — customize your checkout page\",\n\t});\n\n\tcheckout.command(\"create\", {\n\t\tdescription: \"Create a checkout configuration\",\n\t\thint: \"Customize the currency, redirect URL, and payment mode for a plan's checkout page.\",\n\t\toptions: createOptions,\n\t\toutput: CheckoutConfigSchema,\n\t\toutputPolicy: \"agent-only\",\n\t\texamples: [\n\t\t\t{\n\t\t\t\toptions: { plan_id: \"plan_xxx\" },\n\t\t\t\tdescription: \"Basic checkout configuration for a plan\",\n\t\t\t},\n\t\t\t{\n\t\t\t\toptions: { plan_id: \"plan_xxx\", redirect_url: \"https://mysite.com/thank-you\" },\n\t\t\t\tdescription: \"Redirect buyers to a custom thank-you page\",\n\t\t\t},\n\t\t],\n\t\trun: async (c) => {\n\t\t\tconst body = buildBody(c.options);\n\n\t\t\tlet config: z.infer<typeof CheckoutConfigSchema>;\n\t\t\ttry {\n\t\t\t\tconfig = await makeWhopRequest<z.infer<typeof CheckoutConfigSchema>>(\n\t\t\t\t\t\"POST\",\n\t\t\t\t\t\"/checkout_configurations\",\n\t\t\t\t\tbody,\n\t\t\t\t);\n\t\t\t} catch (err) {\n\t\t\t\treturn c.error({\n\t\t\t\t\tcode: \"API_ERROR\",\n\t\t\t\t\tmessage: err instanceof Error ? err.message : \"Failed to create checkout configuration\",\n\t\t\t\t\tretryable: true,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst purchaseUrl = config.purchase_url;\n\t\t\tprintCreateSuccess(c, {\n\t\t\t\ttitle: \"Checkout configured\",\n\t\t\t\tid: config.id,\n\t\t\t\tcheckoutUrl: purchaseUrl,\n\t\t\t\tnext: { command: \"quickstart\", hint: \"See your full setup status\" },\n\t\t\t});\n\t\t\treturn c.ok(config, {\n\t\t\t\tcta: {\n\t\t\t\t\tdescription: purchaseUrl\n\t\t\t\t\t\t? `Checkout configured. Share your link: ${purchaseUrl}`\n\t\t\t\t\t\t: \"Checkout configured.\",\n\t\t\t\t\tcommands: [\n\t\t\t\t\t\t{ command: \"quickstart\", description: \"See your full setup status\" },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t});\n\n\tregisterListCommand(checkout, {\n\t\tpath: \"/checkout_configurations\",\n\t\tdescription: \"List checkout configurations\",\n\t\tfilter: { option: \"plan_id\", param: \"plan_id\", describe: \"Filter by plan\" },\n\t});\n\n\tregisterItemCommands(checkout, {\n\t\tpath: \"/checkout_configurations\",\n\t\tnoun: \"checkout configuration\",\n\t\tidLabel: \"Checkout configuration ID\",\n\t\tschema: CheckoutConfigSchema,\n\t});\n\n\treturn checkout;\n}\n","import { z } from \"incur\";\nimport chalk from \"chalk\";\nimport { text, select, isCancel } from \"@clack/prompts\";\nimport { makeWhopRequest } from \"../commerce/client.js\";\nimport { resolveActiveCompanyId } from \"../api/index.js\";\nimport { BILLING_PERIOD_DAYS } from \"../commerce/billing.js\";\nimport { getActiveProfile } from \"../auth/profiles.js\";\nimport { c } from \"../lib/colors.js\";\n\ninterface ListItem {\n\tid: string;\n\ttitle?: string | null;\n\tpurchase_url?: string | null;\n}\ninterface ListResponse {\n\tdata: ListItem[];\n}\n\nconst StepSchema = z.object({\n\tid: z.string(),\n\tlabel: z.string(),\n\tcomplete: z.boolean(),\n\tcount: z.number().optional(),\n\tfirstId: z.string().optional(),\n\tfirstTitle: z.string().optional(),\n});\n\nconst NextStepSchema = z.object({\n\tcommand: z.string(),\n\toptions: z.record(z.string(), z.string()).optional(),\n\tdescription: z.string(),\n\thint: z.string().optional(),\n});\n\nexport const quickstartOptions = z.object({\n\ttitle: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\n\t\t\t\"Product name — providing this (or --price/--billing_period) makes quickstart create your product\",\n\t\t),\n\tprice: z.coerce\n\t\t.number()\n\t\t.optional()\n\t\t.describe(\"Price in the plan's currency (e.g. 9.99 for $9.99, 0 = free)\"),\n\tbilling_period: z\n\t\t.enum([\n\t\t\t\"monthly\",\n\t\t\t\"annually\",\n\t\t\t\"quarterly\",\n\t\t\t\"weekly\",\n\t\t\t\"daily\",\n\t\t\t\"every_two_years\",\n\t\t\t\"one_time\",\n\t\t])\n\t\t.optional()\n\t\t.describe(\"Billing interval — use 'one_time' for a single payment\"),\n\tcompany_id: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\n\t\t\t\"Business account to act on behalf of (biz_xxx); defaults to your active account\",\n\t\t),\n});\n\nexport const quickstartOutput = z.object({\n\taccount: z.string().nullable().describe(\"Authenticated account name\"),\n\tready: z\n\t\t.boolean()\n\t\t.describe(\"Whether you can take a sale now (a product with a plan exists)\"),\n\tcheckoutUrl: z\n\t\t.string()\n\t\t.nullable()\n\t\t.describe(\n\t\t\t\"The live checkout link to share — the journey's payoff, present once a plan exists\",\n\t\t),\n\tcreated: z\n\t\t.object({ productId: z.string().optional(), planId: z.string().optional() })\n\t\t.nullable()\n\t\t.describe(\n\t\t\t\"What this run created, if anything — null for a read-only status check\",\n\t\t),\n\tsteps: z.array(StepSchema).describe(\"The path to your first sale\"),\n\tnextStep: NextStepSchema.nullable().describe(\n\t\t\"The single command to run next, pre-filled — null when nothing is required\",\n\t),\n});\n\ntype Step = z.infer<typeof StepSchema>;\ntype NextStep = z.infer<typeof NextStepSchema>;\n\ntype CtaCommand = {\n\tcommand: string;\n\tdescription?: string;\n\toptions?: Record<string, string>;\n};\n\ntype RunCtx = {\n\tagent: boolean;\n\tformatExplicit: boolean;\n\toptions: z.infer<typeof quickstartOptions>;\n\tsetupAgents?: () => Promise<void>;\n\tok: (data: z.infer<typeof quickstartOutput>) => never;\n\terror: (opts: {\n\t\tcode: string;\n\t\tmessage: string;\n\t\tretryable?: boolean;\n\t\texitCode?: number;\n\t\tcta?: { description?: string; commands: CtaCommand[] };\n\t}) => never;\n};\n\ntype ErrorEnvelope = Parameters<RunCtx[\"error\"]>[0];\n\n// incur's `c.error` is a sentinel that only takes effect when returned from the\n// command `run`. Nested helpers can't force the caller to return, so they throw\n// this instead; runCreate's caller catches it and returns `c.error(envelope)`,\n// preserving code/retryable/cta (which a plain thrown Error would lose).\nclass QuickstartError extends Error {\n\tconstructor(readonly envelope: ErrorEnvelope) {\n\t\tsuper(envelope.message);\n\t}\n}\n\nexport async function runQuickstart(c: RunCtx): Promise<never> {\n\tconst profile = getActiveProfile();\n\t// Mirror the auth middleware: a saved profile OR a WHOP_API_KEY env var (the\n\t// agent / CI path) is enough — don't reject env-key auth the gate let through.\n\tif (!profile && !process.env.WHOP_API_KEY) {\n\t\treturn c.error({\n\t\t\tcode: \"NOT_AUTHENTICATED\",\n\t\t\tmessage: \"Not logged in.\",\n\t\t\tcta: {\n\t\t\t\tcommands: [{ command: \"auth login\", description: \"Log in to Whop\" }],\n\t\t\t},\n\t\t});\n\t}\n\n\tif (!c.agent && !c.formatExplicit && c.setupAgents) {\n\t\ttry {\n\t\t\tawait c.setupAgents();\n\t\t} catch (err) {\n\t\t\tconst message =\n\t\t\t\terr instanceof Error ? err.message : \"Couldn't set up Whop for agents.\";\n\t\t\tconsole.log(`\\n${chalk.yellow(\"!\")} Agent setup skipped: ${message}`);\n\t\t\tconsole.log(\n\t\t\t\tchalk.dim(\n\t\t\t\t\t\" You can retry later with `whop skills add` and `whop mcp add`.\",\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\n\tconst companyId =\n\t\tc.options.company_id ?? (await resolveActiveCompanyId()) ?? \"\";\n\tconst accountName =\n\t\tprofile?.accountTitle ??\n\t\tprofile?.accountRoute ??\n\t\tprofile?.name ??\n\t\t\"your account\";\n\n\tif (!companyId) {\n\t\treturn c.error({\n\t\t\tcode: \"NO_COMPANY\",\n\t\t\tmessage:\n\t\t\t\t\"No business account is linked to this login. Create a business account on Whop, then log in again.\",\n\t\t\tretryable: false,\n\t\t\tcta: {\n\t\t\t\tdescription: \"Create a business account, then re-authenticate:\",\n\t\t\t\tcommands: [\n\t\t\t\t\t{\n\t\t\t\t\t\tcommand: \"auth login\",\n\t\t\t\t\t\tdescription: \"Log in and pick a business account\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t});\n\t}\n\n\tconst [productsRes, plansRes, checkoutRes] = await Promise.allSettled([\n\t\tmakeWhopRequest<ListResponse>(\n\t\t\t\"GET\",\n\t\t\t`/products?company_id=${companyId}&first=100`,\n\t\t),\n\t\tmakeWhopRequest<ListResponse>(\n\t\t\t\"GET\",\n\t\t\t`/plans?account_id=${companyId}&first=100`,\n\t\t),\n\t\tmakeWhopRequest<ListResponse>(\n\t\t\t\"GET\",\n\t\t\t`/checkout_configurations?company_id=${companyId}&first=100`,\n\t\t),\n\t]);\n\n\t// Don't let a failed products/plans lookup masquerade as \"nothing exists\" —\n\t// that would show empty steps or, worse, prompt a duplicate create. Surface\n\t// the real error instead. A failed checkout lookup is non-critical.\n\tconst critical = [productsRes, plansRes].find((r) => r.status === \"rejected\");\n\tif (critical && critical.status === \"rejected\") {\n\t\tconst reason = critical.reason;\n\t\treturn c.error({\n\t\t\tcode: \"STATUS_CHECK_FAILED\",\n\t\t\tmessage: `Couldn't load your current setup: ${reason instanceof Error ? reason.message : \"API error\"}`,\n\t\t\tretryable: true,\n\t\t});\n\t}\n\n\tconst products =\n\t\tproductsRes.status === \"fulfilled\" ? (productsRes.value.data ?? []) : [];\n\tconst plans =\n\t\tplansRes.status === \"fulfilled\" ? (plansRes.value.data ?? []) : [];\n\tconst checkouts =\n\t\tcheckoutRes.status === \"fulfilled\" ? (checkoutRes.value.data ?? []) : [];\n\n\tconst ready = products.length > 0 && plans.length > 0;\n\tconst hasCreationFlags =\n\t\tc.options.title !== undefined ||\n\t\tc.options.price !== undefined ||\n\t\tc.options.billing_period !== undefined;\n\n\t// Mutate-gate: explicit creation flags always create (the user asked for it,\n\t// even on an already-set-up account). Without flags we only auto-guide a\n\t// create when something is missing AND we're interactive — so a ready account\n\t// in agent mode or with `--format`/`--json` stays a pure read-only status check.\n\tconst canMutateInteractively = !c.agent && !c.formatExplicit;\n\tconst shouldCreate = hasCreationFlags || (!ready && canMutateInteractively);\n\n\tif (shouldCreate) {\n\t\ttry {\n\t\t\treturn await runCreate(c, { companyId, accountName, products });\n\t\t} catch (err) {\n\t\t\tif (err instanceof QuickstartError) return c.error(err.envelope);\n\t\t\tthrow err;\n\t\t}\n\t}\n\n\tconst steps = buildSteps(products, plans);\n\tconst checkoutUrl = plans.find((p) => p.purchase_url)?.purchase_url ?? null;\n\tconst nextStep = resolveNextStep(products, plans, checkouts.length > 0);\n\n\tif (!c.agent && !c.formatExplicit) {\n\t\tprintSummary(accountName, steps, ready, checkoutUrl, nextStep);\n\t}\n\n\treturn c.ok({\n\t\taccount: accountName,\n\t\tready,\n\t\tcheckoutUrl,\n\t\tcreated: null,\n\t\tsteps,\n\t\tnextStep,\n\t});\n}\n\n/** Returns the provided value, errors in agent mode, or prompts interactively. */\nasync function resolveOrPrompt<T>(\n\tc: RunCtx,\n\tprovided: T | undefined,\n\tmissing: { code: string; message: string; example: string },\n\tprompt: () => Promise<T | symbol>,\n): Promise<T> {\n\tif (provided !== undefined) return provided;\n\tif (c.agent) {\n\t\tthrow new QuickstartError({\n\t\t\tcode: missing.code,\n\t\t\tmessage: `${missing.message} Example: ${missing.example}`,\n\t\t\tretryable: true,\n\t\t});\n\t}\n\tconst value = await prompt();\n\tif (isCancel(value))\n\t\tthrow new QuickstartError({\n\t\t\tcode: \"CANCELLED\",\n\t\t\tmessage: \"Setup cancelled.\",\n\t\t\texitCode: 130,\n\t\t});\n\treturn value as T;\n}\n\nconst FULL_EXAMPLE =\n\t'whop quickstart --title \"My Course\" --price 9.99 --billing_period monthly';\n\nasync function runCreate(\n\tc: RunCtx,\n\tstate: { companyId: string; accountName: string; products: ListItem[] },\n): Promise<never> {\n\tif (!c.agent) {\n\t\tconsole.log(`\\n${chalk.bold(\"Let's get you set up to sell.\")}\\n`);\n\t}\n\n\t// Create a new product when none exist or when an explicit --title is given\n\t// (the user named a product, so honor that intent even if they already have\n\t// others). Otherwise attach the new plan to an existing one.\n\t//\n\t// Gather every input up front, before any POST, so a partial invocation (e.g.\n\t// an agent passes --title but omits --price) fails cleanly without leaving an\n\t// orphaned product behind — and so a cancelled TTY prompt creates nothing.\n\tconst needsNewProduct =\n\t\tstate.products.length === 0 || c.options.title !== undefined;\n\tconst newTitle = needsNewProduct\n\t\t? await resolveOrPrompt(\n\t\t\t\tc,\n\t\t\t\tc.options.title,\n\t\t\t\t{\n\t\t\t\t\tcode: \"TITLE_REQUIRED\",\n\t\t\t\t\tmessage: \"Pass --title to name your product.\",\n\t\t\t\t\texample: FULL_EXAMPLE,\n\t\t\t\t},\n\t\t\t\t() =>\n\t\t\t\t\ttext({\n\t\t\t\t\t\tmessage: \"What are you selling?\",\n\t\t\t\t\t\tplaceholder: \"My Online Course\",\n\t\t\t\t\t}),\n\t\t\t)\n\t\t: undefined;\n\tconst existing = needsNewProduct\n\t\t? undefined\n\t\t: await resolveExistingProduct(c, state.products);\n\n\tconst price = await resolveOrPrompt(\n\t\tc,\n\t\tc.options.price,\n\t\t{\n\t\t\tcode: \"PRICE_REQUIRED\",\n\t\t\tmessage: \"Pass --price in dollars (9.99 = $9.99, 0 = free).\",\n\t\t\texample: FULL_EXAMPLE,\n\t\t},\n\t\tasync () => {\n\t\t\tconst p = await text({\n\t\t\t\tmessage: \"Price in dollars (9.99 = $9.99, 0 = free):\",\n\t\t\t\tplaceholder: \"9.99\",\n\t\t\t\tvalidate: (v) => (isNaN(Number(v)) ? \"Enter a number\" : undefined),\n\t\t\t});\n\t\t\treturn isCancel(p) ? p : Number(p);\n\t\t},\n\t);\n\n\tconst billingPeriod = await resolveOrPrompt(\n\t\tc,\n\t\tc.options.billing_period,\n\t\t{\n\t\t\tcode: \"BILLING_PERIOD_REQUIRED\",\n\t\t\tmessage: \"Pass --billing_period (one_time, monthly, annually, …).\",\n\t\t\texample: FULL_EXAMPLE,\n\t\t},\n\t\t() =>\n\t\t\tselect({\n\t\t\t\tmessage: \"How should customers be charged?\",\n\t\t\t\toptions: [\n\t\t\t\t\t{ value: \"one_time\", label: \"One-time payment\" },\n\t\t\t\t\t{ value: \"monthly\", label: \"Monthly subscription\" },\n\t\t\t\t\t{ value: \"annually\", label: \"Annual subscription\" },\n\t\t\t\t\t{ value: \"quarterly\", label: \"Quarterly\" },\n\t\t\t\t],\n\t\t\t}) as Promise<NonNullable<typeof c.options.billing_period> | symbol>,\n\t);\n\n\tlet productId: string;\n\tlet productTitle: string;\n\tlet productCreated = false;\n\tif (existing) {\n\t\tproductId = existing.id;\n\t\tproductTitle = existing.title ?? existing.id;\n\t} else {\n\t\tlet product: { id: string; title: string };\n\t\ttry {\n\t\t\tproduct = await makeWhopRequest<{ id: string; title: string }>(\n\t\t\t\t\"POST\",\n\t\t\t\t\"/products\",\n\t\t\t\t{\n\t\t\t\t\ttitle: newTitle,\n\t\t\t\t\tcompany_id: state.companyId,\n\t\t\t\t},\n\t\t\t);\n\t\t} catch (err) {\n\t\t\treturn c.error({\n\t\t\t\tcode: \"API_ERROR\",\n\t\t\t\tmessage: `Failed to create product: ${err instanceof Error ? err.message : \"unknown error\"}`,\n\t\t\t\tretryable: true,\n\t\t\t});\n\t\t}\n\t\tproductId = product.id;\n\t\tproductTitle = product.title;\n\t\tproductCreated = true;\n\t}\n\n\tconst isRenewal = billingPeriod !== \"one_time\";\n\tconst planBody: Record<string, unknown> = {\n\t\tproduct_id: productId,\n\t\taccount_id: state.companyId,\n\t\tinitial_price: price,\n\t\tplan_type: isRenewal ? \"renewal\" : \"one_time\",\n\t};\n\tif (isRenewal) {\n\t\tplanBody.billing_period = BILLING_PERIOD_DAYS[billingPeriod];\n\t\tplanBody.renewal_price = price;\n\t}\n\n\tlet plan: { id: string; purchase_url?: string | null };\n\ttry {\n\t\tplan = await makeWhopRequest<{ id: string; purchase_url?: string | null }>(\n\t\t\t\"POST\",\n\t\t\t\"/plans\",\n\t\t\tplanBody,\n\t\t);\n\t} catch (err) {\n\t\t// Product is ready but the plan failed — hand back a recovery command with\n\t\t// the product id already filled in. Only claim the product \"was created\"\n\t\t// when we actually created it this run (vs reused an existing one).\n\t\tconst detail = err instanceof Error ? err.message : \"unknown error\";\n\t\treturn c.error({\n\t\t\tcode: \"PLAN_FAILED\",\n\t\t\tmessage: productCreated\n\t\t\t\t? `Your product \"${productTitle}\" (${productId}) was created, but the plan failed: ${detail}`\n\t\t\t\t: `Couldn't add a plan to \"${productTitle}\" (${productId}): ${detail}`,\n\t\t\tretryable: false,\n\t\t\tcta: {\n\t\t\t\tdescription: \"Finish by adding a plan to your product:\",\n\t\t\t\tcommands: [\n\t\t\t\t\t{\n\t\t\t\t\t\tcommand: \"plans create\",\n\t\t\t\t\t\toptions: { product_id: productId },\n\t\t\t\t\t\tdescription: \"Add a pricing plan\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t});\n\t}\n\n\tconst checkoutUrl = plan.purchase_url ?? null;\n\tconst steps: Step[] = [\n\t\t{ id: \"auth\", label: \"Log in\", complete: true },\n\t\t{\n\t\t\tid: \"products\",\n\t\t\tlabel: \"Create a product\",\n\t\t\tcomplete: true,\n\t\t\tcount: 1,\n\t\t\tfirstId: productId,\n\t\t\tfirstTitle: productTitle,\n\t\t},\n\t\t{\n\t\t\tid: \"plans\",\n\t\t\tlabel: \"Add a pricing plan\",\n\t\t\tcomplete: true,\n\t\t\tcount: 1,\n\t\t\tfirstId: plan.id,\n\t\t},\n\t];\n\tconst nextStep = resolveNextStep(\n\t\t[{ id: productId }],\n\t\t[{ id: plan.id }],\n\t\tfalse,\n\t);\n\n\tif (!c.agent && !c.formatExplicit) {\n\t\tprintSummary(\n\t\t\tstate.accountName,\n\t\t\tsteps,\n\t\t\ttrue,\n\t\t\tcheckoutUrl,\n\t\t\tnextStep,\n\t\t\tproductTitle,\n\t\t);\n\t}\n\n\treturn c.ok({\n\t\taccount: state.accountName,\n\t\tready: true,\n\t\tcheckoutUrl,\n\t\tcreated: { productId, planId: plan.id },\n\t\tsteps,\n\t\tnextStep,\n\t});\n}\n\nasync function resolveExistingProduct(\n\tc: RunCtx,\n\tproducts: ListItem[],\n): Promise<ListItem> {\n\tif (products.length === 1) return products[0];\n\tif (c.agent) {\n\t\tthrow new QuickstartError({\n\t\t\tcode: \"PRODUCT_REQUIRED\",\n\t\t\tmessage: `You have ${products.length} products — add the plan to a specific one with plans create --product_id.`,\n\t\t\tretryable: true,\n\t\t\tcta: {\n\t\t\t\tdescription: \"Pick a product:\",\n\t\t\t\tcommands: products.map((p) => ({\n\t\t\t\t\tcommand: \"plans create\",\n\t\t\t\t\toptions: { product_id: p.id },\n\t\t\t\t\tdescription: p.title ?? p.id,\n\t\t\t\t})),\n\t\t\t},\n\t\t});\n\t}\n\tconst chosen = await select<string>({\n\t\tmessage: \"Which product is this plan for?\",\n\t\toptions: products.map((p) => ({\n\t\t\tvalue: p.id,\n\t\t\tlabel: p.title ?? p.id,\n\t\t\thint: p.id,\n\t\t})),\n\t});\n\tif (isCancel(chosen))\n\t\tthrow new QuickstartError({\n\t\t\tcode: \"CANCELLED\",\n\t\t\tmessage: \"Setup cancelled.\",\n\t\t\texitCode: 130,\n\t\t});\n\tconst match = products.find((p) => p.id === chosen);\n\tif (!match) {\n\t\tthrow new QuickstartError({\n\t\t\tcode: \"PRODUCT_NOT_FOUND\",\n\t\t\tmessage: `Selected product \"${chosen}\" is no longer available.`,\n\t\t\tretryable: true,\n\t\t});\n\t}\n\treturn match;\n}\n\nfunction buildSteps(products: ListItem[], plans: ListItem[]): Step[] {\n\treturn [\n\t\t{ id: \"auth\", label: \"Log in\", complete: true },\n\t\t{\n\t\t\tid: \"products\",\n\t\t\tlabel: \"Create a product\",\n\t\t\tcomplete: products.length > 0,\n\t\t\tcount: products.length,\n\t\t\tfirstId: products[0]?.id,\n\t\t\tfirstTitle: products[0]?.title ?? undefined,\n\t\t},\n\t\t{\n\t\t\tid: \"plans\",\n\t\t\tlabel: \"Add a pricing plan\",\n\t\t\tcomplete: plans.length > 0,\n\t\t\tcount: plans.length,\n\t\t\tfirstId: plans[0]?.id,\n\t\t},\n\t];\n}\n\nfunction resolveNextStep(\n\tproducts: Array<{ id: string }>,\n\tplans: Array<{ id: string }>,\n\thasCheckoutConfig: boolean,\n): NextStep | null {\n\tif (products.length === 0 || plans.length === 0) {\n\t\treturn {\n\t\t\tcommand: \"quickstart\",\n\t\t\tdescription:\n\t\t\t\t\"Create your product and pricing — ends with a checkout link\",\n\t\t\thint: \"Walks you through name, price, and billing. Pass --title/--price/--billing_period to skip the prompts.\",\n\t\t};\n\t}\n\tif (!hasCheckoutConfig) {\n\t\treturn {\n\t\t\tcommand: \"checkout-configurations create\",\n\t\t\toptions: plans[0]?.id ? { plan_id: plans[0].id } : undefined,\n\t\t\tdescription: \"Optional: customize your checkout page\",\n\t\t\thint: \"Your checkout link already works — this only tweaks currency, redirect, and payment mode\",\n\t\t};\n\t}\n\treturn null;\n}\n\nfunction printSummary(\n\taccount: string | null,\n\tsteps: Step[],\n\tready: boolean,\n\tcheckoutUrl: string | null,\n\tnextStep: NextStep | null,\n\tcreatedLabel?: string,\n): void {\n\tconst heading = createdLabel\n\t\t? `You're set up to sell \"${createdLabel}\"`\n\t\t: `Setup for \"${account ?? \"your account\"}\"`;\n\tconsole.log(`\\n${chalk.bold(heading)}\\n`);\n\n\tlet pendingMarked = false;\n\tfor (const step of steps) {\n\t\tif (step.complete) {\n\t\t\tlet label = step.label;\n\t\t\tif (step.count !== undefined) {\n\t\t\t\tlabel += chalk.dim(` (${step.count})`);\n\t\t\t\tif (step.firstTitle) label += chalk.dim(` — \"${step.firstTitle}\"`);\n\t\t\t}\n\t\t\tconsole.log(` ${c.success(\"✓\")} ${label}`);\n\t\t} else if (!pendingMarked) {\n\t\t\tpendingMarked = true;\n\t\t\tconsole.log(` ${chalk.cyan(\"●\")} ${chalk.bold(step.label)}`);\n\t\t} else {\n\t\t\tconsole.log(` ${chalk.dim(\"○\")} ${chalk.dim(step.label)}`);\n\t\t}\n\t}\n\n\tif (ready && checkoutUrl) {\n\t\tconsole.log(\n\t\t\t`\\n${chalk.green.bold(\"🎉 You're ready to sell.\")} Share your checkout link:`,\n\t\t);\n\t\tconsole.log(` ${chalk.cyan.underline(checkoutUrl)}`);\n\t}\n\n\tif (nextStep) {\n\t\tconst opts = nextStep.options\n\t\t\t? \" \" +\n\t\t\t\tObject.entries(nextStep.options)\n\t\t\t\t\t.map(([k, v]) => `--${k} ${v}`)\n\t\t\t\t\t.join(\" \")\n\t\t\t: \"\";\n\t\tconst label = ready ? \"Optional next\" : chalk.bold(\"Next step\");\n\t\tconsole.log(\n\t\t\t`\\n${label} ${chalk.cyan.bold(`whop ${nextStep.command}${opts}`)}`,\n\t\t);\n\t\tif (nextStep.hint) console.log(` ${chalk.dim(`→ ${nextStep.hint}`)}`);\n\t} else if (ready) {\n\t\tconsole.log(`\\n${c.success(\"✓ Your store is fully set up.\")}`);\n\t}\n\tconsole.log(\"\");\n}\n","import chalk from \"chalk\";\n\nexport const c = {\n heading: chalk.bold,\n command: chalk.bold,\n description: chalk.dim,\n flag: chalk.yellow,\n tableHeader: chalk.bold,\n separator: chalk.dim,\n number: chalk.dim,\n muted: chalk.dim,\n id: chalk.cyan,\n link: chalk.cyan.underline,\n success: chalk.green,\n error: chalk.red.bold,\n};\n","import groups from \"./api/groups.json\" with { type: \"json\" };\nimport {\n\tbuildAuthGroup,\n\tloginAdapter,\n\tloginEnv,\n\tloginExamples,\n\tloginHint,\n\tloginOptions,\n\tloginOutput,\n\tlogoutAdapter,\n\tlogoutOptions,\n\tlogoutOutput,\n} from \"./auth/commands\";\nimport {\n\tbuildCheckoutGroup,\n\tbuildPlansGroup,\n\tbuildProductsGroup,\n} from \"./commerce/index\";\nimport {\n\tquickstartOptions,\n\tquickstartOutput,\n\trunQuickstart,\n} from \"./journey/quickstart\";\n\ntype CliRegistration = {\n\tcommand: (...args: any[]) => unknown;\n\tserve: (\n\t\targv: string[],\n\t\toptions?: {\n\t\t\texit?: (code: number) => void;\n\t\t\tstdout?: (chunk: string) => void;\n\t\t},\n\t) => Promise<void>;\n};\n\ntype HandwrittenGroup = {\n\tname: string;\n\tdescription: string;\n\tsection: \"get-started\" | \"commerce\" | \"auth\";\n\tregister: (cli: CliRegistration) => unknown;\n};\n\nexport const HANDWRITTEN_GROUPS = [\n\t{\n\t\tname: \"quickstart\",\n\t\tdescription: \"Start here — check status and create your first product + checkout link\",\n\t\tsection: \"get-started\",\n\t\tregister: (cli: CliRegistration) =>\n\t\t\tcli.command(\"quickstart\", {\n\t\t\t\tdescription: \"Start selling — check your status and create what's missing\",\n\t\t\t\thint: \"In a terminal it guides you to your first sale. Agents: a read-only status check unless you pass --title/--price/--billing_period.\",\n\t\t\t\toptions: quickstartOptions,\n\t\t\t\toutput: quickstartOutput,\n\t\t\t\texamples: [\n\t\t\t\t\t{ description: \"Check status / get guided to your first sale\" },\n\t\t\t\t\t{\n\t\t\t\t\t\toptions: {\n\t\t\t\t\t\t\ttitle: \"My Course\",\n\t\t\t\t\t\t\tprice: 9.99,\n\t\t\t\t\t\t\tbilling_period: \"monthly\" as const,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdescription: \"Create a $9.99/mo product non-interactively\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\toutputPolicy: \"agent-only\",\n\t\t\t\trun: (c: Parameters<typeof runQuickstart>[0]) =>\n\t\t\t\t\trunQuickstart({ ...c, setupAgents: () => setupAgents(cli) }),\n\t\t\t}),\n\t},\n\t{\n\t\tname: \"products\",\n\t\tdescription: \"What you're selling\",\n\t\tsection: \"commerce\",\n\t\tregister: (cli: CliRegistration) => cli.command(buildProductsGroup()),\n\t},\n\t{\n\t\tname: \"plans\",\n\t\tdescription: \"Pricing for your products\",\n\t\tsection: \"commerce\",\n\t\tregister: (cli: CliRegistration) => cli.command(buildPlansGroup()),\n\t},\n\t{\n\t\tname: \"checkout-configurations\",\n\t\tdescription: \"Optional / advanced: customize the checkout page\",\n\t\tsection: \"commerce\",\n\t\tregister: (cli: CliRegistration) => cli.command(buildCheckoutGroup()),\n\t},\n\t{\n\t\tname: \"auth\",\n\t\tdescription: \"Manage authentication\",\n\t\tsection: \"auth\",\n\t\tregister: (cli: CliRegistration) => cli.command(buildAuthGroup()),\n\t},\n\t{\n\t\tname: \"login\",\n\t\tdescription: \"Sign in to Whop\",\n\t\tsection: \"auth\",\n\t\tregister: (cli: CliRegistration) =>\n\t\t\tcli.command(\"login\", {\n\t\t\t\tdescription: \"Log in to Whop (alias for `auth login`)\",\n\t\t\t\toptions: loginOptions,\n\t\t\t\tenv: loginEnv,\n\t\t\t\toutput: loginOutput,\n\t\t\t\texamples: loginExamples,\n\t\t\t\thint: loginHint,\n\t\t\t\trun: (c: Parameters<typeof loginAdapter>[0]) => loginAdapter(c),\n\t\t\t}),\n\t},\n\t{\n\t\tname: \"logout\",\n\t\tdescription: \"Sign out\",\n\t\tsection: \"auth\",\n\t\tregister: (cli: CliRegistration) =>\n\t\t\tcli.command(\"logout\", {\n\t\t\t\tdescription: \"Log out (alias for `auth logout`)\",\n\t\t\t\toptions: logoutOptions,\n\t\t\t\toutput: logoutOutput,\n\t\t\t\trun: (c: Parameters<typeof logoutAdapter>[0]) => logoutAdapter(c),\n\t\t\t}),\n\t},\n] satisfies HandwrittenGroup[];\n\nexport const HANDWRITTEN_GROUP_NAMES = new Set(\n\tHANDWRITTEN_GROUPS.map(({ name }) => name),\n);\n\nexport const API_GROUPS = groups\n\t.map(([name, tag]) => ({ name, tag }))\n\t.filter(({ name }) => !HANDWRITTEN_GROUP_NAMES.has(name));\n\nexport const COMMAND_GROUPS = [...API_GROUPS, ...HANDWRITTEN_GROUPS] as const;\n\nexport function registerHandwrittenGroups(cli: CliRegistration) {\n\tfor (const group of HANDWRITTEN_GROUPS) group.register(cli);\n}\n\nasync function setupAgents(cli: CliRegistration) {\n\tfor (const argv of [\n\t\t[\"skills\", \"add\"],\n\t\t[\"mcp\", \"add\"],\n\t]) {\n\t\tlet exitCode = 0;\n\t\tawait cli.serve(argv, {\n\t\t\texit: (code) => {\n\t\t\t\texitCode = code;\n\t\t\t},\n\t\t\tstdout: (chunk) => process.stdout.write(chunk),\n\t\t});\n\t\tif (exitCode !== 0) throw new Error(`whop ${argv.join(\" \")} failed.`);\n\t}\n}\n","{\n\t\"name\": \"@whop/cli\",\n\t\"version\": \"0.0.6\",\n\t\"description\": \"The Whop CLI — build and manage Whop apps from your terminal. Human and agent friendly.\",\n\t\"keywords\": [\n\t\t\"agent\",\n\t\t\"apps\",\n\t\t\"cli\",\n\t\t\"developer\",\n\t\t\"whop\"\n\t],\n\t\"homepage\": \"https://whop.com/developers/\",\n\t\"bugs\": \"https://github.com/whopio/whop-sdk-ts/issues\",\n\t\"license\": \"MIT\",\n\t\"repository\": {\n\t\t\"type\": \"git\",\n\t\t\"url\": \"git+https://github.com/whopio/whop-sdk-ts.git\",\n\t\t\"directory\": \"packages/cli\"\n\t},\n\t\"bin\": {\n\t\t\"whop\": \"dist/index.js\",\n\t\t\"whop-cli\": \"dist/index.js\"\n\t},\n\t\"files\": [\n\t\t\"dist\"\n\t],\n\t\"type\": \"module\",\n\t\"publishConfig\": {\n\t\t\"access\": \"public\"\n\t},\n\t\"scripts\": {\n\t\t\"build\": \"tsx scripts/sync-spec.ts && pnpm run clean && tsup\",\n\t\t\"clean\": \"rm -rf dist\",\n\t\t\"dev\": \"tsx scripts/sync-spec.ts && tsx src/index.ts\",\n\t\t\"start\": \"node dist/index.js\",\n\t\t\"check-types\": \"tsx scripts/sync-spec.ts && tsc --noEmit\",\n\t\t\"lint\": \"oxlint .\",\n\t\t\"lint:fix\": \"oxlint --fix --fix-suggestions && oxfmt\",\n\t\t\"ci:lint\": \"oxlint -f github .\",\n\t\t\"format\": \"oxfmt\",\n\t\t\"sync-spec\": \"tsx scripts/sync-spec.ts\",\n\t\t\"test\": \"tsx --test scripts/*.test.ts\"\n\t},\n\t\"dependencies\": {\n\t\t\"@clack/prompts\": \"^1.5.1\",\n\t\t\"@napi-rs/keyring\": \"^1.3.0\",\n\t\t\"@whop/sdk\": \"^0.0.40\",\n\t\t\"chalk\": \"5.4.1\"\n\t},\n\t\"devDependencies\": {\n\t\t\"@types/node\": \"25.3.5\",\n\t\t\"incur\": \"github:whopio/incur#5ca60d5\",\n\t\t\"tsup\": \"8.5.0\",\n\t\t\"tsx\": \"4.19.4\",\n\t\t\"typescript\": \"5.9.3\"\n\t},\n\t\"engines\": {\n\t\t\"node\": \">=22\"\n\t},\n\t\"packageManager\": \"pnpm@10.23.0\"\n}\n","import { c } from \"./colors\";\n\nconst MAX_CELL_WIDTH = 40\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nfunction isObjectArray(value: unknown): value is Record<string, unknown>[] {\n return Array.isArray(value) && value.length > 0 && value.every(isPlainObject)\n}\n\nconst WHOP_TAG = /^[a-z]+_[A-Za-z0-9]+$/\n\n/** Plain truncated string — used for column width calculation (no ANSI codes). */\nfunction cellText(value: unknown): string {\n if (value == null) return ''\n const text = String(value)\n return text.length > MAX_CELL_WIDTH ? text.slice(0, MAX_CELL_WIDTH - 1) + '…' : text\n}\n\n/** Colored display string — used for rendering. */\nfunction formatCell(value: unknown): string {\n const text = cellText(value)\n if (typeof value === 'boolean') return value ? c.success(text) : c.error(text)\n if (typeof value === 'string' && WHOP_TAG.test(value)) return c.id(text)\n return text\n}\n\n/** Total printable width of one row: sum of column widths plus two-space separators between them. */\nfunction totalRowWidth(colWidths: number[]): number {\n const columnTotal = colWidths.reduce((sum, colWidth) => sum + colWidth, 0)\n return columnTotal + (colWidths.length - 1) * 2\n}\n\n/**\n * Renders an array of plain objects as an aligned terminal grid.\n * Drops columns from the right when the row would exceed the terminal width.\n */\nfunction renderRows(rows: Record<string, unknown>[]): string {\n // Only include keys that are scalar across every row — a column where some rows\n // have an object and others have null would render as \"[object Object]\".\n const isScalar = (value: unknown) => typeof value !== 'object' || value === null\n const scalarKeys = Object.keys(rows[0]!).filter((key) =>\n rows.every((row) => isScalar(row[key])),\n )\n\n if (scalarKeys.length === 0) return '(no displayable columns)'\n\n // Column width = max of the header label and the widest cell value across all rows.\n const allWidths = scalarKeys.map((key) =>\n Math.max(key.length, ...rows.map((row) => cellText(row[key]).length)),\n )\n\n // Drop the rightmost columns until the row fits within the terminal width.\n const termWidth = process.stdout.columns ?? 80\n let numVisible = allWidths.length\n while (numVisible > 1 && totalRowWidth(allWidths.slice(0, numVisible)) > termWidth) {\n numVisible--\n }\n\n const visibleKeys = scalarKeys.slice(0, numVisible)\n const visibleWidths = allWidths.slice(0, numVisible)\n\n const header = visibleKeys\n .map((key, i) => c.tableHeader(key.toUpperCase().padEnd(visibleWidths[i]!)))\n .join(' ')\n\n const separator = c.separator(visibleWidths.map((w) => '─'.repeat(w)).join('──'))\n\n const body = rows.map((row) =>\n visibleKeys\n .map((key, i) => {\n const value = row[key]\n const formatted = formatCell(value)\n const width = visibleWidths[i]!\n const pad = width - cellText(value).length\n // Right-align numbers, left-align everything else.\n return typeof value === 'number'\n ? c.number(' '.repeat(pad) + formatted)\n : formatted + ' '.repeat(pad)\n })\n .join(' '),\n )\n\n const hiddenCount = scalarKeys.length - numVisible\n const overflowHint =\n hiddenCount > 0\n ? `\\n${c.muted(`& ${hiddenCount} more columns — use --format json to see all`)}`\n : ''\n\n return [header, separator, ...body].join('\\n') + overflowHint\n}\n\n/**\n * Human-mode renderer passed to incur as `renderer`.\n * Handles top-level arrays and single-array wrapped responses (e.g. `{ accounts: [...], pagination: {...} }`).\n * Returns null for anything that can't be meaningfully rendered as a grid, falling back to incur's TOON formatter.\n */\nexport function render(data: unknown): string | null {\n if (isObjectArray(data)) return renderRows(data)\n\n if (isPlainObject(data)) {\n const arrayFields = Object.values(data).filter(isObjectArray)\n // Only render when there's exactly one array field — avoids guessing which to show.\n if (arrayFields.length === 1) {\n return renderRows(arrayFields[0] as Record<string, unknown>[])\n }\n }\n\n return null\n}\n","import { Cli } from \"incur\";\nimport { nativeSpec, filterSpecByTag, createWhopFetch } from \"./api\";\nimport { API_GROUPS, registerHandwrittenGroups } from \"./commands\";\nimport pkg from \"../package.json\" with { type: \"json\" };\nimport { render } from \"./lib/renderer\";\nimport { performLogin } from \"./auth/commands\";\nimport { getActiveProfile } from \"./auth/profiles\";\nimport { PromptCancelledError } from \"./auth/prompts\";\n\nconst cli = Cli.create(\"whop\", {\n\tversion: pkg.version,\n\tdescription: \"Build and manage Whop apps from your terminal.\",\n\trenderer: render,\n\tsync: {\n\t\tsuggestions: [\n\t\t\t\"start selling on Whop\",\n\t\t\t\"show my Whop business accounts\",\n\t\t\t\"create a Whop product and pricing plan\",\n\t\t],\n\t},\n\tmcp: {\n\t\tagents: [\"claude-desktop\"],\n\t},\n});\n\nconst spec = (tag: string) =>\n\tfilterSpecByTag(nativeSpec as Record<string, unknown>, tag);\nconst fetch = createWhopFetch();\n\nconst isAuthExempt = (cmd: string) =>\n\t!cmd ||\n\tcmd === \"login\" ||\n\tcmd === \"logout\" ||\n\tcmd === \"completions\" ||\n\tcmd.startsWith(\"auth\") ||\n\tcmd.startsWith(\"mcp\");\n\ncli.use(async (c, next) => {\n\tif (isAuthExempt(c.command)) return next();\n\tif (getActiveProfile()) return next();\n\tif (process.env.WHOP_API_KEY) return next();\n\n\tif (c.agent) {\n\t\treturn c.error({\n\t\t\tcode: \"NOT_AUTHENTICATED\",\n\t\t\tmessage: \"Not logged in. Set WHOP_API_KEY or run `whop login` first.\",\n\t\t\tcta: {\n\t\t\t\tcommands: [{ command: \"auth login\", description: \"Log in to Whop\" }],\n\t\t\t},\n\t\t});\n\t}\n\n\tlet result;\n\ttry {\n\t\tresult = await performLogin({ agent: false });\n\t} catch (err) {\n\t\tif (err instanceof PromptCancelledError) {\n\t\t\treturn c.error({\n\t\t\t\tcode: \"CANCELLED\",\n\t\t\t\tmessage: \"Login cancelled.\",\n\t\t\t\texitCode: 130,\n\t\t\t});\n\t\t}\n\t\tthrow err;\n\t}\n\n\tif (!result.ok) {\n\t\treturn c.error({\n\t\t\tcode: result.code,\n\t\t\tmessage: result.message,\n\t\t\tcta: {\n\t\t\t\tcommands: [{ command: \"auth login\", description: \"Log in to Whop\" }],\n\t\t\t},\n\t\t});\n\t}\n\n\treturn next();\n});\n\nregisterHandwrittenGroups(cli);\n\nfor (const { name, tag } of API_GROUPS) {\n\tcli.command(name, { fetch, openapi: spec(tag) });\n}\n\nexport default cli;\n","[\n {\n \"group\": \"Core Resources\",\n \"tags\": [\n \"Accounts\",\n \"Users\",\n \"Webhooks\",\n \"Stats\"\n ]\n },\n {\n \"group\": \"Money\",\n \"tags\": [\n \"Ledgers\",\n \"Payouts\",\n \"Cards\",\n \"Transfers\",\n \"Deposits\",\n \"Swaps\",\n \"Payout Methods\",\n \"Verifications\"\n ]\n },\n {\n \"group\": \"Commerce\",\n \"tags\": [\n \"Products\",\n \"Plans\",\n \"Checkout Configurations\",\n \"Referrals\"\n ]\n },\n {\n \"group\": \"Ads\",\n \"tags\": [\n \"Ads\",\n \"Ad Campaigns\",\n \"Ad Groups\",\n \"Audiences\"\n ]\n },\n {\n \"group\": \"Identity\",\n \"tags\": [\n \"Social Accounts\"\n ]\n }\n]\n","{\n \"Accounts\": \"Your Whop account\",\n \"Users\": \"Users on your platform\",\n \"Stats\": \"Platform-wide statistics\",\n \"Ledgers\": \"Transaction history\",\n \"Payouts\": \"Withdraw earnings\",\n \"Cards\": \"Issued virtual cards\",\n \"Transfers\": \"Move funds between accounts\",\n \"Deposits\": \"Add funds to your balance\",\n \"Swaps\": \"Convert between currencies\",\n \"Verifications\": \"Identity verification status\",\n \"Products\": \"Description of what you sell\",\n \"Plans\": \"Description of your pricing\",\n \"Checkout Configurations\": \"What your checkout page looks like\",\n \"Referrals\": \"Referral programs\",\n \"Ads\": \"Ad creatives\",\n \"Ad Campaigns\": \"Top-level campaign organization\",\n \"Ad Groups\": \"Sets of related ads\",\n \"Audiences\": \"Who sees your ads\",\n \"Social Accounts\": \"Linked social profiles\"\n}\n","import apiStructure from \"../api/api-structure.json\" with { type: \"json\" };\nimport tagDescriptions from \"../api/tag-descriptions.json\" with { type: \"json\" };\nimport { API_GROUPS, HANDWRITTEN_GROUPS } from \"../commands\";\nimport { c } from \"./colors\";\n\nconst descriptions: Record<string, string> = tagDescriptions;\nconst toCliName = (tag: string) => tag.toLowerCase().replace(/\\s+/g, \"-\");\n\nconst SECTION_LABELS = {\n\t\"get-started\": \"Get Started\",\n\tcommerce: \"Commerce\",\n\tauth: \"Auth\",\n} as const;\n\nconst INTEGRATIONS = [\n\t{ name: \"completions\", desc: \"Generate shell completion script\" },\n\t{ name: \"mcp add\", desc: \"Register as MCP server\" },\n\t{ name: \"skills\", desc: \"Sync skill files to agents (add, list)\" },\n];\n\nconst GLOBAL_FLAGS = [\n\t{\n\t\tflag: \"--filter-output <keys>\",\n\t\tdesc: \"Filter output by key paths (e.g. foo,bar.baz,a[0,3])\",\n\t},\n\t{ flag: \"--format <toon|json|yaml|md|jsonl>\", desc: \"Output format\" },\n\t{ flag: \"--full-output\", desc: \"Show full output envelope\" },\n\t{ flag: \"--help\", desc: \"Show help\" },\n\t{ flag: \"--llms, --llms-full\", desc: \"Print LLM-readable manifest\" },\n\t{ flag: \"--mcp\", desc: \"Start as MCP stdio server\" },\n\t{ flag: \"--schema\", desc: \"Show JSON Schema for command\" },\n\t{\n\t\tflag: \"--token-count\",\n\t\tdesc: \"Print token count of output (instead of output)\",\n\t},\n\t{ flag: \"--token-limit <n>\", desc: \"Limit output to n tokens\" },\n\t{ flag: \"--token-offset <n>\", desc: \"Skip first n tokens of output\" },\n\t{ flag: \"--version\", desc: \"Show version\" },\n];\n\ntype HelpCommand = {\n\tname: string;\n\tdescription: string;\n};\n\ntype HelpSection = {\n\tlabel: string;\n\tcommands: HelpCommand[];\n};\n\nconst handwrittenSection = (\n\tsection: (typeof HANDWRITTEN_GROUPS)[number][\"section\"],\n): HelpSection => ({\n\tlabel: SECTION_LABELS[section],\n\tcommands: HANDWRITTEN_GROUPS.filter((group) => group.section === section).map(\n\t\t({ name, description }) => ({ name, description }),\n\t),\n});\n\nexport function buildGroupedHelp(version: string, description: string): string {\n\tconst lines: string[] = [];\n\n\tconst presentCommands = new Set(API_GROUPS.map(({ name }) => name));\n\n\tconst apiSections = apiStructure\n\t\t.map(({ group, tags }) => ({\n\t\t\tlabel: group,\n\t\t\tcommands: (tags as string[])\n\t\t\t\t.filter((tag) => presentCommands.has(toCliName(tag)))\n\t\t\t\t.map((tag) => ({\n\t\t\t\t\tname: toCliName(tag),\n\t\t\t\t\tdescription: descriptions[tag] ?? \"\",\n\t\t\t\t})),\n\t\t}))\n\t\t.filter((section) => section.commands.length > 0);\n\n\tconst extraCommerce = apiSections\n\t\t.filter((section) => section.label.toLowerCase() === \"commerce\")\n\t\t.flatMap((section) => section.commands);\n\tconst commerceSection = handwrittenSection(\"commerce\");\n\tcommerceSection.commands = [...commerceSection.commands, ...extraCommerce];\n\n\tconst filteredApiSections = apiSections.filter(\n\t\t(section) => section.label.toLowerCase() !== \"commerce\",\n\t);\n\tconst allSections = [\n\t\thandwrittenSection(\"get-started\"),\n\t\tcommerceSection,\n\t\t...filteredApiSections,\n\t\thandwrittenSection(\"auth\"),\n\t].filter((section) => section.commands.length > 0);\n\tconst maxCmdLen = Math.max(\n\t\t...allSections.flatMap((section) =>\n\t\t\tsection.commands.map((command) => command.name.length),\n\t\t),\n\t);\n\n\tlines.push(`whop@${version} — ${description}`);\n\tlines.push(\"\");\n\tlines.push(\"Usage: whop <command>\");\n\n\tfor (const section of allSections) {\n\t\tlines.push(\"\");\n\t\tlines.push(c.heading(section.label.toUpperCase()));\n\t\tfor (const cmd of section.commands) {\n\t\t\tconst pad = \" \".repeat(maxCmdLen - cmd.name.length);\n\t\t\tlines.push(\n\t\t\t\t` ${c.command(cmd.name)}${pad} ${c.description(cmd.description)}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tconst maxIntLen = Math.max(...INTEGRATIONS.map((i) => i.name.length));\n\tlines.push(\"\");\n\tlines.push(\"Integrations:\");\n\tfor (const i of INTEGRATIONS) {\n\t\tlines.push(\n\t\t\t` ${c.command(i.name)}${\" \".repeat(maxIntLen - i.name.length)} ${c.description(i.desc)}`,\n\t\t);\n\t}\n\n\tconst maxFlagLen = Math.max(...GLOBAL_FLAGS.map((f) => f.flag.length));\n\tlines.push(\"\");\n\tlines.push(\"Global Options:\");\n\tfor (const f of GLOBAL_FLAGS) {\n\t\tlines.push(\n\t\t\t` ${c.flag(f.flag)}${\" \".repeat(maxFlagLen - f.flag.length)} ${c.description(f.desc)}`,\n\t\t);\n\t}\n\n\treturn lines.join(\"\\n\");\n}\n","import { c } from \"./colors\";\n\n/**\n * Themes incur's built-in help / error / CTA text so the whole CLI looks\n * consistent with our hand-rendered surfaces (root help, quickstart, tables).\n *\n * incur exposes a `renderer` hook only for command *data*, not for help or\n * errors, so we post-process the text it writes to stdout instead. This runs\n * only in human TTY mode (see `shouldColorize`) — structured output\n * (`--json`, `--format`, piped/agent) is passed through untouched, so machine\n * consumers never see ANSI codes.\n */\n\nconst SECTION_HEADERS = new Set([\n\t\"Usage\",\n\t\"Arguments\",\n\t\"Options\",\n\t\"Examples\",\n\t\"Environment Variables\",\n\t\"Global Options\",\n\t\"Integrations\",\n\t\"Commands\",\n\t\"Aliases\",\n]);\n\nconst FORMAT_FLAGS = [\"--json\", \"--format\", \"--full-output\", \"--schema\", \"--llms\", \"--llms-full\", \"--mcp\", \"--token-count\", \"--token-limit\", \"--token-offset\"];\n\n/** Color only when writing for a human: a TTY, with no structured-output flag. */\nexport function shouldColorize(argv: string[]): boolean {\n\tif (!process.stdout.isTTY) return false;\n\treturn !argv.some((a) => FORMAT_FLAGS.includes(a) || a.startsWith(\"--format=\"));\n}\n\n/** Highlights a flag token and any `<placeholder>` inside an option/flag row. */\nfunction paintFlag(flag: string): string {\n\treturn flag.replace(/(<[^>]+>)/g, (m) => c.muted(m)).replace(/(--[\\w-]+|-[\\w])/g, (m) => c.flag(m));\n}\n\n/** An indented command line (` whop products create # desc`) — in help examples or a CTA. */\nconst COMMAND_ROW = /^(\\s+)(whop\\s+\\S.*?)(\\s{2,}#\\s.*)?$/;\n\n/** Underlines any URL so links (checkout pages, dashboards) stand out. */\nfunction highlightUrls(text: string): string {\n\treturn text.replace(/https?:\\/\\/[^\\s)]+/g, (m) => c.link(m));\n}\n\nfunction colorizeLine(\n\tline: string,\n\tsection: string | null,\n\tnextLine: string | undefined,\n): { line: string; section: string | null } {\n\t// Error header, e.g. \"Error: msg\" or \"Error (HTTP_403): msg\".\n\tconst errMatch = line.match(/^(Error(?: \\([^)]+\\))?:)(.*)$/);\n\tif (errMatch) return { line: c.error(errMatch[1]) + highlightUrls(errMatch[2]), section };\n\tif (line.startsWith(\"Run `\")) return { line: c.heading(line), section };\n\n\t// Section header, e.g. \"Options:\" or \"Usage: whop products create\".\n\tconst header = line.match(/^([A-Z][A-Za-z ]+):(.*)$/);\n\tif (header && SECTION_HEADERS.has(header[1])) {\n\t\tconst rest = header[2].replace(/(whop[\\w\\s-]*)/g, (m) => c.command(m));\n\t\treturn { line: c.heading(`${header[1]}:`) + rest, section: header[1] };\n\t}\n\n\t// A `whop …` command line anywhere (help examples and CTAs alike).\n\tconst cmd = line.match(COMMAND_ROW);\n\tif (cmd) {\n\t\treturn { line: `${cmd[1]}${c.command(cmd[2])}${cmd[3] ? c.description(cmd[3]) : \"\"}`, section };\n\t}\n\n\t// A header-like line (\"Suggested command:\", a CTA description) immediately\n\t// followed by a command — bold it for emphasis.\n\tif (line.trim().endsWith(\":\") && nextLine !== undefined && COMMAND_ROW.test(nextLine)) {\n\t\treturn { line: c.heading(line), section };\n\t}\n\n\tif (line.trim() === \"\") return { line, section: null };\n\n\t// Rows inside a known section.\n\tif (section === \"Options\" || section === \"Global Options\" || section === \"Environment Variables\") {\n\t\tconst m = line.match(/^(\\s+)(\\S.*?)(\\s{2,})(.*)$/);\n\t\tif (m) return { line: `${m[1]}${paintFlag(m[2])}${m[3]}${c.description(m[4])}`, section };\n\t}\n\tif (section === \"Commands\" || section === \"Integrations\" || section === \"Aliases\") {\n\t\tconst m = line.match(/^(\\s+)(\\S+)(\\s{2,})(.*)$/);\n\t\tif (m) return { line: `${m[1]}${c.command(m[2])}${m[3]}${c.description(m[4])}`, section };\n\t}\n\tif (section === \"Arguments\") {\n\t\tconst m = line.match(/^(\\s+)(\\S+)(\\s{2,})(.*)$/);\n\t\tif (m) return { line: `${m[1]}${c.id(m[2])}${m[3]}${c.description(m[4])}`, section };\n\t}\n\n\t// Plain text (messages, CTA descriptions): make any link stand out.\n\treturn { line: highlightUrls(line), section };\n}\n\n/** Themes a chunk of incur help/error/CTA text. Safe to call per write. */\nexport function colorizeOutput(text: string): string {\n\tlet section: string | null = null;\n\tconst lines = text.split(\"\\n\");\n\treturn lines\n\t\t.map((line, i) => {\n\t\t\tconst result = colorizeLine(line, section, lines[i + 1]);\n\t\t\tsection = result.section;\n\t\t\treturn result.line;\n\t\t})\n\t\t.join(\"\\n\");\n}\n","import cli from \"./cli\";\nimport { getActiveProfile } from \"./auth/profiles\";\nimport { buildGroupedHelp } from \"./lib/grouped-help\";\nimport { colorizeOutput, shouldColorize } from \"./lib/colorize-output\";\nimport pkg from \"../package.json\" with { type: \"json\" };\n\nconst argv = process.argv.slice(2);\n\nasync function serve(argv: string[]) {\n\tif (shouldColorize(argv)) {\n\t\tawait cli.serve(argv, {\n\t\t\tstdout: (s) => process.stdout.write(colorizeOutput(s)),\n\t\t});\n\t} else {\n\t\tawait cli.serve(argv);\n\t}\n}\n\nif (argv.length === 0 && !getActiveProfile() && !process.env.WHOP_API_KEY) {\n\tawait serve([\"quickstart\"]);\n} else if (argv.length === 0 || (argv.length === 1 && argv[0] === \"--help\")) {\n\tprocess.stdout.write(\n\t\tbuildGroupedHelp(\n\t\t\tpkg.version,\n\t\t\tcli.description ?? \"Build and manage Whop apps from your terminal.\",\n\t\t) + \"\\n\",\n\t);\n\tprocess.exit(0);\n} else {\n\tawait serve(argv);\n}\n\nexport default cli;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,EACE;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,EACF;AAAA,EACA;AAAA,IACE;AAAA,IAC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I,GAAG;AACzB,UAAM,YAAI,MAAMA,OAAM;AAAA,MACrB,QAAQ,CAAC,MAAM,QAAQ,OAAO,MAAM,eAAe,CAAC,CAAC;AAAA,IACtD,CAAC;AAAA,EACF,OAAO;AACN,UAAM,YAAI,MAAMA,KAAI;AAAA,EACrB;AACD;AAEA,IAAI,KAAK,WAAW,KAAK,CAAC,iBAAiB,KAAK,CAAC,QAAQ,IAAI,cAAc;AAC1E,QAAM,MAAM,CAAC,YAAY,CAAC;AAC3B,WAAW,KAAK,WAAW,KAAM,KAAK,WAAW,KAAK,KAAK,CAAC,MAAM,UAAW;AAC5E,UAAQ,OAAO;AAAA,IACd;AAAA,MACC,gBAAI;AAAA,MACJ,YAAI,eAAe;AAAA,IACpB,IAAI;AAAA,EACL;AACA,UAAQ,KAAK,CAAC;AACf,OAAO;AACN,QAAM,MAAM,IAAI;AACjB;AAEA,IAAO,gBAAQ;","names":["identity","existed","profile","c","createWhopFetch","fetch","removed","text","c","c","c","isCancel","createOptions","isCancel","c","createOptions","c","chalk","text","select","isCancel","chalk","c","chalk","isCancel","text","select","cli","c","argv","text","c","argv","text","argv"]}