@whop/cli 0.1.0 → 0.2.0

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.
@@ -541,7 +541,7 @@ var native_spec_default = {
541
541
  "string",
542
542
  "null"
543
543
  ],
544
- description: "ID of the tax classification code applied by default to the account's products."
544
+ description: "ID of the tax classification code applied by default to the account's products. See the available [product categories](https://docs.numeral.com/essentials/product-categories)."
545
545
  },
546
546
  business_address: {
547
547
  type: "object",
@@ -8615,6 +8615,56 @@ var native_spec_default = {
8615
8615
  "null"
8616
8616
  ]
8617
8617
  },
8618
+ questions: {
8619
+ type: [
8620
+ "array",
8621
+ "null"
8622
+ ],
8623
+ items: {
8624
+ type: "object",
8625
+ properties: {
8626
+ id: {
8627
+ type: [
8628
+ "string",
8629
+ "null"
8630
+ ]
8631
+ },
8632
+ key: {
8633
+ type: [
8634
+ "string",
8635
+ "null"
8636
+ ]
8637
+ },
8638
+ question: {
8639
+ type: [
8640
+ "string",
8641
+ "null"
8642
+ ]
8643
+ },
8644
+ type: {
8645
+ type: [
8646
+ "string",
8647
+ "null"
8648
+ ]
8649
+ },
8650
+ options: {
8651
+ type: [
8652
+ "array",
8653
+ "null"
8654
+ ],
8655
+ items: {
8656
+ type: "string"
8657
+ }
8658
+ },
8659
+ answer: {
8660
+ type: [
8661
+ "string",
8662
+ "null"
8663
+ ]
8664
+ }
8665
+ }
8666
+ }
8667
+ },
8618
8668
  context: {
8619
8669
  type: [
8620
8670
  "object",
@@ -9058,6 +9108,15 @@ var native_spec_default = {
9058
9108
  },
9059
9109
  description: "Grouping granularity for report rows."
9060
9110
  },
9111
+ {
9112
+ name: "timezone",
9113
+ in: "query",
9114
+ required: false,
9115
+ schema: {
9116
+ type: "string"
9117
+ },
9118
+ description: "IANA timezone (for example `America/New_York`) used to bucket report periods and to interpret calendar-day boundaries for balance snapshots. Defaults to UTC. from_date/to_date remain exact Unix instants regardless of this setting. Platform-wide (global) reports are UTC-only and reject other timezones."
9119
+ },
9061
9120
  {
9062
9121
  name: "cumulative",
9063
9122
  in: "query",
@@ -9106,6 +9165,17 @@ var native_spec_default = {
9106
9165
  amount: {
9107
9166
  type: "number"
9108
9167
  },
9168
+ profit_and_loss_section: {
9169
+ type: [
9170
+ "string",
9171
+ "null"
9172
+ ],
9173
+ enum: [
9174
+ "revenue",
9175
+ "cost_of_revenue",
9176
+ null
9177
+ ]
9178
+ },
9109
9179
  account_type: {
9110
9180
  type: [
9111
9181
  "string",
@@ -9189,6 +9259,406 @@ var native_spec_default = {
9189
9259
  }
9190
9260
  }
9191
9261
  },
9262
+ "/payouts/methods": {
9263
+ get: {
9264
+ summary: "List Payout Methods",
9265
+ tags: [
9266
+ "Payouts"
9267
+ ],
9268
+ security: [
9269
+ {
9270
+ bearerAuth: [
9271
+ "payout:destination:read"
9272
+ ]
9273
+ }
9274
+ ],
9275
+ description: "Lists the saved payout methods (bank accounts, digital wallets, crypto addresses) that an account or user can withdraw to, most recently added first. Pass exactly one of account_id (a biz_ identifier) or user_id (a user_ identifier). Pass an amount to additionally get a fee and delivery quote per method for withdrawing that amount.",
9276
+ operationId: "methods",
9277
+ parameters: [
9278
+ {
9279
+ $ref: "#/components/parameters/ApiVersionDate"
9280
+ },
9281
+ {
9282
+ name: "account_id",
9283
+ in: "query",
9284
+ required: false,
9285
+ schema: {
9286
+ type: "string"
9287
+ },
9288
+ description: "The owning account ID (a biz_ identifier). Provide this or user_id."
9289
+ },
9290
+ {
9291
+ name: "user_id",
9292
+ in: "query",
9293
+ required: false,
9294
+ schema: {
9295
+ type: "string"
9296
+ },
9297
+ description: "The owning user ID (a user_ identifier). Provide this or account_id."
9298
+ },
9299
+ {
9300
+ name: "status",
9301
+ in: "query",
9302
+ required: false,
9303
+ schema: {
9304
+ type: "string",
9305
+ enum: [
9306
+ "created",
9307
+ "active",
9308
+ "broken"
9309
+ ]
9310
+ },
9311
+ description: "Optional status filter. `created` means saved but unused, `active` means a payout through it succeeded, `broken` means the last payout failed and the method needs fixing."
9312
+ },
9313
+ {
9314
+ name: "amount",
9315
+ in: "query",
9316
+ required: false,
9317
+ schema: {
9318
+ type: "number"
9319
+ },
9320
+ description: "Optional withdrawal amount in whole currency units, for example `250.00`. When provided, each method includes a quote with the estimated fee, amount received, and delivery date for that amount."
9321
+ },
9322
+ {
9323
+ name: "currency",
9324
+ in: "query",
9325
+ required: false,
9326
+ schema: {
9327
+ type: "string",
9328
+ default: "usd"
9329
+ },
9330
+ description: "Currency code of the amount, for example `usd`. Only meaningful with amount."
9331
+ },
9332
+ {
9333
+ name: "first",
9334
+ in: "query",
9335
+ required: false,
9336
+ schema: {
9337
+ type: "integer",
9338
+ default: 20,
9339
+ maximum: 100
9340
+ },
9341
+ description: "Number of payout methods to return from the start of the window. Capped at 25 when an amount is provided."
9342
+ },
9343
+ {
9344
+ name: "after",
9345
+ in: "query",
9346
+ required: false,
9347
+ schema: {
9348
+ type: "string"
9349
+ },
9350
+ description: "Cursor to fetch the page after (from page_info.end_cursor)."
9351
+ },
9352
+ {
9353
+ name: "last",
9354
+ in: "query",
9355
+ required: false,
9356
+ schema: {
9357
+ type: "integer",
9358
+ maximum: 100
9359
+ },
9360
+ description: "Number of payout methods to return from the end of the window."
9361
+ },
9362
+ {
9363
+ name: "before",
9364
+ in: "query",
9365
+ required: false,
9366
+ schema: {
9367
+ type: "string"
9368
+ },
9369
+ description: "Cursor to fetch the page before (from page_info.start_cursor)."
9370
+ }
9371
+ ],
9372
+ responses: {
9373
+ "200": {
9374
+ description: "internal stablecoin destinations omitted",
9375
+ content: {
9376
+ "application/json": {
9377
+ schema: {
9378
+ type: "object",
9379
+ properties: {
9380
+ data: {
9381
+ type: "array",
9382
+ items: {
9383
+ type: "object",
9384
+ properties: {
9385
+ object: {
9386
+ type: "string",
9387
+ enum: [
9388
+ "payout_method"
9389
+ ]
9390
+ },
9391
+ id: {
9392
+ type: "string",
9393
+ description: "Payout method ID."
9394
+ },
9395
+ status: {
9396
+ type: "string",
9397
+ enum: [
9398
+ "created",
9399
+ "active",
9400
+ "broken"
9401
+ ],
9402
+ description: "Lifecycle status: `created` means saved but unused, `active` means a payout succeeded through it, `broken` means the last payout failed."
9403
+ },
9404
+ is_default: {
9405
+ type: "boolean",
9406
+ description: "Whether this is the default payout method for the account."
9407
+ },
9408
+ nickname: {
9409
+ type: [
9410
+ "string",
9411
+ "null"
9412
+ ],
9413
+ description: "User-defined label for the payout method."
9414
+ },
9415
+ account_reference: {
9416
+ type: [
9417
+ "string",
9418
+ "null"
9419
+ ],
9420
+ description: "Masked identifier for the destination, such as the last four digits of a bank account."
9421
+ },
9422
+ institution_name: {
9423
+ type: [
9424
+ "string",
9425
+ "null"
9426
+ ],
9427
+ description: "Name of the bank or institution receiving payouts."
9428
+ },
9429
+ payer_name: {
9430
+ type: [
9431
+ "string",
9432
+ "null"
9433
+ ],
9434
+ description: "Display name of the payout rail, such as `ACH Bank Deposit`."
9435
+ },
9436
+ destination_currency: {
9437
+ type: "string",
9438
+ description: "Currency payouts are delivered in for this method."
9439
+ },
9440
+ created_at: {
9441
+ type: "string",
9442
+ format: "date-time",
9443
+ description: "When the payout method was added."
9444
+ },
9445
+ payout_destination: {
9446
+ type: [
9447
+ "object",
9448
+ "null"
9449
+ ],
9450
+ description: "The payout rail this method delivers through.",
9451
+ properties: {
9452
+ name: {
9453
+ type: [
9454
+ "string",
9455
+ "null"
9456
+ ],
9457
+ description: "Payout destination display name."
9458
+ },
9459
+ icon_url: {
9460
+ type: [
9461
+ "string",
9462
+ "null"
9463
+ ],
9464
+ description: "Payout destination icon URL."
9465
+ },
9466
+ delivery_type: {
9467
+ type: "string",
9468
+ description: "How funds are delivered, for example `bank_deposit`."
9469
+ },
9470
+ supports_standard_delivery: {
9471
+ type: "boolean"
9472
+ },
9473
+ supports_instant_delivery: {
9474
+ type: "boolean"
9475
+ }
9476
+ },
9477
+ required: [
9478
+ "name",
9479
+ "icon_url",
9480
+ "delivery_type",
9481
+ "supports_standard_delivery",
9482
+ "supports_instant_delivery"
9483
+ ]
9484
+ },
9485
+ quote: {
9486
+ type: [
9487
+ "object",
9488
+ "null"
9489
+ ],
9490
+ description: "Fee and delivery estimate for withdrawing the requested amount through this method. Null unless an amount was provided, or when the estimate is unavailable.",
9491
+ properties: {
9492
+ amount: {
9493
+ type: "number",
9494
+ format: "float",
9495
+ description: "The withdrawal amount the quote is for."
9496
+ },
9497
+ currency: {
9498
+ type: "string",
9499
+ description: "Currency of the quoted amount."
9500
+ },
9501
+ exchange_rate: {
9502
+ type: "number",
9503
+ format: "float",
9504
+ description: "Exchange rate from the withdrawal currency to the destination currency."
9505
+ },
9506
+ min_limit: {
9507
+ type: "number",
9508
+ format: "float",
9509
+ description: "Minimum withdrawal amount for this method, in the withdrawal currency."
9510
+ },
9511
+ max_limit: {
9512
+ type: [
9513
+ "number",
9514
+ "null"
9515
+ ],
9516
+ format: "float",
9517
+ description: "Maximum withdrawal amount for this method, in the withdrawal currency."
9518
+ },
9519
+ standard: {
9520
+ type: [
9521
+ "object",
9522
+ "null"
9523
+ ],
9524
+ description: "Standard-delivery estimate. Null if the method does not support standard delivery, or the amount does not cover the fee.",
9525
+ properties: {
9526
+ fee: {
9527
+ type: "number",
9528
+ format: "float",
9529
+ description: "Total fee charged, in the withdrawal currency."
9530
+ },
9531
+ total_received: {
9532
+ type: "number",
9533
+ format: "float",
9534
+ description: "Amount delivered after fees, in the withdrawal currency."
9535
+ },
9536
+ estimated_arrival: {
9537
+ type: "string",
9538
+ format: "date-time",
9539
+ description: "Estimated time the funds become available."
9540
+ }
9541
+ },
9542
+ required: [
9543
+ "fee",
9544
+ "total_received",
9545
+ "estimated_arrival"
9546
+ ]
9547
+ },
9548
+ instant: {
9549
+ type: [
9550
+ "object",
9551
+ "null"
9552
+ ],
9553
+ description: "Instant-delivery estimate. Null if the method does not support instant delivery, instant delivery is unavailable for the account, or the amount does not cover the fee.",
9554
+ properties: {
9555
+ fee: {
9556
+ type: "number",
9557
+ format: "float",
9558
+ description: "Total fee charged, in the withdrawal currency."
9559
+ },
9560
+ total_received: {
9561
+ type: "number",
9562
+ format: "float",
9563
+ description: "Amount delivered after fees, in the withdrawal currency."
9564
+ },
9565
+ estimated_arrival: {
9566
+ type: "string",
9567
+ format: "date-time",
9568
+ description: "Estimated time the funds become available."
9569
+ }
9570
+ },
9571
+ required: [
9572
+ "fee",
9573
+ "total_received",
9574
+ "estimated_arrival"
9575
+ ]
9576
+ }
9577
+ },
9578
+ required: [
9579
+ "amount",
9580
+ "currency",
9581
+ "exchange_rate",
9582
+ "min_limit",
9583
+ "max_limit",
9584
+ "standard",
9585
+ "instant"
9586
+ ]
9587
+ }
9588
+ },
9589
+ required: [
9590
+ "object",
9591
+ "id",
9592
+ "status",
9593
+ "is_default",
9594
+ "nickname",
9595
+ "account_reference",
9596
+ "institution_name",
9597
+ "payer_name",
9598
+ "destination_currency",
9599
+ "created_at",
9600
+ "payout_destination",
9601
+ "quote"
9602
+ ]
9603
+ }
9604
+ },
9605
+ page_info: {
9606
+ type: "object",
9607
+ properties: {
9608
+ has_next_page: {
9609
+ type: "boolean"
9610
+ },
9611
+ end_cursor: {
9612
+ type: [
9613
+ "string",
9614
+ "null"
9615
+ ]
9616
+ },
9617
+ has_previous_page: {
9618
+ type: "boolean"
9619
+ },
9620
+ start_cursor: {
9621
+ type: [
9622
+ "string",
9623
+ "null"
9624
+ ]
9625
+ }
9626
+ },
9627
+ required: [
9628
+ "has_next_page",
9629
+ "end_cursor",
9630
+ "has_previous_page",
9631
+ "start_cursor"
9632
+ ]
9633
+ }
9634
+ },
9635
+ required: [
9636
+ "data",
9637
+ "page_info"
9638
+ ]
9639
+ }
9640
+ }
9641
+ }
9642
+ },
9643
+ "400": {
9644
+ description: "neither account_id nor user_id provided",
9645
+ $ref: "#/components/responses/InvalidParameters"
9646
+ },
9647
+ "401": {
9648
+ description: "missing or invalid authentication",
9649
+ $ref: "#/components/responses/Unauthorized"
9650
+ },
9651
+ "403": {
9652
+ description: "credential lacks the destination-read scope",
9653
+ $ref: "#/components/responses/Forbidden"
9654
+ },
9655
+ "404": {
9656
+ description: "no ledger for that owner is visible to the credential",
9657
+ $ref: "#/components/responses/NotFound"
9658
+ }
9659
+ }
9660
+ }
9661
+ },
9192
9662
  "/payouts": {
9193
9663
  get: {
9194
9664
  summary: "List Payouts",
@@ -11464,7 +11934,7 @@ var native_spec_default = {
11464
11934
  "string",
11465
11935
  "null"
11466
11936
  ],
11467
- description: "The unique identifier of the tax classification code."
11937
+ description: "The unique identifier of the tax classification code. See the available [product categories](https://docs.numeral.com/essentials/product-categories)."
11468
11938
  },
11469
11939
  redirect_purchase_url: {
11470
11940
  type: [
@@ -11479,6 +11949,13 @@ var native_spec_default = {
11479
11949
  "null"
11480
11950
  ],
11481
11951
  description: "Whether to collect a shipping address at checkout."
11952
+ },
11953
+ send_welcome_message: {
11954
+ type: [
11955
+ "boolean",
11956
+ "null"
11957
+ ],
11958
+ description: "Whether to send an automated welcome message via support chat when a user joins this product. Defaults to true."
11482
11959
  }
11483
11960
  },
11484
11961
  required: [
@@ -11623,7 +12100,14 @@ var native_spec_default = {
11623
12100
  "string",
11624
12101
  "null"
11625
12102
  ],
11626
- description: "The unique identifier of the tax classification code."
12103
+ description: "The unique identifier of the tax classification code. See the available [product categories](https://docs.numeral.com/essentials/product-categories)."
12104
+ },
12105
+ send_welcome_message: {
12106
+ type: [
12107
+ "boolean",
12108
+ "null"
12109
+ ],
12110
+ description: "Whether to send an automated welcome message via support chat when a user joins this product."
11627
12111
  }
11628
12112
  }
11629
12113
  }
@@ -16865,12 +17349,13 @@ var native_spec_default = {
16865
17349
  "payment_failed",
16866
17350
  "all_ads_rejected",
16867
17351
  "draft",
17352
+ "no_ad_groups",
17353
+ "no_ads",
16868
17354
  "paused",
17355
+ "processing",
16869
17356
  "issues",
16870
17357
  "scheduled",
16871
17358
  "completed",
16872
- "no_ad_groups",
16873
- "no_ads",
16874
17359
  "ad_groups_off",
16875
17360
  "active"
16876
17361
  ],
@@ -17307,13 +17792,13 @@ var native_spec_default = {
17307
17792
  enum: [
17308
17793
  "all_ads_rejected",
17309
17794
  "rejected",
17795
+ "no_ads",
17310
17796
  "campaign_paused",
17311
17797
  "paused",
17312
17798
  "processing",
17313
17799
  "issues",
17314
17800
  "scheduled",
17315
17801
  "completed",
17316
- "no_ads",
17317
17802
  "ads_off",
17318
17803
  "learning_limited",
17319
17804
  "learning",
@@ -26341,35 +26826,16 @@ var Identity = external_exports.object({
26341
26826
  route: external_exports.string().optional().describe("The account's public route"),
26342
26827
  email: external_exports.string().optional().describe("User email address (oauth only)")
26343
26828
  });
26344
- var Profile = external_exports.preprocess(
26345
- (value) => {
26346
- if (!value || typeof value !== "object" || Array.isArray(value))
26347
- return value;
26348
- const profile = value;
26349
- return {
26350
- ...profile,
26351
- accountId: profile.accountId ?? profile.companyId,
26352
- accountTitle: profile.accountTitle ?? profile.companyTitle,
26353
- accountRoute: profile.accountRoute ?? profile.companyRoute,
26354
- companyId: profile.accountId ?? profile.companyId,
26355
- companyTitle: profile.accountTitle ?? profile.companyTitle,
26356
- companyRoute: profile.accountRoute ?? profile.companyRoute
26357
- };
26358
- },
26359
- external_exports.object({
26360
- name: external_exports.string().describe("The local profile name"),
26361
- method: AuthMethod,
26362
- accountId: external_exports.string().optional(),
26363
- accountTitle: external_exports.string().optional(),
26364
- accountRoute: external_exports.string().optional(),
26365
- companyId: external_exports.string().optional(),
26366
- companyTitle: external_exports.string().optional(),
26367
- companyRoute: external_exports.string().optional(),
26368
- userId: external_exports.string().optional(),
26369
- userEmail: external_exports.string().optional(),
26370
- createdAt: external_exports.string().describe("ISO timestamp of when the profile was first created")
26371
- })
26372
- );
26829
+ var Profile = external_exports.object({
26830
+ name: external_exports.string().describe("The local profile name"),
26831
+ method: AuthMethod,
26832
+ accountId: external_exports.string().optional(),
26833
+ accountTitle: external_exports.string().optional(),
26834
+ accountRoute: external_exports.string().optional(),
26835
+ userId: external_exports.string().optional(),
26836
+ userEmail: external_exports.string().optional(),
26837
+ createdAt: external_exports.string().describe("ISO timestamp of when the profile was first created")
26838
+ });
26373
26839
 
26374
26840
  // src/auth/config.ts
26375
26841
  var Config = external_exports.object({
@@ -26774,17 +27240,17 @@ async function promptApiKey() {
26774
27240
  });
26775
27241
  return ensure(key).trim();
26776
27242
  }
26777
- async function selectCompany(companies) {
27243
+ async function selectAccount(accounts) {
26778
27244
  const id = await select({
26779
27245
  message: "Which business account do you want to use?",
26780
- options: companies.map((company) => ({
26781
- value: company.id,
26782
- label: company.title,
26783
- hint: company.id
27246
+ options: accounts.map((account) => ({
27247
+ value: account.id,
27248
+ label: account.title,
27249
+ hint: account.id
26784
27250
  }))
26785
27251
  });
26786
27252
  const chosen = ensure(id);
26787
- const match = companies.find((company) => company.id === chosen);
27253
+ const match = accounts.find((account) => account.id === chosen);
26788
27254
  if (!match) {
26789
27255
  throw new Error(
26790
27256
  `Selected business account "${chosen}" is no longer available.`
@@ -26852,7 +27318,9 @@ var WHOP_SCOPES = [
26852
27318
  "courses:update",
26853
27319
  "custom_emoji:update",
26854
27320
  "developer:basic:read",
27321
+ "developer:create_app",
26855
27322
  "developer:manage_builds",
27323
+ "developer:update_app",
26856
27324
  "dms:channel:manage",
26857
27325
  "dms:message:manage",
26858
27326
  "dms:read",
@@ -27026,61 +27494,61 @@ var OAuthError = class extends Error {
27026
27494
  this.name = "OAuthError";
27027
27495
  }
27028
27496
  };
27029
- async function resolveOAuthCompany(accessToken, opts) {
27497
+ async function resolveOAuthAccount(accessToken, opts) {
27030
27498
  const whop = new Whop2({ apiKey: accessToken, baseURL: apiBaseUrl() });
27031
27499
  const s = opts.agent ? null : startSpinner("Loading your business accounts\u2026");
27032
- const MAX_COMPANIES = 1e3;
27033
- const companies = [];
27500
+ const MAX_ACCOUNTS = 1e3;
27501
+ const accounts = [];
27034
27502
  try {
27035
- for await (const company of whop.companies.list({ first: 100 })) {
27036
- companies.push({
27037
- id: company.id,
27038
- title: company.title,
27039
- route: company.route
27503
+ for await (const account of whop.companies.list({ first: 100 })) {
27504
+ accounts.push({
27505
+ id: account.id,
27506
+ title: account.title,
27507
+ route: account.route
27040
27508
  });
27041
- if (opts.companyId && company.id === opts.companyId) break;
27042
- if (companies.length >= MAX_COMPANIES) break;
27509
+ if (opts.accountId && account.id === opts.accountId) break;
27510
+ if (accounts.length >= MAX_ACCOUNTS) break;
27043
27511
  }
27044
27512
  } catch {
27045
27513
  s?.stop("Couldn't load your business accounts.");
27046
- if (opts.companyId) {
27514
+ if (opts.accountId) {
27047
27515
  throw new OAuthError(
27048
- "COMPANY_LOOKUP_FAILED",
27049
- `Couldn't load your business accounts to verify "${opts.companyId}". Please try again.`
27516
+ "ACCOUNT_LOOKUP_FAILED",
27517
+ `Couldn't load your business accounts to verify "${opts.accountId}". Please try again.`
27050
27518
  );
27051
27519
  }
27052
27520
  return null;
27053
27521
  }
27054
- if (opts.companyId) {
27055
- const match = companies.find((company) => company.id === opts.companyId);
27522
+ if (opts.accountId) {
27523
+ const match = accounts.find((account) => account.id === opts.accountId);
27056
27524
  if (!match) {
27057
27525
  s?.stop("");
27058
- const available = companies.length ? companies.map((company) => company.id).join(", ") : "none \u2014 this user has no business accounts yet";
27526
+ const available = accounts.length ? accounts.map((account) => account.id).join(", ") : "none \u2014 this user has no business accounts yet";
27059
27527
  throw new OAuthError(
27060
- "COMPANY_NOT_FOUND",
27061
- `No business account "${opts.companyId}" for this user. Available: ${available}.`
27528
+ "ACCOUNT_NOT_FOUND",
27529
+ `No business account "${opts.accountId}" for this user. Available: ${available}.`
27062
27530
  );
27063
27531
  }
27064
27532
  s?.stop(`Using ${match.title}.`);
27065
27533
  return match;
27066
27534
  }
27067
- if (companies.length === 0) {
27535
+ if (accounts.length === 0) {
27068
27536
  s?.stop("No business account found on your account.");
27069
27537
  return null;
27070
27538
  }
27071
- if (companies.length === 1) {
27072
- s?.stop(`Using ${companies[0].title}.`);
27073
- return companies[0];
27539
+ if (accounts.length === 1) {
27540
+ s?.stop(`Using ${accounts[0].title}.`);
27541
+ return accounts[0];
27074
27542
  }
27075
27543
  if (opts.agent) {
27076
27544
  s?.stop("");
27077
27545
  throw new OAuthError(
27078
- "MULTIPLE_COMPANIES",
27079
- `You can manage ${companies.length} business accounts \u2014 pass --company-id to choose one: ${companies.map((company) => `${company.id} (${company.title})`).join(", ")}.`
27546
+ "MULTIPLE_ACCOUNTS",
27547
+ `You can manage ${accounts.length} business accounts \u2014 pass --account-id to choose one: ${accounts.map((account) => `${account.id} (${account.title})`).join(", ")}.`
27080
27548
  );
27081
27549
  }
27082
- s?.stop(`Found ${companies.length} business accounts.`);
27083
- return selectCompany(companies);
27550
+ s?.stop(`Found ${accounts.length} business accounts.`);
27551
+ return selectAccount(accounts);
27084
27552
  }
27085
27553
  async function performOAuthLogin(input) {
27086
27554
  const { verifier, challenge } = generatePKCE();
@@ -27115,7 +27583,7 @@ ${authUrl}`);
27115
27583
  }
27116
27584
  const base = oauthBaseUrl();
27117
27585
  let identity = {};
27118
- let companyIdentity = null;
27586
+ let accountIdentity = null;
27119
27587
  try {
27120
27588
  const res = await fetch(`${base}/oauth/userinfo`, {
27121
27589
  headers: { Authorization: `Bearer ${tokens.accessToken}` }
@@ -27126,9 +27594,9 @@ ${authUrl}`);
27126
27594
  }
27127
27595
  } catch {
27128
27596
  }
27129
- companyIdentity = await resolveOAuthCompany(tokens.accessToken, {
27597
+ accountIdentity = await resolveOAuthAccount(tokens.accessToken, {
27130
27598
  agent: input.agent ?? false,
27131
- companyId: input.companyId
27599
+ accountId: input.accountId
27132
27600
  });
27133
27601
  const name = input.profile ?? deriveProfileName(identity);
27134
27602
  const existed = listProfiles().some((p) => p.name === name);
@@ -27140,7 +27608,7 @@ ${authUrl}`);
27140
27608
  method: "oauth",
27141
27609
  secret: tokens.refreshToken,
27142
27610
  identity,
27143
- companyIdentity: companyIdentity ?? void 0,
27611
+ accountIdentity: accountIdentity ?? void 0,
27144
27612
  accessToken: tokens.accessToken,
27145
27613
  tokenExpiresAt
27146
27614
  });
@@ -27219,16 +27687,13 @@ function upsertProfile(input, env = process.env) {
27219
27687
  (profile2) => profile2.name === input.name
27220
27688
  );
27221
27689
  const isOauth = input.method === "oauth";
27222
- const account = isOauth ? input.companyIdentity : input.identity;
27690
+ const account = isOauth ? input.accountIdentity : input.identity;
27223
27691
  const profile = {
27224
27692
  name: input.name,
27225
27693
  method: input.method,
27226
27694
  accountId: account?.id,
27227
27695
  accountTitle: account?.title,
27228
27696
  accountRoute: account?.route,
27229
- companyId: account?.id,
27230
- companyTitle: account?.title,
27231
- companyRoute: account?.route,
27232
27697
  userId: isOauth ? input.identity.id : void 0,
27233
27698
  userEmail: isOauth ? input.identity.email : void 0,
27234
27699
  createdAt: existing?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString()
@@ -27247,6 +27712,17 @@ function upsertProfile(input, env = process.env) {
27247
27712
  setSecret(input.name, secret);
27248
27713
  return profile;
27249
27714
  }
27715
+ function setActiveProfileAccount(identity, env = process.env) {
27716
+ const config = readConfig(env);
27717
+ const profile = config.profiles.find(
27718
+ (candidate) => candidate.name === config.activeProfile
27719
+ );
27720
+ if (!profile) return;
27721
+ profile.accountId = identity.id;
27722
+ profile.accountTitle = identity.title;
27723
+ profile.accountRoute = identity.route;
27724
+ writeConfig(config, env);
27725
+ }
27250
27726
  function removeProfile(name, env = process.env) {
27251
27727
  const config = readConfig(env);
27252
27728
  const existed = config.profiles.some((profile) => profile.name === name);
@@ -27353,7 +27829,7 @@ function filterSpecByTag(spec, tag) {
27353
27829
  }
27354
27830
  return { ...spec, paths };
27355
27831
  }
27356
- var COMPANY_FIELDS = ["company_id", "account_id"];
27832
+ var ACCOUNT_FIELDS = ["company_id", "account_id"];
27357
27833
  function findOperation(method, pathname) {
27358
27834
  const paths = native_spec_default.paths;
27359
27835
  if (!paths) return null;
@@ -27388,28 +27864,28 @@ function extractApiMessage(payload) {
27388
27864
  }
27389
27865
  return void 0;
27390
27866
  }
27391
- var envCompanyId = null;
27867
+ var envAccountId = null;
27392
27868
  function normalizeApiKey(key) {
27393
27869
  return key.replace(/^Bearer\s+/i, "").trim();
27394
27870
  }
27395
- async function resolveCompanyId(profile, apiKey) {
27396
- if (profile?.companyId) return profile.companyId;
27871
+ async function resolveAccountId(profile, apiKey) {
27872
+ if (profile?.accountId) return profile.accountId;
27397
27873
  const envKey = process.env.WHOP_API_KEY ? normalizeApiKey(process.env.WHOP_API_KEY) : void 0;
27398
27874
  if (!profile && envKey && apiKey === envKey) {
27399
- envCompanyId ??= validateApiKey(envKey, apiBaseUrl()).then(
27875
+ envAccountId ??= validateApiKey(envKey, apiBaseUrl()).then(
27400
27876
  (result) => result.status === "valid" || result.status === "underscoped" ? result.identity.id : void 0
27401
27877
  ).catch(() => void 0);
27402
- const resolved = await envCompanyId;
27403
- if (resolved === void 0) envCompanyId = null;
27878
+ const resolved = await envAccountId;
27879
+ if (resolved === void 0) envAccountId = null;
27404
27880
  return resolved;
27405
27881
  }
27406
27882
  return void 0;
27407
27883
  }
27408
- async function resolveActiveCompanyId() {
27884
+ async function resolveActiveAccountId() {
27409
27885
  const profile = getActiveProfile();
27410
27886
  const rawKey = profile ? await getValidAccessToken(profile) : process.env.WHOP_API_KEY ?? null;
27411
27887
  if (!rawKey) return void 0;
27412
- return resolveCompanyId(profile, normalizeApiKey(rawKey));
27888
+ return resolveAccountId(profile, normalizeApiKey(rawKey));
27413
27889
  }
27414
27890
  function createWhopFetch() {
27415
27891
  return async (request) => {
@@ -27422,14 +27898,14 @@ function createWhopFetch() {
27422
27898
  const token = normalizeApiKey(rawKey);
27423
27899
  const incomingUrl = new URL(request.url);
27424
27900
  const op = findOperation(request.method, incomingUrl.pathname);
27425
- const companyId = await resolveCompanyId(profile, token);
27901
+ const accountId = await resolveAccountId(profile, token);
27426
27902
  const method = request.method.toUpperCase();
27427
27903
  let body = request.body ? await request.text() : void 0;
27428
- if (op && companyId) {
27904
+ if (op && accountId) {
27429
27905
  if (method === "GET" || method === "DELETE" || method === "HEAD") {
27430
- for (const name of COMPANY_FIELDS) {
27906
+ for (const name of ACCOUNT_FIELDS) {
27431
27907
  if (!incomingUrl.searchParams.has(name) && declaresQueryParam(op, name)) {
27432
- incomingUrl.searchParams.set(name, companyId);
27908
+ incomingUrl.searchParams.set(name, accountId);
27433
27909
  }
27434
27910
  }
27435
27911
  } else {
@@ -27437,10 +27913,10 @@ function createWhopFetch() {
27437
27913
  if (parsed && typeof parsed === "object") {
27438
27914
  const rec = parsed;
27439
27915
  let changed = false;
27440
- for (const name of COMPANY_FIELDS) {
27916
+ for (const name of ACCOUNT_FIELDS) {
27441
27917
  if (name === "company_id" && rec.plan_id != null) continue;
27442
27918
  if (rec[name] == null && declaresBodyProp(op, name)) {
27443
- rec[name] = companyId;
27919
+ rec[name] = accountId;
27444
27920
  changed = true;
27445
27921
  }
27446
27922
  }
@@ -27500,11 +27976,12 @@ export {
27500
27976
  getActiveProfile,
27501
27977
  deriveProfileName,
27502
27978
  upsertProfile,
27979
+ setActiveProfileAccount,
27503
27980
  removeProfile,
27504
27981
  removeAllProfiles,
27505
27982
  switchProfile,
27506
27983
  filterSpecByTag,
27507
- resolveActiveCompanyId,
27984
+ resolveActiveAccountId,
27508
27985
  createWhopFetch
27509
27986
  };
27510
- //# sourceMappingURL=chunk-ET6QSHSA.js.map
27987
+ //# sourceMappingURL=chunk-2Y4EKBOD.js.map