@dominusnode/sdk 1.0.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/LICENSE +21 -0
- package/README.md +679 -0
- package/dist/cjs/admin.d.ts +71 -0
- package/dist/cjs/admin.js +60 -0
- package/dist/cjs/auth.d.ts +47 -0
- package/dist/cjs/auth.js +46 -0
- package/dist/cjs/client.d.ts +56 -0
- package/dist/cjs/client.js +109 -0
- package/dist/cjs/constants.d.ts +8 -0
- package/dist/cjs/constants.js +11 -0
- package/dist/cjs/errors.d.ts +36 -0
- package/dist/cjs/errors.js +86 -0
- package/dist/cjs/http.d.ts +19 -0
- package/dist/cjs/http.js +195 -0
- package/dist/cjs/index.d.ts +30 -0
- package/dist/cjs/index.js +58 -0
- package/dist/cjs/keys.d.ts +27 -0
- package/dist/cjs/keys.js +22 -0
- package/dist/cjs/plans.d.ts +37 -0
- package/dist/cjs/plans.js +22 -0
- package/dist/cjs/proxy.d.ts +62 -0
- package/dist/cjs/proxy.js +71 -0
- package/dist/cjs/resources/agent-wallet.d.ts +52 -0
- package/dist/cjs/resources/agent-wallet.js +64 -0
- package/dist/cjs/resources/teams.d.ts +93 -0
- package/dist/cjs/resources/teams.js +82 -0
- package/dist/cjs/resources/wallet-auth.d.ts +66 -0
- package/dist/cjs/resources/wallet-auth.js +105 -0
- package/dist/cjs/resources/x402.d.ts +39 -0
- package/dist/cjs/resources/x402.js +25 -0
- package/dist/cjs/sessions.d.ts +15 -0
- package/dist/cjs/sessions.js +14 -0
- package/dist/cjs/slots.d.ts +9 -0
- package/dist/cjs/slots.js +19 -0
- package/dist/cjs/token-manager.d.ts +21 -0
- package/dist/cjs/token-manager.js +105 -0
- package/dist/cjs/types.d.ts +154 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/usage.d.ts +80 -0
- package/dist/cjs/usage.js +56 -0
- package/dist/cjs/wallet.d.ts +59 -0
- package/dist/cjs/wallet.js +56 -0
- package/dist/esm/admin.d.ts +71 -0
- package/dist/esm/admin.js +56 -0
- package/dist/esm/auth.d.ts +47 -0
- package/dist/esm/auth.js +42 -0
- package/dist/esm/client.d.ts +56 -0
- package/dist/esm/client.js +105 -0
- package/dist/esm/constants.d.ts +8 -0
- package/dist/esm/constants.js +8 -0
- package/dist/esm/errors.d.ts +36 -0
- package/dist/esm/errors.js +72 -0
- package/dist/esm/http.d.ts +19 -0
- package/dist/esm/http.js +191 -0
- package/dist/esm/index.d.ts +30 -0
- package/dist/esm/index.js +23 -0
- package/dist/esm/keys.d.ts +27 -0
- package/dist/esm/keys.js +18 -0
- package/dist/esm/plans.d.ts +37 -0
- package/dist/esm/plans.js +18 -0
- package/dist/esm/proxy.d.ts +62 -0
- package/dist/esm/proxy.js +67 -0
- package/dist/esm/resources/agent-wallet.d.ts +52 -0
- package/dist/esm/resources/agent-wallet.js +60 -0
- package/dist/esm/resources/teams.d.ts +93 -0
- package/dist/esm/resources/teams.js +78 -0
- package/dist/esm/resources/wallet-auth.d.ts +66 -0
- package/dist/esm/resources/wallet-auth.js +101 -0
- package/dist/esm/resources/x402.d.ts +39 -0
- package/dist/esm/resources/x402.js +21 -0
- package/dist/esm/sessions.d.ts +15 -0
- package/dist/esm/sessions.js +10 -0
- package/dist/esm/slots.d.ts +9 -0
- package/dist/esm/slots.js +15 -0
- package/dist/esm/token-manager.d.ts +21 -0
- package/dist/esm/token-manager.js +101 -0
- package/dist/esm/types.d.ts +154 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/usage.d.ts +80 -0
- package/dist/esm/usage.js +52 -0
- package/dist/esm/wallet.d.ts +59 -0
- package/dist/esm/wallet.js +52 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +31 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { TOKEN_REFRESH_BUFFER_MS } from "./constants.js";
|
|
2
|
+
import { AuthenticationError } from "./errors.js";
|
|
3
|
+
export class TokenManager {
|
|
4
|
+
accessToken = null;
|
|
5
|
+
refreshTokenValue = null;
|
|
6
|
+
refreshPromise = null;
|
|
7
|
+
refreshFn = null;
|
|
8
|
+
setTokens(access, refresh) {
|
|
9
|
+
this.accessToken = access;
|
|
10
|
+
if (refresh)
|
|
11
|
+
this.refreshTokenValue = refresh;
|
|
12
|
+
}
|
|
13
|
+
setRefreshFunction(fn) {
|
|
14
|
+
this.refreshFn = fn;
|
|
15
|
+
}
|
|
16
|
+
getAccessToken() {
|
|
17
|
+
return this.accessToken;
|
|
18
|
+
}
|
|
19
|
+
getRefreshToken() {
|
|
20
|
+
return this.refreshTokenValue;
|
|
21
|
+
}
|
|
22
|
+
isExpired(token) {
|
|
23
|
+
try {
|
|
24
|
+
const parts = token.split(".");
|
|
25
|
+
if (parts.length !== 3)
|
|
26
|
+
return true;
|
|
27
|
+
const payload = JSON.parse(Buffer.from(parts[1].replace(/-/g, "+").replace(/_/g, "/"), "base64").toString());
|
|
28
|
+
return payload.exp * 1000 < Date.now() + TOKEN_REFRESH_BUFFER_MS;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async getValidToken() {
|
|
35
|
+
if (this.accessToken && !this.isExpired(this.accessToken)) {
|
|
36
|
+
return this.accessToken;
|
|
37
|
+
}
|
|
38
|
+
if (!this.refreshTokenValue || !this.refreshFn) {
|
|
39
|
+
throw new AuthenticationError("No valid token and cannot refresh");
|
|
40
|
+
}
|
|
41
|
+
// Singleton refresh
|
|
42
|
+
if (this.refreshPromise)
|
|
43
|
+
return this.refreshPromise;
|
|
44
|
+
this.refreshPromise = (async () => {
|
|
45
|
+
try {
|
|
46
|
+
const result = await this.refreshFn(this.refreshTokenValue);
|
|
47
|
+
this.accessToken = result.accessToken;
|
|
48
|
+
if (result.refreshToken) {
|
|
49
|
+
this.refreshTokenValue = result.refreshToken;
|
|
50
|
+
}
|
|
51
|
+
return this.accessToken;
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
// Clear tokens on refresh failure to prevent rapid-fire retry loops
|
|
55
|
+
this.accessToken = null;
|
|
56
|
+
this.refreshTokenValue = null;
|
|
57
|
+
throw err;
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
this.refreshPromise = null;
|
|
61
|
+
}
|
|
62
|
+
})();
|
|
63
|
+
return this.refreshPromise;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Force a token refresh regardless of expiry state.
|
|
67
|
+
* Used after a 401 response to avoid re-using a rejected token.
|
|
68
|
+
*/
|
|
69
|
+
async forceRefresh() {
|
|
70
|
+
if (!this.refreshTokenValue || !this.refreshFn) {
|
|
71
|
+
throw new AuthenticationError("No valid token and cannot refresh");
|
|
72
|
+
}
|
|
73
|
+
// Singleton refresh (reuse in-flight refresh if one is already happening)
|
|
74
|
+
if (this.refreshPromise)
|
|
75
|
+
return this.refreshPromise;
|
|
76
|
+
this.refreshPromise = (async () => {
|
|
77
|
+
try {
|
|
78
|
+
const result = await this.refreshFn(this.refreshTokenValue);
|
|
79
|
+
this.accessToken = result.accessToken;
|
|
80
|
+
if (result.refreshToken) {
|
|
81
|
+
this.refreshTokenValue = result.refreshToken;
|
|
82
|
+
}
|
|
83
|
+
return this.accessToken;
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
this.accessToken = null;
|
|
87
|
+
this.refreshTokenValue = null;
|
|
88
|
+
throw err;
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
this.refreshPromise = null;
|
|
92
|
+
}
|
|
93
|
+
})();
|
|
94
|
+
return this.refreshPromise;
|
|
95
|
+
}
|
|
96
|
+
clear() {
|
|
97
|
+
this.accessToken = null;
|
|
98
|
+
this.refreshTokenValue = null;
|
|
99
|
+
this.refreshPromise = null;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
export interface DominusNodeConfig {
|
|
2
|
+
baseUrl?: string;
|
|
3
|
+
apiKey?: string;
|
|
4
|
+
accessToken?: string;
|
|
5
|
+
refreshToken?: string;
|
|
6
|
+
proxyHost?: string;
|
|
7
|
+
httpProxyPort?: number;
|
|
8
|
+
socks5ProxyPort?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface User {
|
|
11
|
+
id: string;
|
|
12
|
+
email: string;
|
|
13
|
+
is_admin: boolean;
|
|
14
|
+
created_at?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ApiKey {
|
|
17
|
+
id: string;
|
|
18
|
+
key_prefix: string;
|
|
19
|
+
label: string;
|
|
20
|
+
created_at: string;
|
|
21
|
+
raw?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface Wallet {
|
|
24
|
+
balance_cents: number;
|
|
25
|
+
currency: string;
|
|
26
|
+
}
|
|
27
|
+
export interface WalletTransaction {
|
|
28
|
+
id: string;
|
|
29
|
+
type: "topup" | "debit" | "refund";
|
|
30
|
+
amount_cents: number;
|
|
31
|
+
description: string;
|
|
32
|
+
created_at: string;
|
|
33
|
+
}
|
|
34
|
+
export interface UsageRecord {
|
|
35
|
+
date: string;
|
|
36
|
+
bytes_in: number;
|
|
37
|
+
bytes_out: number;
|
|
38
|
+
total_bytes: number;
|
|
39
|
+
cost_cents: number;
|
|
40
|
+
request_count: number;
|
|
41
|
+
}
|
|
42
|
+
export interface TopHost {
|
|
43
|
+
target_host: string;
|
|
44
|
+
total_bytes: number;
|
|
45
|
+
request_count: number;
|
|
46
|
+
}
|
|
47
|
+
export interface Plan {
|
|
48
|
+
id: string;
|
|
49
|
+
name: string;
|
|
50
|
+
price_per_gb_cents: number;
|
|
51
|
+
monthly_bandwidth_bytes: number;
|
|
52
|
+
is_default: boolean;
|
|
53
|
+
}
|
|
54
|
+
export interface ActiveSession {
|
|
55
|
+
id: string;
|
|
56
|
+
started_at: string;
|
|
57
|
+
status: string;
|
|
58
|
+
}
|
|
59
|
+
export interface ProxyUrlOptions {
|
|
60
|
+
protocol?: "http" | "socks5";
|
|
61
|
+
country?: string;
|
|
62
|
+
state?: string;
|
|
63
|
+
city?: string;
|
|
64
|
+
asn?: number;
|
|
65
|
+
sessionId?: string;
|
|
66
|
+
}
|
|
67
|
+
export interface ProxyHealth {
|
|
68
|
+
status: string;
|
|
69
|
+
providers?: unknown;
|
|
70
|
+
}
|
|
71
|
+
export interface ProxyConfig {
|
|
72
|
+
httpProxy: {
|
|
73
|
+
host: string;
|
|
74
|
+
port: number;
|
|
75
|
+
};
|
|
76
|
+
socks5Proxy: {
|
|
77
|
+
host: string;
|
|
78
|
+
port: number;
|
|
79
|
+
};
|
|
80
|
+
supportedCountries: string[];
|
|
81
|
+
blockedCountries: string[];
|
|
82
|
+
geoTargeting?: {
|
|
83
|
+
stateSupport: boolean;
|
|
84
|
+
citySupport: boolean;
|
|
85
|
+
asnSupport: boolean;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export interface StripeCheckout {
|
|
89
|
+
url: string;
|
|
90
|
+
sessionId: string;
|
|
91
|
+
}
|
|
92
|
+
export interface CryptoInvoice {
|
|
93
|
+
invoiceId: string;
|
|
94
|
+
paymentUrl: string;
|
|
95
|
+
amount: number;
|
|
96
|
+
currency: string;
|
|
97
|
+
}
|
|
98
|
+
export interface PaypalOrder {
|
|
99
|
+
orderId: string;
|
|
100
|
+
approvalUrl: string;
|
|
101
|
+
amountCents: number;
|
|
102
|
+
}
|
|
103
|
+
export interface AdminUser {
|
|
104
|
+
id: string;
|
|
105
|
+
email: string;
|
|
106
|
+
status: string;
|
|
107
|
+
is_admin: boolean;
|
|
108
|
+
created_at: string;
|
|
109
|
+
balance_cents: number;
|
|
110
|
+
}
|
|
111
|
+
export interface RevenueStats {
|
|
112
|
+
total_revenue_cents: number;
|
|
113
|
+
total_topups_cents: number;
|
|
114
|
+
total_usage_cents: number;
|
|
115
|
+
user_count: number;
|
|
116
|
+
}
|
|
117
|
+
export interface DailyRevenue {
|
|
118
|
+
date: string;
|
|
119
|
+
revenue_cents: number;
|
|
120
|
+
}
|
|
121
|
+
export interface SystemStats {
|
|
122
|
+
active_sessions: number;
|
|
123
|
+
total_users: number;
|
|
124
|
+
total_bandwidth_bytes: number;
|
|
125
|
+
}
|
|
126
|
+
export interface MfaStatus {
|
|
127
|
+
enabled: boolean;
|
|
128
|
+
backupCodesRemaining: number;
|
|
129
|
+
}
|
|
130
|
+
export interface MfaSetup {
|
|
131
|
+
secret: string;
|
|
132
|
+
otpauthUri: string;
|
|
133
|
+
backupCodes: string[];
|
|
134
|
+
}
|
|
135
|
+
export interface LoginResult {
|
|
136
|
+
user?: User;
|
|
137
|
+
mfaRequired?: boolean;
|
|
138
|
+
}
|
|
139
|
+
export interface TokenPair {
|
|
140
|
+
accessToken: string;
|
|
141
|
+
refreshToken: string;
|
|
142
|
+
}
|
|
143
|
+
export interface SlotsInfo {
|
|
144
|
+
total: number;
|
|
145
|
+
used: number;
|
|
146
|
+
remaining: number;
|
|
147
|
+
unlimited: boolean;
|
|
148
|
+
}
|
|
149
|
+
export interface WaitlistJoinResult {
|
|
150
|
+
message: string;
|
|
151
|
+
}
|
|
152
|
+
export interface WaitlistCount {
|
|
153
|
+
pending: number;
|
|
154
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { HttpClient } from "./http.js";
|
|
2
|
+
export interface DateRangeOptions {
|
|
3
|
+
from?: string;
|
|
4
|
+
to?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface UsageSummary {
|
|
7
|
+
totalBytes: number;
|
|
8
|
+
totalCostCents: number;
|
|
9
|
+
requestCount: number;
|
|
10
|
+
totalGB: number;
|
|
11
|
+
totalCostUsd: number;
|
|
12
|
+
}
|
|
13
|
+
export interface UsageResponse {
|
|
14
|
+
summary: UsageSummary;
|
|
15
|
+
records: Array<{
|
|
16
|
+
id: string;
|
|
17
|
+
sessionId: string;
|
|
18
|
+
bytesIn: number;
|
|
19
|
+
bytesOut: number;
|
|
20
|
+
totalBytes: number;
|
|
21
|
+
costCents: number;
|
|
22
|
+
proxyType: string;
|
|
23
|
+
targetHost: string;
|
|
24
|
+
createdAt: string;
|
|
25
|
+
}>;
|
|
26
|
+
pagination: {
|
|
27
|
+
limit: number;
|
|
28
|
+
offset: number;
|
|
29
|
+
total: number;
|
|
30
|
+
};
|
|
31
|
+
period: {
|
|
32
|
+
since: string;
|
|
33
|
+
until: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export interface DailyUsageDay {
|
|
37
|
+
date: string;
|
|
38
|
+
totalBytes: number;
|
|
39
|
+
totalGB: number;
|
|
40
|
+
totalCostCents: number;
|
|
41
|
+
totalCostUsd: number;
|
|
42
|
+
requestCount: number;
|
|
43
|
+
}
|
|
44
|
+
export interface DailyUsageResponse {
|
|
45
|
+
days: DailyUsageDay[];
|
|
46
|
+
period: {
|
|
47
|
+
since: string;
|
|
48
|
+
until: string;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export interface TopHostEntry {
|
|
52
|
+
targetHost: string;
|
|
53
|
+
totalBytes: number;
|
|
54
|
+
totalGB: number;
|
|
55
|
+
requestCount: number;
|
|
56
|
+
}
|
|
57
|
+
export interface TopHostsResponse {
|
|
58
|
+
hosts: TopHostEntry[];
|
|
59
|
+
period: {
|
|
60
|
+
since: string;
|
|
61
|
+
until: string;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export declare class UsageResource {
|
|
65
|
+
private http;
|
|
66
|
+
constructor(http: HttpClient);
|
|
67
|
+
/** Get detailed usage records with summary. */
|
|
68
|
+
get(opts?: DateRangeOptions & {
|
|
69
|
+
limit?: number;
|
|
70
|
+
offset?: number;
|
|
71
|
+
}): Promise<UsageResponse>;
|
|
72
|
+
/** Get daily usage aggregation for charts. */
|
|
73
|
+
getDaily(opts?: DateRangeOptions): Promise<DailyUsageResponse>;
|
|
74
|
+
/** Get top target hosts by bandwidth. */
|
|
75
|
+
getTopHosts(opts?: DateRangeOptions & {
|
|
76
|
+
limit?: number;
|
|
77
|
+
}): Promise<TopHostsResponse>;
|
|
78
|
+
/** Export usage records as CSV string. */
|
|
79
|
+
exportCsv(opts?: DateRangeOptions): Promise<string>;
|
|
80
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export class UsageResource {
|
|
2
|
+
http;
|
|
3
|
+
constructor(http) {
|
|
4
|
+
this.http = http;
|
|
5
|
+
}
|
|
6
|
+
/** Get detailed usage records with summary. */
|
|
7
|
+
async get(opts) {
|
|
8
|
+
const params = new URLSearchParams();
|
|
9
|
+
if (opts?.from)
|
|
10
|
+
params.set("since", opts.from);
|
|
11
|
+
if (opts?.to)
|
|
12
|
+
params.set("until", opts.to);
|
|
13
|
+
if (opts?.limit !== undefined)
|
|
14
|
+
params.set("limit", String(opts.limit));
|
|
15
|
+
if (opts?.offset !== undefined)
|
|
16
|
+
params.set("offset", String(opts.offset));
|
|
17
|
+
const qs = params.toString();
|
|
18
|
+
return this.http.get(`/api/usage${qs ? `?${qs}` : ""}`);
|
|
19
|
+
}
|
|
20
|
+
/** Get daily usage aggregation for charts. */
|
|
21
|
+
async getDaily(opts) {
|
|
22
|
+
const params = new URLSearchParams();
|
|
23
|
+
if (opts?.from)
|
|
24
|
+
params.set("since", opts.from);
|
|
25
|
+
if (opts?.to)
|
|
26
|
+
params.set("until", opts.to);
|
|
27
|
+
const qs = params.toString();
|
|
28
|
+
return this.http.get(`/api/usage/daily${qs ? `?${qs}` : ""}`);
|
|
29
|
+
}
|
|
30
|
+
/** Get top target hosts by bandwidth. */
|
|
31
|
+
async getTopHosts(opts) {
|
|
32
|
+
const params = new URLSearchParams();
|
|
33
|
+
if (opts?.from)
|
|
34
|
+
params.set("since", opts.from);
|
|
35
|
+
if (opts?.to)
|
|
36
|
+
params.set("until", opts.to);
|
|
37
|
+
if (opts?.limit !== undefined)
|
|
38
|
+
params.set("limit", String(opts.limit));
|
|
39
|
+
const qs = params.toString();
|
|
40
|
+
return this.http.get(`/api/usage/top-hosts${qs ? `?${qs}` : ""}`);
|
|
41
|
+
}
|
|
42
|
+
/** Export usage records as CSV string. */
|
|
43
|
+
async exportCsv(opts) {
|
|
44
|
+
const params = new URLSearchParams();
|
|
45
|
+
if (opts?.from)
|
|
46
|
+
params.set("since", opts.from);
|
|
47
|
+
if (opts?.to)
|
|
48
|
+
params.set("until", opts.to);
|
|
49
|
+
const qs = params.toString();
|
|
50
|
+
return this.http.get(`/api/usage/export${qs ? `?${qs}` : ""}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { HttpClient } from "./http.js";
|
|
2
|
+
import type { WalletTransaction } from "./types.js";
|
|
3
|
+
export interface WalletBalanceResponse {
|
|
4
|
+
balanceCents: number;
|
|
5
|
+
balanceUsd: number;
|
|
6
|
+
currency: string;
|
|
7
|
+
lastToppedUp: string | null;
|
|
8
|
+
}
|
|
9
|
+
export interface TransactionsResponse {
|
|
10
|
+
transactions: Array<{
|
|
11
|
+
id: string;
|
|
12
|
+
type: WalletTransaction["type"];
|
|
13
|
+
amountCents: number;
|
|
14
|
+
amountUsd: number;
|
|
15
|
+
description: string;
|
|
16
|
+
paymentProvider: string | null;
|
|
17
|
+
createdAt: string;
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
20
|
+
export interface StripeCheckoutResponse {
|
|
21
|
+
sessionId: string;
|
|
22
|
+
url: string;
|
|
23
|
+
}
|
|
24
|
+
export interface CryptoInvoiceResponse {
|
|
25
|
+
invoiceId: string;
|
|
26
|
+
invoiceUrl: string;
|
|
27
|
+
payCurrency: string;
|
|
28
|
+
priceAmount: number;
|
|
29
|
+
}
|
|
30
|
+
export interface PaypalOrderResponse {
|
|
31
|
+
orderId: string;
|
|
32
|
+
approvalUrl: string;
|
|
33
|
+
amountCents: number;
|
|
34
|
+
}
|
|
35
|
+
export interface ForecastResponse {
|
|
36
|
+
dailyAvgCents: number;
|
|
37
|
+
daysRemaining: number | null;
|
|
38
|
+
trend: "up" | "down" | "stable";
|
|
39
|
+
trendPct: number;
|
|
40
|
+
}
|
|
41
|
+
export declare class WalletResource {
|
|
42
|
+
private http;
|
|
43
|
+
constructor(http: HttpClient);
|
|
44
|
+
/** Get current wallet balance. */
|
|
45
|
+
getBalance(): Promise<WalletBalanceResponse>;
|
|
46
|
+
/** Get wallet transaction history. */
|
|
47
|
+
getTransactions(opts?: {
|
|
48
|
+
limit?: number;
|
|
49
|
+
offset?: number;
|
|
50
|
+
}): Promise<TransactionsResponse>;
|
|
51
|
+
/** Create a Stripe checkout session for wallet top-up. */
|
|
52
|
+
topUpStripe(amountCents: number): Promise<StripeCheckoutResponse>;
|
|
53
|
+
/** Create a crypto invoice for wallet top-up. Minimum $10 (1000 cents). */
|
|
54
|
+
topUpCrypto(amountCents: number, currency: string): Promise<CryptoInvoiceResponse>;
|
|
55
|
+
/** Create a PayPal order for wallet top-up. Minimum $5 (500 cents). */
|
|
56
|
+
topUpPaypal(amountCents: number): Promise<PaypalOrderResponse>;
|
|
57
|
+
/** Get spending forecast based on recent usage. */
|
|
58
|
+
getForecast(): Promise<ForecastResponse>;
|
|
59
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export class WalletResource {
|
|
2
|
+
http;
|
|
3
|
+
constructor(http) {
|
|
4
|
+
this.http = http;
|
|
5
|
+
}
|
|
6
|
+
/** Get current wallet balance. */
|
|
7
|
+
async getBalance() {
|
|
8
|
+
return this.http.get("/api/wallet");
|
|
9
|
+
}
|
|
10
|
+
/** Get wallet transaction history. */
|
|
11
|
+
async getTransactions(opts) {
|
|
12
|
+
const params = new URLSearchParams();
|
|
13
|
+
if (opts?.limit !== undefined)
|
|
14
|
+
params.set("limit", String(opts.limit));
|
|
15
|
+
if (opts?.offset !== undefined)
|
|
16
|
+
params.set("offset", String(opts.offset));
|
|
17
|
+
const qs = params.toString();
|
|
18
|
+
return this.http.get(`/api/wallet/transactions${qs ? `?${qs}` : ""}`);
|
|
19
|
+
}
|
|
20
|
+
/** Create a Stripe checkout session for wallet top-up. */
|
|
21
|
+
async topUpStripe(amountCents) {
|
|
22
|
+
if (!Number.isInteger(amountCents) || amountCents <= 0 || amountCents > 2_147_483_647) {
|
|
23
|
+
throw new Error("amountCents must be a positive integer <= 2,147,483,647");
|
|
24
|
+
}
|
|
25
|
+
return this.http.post("/api/wallet/topup/stripe", { amountCents });
|
|
26
|
+
}
|
|
27
|
+
/** Create a crypto invoice for wallet top-up. Minimum $10 (1000 cents). */
|
|
28
|
+
async topUpCrypto(amountCents, currency) {
|
|
29
|
+
if (!Number.isInteger(amountCents) || amountCents <= 0 || amountCents > 2_147_483_647) {
|
|
30
|
+
throw new Error("amountCents must be a positive integer <= 2,147,483,647");
|
|
31
|
+
}
|
|
32
|
+
if (amountCents < 1000) {
|
|
33
|
+
throw new Error("Minimum crypto top-up is $10.00 (1000 cents)");
|
|
34
|
+
}
|
|
35
|
+
const amountUsd = amountCents / 100;
|
|
36
|
+
return this.http.post("/api/wallet/topup/crypto", { amountUsd, currency });
|
|
37
|
+
}
|
|
38
|
+
/** Create a PayPal order for wallet top-up. Minimum $5 (500 cents). */
|
|
39
|
+
async topUpPaypal(amountCents) {
|
|
40
|
+
if (!Number.isInteger(amountCents) || amountCents <= 0 || amountCents > 2_147_483_647) {
|
|
41
|
+
throw new Error("amountCents must be a positive integer <= 2,147,483,647");
|
|
42
|
+
}
|
|
43
|
+
if (amountCents < 500) {
|
|
44
|
+
throw new Error("Minimum PayPal top-up is $5.00 (500 cents)");
|
|
45
|
+
}
|
|
46
|
+
return this.http.post("/api/wallet/topup/paypal", { amountCents });
|
|
47
|
+
}
|
|
48
|
+
/** Get spending forecast based on recent usage. */
|
|
49
|
+
async getForecast() {
|
|
50
|
+
return this.http.get("/api/wallet/forecast");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../src/admin.ts","../src/auth.ts","../src/client.ts","../src/constants.ts","../src/errors.ts","../src/http.ts","../src/index.ts","../src/keys.ts","../src/plans.ts","../src/proxy.ts","../src/sessions.ts","../src/slots.ts","../src/token-manager.ts","../src/types.ts","../src/usage.ts","../src/wallet.ts","../src/resources/agent-wallet.ts","../src/resources/teams.ts"],"version":"5.9.3"}
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dominusnode/sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Official Dominus Node SDK for Node.js/TypeScript",
|
|
5
|
+
"author": "Dominus Node",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/cjs/index.js",
|
|
9
|
+
"module": "./dist/esm/index.js",
|
|
10
|
+
"types": "./dist/esm/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/esm/index.js",
|
|
14
|
+
"require": "./dist/cjs/index.js",
|
|
15
|
+
"types": "./dist/esm/index.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": ["dist"],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc -p tsconfig.json && tsc -p tsconfig.cjs.json",
|
|
21
|
+
"test": "vitest run",
|
|
22
|
+
"clean": "rm -rf dist"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=18.0.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"typescript": "^5.3.0",
|
|
29
|
+
"vitest": "^4.0.0"
|
|
30
|
+
}
|
|
31
|
+
}
|