@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.
Files changed (84) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +679 -0
  3. package/dist/cjs/admin.d.ts +71 -0
  4. package/dist/cjs/admin.js +60 -0
  5. package/dist/cjs/auth.d.ts +47 -0
  6. package/dist/cjs/auth.js +46 -0
  7. package/dist/cjs/client.d.ts +56 -0
  8. package/dist/cjs/client.js +109 -0
  9. package/dist/cjs/constants.d.ts +8 -0
  10. package/dist/cjs/constants.js +11 -0
  11. package/dist/cjs/errors.d.ts +36 -0
  12. package/dist/cjs/errors.js +86 -0
  13. package/dist/cjs/http.d.ts +19 -0
  14. package/dist/cjs/http.js +195 -0
  15. package/dist/cjs/index.d.ts +30 -0
  16. package/dist/cjs/index.js +58 -0
  17. package/dist/cjs/keys.d.ts +27 -0
  18. package/dist/cjs/keys.js +22 -0
  19. package/dist/cjs/plans.d.ts +37 -0
  20. package/dist/cjs/plans.js +22 -0
  21. package/dist/cjs/proxy.d.ts +62 -0
  22. package/dist/cjs/proxy.js +71 -0
  23. package/dist/cjs/resources/agent-wallet.d.ts +52 -0
  24. package/dist/cjs/resources/agent-wallet.js +64 -0
  25. package/dist/cjs/resources/teams.d.ts +93 -0
  26. package/dist/cjs/resources/teams.js +82 -0
  27. package/dist/cjs/resources/wallet-auth.d.ts +66 -0
  28. package/dist/cjs/resources/wallet-auth.js +105 -0
  29. package/dist/cjs/resources/x402.d.ts +39 -0
  30. package/dist/cjs/resources/x402.js +25 -0
  31. package/dist/cjs/sessions.d.ts +15 -0
  32. package/dist/cjs/sessions.js +14 -0
  33. package/dist/cjs/slots.d.ts +9 -0
  34. package/dist/cjs/slots.js +19 -0
  35. package/dist/cjs/token-manager.d.ts +21 -0
  36. package/dist/cjs/token-manager.js +105 -0
  37. package/dist/cjs/types.d.ts +154 -0
  38. package/dist/cjs/types.js +2 -0
  39. package/dist/cjs/usage.d.ts +80 -0
  40. package/dist/cjs/usage.js +56 -0
  41. package/dist/cjs/wallet.d.ts +59 -0
  42. package/dist/cjs/wallet.js +56 -0
  43. package/dist/esm/admin.d.ts +71 -0
  44. package/dist/esm/admin.js +56 -0
  45. package/dist/esm/auth.d.ts +47 -0
  46. package/dist/esm/auth.js +42 -0
  47. package/dist/esm/client.d.ts +56 -0
  48. package/dist/esm/client.js +105 -0
  49. package/dist/esm/constants.d.ts +8 -0
  50. package/dist/esm/constants.js +8 -0
  51. package/dist/esm/errors.d.ts +36 -0
  52. package/dist/esm/errors.js +72 -0
  53. package/dist/esm/http.d.ts +19 -0
  54. package/dist/esm/http.js +191 -0
  55. package/dist/esm/index.d.ts +30 -0
  56. package/dist/esm/index.js +23 -0
  57. package/dist/esm/keys.d.ts +27 -0
  58. package/dist/esm/keys.js +18 -0
  59. package/dist/esm/plans.d.ts +37 -0
  60. package/dist/esm/plans.js +18 -0
  61. package/dist/esm/proxy.d.ts +62 -0
  62. package/dist/esm/proxy.js +67 -0
  63. package/dist/esm/resources/agent-wallet.d.ts +52 -0
  64. package/dist/esm/resources/agent-wallet.js +60 -0
  65. package/dist/esm/resources/teams.d.ts +93 -0
  66. package/dist/esm/resources/teams.js +78 -0
  67. package/dist/esm/resources/wallet-auth.d.ts +66 -0
  68. package/dist/esm/resources/wallet-auth.js +101 -0
  69. package/dist/esm/resources/x402.d.ts +39 -0
  70. package/dist/esm/resources/x402.js +21 -0
  71. package/dist/esm/sessions.d.ts +15 -0
  72. package/dist/esm/sessions.js +10 -0
  73. package/dist/esm/slots.d.ts +9 -0
  74. package/dist/esm/slots.js +15 -0
  75. package/dist/esm/token-manager.d.ts +21 -0
  76. package/dist/esm/token-manager.js +101 -0
  77. package/dist/esm/types.d.ts +154 -0
  78. package/dist/esm/types.js +1 -0
  79. package/dist/esm/usage.d.ts +80 -0
  80. package/dist/esm/usage.js +52 -0
  81. package/dist/esm/wallet.d.ts +59 -0
  82. package/dist/esm/wallet.js +52 -0
  83. package/dist/tsconfig.tsbuildinfo +1 -0
  84. package/package.json +31 -0
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpClient = void 0;
4
+ const constants_js_1 = require("./constants.js");
5
+ const errors_js_1 = require("./errors.js");
6
+ // Sanitize parsed JSON to prevent prototype pollution from untrusted API responses
7
+ // Recursive prototype pollution stripping (covers nested objects too)
8
+ const DANGEROUS_KEYS = new Set(["__proto__", "constructor", "prototype"]);
9
+ // Depth limit prevents stack overflow on deeply nested JSON
10
+ function stripDangerousKeys(obj, depth = 0) {
11
+ if (depth > 50 || !obj || typeof obj !== "object")
12
+ return;
13
+ if (Array.isArray(obj)) {
14
+ for (const item of obj)
15
+ stripDangerousKeys(item, depth + 1);
16
+ return;
17
+ }
18
+ const record = obj;
19
+ for (const key of Object.keys(record)) {
20
+ if (DANGEROUS_KEYS.has(key)) {
21
+ delete record[key];
22
+ }
23
+ else if (record[key] && typeof record[key] === "object") {
24
+ stripDangerousKeys(record[key], depth + 1);
25
+ }
26
+ }
27
+ }
28
+ function safeJsonParse(text) {
29
+ const parsed = JSON.parse(text);
30
+ stripDangerousKeys(parsed);
31
+ return parsed;
32
+ }
33
+ // Add jitter to retry delays to prevent thundering-herd on rate-limited endpoints
34
+ function addJitter(ms) {
35
+ const jitter = ms * 0.2 * (Math.random() - 0.5); // ±10% jitter
36
+ return Math.max(100, Math.round(ms + jitter));
37
+ }
38
+ function throwForStatus(status, body, headers) {
39
+ let message;
40
+ try {
41
+ const parsed = JSON.parse(body);
42
+ message = parsed.error ?? parsed.message ?? body;
43
+ }
44
+ catch {
45
+ message = body;
46
+ }
47
+ // Truncate error message to prevent unbounded body in exception strings
48
+ if (message.length > 500)
49
+ message = message.slice(0, 500) + "... [truncated]";
50
+ switch (status) {
51
+ case 400: throw new errors_js_1.ValidationError(message);
52
+ case 401: throw new errors_js_1.AuthenticationError(message);
53
+ case 402: throw new errors_js_1.InsufficientBalanceError(message);
54
+ case 403: throw new errors_js_1.AuthorizationError(message);
55
+ case 404: throw new errors_js_1.NotFoundError(message);
56
+ case 409: throw new errors_js_1.ConflictError(message);
57
+ case 429: {
58
+ const parsed = parseInt(headers.get("retry-after") ?? "60", 10);
59
+ const retryAfter = Number.isFinite(parsed) ? parsed : 60; // NaN guard
60
+ throw new errors_js_1.RateLimitError(message, retryAfter);
61
+ }
62
+ default:
63
+ if (status >= 500)
64
+ throw new errors_js_1.ServerError(message);
65
+ throw new errors_js_1.DominusNodeError(message, status);
66
+ }
67
+ }
68
+ // Max response body size to prevent OOM from malicious/large API responses
69
+ const MAX_RESPONSE_BYTES = 10 * 1024 * 1024; // 10 MB
70
+ class HttpClient {
71
+ baseUrl;
72
+ tokenManager;
73
+ constructor(baseUrl, tokenManager) {
74
+ this.baseUrl = baseUrl;
75
+ this.tokenManager = tokenManager;
76
+ }
77
+ async request(opts) {
78
+ const headers = {
79
+ "User-Agent": constants_js_1.USER_AGENT,
80
+ "Content-Type": "application/json",
81
+ ...opts.headers,
82
+ };
83
+ if (opts.requiresAuth !== false) {
84
+ const token = await this.tokenManager.getValidToken();
85
+ // Guard against null/empty token to prevent "Bearer " header
86
+ if (!token) {
87
+ throw new Error("No valid token available. Call connectWithKey() or login() first.");
88
+ }
89
+ headers["Authorization"] = `Bearer ${token}`;
90
+ }
91
+ const url = `${this.baseUrl}${opts.path}`;
92
+ let response;
93
+ const timeoutMs = 30_000; // 30s request timeout
94
+ try {
95
+ response = await fetch(url, {
96
+ method: opts.method,
97
+ headers,
98
+ body: opts.body !== undefined ? JSON.stringify(opts.body) : undefined,
99
+ signal: AbortSignal.timeout(timeoutMs),
100
+ redirect: "error", // Reject redirects — prevents HTTPS→HTTP credential leakage
101
+ });
102
+ }
103
+ catch (err) {
104
+ throw new errors_js_1.NetworkError(err instanceof Error ? err.message : "Network request failed");
105
+ }
106
+ if (response.status === 429) {
107
+ // Auto-retry once on rate limit (cap wait at 10s to avoid client-side DoS)
108
+ const parsed = parseInt(response.headers.get("retry-after") ?? "5", 10);
109
+ const retryAfter = Number.isFinite(parsed) ? parsed : 5; // NaN guard
110
+ // Cancel body stream instead of buffering — prevents OOM from large 429 responses
111
+ await response.body?.cancel();
112
+ await new Promise((resolve) => setTimeout(resolve, addJitter(Math.min(retryAfter * 1000, 10_000))));
113
+ // Refresh token before retry in case it expired during the wait
114
+ if (opts.requiresAuth !== false) {
115
+ const freshToken = await this.tokenManager.getValidToken();
116
+ headers["Authorization"] = `Bearer ${freshToken}`;
117
+ }
118
+ try {
119
+ response = await fetch(url, {
120
+ method: opts.method,
121
+ headers,
122
+ body: opts.body !== undefined ? JSON.stringify(opts.body) : undefined,
123
+ signal: AbortSignal.timeout(timeoutMs),
124
+ redirect: "error",
125
+ });
126
+ }
127
+ catch (err) {
128
+ throw new errors_js_1.NetworkError(err instanceof Error ? err.message : "Network request failed");
129
+ }
130
+ }
131
+ if (response.status === 401 && opts.requiresAuth !== false) {
132
+ // Cancel body stream before retry to prevent memory leak from unconsumed response
133
+ await response.body?.cancel();
134
+ // Force a token refresh (don't reuse the rejected token) and retry once
135
+ try {
136
+ const newToken = await this.tokenManager.forceRefresh();
137
+ headers["Authorization"] = `Bearer ${newToken}`;
138
+ const retry = await fetch(url, {
139
+ method: opts.method,
140
+ headers,
141
+ body: opts.body !== undefined ? JSON.stringify(opts.body) : undefined,
142
+ signal: AbortSignal.timeout(timeoutMs),
143
+ redirect: "error",
144
+ });
145
+ // Apply response size limit to 401 retry path too
146
+ const retryContentLength = parseInt(retry.headers.get("content-length") ?? "0", 10);
147
+ if (retryContentLength > MAX_RESPONSE_BYTES) {
148
+ throw new errors_js_1.ServerError("Response body too large");
149
+ }
150
+ const retryText = await retry.text();
151
+ if (retryText.length > MAX_RESPONSE_BYTES) {
152
+ throw new errors_js_1.ServerError("Response body exceeds size limit");
153
+ }
154
+ if (retry.ok) {
155
+ return retryText ? safeJsonParse(retryText) : {};
156
+ }
157
+ throwForStatus(retry.status, retryText, retry.headers);
158
+ }
159
+ catch (err) {
160
+ if (err instanceof errors_js_1.DominusNodeError)
161
+ throw err;
162
+ // Refresh failed — fall through to original 401 handling
163
+ }
164
+ }
165
+ // Enforce response body size limit to prevent OOM
166
+ const contentLength = parseInt(response.headers.get("content-length") ?? "0", 10);
167
+ if (contentLength > MAX_RESPONSE_BYTES) {
168
+ throw new errors_js_1.ServerError("Response body too large");
169
+ }
170
+ const responseText = await response.text();
171
+ if (responseText.length > MAX_RESPONSE_BYTES) {
172
+ throw new errors_js_1.ServerError("Response body exceeds size limit");
173
+ }
174
+ if (!response.ok) {
175
+ throwForStatus(response.status, responseText, response.headers);
176
+ }
177
+ return responseText ? safeJsonParse(responseText) : {};
178
+ }
179
+ async get(path, requiresAuth = true) {
180
+ return this.request({ method: "GET", path, requiresAuth });
181
+ }
182
+ async post(path, body, requiresAuth = true) {
183
+ return this.request({ method: "POST", path, body, requiresAuth });
184
+ }
185
+ async put(path, body) {
186
+ return this.request({ method: "PUT", path, body });
187
+ }
188
+ async patch(path, body) {
189
+ return this.request({ method: "PATCH", path, body });
190
+ }
191
+ async delete(path) {
192
+ return this.request({ method: "DELETE", path });
193
+ }
194
+ }
195
+ exports.HttpClient = HttpClient;
@@ -0,0 +1,30 @@
1
+ export { DominusNodeClient } from "./client.js";
2
+ export { AuthResource } from "./auth.js";
3
+ export { KeysResource } from "./keys.js";
4
+ export type { CreateKeyResponse, ListKeysResponse } from "./keys.js";
5
+ export { WalletResource } from "./wallet.js";
6
+ export type { WalletBalanceResponse, TransactionsResponse, StripeCheckoutResponse, CryptoInvoiceResponse, ForecastResponse, } from "./wallet.js";
7
+ export { UsageResource } from "./usage.js";
8
+ export type { DateRangeOptions as UsageDateRangeOptions, UsageSummary, UsageResponse, DailyUsageDay, DailyUsageResponse, TopHostEntry, TopHostsResponse, } from "./usage.js";
9
+ export { PlansResource } from "./plans.js";
10
+ export type { PlanEntry, ListPlansResponse, UserPlanResponse, ChangePlanResponse, } from "./plans.js";
11
+ export { SessionsResource } from "./sessions.js";
12
+ export type { ActiveSessionEntry, ActiveSessionsResponse } from "./sessions.js";
13
+ export { ProxyResource } from "./proxy.js";
14
+ export type { ProxyHealthResponse, ProxyStatusResponse } from "./proxy.js";
15
+ export { AdminResource } from "./admin.js";
16
+ export { SlotsResource } from "./slots.js";
17
+ export { AgenticWalletResource } from "./resources/agent-wallet.js";
18
+ export type { AgenticWallet, AgenticWalletTransaction, AgenticWalletListResponse, AgenticWalletFundResponse, AgenticWalletTransactionsResponse, AgenticWalletDeleteResponse, } from "./resources/agent-wallet.js";
19
+ export { TeamsResource } from "./resources/teams.js";
20
+ export type { Team, TeamMember, TeamInvite, TeamListResponse, TeamMembersResponse, TeamInvitesResponse, TeamKeysResponse, TeamKeyCreateResponse, TeamDeleteResponse, TeamFundResponse, TeamTransactionsResponse, } from "./resources/teams.js";
21
+ export { X402Resource } from "./resources/x402.js";
22
+ export type { X402Info, X402Facilitator, X402Pricing, } from "./resources/x402.js";
23
+ export { WalletAuthResource } from "./resources/wallet-auth.js";
24
+ export type { WalletChallenge, WalletVerifyResult, WalletLinkResult, } from "./resources/wallet-auth.js";
25
+ export type { DateRangeOptions as AdminDateRangeOptions, ListUsersResponse, GetUserResponse, RevenueResponse, DailyRevenueEntry, DailyRevenueResponse, } from "./admin.js";
26
+ export { HttpClient } from "./http.js";
27
+ export type { HttpOptions } from "./http.js";
28
+ export { DominusNodeError, AuthenticationError, AuthorizationError, RateLimitError, InsufficientBalanceError, ValidationError, NotFoundError, ConflictError, ServerError, NetworkError, ProxyError, } from "./errors.js";
29
+ export type { DominusNodeConfig, User, ApiKey, Wallet, WalletTransaction, UsageRecord, TopHost, Plan, ActiveSession, ProxyUrlOptions, ProxyHealth, ProxyConfig, StripeCheckout, CryptoInvoice, AdminUser, RevenueStats, DailyRevenue, SystemStats, MfaStatus, MfaSetup, LoginResult, TokenPair, SlotsInfo, WaitlistJoinResult, WaitlistCount, } from "./types.js";
30
+ export { SDK_VERSION, USER_AGENT, DEFAULT_BASE_URL, DEFAULT_PROXY_HOST, DEFAULT_HTTP_PROXY_PORT, DEFAULT_SOCKS5_PROXY_PORT, } from "./constants.js";
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_SOCKS5_PROXY_PORT = exports.DEFAULT_HTTP_PROXY_PORT = exports.DEFAULT_PROXY_HOST = exports.DEFAULT_BASE_URL = exports.USER_AGENT = exports.SDK_VERSION = exports.ProxyError = exports.NetworkError = exports.ServerError = exports.ConflictError = exports.NotFoundError = exports.ValidationError = exports.InsufficientBalanceError = exports.RateLimitError = exports.AuthorizationError = exports.AuthenticationError = exports.DominusNodeError = exports.HttpClient = exports.WalletAuthResource = exports.X402Resource = exports.TeamsResource = exports.AgenticWalletResource = exports.SlotsResource = exports.AdminResource = exports.ProxyResource = exports.SessionsResource = exports.PlansResource = exports.UsageResource = exports.WalletResource = exports.KeysResource = exports.AuthResource = exports.DominusNodeClient = void 0;
4
+ // Main client
5
+ var client_js_1 = require("./client.js");
6
+ Object.defineProperty(exports, "DominusNodeClient", { enumerable: true, get: function () { return client_js_1.DominusNodeClient; } });
7
+ // Resource modules
8
+ var auth_js_1 = require("./auth.js");
9
+ Object.defineProperty(exports, "AuthResource", { enumerable: true, get: function () { return auth_js_1.AuthResource; } });
10
+ var keys_js_1 = require("./keys.js");
11
+ Object.defineProperty(exports, "KeysResource", { enumerable: true, get: function () { return keys_js_1.KeysResource; } });
12
+ var wallet_js_1 = require("./wallet.js");
13
+ Object.defineProperty(exports, "WalletResource", { enumerable: true, get: function () { return wallet_js_1.WalletResource; } });
14
+ var usage_js_1 = require("./usage.js");
15
+ Object.defineProperty(exports, "UsageResource", { enumerable: true, get: function () { return usage_js_1.UsageResource; } });
16
+ var plans_js_1 = require("./plans.js");
17
+ Object.defineProperty(exports, "PlansResource", { enumerable: true, get: function () { return plans_js_1.PlansResource; } });
18
+ var sessions_js_1 = require("./sessions.js");
19
+ Object.defineProperty(exports, "SessionsResource", { enumerable: true, get: function () { return sessions_js_1.SessionsResource; } });
20
+ var proxy_js_1 = require("./proxy.js");
21
+ Object.defineProperty(exports, "ProxyResource", { enumerable: true, get: function () { return proxy_js_1.ProxyResource; } });
22
+ var admin_js_1 = require("./admin.js");
23
+ Object.defineProperty(exports, "AdminResource", { enumerable: true, get: function () { return admin_js_1.AdminResource; } });
24
+ var slots_js_1 = require("./slots.js");
25
+ Object.defineProperty(exports, "SlotsResource", { enumerable: true, get: function () { return slots_js_1.SlotsResource; } });
26
+ var agent_wallet_js_1 = require("./resources/agent-wallet.js");
27
+ Object.defineProperty(exports, "AgenticWalletResource", { enumerable: true, get: function () { return agent_wallet_js_1.AgenticWalletResource; } });
28
+ var teams_js_1 = require("./resources/teams.js");
29
+ Object.defineProperty(exports, "TeamsResource", { enumerable: true, get: function () { return teams_js_1.TeamsResource; } });
30
+ var x402_js_1 = require("./resources/x402.js");
31
+ Object.defineProperty(exports, "X402Resource", { enumerable: true, get: function () { return x402_js_1.X402Resource; } });
32
+ var wallet_auth_js_1 = require("./resources/wallet-auth.js");
33
+ Object.defineProperty(exports, "WalletAuthResource", { enumerable: true, get: function () { return wallet_auth_js_1.WalletAuthResource; } });
34
+ // Infrastructure (HttpClient for advanced custom integrations)
35
+ var http_js_1 = require("./http.js");
36
+ Object.defineProperty(exports, "HttpClient", { enumerable: true, get: function () { return http_js_1.HttpClient; } });
37
+ // TokenManager is internal — not exported to prevent misuse of token lifecycle
38
+ // Errors
39
+ var errors_js_1 = require("./errors.js");
40
+ Object.defineProperty(exports, "DominusNodeError", { enumerable: true, get: function () { return errors_js_1.DominusNodeError; } });
41
+ Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return errors_js_1.AuthenticationError; } });
42
+ Object.defineProperty(exports, "AuthorizationError", { enumerable: true, get: function () { return errors_js_1.AuthorizationError; } });
43
+ Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return errors_js_1.RateLimitError; } });
44
+ Object.defineProperty(exports, "InsufficientBalanceError", { enumerable: true, get: function () { return errors_js_1.InsufficientBalanceError; } });
45
+ Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return errors_js_1.ValidationError; } });
46
+ Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return errors_js_1.NotFoundError; } });
47
+ Object.defineProperty(exports, "ConflictError", { enumerable: true, get: function () { return errors_js_1.ConflictError; } });
48
+ Object.defineProperty(exports, "ServerError", { enumerable: true, get: function () { return errors_js_1.ServerError; } });
49
+ Object.defineProperty(exports, "NetworkError", { enumerable: true, get: function () { return errors_js_1.NetworkError; } });
50
+ Object.defineProperty(exports, "ProxyError", { enumerable: true, get: function () { return errors_js_1.ProxyError; } });
51
+ // Constants
52
+ var constants_js_1 = require("./constants.js");
53
+ Object.defineProperty(exports, "SDK_VERSION", { enumerable: true, get: function () { return constants_js_1.SDK_VERSION; } });
54
+ Object.defineProperty(exports, "USER_AGENT", { enumerable: true, get: function () { return constants_js_1.USER_AGENT; } });
55
+ Object.defineProperty(exports, "DEFAULT_BASE_URL", { enumerable: true, get: function () { return constants_js_1.DEFAULT_BASE_URL; } });
56
+ Object.defineProperty(exports, "DEFAULT_PROXY_HOST", { enumerable: true, get: function () { return constants_js_1.DEFAULT_PROXY_HOST; } });
57
+ Object.defineProperty(exports, "DEFAULT_HTTP_PROXY_PORT", { enumerable: true, get: function () { return constants_js_1.DEFAULT_HTTP_PROXY_PORT; } });
58
+ Object.defineProperty(exports, "DEFAULT_SOCKS5_PROXY_PORT", { enumerable: true, get: function () { return constants_js_1.DEFAULT_SOCKS5_PROXY_PORT; } });
@@ -0,0 +1,27 @@
1
+ import type { HttpClient } from "./http.js";
2
+ export interface CreateKeyResponse {
3
+ key: string;
4
+ id: string;
5
+ prefix: string;
6
+ label: string;
7
+ created_at: string;
8
+ }
9
+ export interface ListKeysResponse {
10
+ keys: Array<{
11
+ id: string;
12
+ prefix: string;
13
+ label: string;
14
+ created_at: string;
15
+ revoked_at: string | null;
16
+ }>;
17
+ }
18
+ export declare class KeysResource {
19
+ private http;
20
+ constructor(http: HttpClient);
21
+ /** Create a new API key. The raw key is returned only once. */
22
+ create(label?: string): Promise<CreateKeyResponse>;
23
+ /** List all API keys for the authenticated user. */
24
+ list(): Promise<ListKeysResponse>;
25
+ /** Revoke an API key by its ID. */
26
+ revoke(id: string): Promise<void>;
27
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KeysResource = void 0;
4
+ class KeysResource {
5
+ http;
6
+ constructor(http) {
7
+ this.http = http;
8
+ }
9
+ /** Create a new API key. The raw key is returned only once. */
10
+ async create(label) {
11
+ return this.http.post("/api/keys", { label: label ?? "Default" });
12
+ }
13
+ /** List all API keys for the authenticated user. */
14
+ async list() {
15
+ return this.http.get("/api/keys");
16
+ }
17
+ /** Revoke an API key by its ID. */
18
+ async revoke(id) {
19
+ await this.http.delete(`/api/keys/${encodeURIComponent(id)}`);
20
+ }
21
+ }
22
+ exports.KeysResource = KeysResource;
@@ -0,0 +1,37 @@
1
+ import type { HttpClient } from "./http.js";
2
+ export interface PlanEntry {
3
+ id: string;
4
+ name: string;
5
+ pricePerGbCents: number;
6
+ pricePerGbUsd: number;
7
+ monthlyBandwidthBytes: number;
8
+ monthlyBandwidthGB: number | null;
9
+ isDefault: boolean;
10
+ }
11
+ export interface ListPlansResponse {
12
+ plans: PlanEntry[];
13
+ }
14
+ export interface UserPlanResponse {
15
+ plan: PlanEntry;
16
+ usage: {
17
+ monthlyUsageBytes: number;
18
+ monthlyUsageGB: number;
19
+ limitBytes: number;
20
+ limitGB: number | null;
21
+ percentUsed: number | null;
22
+ };
23
+ }
24
+ export interface ChangePlanResponse {
25
+ message: string;
26
+ plan: PlanEntry;
27
+ }
28
+ export declare class PlansResource {
29
+ private http;
30
+ constructor(http: HttpClient);
31
+ /** List all available plans (does not require authentication). */
32
+ list(): Promise<ListPlansResponse>;
33
+ /** Get the current user's plan and monthly usage. */
34
+ getUserPlan(): Promise<UserPlanResponse>;
35
+ /** Change the current user's plan. */
36
+ changePlan(planId: string): Promise<ChangePlanResponse>;
37
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlansResource = void 0;
4
+ class PlansResource {
5
+ http;
6
+ constructor(http) {
7
+ this.http = http;
8
+ }
9
+ /** List all available plans (does not require authentication). */
10
+ async list() {
11
+ return this.http.get("/api/plans", false);
12
+ }
13
+ /** Get the current user's plan and monthly usage. */
14
+ async getUserPlan() {
15
+ return this.http.get("/api/plans/user/plan");
16
+ }
17
+ /** Change the current user's plan. */
18
+ async changePlan(planId) {
19
+ return this.http.put("/api/plans/user/plan", { planId });
20
+ }
21
+ }
22
+ exports.PlansResource = PlansResource;
@@ -0,0 +1,62 @@
1
+ import type { HttpClient } from "./http.js";
2
+ import type { ProxyUrlOptions, ProxyConfig, DominusNodeConfig } from "./types.js";
3
+ export interface ProxyHealthResponse {
4
+ status: string;
5
+ activeSessions: number;
6
+ uptimeSeconds: number;
7
+ }
8
+ export interface ProxyStatusResponse {
9
+ status: string;
10
+ activeSessions: number;
11
+ userActiveSessions: number;
12
+ avgLatencyMs: number;
13
+ providers: Array<{
14
+ name: string;
15
+ state: string;
16
+ consecutiveFailures: number;
17
+ totalRequests: number;
18
+ totalErrors: number;
19
+ avgLatencyMs: number;
20
+ fallbackOnly: boolean;
21
+ }>;
22
+ endpoints: {
23
+ http: string;
24
+ socks5: string;
25
+ };
26
+ supportedCountries: string[];
27
+ uptimeSeconds: number;
28
+ }
29
+ export declare class ProxyResource {
30
+ private http;
31
+ private proxyHost;
32
+ private httpPort;
33
+ private socks5Port;
34
+ constructor(http: HttpClient, config: DominusNodeConfig);
35
+ /**
36
+ * Build a proxy URL string for use with HTTP clients.
37
+ *
38
+ * The returned URL includes authentication via the username field.
39
+ * Geo-targeting and sticky sessions are encoded in the username portion
40
+ * following Dominus Node proxy conventions.
41
+ *
42
+ * @param apiKey - The API key to authenticate proxy requests.
43
+ * @param opts - Optional targeting parameters (protocol, country, etc.).
44
+ * @returns A fully-formed proxy URL string.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * const url = client.proxy.buildUrl("dn_live_abc123");
49
+ * // => "http://user:dn_live_abc123@proxy.dominusnode.com:8080"
50
+ *
51
+ * const socksUrl = client.proxy.buildUrl("dn_live_abc123", { protocol: "socks5", country: "US" });
52
+ * // => "socks5://user-country-US:dn_live_abc123@proxy.dominusnode.com:1080"
53
+ * ```
54
+ */
55
+ buildUrl(apiKey: string, opts?: ProxyUrlOptions): string;
56
+ /** Get public proxy health status (does not require authentication). */
57
+ getHealth(): Promise<ProxyHealthResponse>;
58
+ /** Get detailed proxy status including provider info (requires authentication). */
59
+ getStatus(): Promise<ProxyStatusResponse>;
60
+ /** Get proxy server configuration (requires authentication). */
61
+ getConfig(): Promise<ProxyConfig>;
62
+ }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProxyResource = void 0;
4
+ const constants_js_1 = require("./constants.js");
5
+ class ProxyResource {
6
+ http;
7
+ proxyHost;
8
+ httpPort;
9
+ socks5Port;
10
+ constructor(http, config) {
11
+ this.http = http;
12
+ this.proxyHost = config.proxyHost ?? constants_js_1.DEFAULT_PROXY_HOST;
13
+ // Validate proxyHost to prevent URL injection via crafted hostnames
14
+ if (/[\s\/\\@?#]/.test(this.proxyHost)) {
15
+ throw new Error("proxyHost contains invalid characters");
16
+ }
17
+ this.httpPort = config.httpProxyPort ?? constants_js_1.DEFAULT_HTTP_PROXY_PORT;
18
+ this.socks5Port = config.socks5ProxyPort ?? constants_js_1.DEFAULT_SOCKS5_PROXY_PORT;
19
+ }
20
+ /**
21
+ * Build a proxy URL string for use with HTTP clients.
22
+ *
23
+ * The returned URL includes authentication via the username field.
24
+ * Geo-targeting and sticky sessions are encoded in the username portion
25
+ * following Dominus Node proxy conventions.
26
+ *
27
+ * @param apiKey - The API key to authenticate proxy requests.
28
+ * @param opts - Optional targeting parameters (protocol, country, etc.).
29
+ * @returns A fully-formed proxy URL string.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * const url = client.proxy.buildUrl("dn_live_abc123");
34
+ * // => "http://user:dn_live_abc123@proxy.dominusnode.com:8080"
35
+ *
36
+ * const socksUrl = client.proxy.buildUrl("dn_live_abc123", { protocol: "socks5", country: "US" });
37
+ * // => "socks5://user-country-US:dn_live_abc123@proxy.dominusnode.com:1080"
38
+ * ```
39
+ */
40
+ buildUrl(apiKey, opts) {
41
+ const protocol = opts?.protocol ?? "http";
42
+ const port = protocol === "socks5" ? this.socks5Port : this.httpPort;
43
+ // Build username with geo-targeting parameters (URL-encoded to prevent injection)
44
+ const userParts = ["user"];
45
+ if (opts?.country)
46
+ userParts.push(`country-${encodeURIComponent(opts.country)}`);
47
+ if (opts?.state)
48
+ userParts.push(`state-${encodeURIComponent(opts.state)}`);
49
+ if (opts?.city)
50
+ userParts.push(`city-${encodeURIComponent(opts.city)}`);
51
+ if (opts?.asn)
52
+ userParts.push(`asn-${encodeURIComponent(String(opts.asn))}`);
53
+ if (opts?.sessionId)
54
+ userParts.push(`session-${encodeURIComponent(opts.sessionId)}`);
55
+ const username = userParts.join("-");
56
+ return `${protocol}://${username}:${encodeURIComponent(apiKey)}@${this.proxyHost}:${port}`;
57
+ }
58
+ /** Get public proxy health status (does not require authentication). */
59
+ async getHealth() {
60
+ return this.http.get("/api/proxy/health", false);
61
+ }
62
+ /** Get detailed proxy status including provider info (requires authentication). */
63
+ async getStatus() {
64
+ return this.http.get("/api/proxy/status");
65
+ }
66
+ /** Get proxy server configuration (requires authentication). */
67
+ async getConfig() {
68
+ return this.http.get("/api/proxy/config");
69
+ }
70
+ }
71
+ exports.ProxyResource = ProxyResource;
@@ -0,0 +1,52 @@
1
+ import type { HttpClient } from "../http.js";
2
+ export interface AgenticWallet {
3
+ id: string;
4
+ label: string;
5
+ balanceCents: number;
6
+ spendingLimitCents: number;
7
+ dailyLimitCents: number | null;
8
+ allowedDomains: string[] | null;
9
+ status: string;
10
+ createdAt: string;
11
+ }
12
+ export interface AgenticWalletTransaction {
13
+ id: string;
14
+ walletId: string;
15
+ type: string;
16
+ amountCents: number;
17
+ description: string;
18
+ sessionId: string | null;
19
+ createdAt: string;
20
+ }
21
+ export interface AgenticWalletListResponse {
22
+ wallets: AgenticWallet[];
23
+ }
24
+ export interface AgenticWalletFundResponse {
25
+ transaction: AgenticWalletTransaction;
26
+ }
27
+ export interface AgenticWalletTransactionsResponse {
28
+ transactions: AgenticWalletTransaction[];
29
+ }
30
+ export interface AgenticWalletDeleteResponse {
31
+ deleted: boolean;
32
+ refundedCents: number;
33
+ }
34
+ export declare class AgenticWalletResource {
35
+ private http;
36
+ constructor(http: HttpClient);
37
+ create(label: string, spendingLimitCents?: number, options?: {
38
+ dailyLimitCents?: number | null;
39
+ allowedDomains?: string[] | null;
40
+ }): Promise<AgenticWallet>;
41
+ list(): Promise<AgenticWalletListResponse>;
42
+ get(walletId: string): Promise<AgenticWallet>;
43
+ fund(walletId: string, amountCents: number): Promise<AgenticWalletFundResponse>;
44
+ updateWalletPolicy(walletId: string, policy: {
45
+ dailyLimitCents?: number | null;
46
+ allowedDomains?: string[] | null;
47
+ }): Promise<AgenticWallet>;
48
+ transactions(walletId: string, limit?: number, offset?: number): Promise<AgenticWalletTransactionsResponse>;
49
+ freeze(walletId: string): Promise<AgenticWallet>;
50
+ unfreeze(walletId: string): Promise<AgenticWallet>;
51
+ delete(walletId: string): Promise<AgenticWalletDeleteResponse>;
52
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AgenticWalletResource = void 0;
4
+ class AgenticWalletResource {
5
+ http;
6
+ constructor(http) {
7
+ this.http = http;
8
+ }
9
+ async create(label, spendingLimitCents = 10000, options) {
10
+ if (!Number.isInteger(spendingLimitCents) || spendingLimitCents < 0 || spendingLimitCents > 2_147_483_647) {
11
+ throw new Error("spendingLimitCents must be a non-negative integer <= 2,147,483,647");
12
+ }
13
+ if (options?.dailyLimitCents !== undefined && options.dailyLimitCents !== null) {
14
+ if (!Number.isInteger(options.dailyLimitCents) || options.dailyLimitCents < 0 || options.dailyLimitCents > 2_147_483_647) {
15
+ throw new Error("dailyLimitCents must be a non-negative integer <= 2,147,483,647");
16
+ }
17
+ }
18
+ const body = { label, spendingLimitCents };
19
+ if (options?.dailyLimitCents !== undefined)
20
+ body.dailyLimitCents = options.dailyLimitCents;
21
+ if (options?.allowedDomains !== undefined)
22
+ body.allowedDomains = options.allowedDomains;
23
+ return this.http.post("/api/agent-wallet", body);
24
+ }
25
+ async list() {
26
+ return this.http.get("/api/agent-wallet");
27
+ }
28
+ async get(walletId) {
29
+ return this.http.get(`/api/agent-wallet/${encodeURIComponent(walletId)}`);
30
+ }
31
+ async fund(walletId, amountCents) {
32
+ if (!Number.isInteger(amountCents) || amountCents <= 0 || amountCents > 2_147_483_647) {
33
+ throw new Error("amountCents must be a positive integer <= 2,147,483,647");
34
+ }
35
+ return this.http.post(`/api/agent-wallet/${encodeURIComponent(walletId)}/fund`, { amountCents });
36
+ }
37
+ async updateWalletPolicy(walletId, policy) {
38
+ if (policy.dailyLimitCents !== undefined && policy.dailyLimitCents !== null) {
39
+ if (!Number.isInteger(policy.dailyLimitCents) || policy.dailyLimitCents < 0 || policy.dailyLimitCents > 2_147_483_647) {
40
+ throw new Error("dailyLimitCents must be a non-negative integer <= 2,147,483,647");
41
+ }
42
+ }
43
+ return this.http.patch(`/api/agent-wallet/${encodeURIComponent(walletId)}/policy`, policy);
44
+ }
45
+ async transactions(walletId, limit, offset) {
46
+ const params = new URLSearchParams();
47
+ if (limit !== undefined)
48
+ params.set("limit", String(limit));
49
+ if (offset !== undefined)
50
+ params.set("offset", String(offset));
51
+ const qs = params.toString();
52
+ return this.http.get(`/api/agent-wallet/${encodeURIComponent(walletId)}/transactions${qs ? `?${qs}` : ""}`);
53
+ }
54
+ async freeze(walletId) {
55
+ return this.http.post(`/api/agent-wallet/${encodeURIComponent(walletId)}/freeze`, {});
56
+ }
57
+ async unfreeze(walletId) {
58
+ return this.http.post(`/api/agent-wallet/${encodeURIComponent(walletId)}/unfreeze`, {});
59
+ }
60
+ async delete(walletId) {
61
+ return this.http.delete(`/api/agent-wallet/${encodeURIComponent(walletId)}`);
62
+ }
63
+ }
64
+ exports.AgenticWalletResource = AgenticWalletResource;