@roxyon/api-client 0.4.0 → 0.5.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.
package/dist/index.cjs CHANGED
@@ -501,7 +501,7 @@ var BillingApi = class {
501
501
  {
502
502
  className: "Pricing",
503
503
  field: "Plan",
504
- fields: "Prices,SetupFee,MetaData",
504
+ fields: "Prices,SetupFee,MetaData,IsActive",
505
505
  reverse: 1
506
506
  }
507
507
  ]
@@ -512,18 +512,20 @@ var BillingApi = class {
512
512
  const out = [];
513
513
  for (const p of r.results) {
514
514
  const pricing = p._Pricing?.results?.[0];
515
- if (!pricing) continue;
515
+ if (!p.Code || !pricing || Number(pricing.IsActive) === 0) continue;
516
516
  const limits = json(p.Limits, {});
517
517
  const features = json(p.Features, {});
518
518
  const meta = json(pricing.MetaData, {});
519
519
  const network = json(features.Network, {});
520
520
  const setup = numbers(pricing.SetupFee);
521
+ const pricesUSD = numbers(pricing.Prices);
522
+ if (pricesUSD.monthly === void 0) continue;
521
523
  const product = {
522
524
  planId: p.objectId,
523
525
  sku: p.Code ?? "",
524
526
  name: p.Name ?? "",
525
527
  category: p._Service?.results?.[0]?.Type ?? "",
526
- pricesUSD: numbers(pricing.Prices),
528
+ pricesUSD,
527
529
  stock: String(meta.stock ?? "in").toLowerCase() === "out" ? "out" : "in"
528
530
  };
529
531
  if (limits.vcpu != null) {
@@ -575,6 +577,16 @@ var BillingApi = class {
575
577
  baseAmountUSD: String(r.baseAmount ?? "")
576
578
  };
577
579
  }
580
+ /**
581
+ * A new order for the caller (POST /account/order): dry run unless `confirm`. The engine prices and creates it
582
+ * (Subscription in payment + pending invoice); a person pays at `payUrl`. Needs a session or a PAT with the
583
+ * `billing:order` scope, within that token's monthly budget and allowed SKUs.
584
+ */
585
+ async order(input) {
586
+ const r = await this.client.console("POST", "/account/order", { body: input, tolerateHttpError: true });
587
+ if (!r?.ok) throw new RoxyonApiError(r?.error || "The order was not placed.", { body: r });
588
+ return r;
589
+ }
578
590
  /** The caller's own subscriptions (rows they own), newest first. */
579
591
  async subscriptions() {
580
592
  const r = await this.client.console("GET", "/account/subscriptions", { tolerateHttpError: true });
@@ -760,7 +772,11 @@ var RoxyonClient = class _RoxyonClient {
760
772
  try {
761
773
  json2 = text ? JSON.parse(text) : {};
762
774
  } catch {
763
- json2 = { error: text || `HTTP ${res.status}`, _raw: text };
775
+ const html = /^\s*</.test(text);
776
+ json2 = {
777
+ error: html ? `${method} ${path} is not available on this server yet (got a web page instead of the API).` : text || `HTTP ${res.status}`,
778
+ _raw: html ? "" : text
779
+ };
764
780
  }
765
781
  if (!res.ok && !opts.tolerateHttpError) {
766
782
  const msg = json2 && typeof json2 === "object" && "error" in json2 && json2.error || `HTTP ${res.status} calling ${method} ${path}`;
@@ -1029,7 +1045,9 @@ var TokensApi = class {
1029
1045
  body: {
1030
1046
  name,
1031
1047
  scopes: opts.scopes ?? ["deploy", "logs"],
1032
- ...opts.expiresInDays ? { expiresInDays: opts.expiresInDays } : {}
1048
+ ...opts.expiresInDays ? { expiresInDays: opts.expiresInDays } : {},
1049
+ ...opts.monthlyBudgetUSD ? { monthlyBudgetUSD: opts.monthlyBudgetUSD } : {},
1050
+ ...opts.allowedSkus?.length ? { allowedSkus: opts.allowedSkus } : {}
1033
1051
  },
1034
1052
  tolerateHttpError: true
1035
1053
  }