@roxyon/api-client 0.4.0 → 0.6.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}`;
@@ -788,14 +804,14 @@ var DatabasesApi = class {
788
804
  this.client = client;
789
805
  }
790
806
  client;
807
+ /** `POST /databases/list` — through the console, because PAT/OAuth callers can't read /Databases directly. */
791
808
  async list(subscriptionId) {
792
- const r = await this.client.get("/Databases", {
793
- fields: "objectId,Name,Username,Status",
794
- limit: -1,
795
- order: "-createdAt",
796
- where: { Subscription: subscriptionId, eye: { in: "1,0" } }
809
+ const r = await this.client.console("POST", "/databases/list", {
810
+ body: { subscription: subscriptionId },
811
+ tolerateHttpError: true
797
812
  });
798
- return r.results ?? [];
813
+ if (!r?.ok) throw new RoxyonApiError(r?.error || "Could not list the databases.", { body: r });
814
+ return r.databases ?? [];
799
815
  }
800
816
  /** `POST /databases/create` — provision a database + user; the reconciler does the rest. */
801
817
  async create(input) {
@@ -853,14 +869,11 @@ var EmailApi = class {
853
869
  this.client = client;
854
870
  }
855
871
  client;
872
+ /** `POST /emails/list` — through the console, because PAT/OAuth callers can't read /Emails directly. */
856
873
  async list(subscriptionId) {
857
- const r = await this.client.get("/Emails", {
858
- fields: "objectId,Email,LocalPart,Status,Quota",
859
- limit: -1,
860
- order: "-createdAt",
861
- where: { Subscription: subscriptionId, eye: { in: "1,0" } }
862
- });
863
- return r.results ?? [];
874
+ const r = await this.client.console("POST", "/emails/list", { body: { subscription: subscriptionId }, tolerateHttpError: true });
875
+ if (!r?.ok) throw new RoxyonApiError(r?.error || "Could not list the mailboxes.", { body: r });
876
+ return (r.emails ?? []).map((e) => ({ ...e, LocalPart: e.Email.split("@")[0] ?? "" }));
864
877
  }
865
878
  /** `POST /emails/create` — provision a mailbox; the reconciler does the rest. */
866
879
  async create(input) {
@@ -1029,7 +1042,9 @@ var TokensApi = class {
1029
1042
  body: {
1030
1043
  name,
1031
1044
  scopes: opts.scopes ?? ["deploy", "logs"],
1032
- ...opts.expiresInDays ? { expiresInDays: opts.expiresInDays } : {}
1045
+ ...opts.expiresInDays ? { expiresInDays: opts.expiresInDays } : {},
1046
+ ...opts.monthlyBudgetUSD ? { monthlyBudgetUSD: opts.monthlyBudgetUSD } : {},
1047
+ ...opts.allowedSkus?.length ? { allowedSkus: opts.allowedSkus } : {}
1033
1048
  },
1034
1049
  tolerateHttpError: true
1035
1050
  }