@roxyon/api-client 0.3.0 → 0.4.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.d.cts CHANGED
@@ -59,6 +59,9 @@ declare class RoxyonClient {
59
59
  private sessionToken?;
60
60
  private anon?;
61
61
  constructor(opts?: RoxyonClientOptions);
62
+ /** Same endpoints and app, no user credentials: for public reads (catalog, quotes)
63
+ * that must work for PAT callers too, whose token the BaaS does not accept. */
64
+ publicClient(): RoxyonClient;
62
65
  getSessionToken(): string | undefined;
63
66
  setSessionToken(token: string | undefined): void;
64
67
  /** Mint (or reuse) an anonymous access token from the public app credentials. */
@@ -364,6 +367,107 @@ declare class AuthApi {
364
367
  logout(): Promise<void>;
365
368
  }
366
369
 
370
+ /** Billing cycles the checkout accepts (Pricing::CYCLE_MONTHS). */
371
+ declare const BILLING_CYCLES: readonly ["monthly", "quarterly", "yearly", "biennial"];
372
+ type BillingCycle = (typeof BILLING_CYCLES)[number];
373
+ interface CatalogProduct {
374
+ /** Plan objectId: what quotes and orders take. */
375
+ planId: string;
376
+ /** Plan code, e.g. `SCALE-S`. */
377
+ sku: string;
378
+ name: string;
379
+ /** Service type, e.g. `cloud.vps.scale`, `cloud.hosting.solo`. */
380
+ category: string;
381
+ vcpu?: number;
382
+ ramGb?: number;
383
+ diskGb?: number;
384
+ cpuType?: string;
385
+ /** Dedicated IPv4 addresses included (servers). */
386
+ ipv4Included?: number;
387
+ /** List prices in USD before tax, per cycle. Quote for the buyer's currency and tax. */
388
+ pricesUSD: Partial<Record<BillingCycle, number>>;
389
+ /** Setup fee in USD per cycle, when not zero. */
390
+ setupFeeUSD?: Partial<Record<BillingCycle, number>>;
391
+ /** `out` = cannot be ordered right now. */
392
+ stock: 'in' | 'out';
393
+ /** Feature table as the console shows it. */
394
+ features?: Record<string, unknown>;
395
+ }
396
+ interface QuoteInput {
397
+ planId: string;
398
+ cycle: BillingCycle;
399
+ /** ISO 4217, e.g. `SAR`. Default USD. */
400
+ currency?: string;
401
+ /** ISO 3166 alpha-2, decides tax (e.g. `SA` = 15% VAT). Empty = no tax line. */
402
+ country?: string;
403
+ }
404
+ interface Quote {
405
+ planId: string;
406
+ cycle: string;
407
+ currency: string;
408
+ lineItems: Array<{
409
+ label: string;
410
+ amount: string;
411
+ amountUSD: string;
412
+ }>;
413
+ subtotal: string;
414
+ taxRate: string;
415
+ taxLabel: string;
416
+ taxAmount: string;
417
+ discountAmount: string;
418
+ total: string;
419
+ fxRate: string;
420
+ baseAmountUSD: string;
421
+ }
422
+ interface BillingSubscription {
423
+ id: string;
424
+ name: string;
425
+ status: string;
426
+ plan: string;
427
+ sku: string;
428
+ cycle: string;
429
+ price: string;
430
+ currency: string;
431
+ nextBillingDate: string | null;
432
+ autoRenew: boolean;
433
+ serverState: string | null;
434
+ publicIp: string | null;
435
+ }
436
+ interface Invoice {
437
+ id: string;
438
+ number: string;
439
+ type: string;
440
+ status: string;
441
+ total: string;
442
+ currency: string;
443
+ dueDate: string | null;
444
+ subscription: string | null;
445
+ createdAt: string;
446
+ payUrl: string | null;
447
+ }
448
+ /** Invoice statuses a customer can still pay. */
449
+ declare const PAYABLE_STATUSES: readonly ["pending", "overdue", "failed"];
450
+ declare function isPayable(status: string): boolean;
451
+ /**
452
+ * Catalog + quotes (public, no sign-in) and the caller's own subscriptions + invoices
453
+ * (console, session or PAT). Read-only: nothing here creates orders or invoices.
454
+ */
455
+ declare class BillingApi {
456
+ private readonly client;
457
+ private readonly pub;
458
+ constructor(client: RoxyonClient, pub?: RoxyonClient);
459
+ catalog(): Promise<CatalogProduct[]>;
460
+ /** What checkout would charge for a new subscription: the server's own pricing (GET /_payment/quote). */
461
+ quote(input: QuoteInput): Promise<Quote>;
462
+ /** The caller's own subscriptions (rows they own), newest first. */
463
+ subscriptions(): Promise<BillingSubscription[]>;
464
+ /** The caller's own invoices, newest first. */
465
+ invoices(opts?: {
466
+ status?: string;
467
+ limit?: number;
468
+ }): Promise<Invoice[]>;
469
+ }
470
+
367
471
  interface CreateDatabaseInput {
368
472
  /** DB name suffix — the platform prefixes it with the subscription's own username (globally unique). */
369
473
  name: string;
@@ -586,6 +690,76 @@ declare class SubscriptionsApi {
586
690
  resolve(userId: string, preferred?: string): Promise<Subscription>;
587
691
  }
588
692
 
693
+ /** BaaS V2 base. V1 (`/1`) is frozen; app data tools speak V2 only. */
694
+ declare const DEFAULT_BAAS_V2_URL = "https://www.beaapis.com/2";
695
+ /** V2 caps one page at 200 rows. */
696
+ declare const BAAS_MAX_PAGE = 200;
697
+ /** V2 takes 1 to 50 requests per batch. */
698
+ declare const BAAS_MAX_BATCH = 50;
699
+ interface BaasDataOptions {
700
+ /** The app's secret key (`rxsk_…`): server scope, from the project's API keys in Roxyon Base. */
701
+ secretKey: string;
702
+ baseUrl?: string;
703
+ fetch?: typeof fetch;
704
+ }
705
+ type BaasRow = Record<string, unknown>;
706
+ interface BaasQuery {
707
+ /** e.g. `{ Status: 'active', Age: { gt: 18 } }`; `in` takes a comma-joined string. */
708
+ where?: Record<string, unknown>;
709
+ /** `*` and/or column names, comma separated. Defaults to `*`. */
710
+ fields?: string;
711
+ /** Comma list, `-` for descending, e.g. `-createdAt`. */
712
+ order?: string;
713
+ /** 1 to 200 (default 50). */
714
+ limit?: number;
715
+ skip?: number;
716
+ /** Also return the total number of matching rows. */
717
+ count?: boolean;
718
+ }
719
+ interface BaasBatchRequest {
720
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE';
721
+ /** `/Class` or `/Class/<id>`. */
722
+ path: string;
723
+ body?: Record<string, unknown>;
724
+ }
725
+ /** One batch answer: `ok:false` with `error`/`message`, or that request's own V2 answer. */
726
+ interface BaasBatchResult {
727
+ status: number;
728
+ ok?: boolean;
729
+ error?: string;
730
+ message?: string;
731
+ result?: BaasRow;
732
+ results?: BaasRow[];
733
+ count?: number;
734
+ id?: string;
735
+ }
736
+ /**
737
+ * Records of ONE app on BaaS V2, as that app's own backend (server scope, `X-RX-Secret-Key`).
738
+ * Server scope passes every class rule, so treat the key like a database password. V2 answers
739
+ * failures as `{ok:false, error, message}` with an HTTP status; every call throws on those.
740
+ * Schema changes are not reachable with a secret key (console API only).
741
+ */
742
+ declare class BaasDataApi {
743
+ private readonly baseUrl;
744
+ private readonly secretKey;
745
+ private readonly _fetch;
746
+ constructor(opts: BaasDataOptions);
747
+ private call;
748
+ private static recordPath;
749
+ query(className: string, q?: BaasQuery): Promise<{
750
+ rows: BaasRow[];
751
+ count?: number;
752
+ }>;
753
+ get(className: string, objectId: string): Promise<BaasRow>;
754
+ /** Returns the created row as stored. */
755
+ create(className: string, data: BaasRow): Promise<BaasRow>;
756
+ update(className: string, objectId: string, data: BaasRow): Promise<BaasRow>;
757
+ /** The id goes in the URL path, never the body. */
758
+ delete(className: string, objectId: string): Promise<void>;
759
+ /** 1 to 50 record requests in one call; one failing doesn't stop the others. */
760
+ batch(requests: BaasBatchRequest[]): Promise<BaasBatchResult[]>;
761
+ }
762
+
589
763
  /** Returns the error message from a BaaS response, or `''` when the call worked. */
590
764
  declare function rxError(r: unknown): string;
591
765
  declare class RoxyonApiError extends Error {
@@ -695,8 +869,9 @@ declare class Roxyon {
695
869
  readonly databases: DatabasesApi;
696
870
  readonly email: EmailApi;
697
871
  readonly ssh: SshApi;
872
+ readonly billing: BillingApi;
698
873
  constructor(options?: RoxyonClientOptions | RoxyonClient);
699
874
  get sessionToken(): string | undefined;
700
875
  }
701
876
 
702
- export { AccountApi, type AccountApp, type AccountContext, type AccountDomain, type AccountSubscription, type Application, type ApplicationProcess, type ApplicationRoute, ApplicationsApi, AuthApi, type CreateApplicationInput, type CreateDatabaseInput, type CreateDatabaseResult, type CreateDomainInput, type CreateDomainResult, type CreateEmailInput, type CreateEmailResult, type CreateOnDeploy, type CreatedToken, DEFAULT_APP, DEFAULT_BAAS_URL, DEFAULT_CONSOLE_URL, type DatabaseSummary, DatabasesApi, type DeleteDatabaseResult, type DeleteEmailResult, type DeployKind, type DeployOptions, type DeployResult, type Domain, DomainsApi, EmailApi, type EmailSummary, LUMEN_BUILD, type LoginPrecheck, type LoginResult, type Privilege, RUNTIMES, type RequestOptions, type ResetSshPasswordInput, type ResetSshPasswordResult, Roxyon, RoxyonApiError, RoxyonClient, type RoxyonClientOptions, type RoxyonUser, type RuntimeName, type RuntimeSpec, type SessionGrant, type SiteFile, type SiteFileContent, SitesApi, SshApi, type StaticDeployResult, type Subscription, SubscriptionsApi, type TokenScope, type TokenSummary, TokensApi, assertOk, envFromStored, formatEnv, isAuthError, parseEnv, rxError, toQueryString };
877
+ export { AccountApi, type AccountApp, type AccountContext, type AccountDomain, type AccountSubscription, type Application, type ApplicationProcess, type ApplicationRoute, ApplicationsApi, AuthApi, BAAS_MAX_BATCH, BAAS_MAX_PAGE, BILLING_CYCLES, type BaasBatchRequest, type BaasBatchResult, BaasDataApi, type BaasDataOptions, type BaasQuery, type BaasRow, BillingApi, type BillingCycle, type BillingSubscription, type CatalogProduct, type CreateApplicationInput, type CreateDatabaseInput, type CreateDatabaseResult, type CreateDomainInput, type CreateDomainResult, type CreateEmailInput, type CreateEmailResult, type CreateOnDeploy, type CreatedToken, DEFAULT_APP, DEFAULT_BAAS_URL, DEFAULT_BAAS_V2_URL, DEFAULT_CONSOLE_URL, type DatabaseSummary, DatabasesApi, type DeleteDatabaseResult, type DeleteEmailResult, type DeployKind, type DeployOptions, type DeployResult, type Domain, DomainsApi, EmailApi, type EmailSummary, type Invoice, LUMEN_BUILD, type LoginPrecheck, type LoginResult, PAYABLE_STATUSES, type Privilege, type Quote, type QuoteInput, RUNTIMES, type RequestOptions, type ResetSshPasswordInput, type ResetSshPasswordResult, Roxyon, RoxyonApiError, RoxyonClient, type RoxyonClientOptions, type RoxyonUser, type RuntimeName, type RuntimeSpec, type SessionGrant, type SiteFile, type SiteFileContent, SitesApi, SshApi, type StaticDeployResult, type Subscription, SubscriptionsApi, type TokenScope, type TokenSummary, TokensApi, assertOk, envFromStored, formatEnv, isAuthError, isPayable, parseEnv, rxError, toQueryString };
package/dist/index.d.ts CHANGED
@@ -59,6 +59,9 @@ declare class RoxyonClient {
59
59
  private sessionToken?;
60
60
  private anon?;
61
61
  constructor(opts?: RoxyonClientOptions);
62
+ /** Same endpoints and app, no user credentials: for public reads (catalog, quotes)
63
+ * that must work for PAT callers too, whose token the BaaS does not accept. */
64
+ publicClient(): RoxyonClient;
62
65
  getSessionToken(): string | undefined;
63
66
  setSessionToken(token: string | undefined): void;
64
67
  /** Mint (or reuse) an anonymous access token from the public app credentials. */
@@ -364,6 +367,107 @@ declare class AuthApi {
364
367
  logout(): Promise<void>;
365
368
  }
366
369
 
370
+ /** Billing cycles the checkout accepts (Pricing::CYCLE_MONTHS). */
371
+ declare const BILLING_CYCLES: readonly ["monthly", "quarterly", "yearly", "biennial"];
372
+ type BillingCycle = (typeof BILLING_CYCLES)[number];
373
+ interface CatalogProduct {
374
+ /** Plan objectId: what quotes and orders take. */
375
+ planId: string;
376
+ /** Plan code, e.g. `SCALE-S`. */
377
+ sku: string;
378
+ name: string;
379
+ /** Service type, e.g. `cloud.vps.scale`, `cloud.hosting.solo`. */
380
+ category: string;
381
+ vcpu?: number;
382
+ ramGb?: number;
383
+ diskGb?: number;
384
+ cpuType?: string;
385
+ /** Dedicated IPv4 addresses included (servers). */
386
+ ipv4Included?: number;
387
+ /** List prices in USD before tax, per cycle. Quote for the buyer's currency and tax. */
388
+ pricesUSD: Partial<Record<BillingCycle, number>>;
389
+ /** Setup fee in USD per cycle, when not zero. */
390
+ setupFeeUSD?: Partial<Record<BillingCycle, number>>;
391
+ /** `out` = cannot be ordered right now. */
392
+ stock: 'in' | 'out';
393
+ /** Feature table as the console shows it. */
394
+ features?: Record<string, unknown>;
395
+ }
396
+ interface QuoteInput {
397
+ planId: string;
398
+ cycle: BillingCycle;
399
+ /** ISO 4217, e.g. `SAR`. Default USD. */
400
+ currency?: string;
401
+ /** ISO 3166 alpha-2, decides tax (e.g. `SA` = 15% VAT). Empty = no tax line. */
402
+ country?: string;
403
+ }
404
+ interface Quote {
405
+ planId: string;
406
+ cycle: string;
407
+ currency: string;
408
+ lineItems: Array<{
409
+ label: string;
410
+ amount: string;
411
+ amountUSD: string;
412
+ }>;
413
+ subtotal: string;
414
+ taxRate: string;
415
+ taxLabel: string;
416
+ taxAmount: string;
417
+ discountAmount: string;
418
+ total: string;
419
+ fxRate: string;
420
+ baseAmountUSD: string;
421
+ }
422
+ interface BillingSubscription {
423
+ id: string;
424
+ name: string;
425
+ status: string;
426
+ plan: string;
427
+ sku: string;
428
+ cycle: string;
429
+ price: string;
430
+ currency: string;
431
+ nextBillingDate: string | null;
432
+ autoRenew: boolean;
433
+ serverState: string | null;
434
+ publicIp: string | null;
435
+ }
436
+ interface Invoice {
437
+ id: string;
438
+ number: string;
439
+ type: string;
440
+ status: string;
441
+ total: string;
442
+ currency: string;
443
+ dueDate: string | null;
444
+ subscription: string | null;
445
+ createdAt: string;
446
+ payUrl: string | null;
447
+ }
448
+ /** Invoice statuses a customer can still pay. */
449
+ declare const PAYABLE_STATUSES: readonly ["pending", "overdue", "failed"];
450
+ declare function isPayable(status: string): boolean;
451
+ /**
452
+ * Catalog + quotes (public, no sign-in) and the caller's own subscriptions + invoices
453
+ * (console, session or PAT). Read-only: nothing here creates orders or invoices.
454
+ */
455
+ declare class BillingApi {
456
+ private readonly client;
457
+ private readonly pub;
458
+ constructor(client: RoxyonClient, pub?: RoxyonClient);
459
+ catalog(): Promise<CatalogProduct[]>;
460
+ /** What checkout would charge for a new subscription: the server's own pricing (GET /_payment/quote). */
461
+ quote(input: QuoteInput): Promise<Quote>;
462
+ /** The caller's own subscriptions (rows they own), newest first. */
463
+ subscriptions(): Promise<BillingSubscription[]>;
464
+ /** The caller's own invoices, newest first. */
465
+ invoices(opts?: {
466
+ status?: string;
467
+ limit?: number;
468
+ }): Promise<Invoice[]>;
469
+ }
470
+
367
471
  interface CreateDatabaseInput {
368
472
  /** DB name suffix — the platform prefixes it with the subscription's own username (globally unique). */
369
473
  name: string;
@@ -586,6 +690,76 @@ declare class SubscriptionsApi {
586
690
  resolve(userId: string, preferred?: string): Promise<Subscription>;
587
691
  }
588
692
 
693
+ /** BaaS V2 base. V1 (`/1`) is frozen; app data tools speak V2 only. */
694
+ declare const DEFAULT_BAAS_V2_URL = "https://www.beaapis.com/2";
695
+ /** V2 caps one page at 200 rows. */
696
+ declare const BAAS_MAX_PAGE = 200;
697
+ /** V2 takes 1 to 50 requests per batch. */
698
+ declare const BAAS_MAX_BATCH = 50;
699
+ interface BaasDataOptions {
700
+ /** The app's secret key (`rxsk_…`): server scope, from the project's API keys in Roxyon Base. */
701
+ secretKey: string;
702
+ baseUrl?: string;
703
+ fetch?: typeof fetch;
704
+ }
705
+ type BaasRow = Record<string, unknown>;
706
+ interface BaasQuery {
707
+ /** e.g. `{ Status: 'active', Age: { gt: 18 } }`; `in` takes a comma-joined string. */
708
+ where?: Record<string, unknown>;
709
+ /** `*` and/or column names, comma separated. Defaults to `*`. */
710
+ fields?: string;
711
+ /** Comma list, `-` for descending, e.g. `-createdAt`. */
712
+ order?: string;
713
+ /** 1 to 200 (default 50). */
714
+ limit?: number;
715
+ skip?: number;
716
+ /** Also return the total number of matching rows. */
717
+ count?: boolean;
718
+ }
719
+ interface BaasBatchRequest {
720
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE';
721
+ /** `/Class` or `/Class/<id>`. */
722
+ path: string;
723
+ body?: Record<string, unknown>;
724
+ }
725
+ /** One batch answer: `ok:false` with `error`/`message`, or that request's own V2 answer. */
726
+ interface BaasBatchResult {
727
+ status: number;
728
+ ok?: boolean;
729
+ error?: string;
730
+ message?: string;
731
+ result?: BaasRow;
732
+ results?: BaasRow[];
733
+ count?: number;
734
+ id?: string;
735
+ }
736
+ /**
737
+ * Records of ONE app on BaaS V2, as that app's own backend (server scope, `X-RX-Secret-Key`).
738
+ * Server scope passes every class rule, so treat the key like a database password. V2 answers
739
+ * failures as `{ok:false, error, message}` with an HTTP status; every call throws on those.
740
+ * Schema changes are not reachable with a secret key (console API only).
741
+ */
742
+ declare class BaasDataApi {
743
+ private readonly baseUrl;
744
+ private readonly secretKey;
745
+ private readonly _fetch;
746
+ constructor(opts: BaasDataOptions);
747
+ private call;
748
+ private static recordPath;
749
+ query(className: string, q?: BaasQuery): Promise<{
750
+ rows: BaasRow[];
751
+ count?: number;
752
+ }>;
753
+ get(className: string, objectId: string): Promise<BaasRow>;
754
+ /** Returns the created row as stored. */
755
+ create(className: string, data: BaasRow): Promise<BaasRow>;
756
+ update(className: string, objectId: string, data: BaasRow): Promise<BaasRow>;
757
+ /** The id goes in the URL path, never the body. */
758
+ delete(className: string, objectId: string): Promise<void>;
759
+ /** 1 to 50 record requests in one call; one failing doesn't stop the others. */
760
+ batch(requests: BaasBatchRequest[]): Promise<BaasBatchResult[]>;
761
+ }
762
+
589
763
  /** Returns the error message from a BaaS response, or `''` when the call worked. */
590
764
  declare function rxError(r: unknown): string;
591
765
  declare class RoxyonApiError extends Error {
@@ -695,8 +869,9 @@ declare class Roxyon {
695
869
  readonly databases: DatabasesApi;
696
870
  readonly email: EmailApi;
697
871
  readonly ssh: SshApi;
872
+ readonly billing: BillingApi;
698
873
  constructor(options?: RoxyonClientOptions | RoxyonClient);
699
874
  get sessionToken(): string | undefined;
700
875
  }
701
876
 
702
- export { AccountApi, type AccountApp, type AccountContext, type AccountDomain, type AccountSubscription, type Application, type ApplicationProcess, type ApplicationRoute, ApplicationsApi, AuthApi, type CreateApplicationInput, type CreateDatabaseInput, type CreateDatabaseResult, type CreateDomainInput, type CreateDomainResult, type CreateEmailInput, type CreateEmailResult, type CreateOnDeploy, type CreatedToken, DEFAULT_APP, DEFAULT_BAAS_URL, DEFAULT_CONSOLE_URL, type DatabaseSummary, DatabasesApi, type DeleteDatabaseResult, type DeleteEmailResult, type DeployKind, type DeployOptions, type DeployResult, type Domain, DomainsApi, EmailApi, type EmailSummary, LUMEN_BUILD, type LoginPrecheck, type LoginResult, type Privilege, RUNTIMES, type RequestOptions, type ResetSshPasswordInput, type ResetSshPasswordResult, Roxyon, RoxyonApiError, RoxyonClient, type RoxyonClientOptions, type RoxyonUser, type RuntimeName, type RuntimeSpec, type SessionGrant, type SiteFile, type SiteFileContent, SitesApi, SshApi, type StaticDeployResult, type Subscription, SubscriptionsApi, type TokenScope, type TokenSummary, TokensApi, assertOk, envFromStored, formatEnv, isAuthError, parseEnv, rxError, toQueryString };
877
+ export { AccountApi, type AccountApp, type AccountContext, type AccountDomain, type AccountSubscription, type Application, type ApplicationProcess, type ApplicationRoute, ApplicationsApi, AuthApi, BAAS_MAX_BATCH, BAAS_MAX_PAGE, BILLING_CYCLES, type BaasBatchRequest, type BaasBatchResult, BaasDataApi, type BaasDataOptions, type BaasQuery, type BaasRow, BillingApi, type BillingCycle, type BillingSubscription, type CatalogProduct, type CreateApplicationInput, type CreateDatabaseInput, type CreateDatabaseResult, type CreateDomainInput, type CreateDomainResult, type CreateEmailInput, type CreateEmailResult, type CreateOnDeploy, type CreatedToken, DEFAULT_APP, DEFAULT_BAAS_URL, DEFAULT_BAAS_V2_URL, DEFAULT_CONSOLE_URL, type DatabaseSummary, DatabasesApi, type DeleteDatabaseResult, type DeleteEmailResult, type DeployKind, type DeployOptions, type DeployResult, type Domain, DomainsApi, EmailApi, type EmailSummary, type Invoice, LUMEN_BUILD, type LoginPrecheck, type LoginResult, PAYABLE_STATUSES, type Privilege, type Quote, type QuoteInput, RUNTIMES, type RequestOptions, type ResetSshPasswordInput, type ResetSshPasswordResult, Roxyon, RoxyonApiError, RoxyonClient, type RoxyonClientOptions, type RoxyonUser, type RuntimeName, type RuntimeSpec, type SessionGrant, type SiteFile, type SiteFileContent, SitesApi, SshApi, type StaticDeployResult, type Subscription, SubscriptionsApi, type TokenScope, type TokenSummary, TokensApi, assertOk, envFromStored, formatEnv, isAuthError, isPayable, parseEnv, rxError, toQueryString };