@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,71 @@
|
|
|
1
|
+
import type { HttpClient } from "./http.js";
|
|
2
|
+
import type { AdminUser, SystemStats } from "./types.js";
|
|
3
|
+
export interface DateRangeOptions {
|
|
4
|
+
since?: string;
|
|
5
|
+
until?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ListUsersResponse {
|
|
8
|
+
users: AdminUser[];
|
|
9
|
+
pagination: {
|
|
10
|
+
page: number;
|
|
11
|
+
limit: number;
|
|
12
|
+
total: number;
|
|
13
|
+
totalPages: number;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export interface GetUserResponse {
|
|
17
|
+
user: AdminUser;
|
|
18
|
+
}
|
|
19
|
+
export interface RevenueResponse {
|
|
20
|
+
totalRevenueCents: number;
|
|
21
|
+
totalRevenueUsd: number;
|
|
22
|
+
avgTransactionCents: number;
|
|
23
|
+
avgTransactionUsd: number;
|
|
24
|
+
transactionCount: number;
|
|
25
|
+
topupCount: number;
|
|
26
|
+
period: {
|
|
27
|
+
since: string;
|
|
28
|
+
until: string;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export interface DailyRevenueEntry {
|
|
32
|
+
date: string;
|
|
33
|
+
revenueCents: number;
|
|
34
|
+
revenueUsd: number;
|
|
35
|
+
}
|
|
36
|
+
export interface DailyRevenueResponse {
|
|
37
|
+
days: DailyRevenueEntry[];
|
|
38
|
+
period: {
|
|
39
|
+
since: string;
|
|
40
|
+
until: string;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export declare class AdminResource {
|
|
44
|
+
private http;
|
|
45
|
+
constructor(http: HttpClient);
|
|
46
|
+
/** List all users (paginated). Requires admin privileges. */
|
|
47
|
+
listUsers(opts?: {
|
|
48
|
+
page?: number;
|
|
49
|
+
limit?: number;
|
|
50
|
+
}): Promise<ListUsersResponse>;
|
|
51
|
+
/** Get detailed info for a specific user. Requires admin privileges. */
|
|
52
|
+
getUser(id: string): Promise<GetUserResponse>;
|
|
53
|
+
/** Suspend a user account. Requires admin privileges. */
|
|
54
|
+
suspendUser(id: string): Promise<{
|
|
55
|
+
message: string;
|
|
56
|
+
}>;
|
|
57
|
+
/** Reactivate a suspended user account. Requires admin privileges. */
|
|
58
|
+
activateUser(id: string): Promise<{
|
|
59
|
+
message: string;
|
|
60
|
+
}>;
|
|
61
|
+
/** Soft-delete a user account. Requires admin privileges. */
|
|
62
|
+
deleteUser(id: string): Promise<{
|
|
63
|
+
message: string;
|
|
64
|
+
}>;
|
|
65
|
+
/** Get revenue statistics for a date range. Requires admin privileges. */
|
|
66
|
+
getRevenue(opts?: DateRangeOptions): Promise<RevenueResponse>;
|
|
67
|
+
/** Get daily revenue breakdown. Requires admin privileges. */
|
|
68
|
+
getDailyRevenue(opts?: DateRangeOptions): Promise<DailyRevenueResponse>;
|
|
69
|
+
/** Get system-wide statistics. Requires admin privileges. */
|
|
70
|
+
getStats(): Promise<SystemStats>;
|
|
71
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AdminResource = void 0;
|
|
4
|
+
class AdminResource {
|
|
5
|
+
http;
|
|
6
|
+
constructor(http) {
|
|
7
|
+
this.http = http;
|
|
8
|
+
}
|
|
9
|
+
/** List all users (paginated). Requires admin privileges. */
|
|
10
|
+
async listUsers(opts) {
|
|
11
|
+
const params = new URLSearchParams();
|
|
12
|
+
if (opts?.page !== undefined)
|
|
13
|
+
params.set("page", String(opts.page));
|
|
14
|
+
if (opts?.limit !== undefined)
|
|
15
|
+
params.set("limit", String(opts.limit));
|
|
16
|
+
const qs = params.toString();
|
|
17
|
+
return this.http.get(`/api/admin/users${qs ? `?${qs}` : ""}`);
|
|
18
|
+
}
|
|
19
|
+
/** Get detailed info for a specific user. Requires admin privileges. */
|
|
20
|
+
async getUser(id) {
|
|
21
|
+
return this.http.get(`/api/admin/users/${encodeURIComponent(id)}`);
|
|
22
|
+
}
|
|
23
|
+
/** Suspend a user account. Requires admin privileges. */
|
|
24
|
+
async suspendUser(id) {
|
|
25
|
+
return this.http.put(`/api/admin/users/${encodeURIComponent(id)}/suspend`);
|
|
26
|
+
}
|
|
27
|
+
/** Reactivate a suspended user account. Requires admin privileges. */
|
|
28
|
+
async activateUser(id) {
|
|
29
|
+
return this.http.put(`/api/admin/users/${encodeURIComponent(id)}/activate`);
|
|
30
|
+
}
|
|
31
|
+
/** Soft-delete a user account. Requires admin privileges. */
|
|
32
|
+
async deleteUser(id) {
|
|
33
|
+
return this.http.delete(`/api/admin/users/${encodeURIComponent(id)}`);
|
|
34
|
+
}
|
|
35
|
+
/** Get revenue statistics for a date range. Requires admin privileges. */
|
|
36
|
+
async getRevenue(opts) {
|
|
37
|
+
const params = new URLSearchParams();
|
|
38
|
+
if (opts?.since)
|
|
39
|
+
params.set("since", opts.since);
|
|
40
|
+
if (opts?.until)
|
|
41
|
+
params.set("until", opts.until);
|
|
42
|
+
const qs = params.toString();
|
|
43
|
+
return this.http.get(`/api/admin/revenue${qs ? `?${qs}` : ""}`);
|
|
44
|
+
}
|
|
45
|
+
/** Get daily revenue breakdown. Requires admin privileges. */
|
|
46
|
+
async getDailyRevenue(opts) {
|
|
47
|
+
const params = new URLSearchParams();
|
|
48
|
+
if (opts?.since)
|
|
49
|
+
params.set("since", opts.since);
|
|
50
|
+
if (opts?.until)
|
|
51
|
+
params.set("until", opts.until);
|
|
52
|
+
const qs = params.toString();
|
|
53
|
+
return this.http.get(`/api/admin/revenue/daily${qs ? `?${qs}` : ""}`);
|
|
54
|
+
}
|
|
55
|
+
/** Get system-wide statistics. Requires admin privileges. */
|
|
56
|
+
async getStats() {
|
|
57
|
+
return this.http.get("/api/admin/stats");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.AdminResource = AdminResource;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { HttpClient } from "./http.js";
|
|
2
|
+
import type { User, LoginResult, MfaStatus, MfaSetup } from "./types.js";
|
|
3
|
+
export declare class AuthResource {
|
|
4
|
+
private http;
|
|
5
|
+
constructor(http: HttpClient);
|
|
6
|
+
register(email: string, password: string): Promise<{
|
|
7
|
+
user: User;
|
|
8
|
+
token?: string;
|
|
9
|
+
refreshToken?: string;
|
|
10
|
+
}>;
|
|
11
|
+
login(email: string, password: string): Promise<LoginResult & {
|
|
12
|
+
token?: string;
|
|
13
|
+
refreshToken?: string;
|
|
14
|
+
}>;
|
|
15
|
+
verifyMfa(code: string, opts?: {
|
|
16
|
+
mfaChallengeToken?: string;
|
|
17
|
+
isBackupCode?: boolean;
|
|
18
|
+
}): Promise<{
|
|
19
|
+
user: User;
|
|
20
|
+
token: string;
|
|
21
|
+
refreshToken: string;
|
|
22
|
+
}>;
|
|
23
|
+
refresh(refreshToken: string): Promise<{
|
|
24
|
+
token: string;
|
|
25
|
+
refreshToken?: string;
|
|
26
|
+
}>;
|
|
27
|
+
logout(): Promise<void>;
|
|
28
|
+
me(): Promise<{
|
|
29
|
+
user: User;
|
|
30
|
+
}>;
|
|
31
|
+
changePassword(currentPassword: string, newPassword: string): Promise<void>;
|
|
32
|
+
verifyKey(apiKey: string): Promise<{
|
|
33
|
+
valid: boolean;
|
|
34
|
+
token: string;
|
|
35
|
+
refreshToken: string;
|
|
36
|
+
userId: string;
|
|
37
|
+
email: string;
|
|
38
|
+
}>;
|
|
39
|
+
mfaSetup(): Promise<MfaSetup>;
|
|
40
|
+
mfaEnable(code: string): Promise<{
|
|
41
|
+
enabled: boolean;
|
|
42
|
+
}>;
|
|
43
|
+
mfaDisable(password: string, code: string): Promise<{
|
|
44
|
+
enabled: boolean;
|
|
45
|
+
}>;
|
|
46
|
+
mfaStatus(): Promise<MfaStatus>;
|
|
47
|
+
}
|
package/dist/cjs/auth.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthResource = void 0;
|
|
4
|
+
class AuthResource {
|
|
5
|
+
http;
|
|
6
|
+
constructor(http) {
|
|
7
|
+
this.http = http;
|
|
8
|
+
}
|
|
9
|
+
async register(email, password) {
|
|
10
|
+
return this.http.post("/api/auth/register", { email, password }, false);
|
|
11
|
+
}
|
|
12
|
+
async login(email, password) {
|
|
13
|
+
return this.http.post("/api/auth/login", { email, password }, false);
|
|
14
|
+
}
|
|
15
|
+
async verifyMfa(code, opts) {
|
|
16
|
+
return this.http.post("/api/auth/mfa/verify", { code, ...opts }, false);
|
|
17
|
+
}
|
|
18
|
+
async refresh(refreshToken) {
|
|
19
|
+
return this.http.post("/api/auth/refresh", { refreshToken }, false);
|
|
20
|
+
}
|
|
21
|
+
async logout() {
|
|
22
|
+
await this.http.post("/api/auth/logout", {});
|
|
23
|
+
}
|
|
24
|
+
async me() {
|
|
25
|
+
return this.http.get("/api/auth/me");
|
|
26
|
+
}
|
|
27
|
+
async changePassword(currentPassword, newPassword) {
|
|
28
|
+
await this.http.post("/api/auth/change-password", { currentPassword, newPassword });
|
|
29
|
+
}
|
|
30
|
+
async verifyKey(apiKey) {
|
|
31
|
+
return this.http.post("/api/auth/verify-key", { apiKey }, false);
|
|
32
|
+
}
|
|
33
|
+
async mfaSetup() {
|
|
34
|
+
return this.http.post("/api/auth/mfa/setup", {});
|
|
35
|
+
}
|
|
36
|
+
async mfaEnable(code) {
|
|
37
|
+
return this.http.post("/api/auth/mfa/enable", { code });
|
|
38
|
+
}
|
|
39
|
+
async mfaDisable(password, code) {
|
|
40
|
+
return this.http.post("/api/auth/mfa/disable", { password, code });
|
|
41
|
+
}
|
|
42
|
+
async mfaStatus() {
|
|
43
|
+
return this.http.get("/api/auth/mfa/status");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.AuthResource = AuthResource;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { AuthResource } from "./auth.js";
|
|
2
|
+
import { KeysResource } from "./keys.js";
|
|
3
|
+
import { WalletResource } from "./wallet.js";
|
|
4
|
+
import { UsageResource } from "./usage.js";
|
|
5
|
+
import { PlansResource } from "./plans.js";
|
|
6
|
+
import { SessionsResource } from "./sessions.js";
|
|
7
|
+
import { ProxyResource } from "./proxy.js";
|
|
8
|
+
import { AdminResource } from "./admin.js";
|
|
9
|
+
import { SlotsResource } from "./slots.js";
|
|
10
|
+
import { AgenticWalletResource } from "./resources/agent-wallet.js";
|
|
11
|
+
import { TeamsResource } from "./resources/teams.js";
|
|
12
|
+
import { X402Resource } from "./resources/x402.js";
|
|
13
|
+
import { WalletAuthResource } from "./resources/wallet-auth.js";
|
|
14
|
+
import type { DominusNodeConfig, LoginResult } from "./types.js";
|
|
15
|
+
export declare class DominusNodeClient {
|
|
16
|
+
readonly auth: AuthResource;
|
|
17
|
+
readonly keys: KeysResource;
|
|
18
|
+
readonly wallet: WalletResource;
|
|
19
|
+
readonly usage: UsageResource;
|
|
20
|
+
readonly plans: PlansResource;
|
|
21
|
+
readonly sessions: SessionsResource;
|
|
22
|
+
readonly proxy: ProxyResource;
|
|
23
|
+
readonly admin: AdminResource;
|
|
24
|
+
readonly slots: SlotsResource;
|
|
25
|
+
readonly agenticWallets: AgenticWalletResource;
|
|
26
|
+
readonly teams: TeamsResource;
|
|
27
|
+
readonly x402: X402Resource;
|
|
28
|
+
readonly walletAuth: WalletAuthResource;
|
|
29
|
+
private tokenManager;
|
|
30
|
+
private http;
|
|
31
|
+
private apiKey;
|
|
32
|
+
constructor(config?: DominusNodeConfig);
|
|
33
|
+
/**
|
|
34
|
+
* Authenticate with an API key.
|
|
35
|
+
* Verifies the key against the server and stores the resulting JWT tokens
|
|
36
|
+
* for subsequent authenticated requests.
|
|
37
|
+
*/
|
|
38
|
+
connectWithKey(apiKey: string): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Authenticate with email and password.
|
|
41
|
+
* If MFA is required, the returned result will have `mfaRequired: true`.
|
|
42
|
+
* Call `completeMfa()` to finish authentication in that case.
|
|
43
|
+
*/
|
|
44
|
+
connectWithCredentials(email: string, password: string): Promise<LoginResult>;
|
|
45
|
+
/**
|
|
46
|
+
* Complete MFA verification after a login that returned `mfaRequired: true`.
|
|
47
|
+
*/
|
|
48
|
+
completeMfa(code: string, opts?: {
|
|
49
|
+
mfaChallengeToken?: string;
|
|
50
|
+
isBackupCode?: boolean;
|
|
51
|
+
}): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Disconnect: revoke refresh tokens server-side (best-effort) and clear all stored tokens.
|
|
54
|
+
*/
|
|
55
|
+
disconnect(): Promise<void>;
|
|
56
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DominusNodeClient = void 0;
|
|
4
|
+
const token_manager_js_1 = require("./token-manager.js");
|
|
5
|
+
const http_js_1 = require("./http.js");
|
|
6
|
+
const auth_js_1 = require("./auth.js");
|
|
7
|
+
const keys_js_1 = require("./keys.js");
|
|
8
|
+
const wallet_js_1 = require("./wallet.js");
|
|
9
|
+
const usage_js_1 = require("./usage.js");
|
|
10
|
+
const plans_js_1 = require("./plans.js");
|
|
11
|
+
const sessions_js_1 = require("./sessions.js");
|
|
12
|
+
const proxy_js_1 = require("./proxy.js");
|
|
13
|
+
const admin_js_1 = require("./admin.js");
|
|
14
|
+
const slots_js_1 = require("./slots.js");
|
|
15
|
+
const agent_wallet_js_1 = require("./resources/agent-wallet.js");
|
|
16
|
+
const teams_js_1 = require("./resources/teams.js");
|
|
17
|
+
const x402_js_1 = require("./resources/x402.js");
|
|
18
|
+
const wallet_auth_js_1 = require("./resources/wallet-auth.js");
|
|
19
|
+
const constants_js_1 = require("./constants.js");
|
|
20
|
+
class DominusNodeClient {
|
|
21
|
+
auth;
|
|
22
|
+
keys;
|
|
23
|
+
wallet;
|
|
24
|
+
usage;
|
|
25
|
+
plans;
|
|
26
|
+
sessions;
|
|
27
|
+
proxy;
|
|
28
|
+
admin;
|
|
29
|
+
slots;
|
|
30
|
+
agenticWallets;
|
|
31
|
+
teams;
|
|
32
|
+
x402;
|
|
33
|
+
walletAuth;
|
|
34
|
+
tokenManager;
|
|
35
|
+
http;
|
|
36
|
+
apiKey = null;
|
|
37
|
+
constructor(config = {}) {
|
|
38
|
+
const baseUrl = config.baseUrl ?? constants_js_1.DEFAULT_BASE_URL;
|
|
39
|
+
this.tokenManager = new token_manager_js_1.TokenManager();
|
|
40
|
+
this.http = new http_js_1.HttpClient(baseUrl, this.tokenManager);
|
|
41
|
+
// Initialize all resource modules BEFORE setting refresh function
|
|
42
|
+
// this.auth must exist before refresh function can be invoked
|
|
43
|
+
this.auth = new auth_js_1.AuthResource(this.http);
|
|
44
|
+
this.keys = new keys_js_1.KeysResource(this.http);
|
|
45
|
+
this.wallet = new wallet_js_1.WalletResource(this.http);
|
|
46
|
+
this.usage = new usage_js_1.UsageResource(this.http);
|
|
47
|
+
this.plans = new plans_js_1.PlansResource(this.http);
|
|
48
|
+
this.sessions = new sessions_js_1.SessionsResource(this.http);
|
|
49
|
+
this.proxy = new proxy_js_1.ProxyResource(this.http, config);
|
|
50
|
+
this.admin = new admin_js_1.AdminResource(this.http);
|
|
51
|
+
this.slots = new slots_js_1.SlotsResource(this.http);
|
|
52
|
+
this.agenticWallets = new agent_wallet_js_1.AgenticWalletResource(this.http);
|
|
53
|
+
this.teams = new teams_js_1.TeamsResource(this.http);
|
|
54
|
+
this.x402 = new x402_js_1.X402Resource(this.http);
|
|
55
|
+
this.walletAuth = new wallet_auth_js_1.WalletAuthResource(this.http, this.tokenManager);
|
|
56
|
+
// Set refresh function AFTER auth is initialized
|
|
57
|
+
this.tokenManager.setRefreshFunction(async (rt) => {
|
|
58
|
+
const res = await this.auth.refresh(rt);
|
|
59
|
+
return { accessToken: res.token, refreshToken: res.refreshToken };
|
|
60
|
+
});
|
|
61
|
+
// Auto-authenticate if tokens were provided in config
|
|
62
|
+
if (config.accessToken) {
|
|
63
|
+
this.tokenManager.setTokens(config.accessToken, config.refreshToken);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Authenticate with an API key.
|
|
68
|
+
* Verifies the key against the server and stores the resulting JWT tokens
|
|
69
|
+
* for subsequent authenticated requests.
|
|
70
|
+
*/
|
|
71
|
+
async connectWithKey(apiKey) {
|
|
72
|
+
const res = await this.auth.verifyKey(apiKey);
|
|
73
|
+
this.apiKey = apiKey;
|
|
74
|
+
this.tokenManager.setTokens(res.token, res.refreshToken);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Authenticate with email and password.
|
|
78
|
+
* If MFA is required, the returned result will have `mfaRequired: true`.
|
|
79
|
+
* Call `completeMfa()` to finish authentication in that case.
|
|
80
|
+
*/
|
|
81
|
+
async connectWithCredentials(email, password) {
|
|
82
|
+
const res = await this.auth.login(email, password);
|
|
83
|
+
if (res.token) {
|
|
84
|
+
this.tokenManager.setTokens(res.token, res.refreshToken);
|
|
85
|
+
}
|
|
86
|
+
return { user: res.user, mfaRequired: res.mfaRequired };
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Complete MFA verification after a login that returned `mfaRequired: true`.
|
|
90
|
+
*/
|
|
91
|
+
async completeMfa(code, opts) {
|
|
92
|
+
const res = await this.auth.verifyMfa(code, opts);
|
|
93
|
+
this.tokenManager.setTokens(res.token, res.refreshToken);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Disconnect: revoke refresh tokens server-side (best-effort) and clear all stored tokens.
|
|
97
|
+
*/
|
|
98
|
+
async disconnect() {
|
|
99
|
+
try {
|
|
100
|
+
await this.auth.logout();
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// Best-effort — server may be unreachable
|
|
104
|
+
}
|
|
105
|
+
this.apiKey = null;
|
|
106
|
+
this.tokenManager.clear();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.DominusNodeClient = DominusNodeClient;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const SDK_VERSION = "1.0.0";
|
|
2
|
+
export declare const USER_AGENT = "dominusnode-sdk-node/1.0.0";
|
|
3
|
+
export declare const DEFAULT_BASE_URL = "https://api.dominusnode.com";
|
|
4
|
+
export declare const DEFAULT_PROXY_HOST = "proxy.dominusnode.com";
|
|
5
|
+
export declare const DEFAULT_HTTP_PROXY_PORT = 8080;
|
|
6
|
+
export declare const DEFAULT_SOCKS5_PROXY_PORT = 1080;
|
|
7
|
+
export declare const TOKEN_REFRESH_BUFFER_MS = 60000;
|
|
8
|
+
export declare const MAX_RATE_LIMIT_RETRIES = 1;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAX_RATE_LIMIT_RETRIES = exports.TOKEN_REFRESH_BUFFER_MS = exports.DEFAULT_SOCKS5_PROXY_PORT = exports.DEFAULT_HTTP_PROXY_PORT = exports.DEFAULT_PROXY_HOST = exports.DEFAULT_BASE_URL = exports.USER_AGENT = exports.SDK_VERSION = void 0;
|
|
4
|
+
exports.SDK_VERSION = "1.0.0";
|
|
5
|
+
exports.USER_AGENT = `dominusnode-sdk-node/${exports.SDK_VERSION}`;
|
|
6
|
+
exports.DEFAULT_BASE_URL = "https://api.dominusnode.com";
|
|
7
|
+
exports.DEFAULT_PROXY_HOST = "proxy.dominusnode.com";
|
|
8
|
+
exports.DEFAULT_HTTP_PROXY_PORT = 8080;
|
|
9
|
+
exports.DEFAULT_SOCKS5_PROXY_PORT = 1080;
|
|
10
|
+
exports.TOKEN_REFRESH_BUFFER_MS = 60_000; // Refresh 60s before expiry
|
|
11
|
+
exports.MAX_RATE_LIMIT_RETRIES = 1;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare class DominusNodeError extends Error {
|
|
2
|
+
readonly statusCode?: number | undefined;
|
|
3
|
+
constructor(message: string, statusCode?: number | undefined);
|
|
4
|
+
}
|
|
5
|
+
export declare class AuthenticationError extends DominusNodeError {
|
|
6
|
+
constructor(message?: string);
|
|
7
|
+
}
|
|
8
|
+
export declare class AuthorizationError extends DominusNodeError {
|
|
9
|
+
constructor(message?: string);
|
|
10
|
+
}
|
|
11
|
+
export declare class RateLimitError extends DominusNodeError {
|
|
12
|
+
readonly retryAfterSeconds: number;
|
|
13
|
+
constructor(message?: string, retryAfter?: number);
|
|
14
|
+
}
|
|
15
|
+
export declare class InsufficientBalanceError extends DominusNodeError {
|
|
16
|
+
constructor(message?: string);
|
|
17
|
+
}
|
|
18
|
+
export declare class ValidationError extends DominusNodeError {
|
|
19
|
+
constructor(message?: string);
|
|
20
|
+
}
|
|
21
|
+
export declare class NotFoundError extends DominusNodeError {
|
|
22
|
+
constructor(message?: string);
|
|
23
|
+
}
|
|
24
|
+
export declare class ConflictError extends DominusNodeError {
|
|
25
|
+
constructor(message?: string);
|
|
26
|
+
}
|
|
27
|
+
export declare class ServerError extends DominusNodeError {
|
|
28
|
+
constructor(message?: string);
|
|
29
|
+
}
|
|
30
|
+
export declare class NetworkError extends DominusNodeError {
|
|
31
|
+
constructor(message?: string);
|
|
32
|
+
}
|
|
33
|
+
export declare class ProxyError extends DominusNodeError {
|
|
34
|
+
readonly proxyErrorCode?: string;
|
|
35
|
+
constructor(message: string, proxyErrorCode?: string);
|
|
36
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProxyError = exports.NetworkError = exports.ServerError = exports.ConflictError = exports.NotFoundError = exports.ValidationError = exports.InsufficientBalanceError = exports.RateLimitError = exports.AuthorizationError = exports.AuthenticationError = exports.DominusNodeError = void 0;
|
|
4
|
+
class DominusNodeError extends Error {
|
|
5
|
+
statusCode;
|
|
6
|
+
constructor(message, statusCode) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.statusCode = statusCode;
|
|
9
|
+
this.name = "DominusNodeError";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.DominusNodeError = DominusNodeError;
|
|
13
|
+
class AuthenticationError extends DominusNodeError {
|
|
14
|
+
constructor(message = "Authentication failed") {
|
|
15
|
+
super(message, 401);
|
|
16
|
+
this.name = "AuthenticationError";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.AuthenticationError = AuthenticationError;
|
|
20
|
+
class AuthorizationError extends DominusNodeError {
|
|
21
|
+
constructor(message = "Access denied") {
|
|
22
|
+
super(message, 403);
|
|
23
|
+
this.name = "AuthorizationError";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.AuthorizationError = AuthorizationError;
|
|
27
|
+
class RateLimitError extends DominusNodeError {
|
|
28
|
+
retryAfterSeconds;
|
|
29
|
+
constructor(message = "Rate limit exceeded", retryAfter = 60) {
|
|
30
|
+
super(message, 429);
|
|
31
|
+
this.name = "RateLimitError";
|
|
32
|
+
this.retryAfterSeconds = retryAfter;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.RateLimitError = RateLimitError;
|
|
36
|
+
class InsufficientBalanceError extends DominusNodeError {
|
|
37
|
+
constructor(message = "Insufficient balance") {
|
|
38
|
+
super(message, 402);
|
|
39
|
+
this.name = "InsufficientBalanceError";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.InsufficientBalanceError = InsufficientBalanceError;
|
|
43
|
+
class ValidationError extends DominusNodeError {
|
|
44
|
+
constructor(message = "Validation failed") {
|
|
45
|
+
super(message, 400);
|
|
46
|
+
this.name = "ValidationError";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.ValidationError = ValidationError;
|
|
50
|
+
class NotFoundError extends DominusNodeError {
|
|
51
|
+
constructor(message = "Resource not found") {
|
|
52
|
+
super(message, 404);
|
|
53
|
+
this.name = "NotFoundError";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.NotFoundError = NotFoundError;
|
|
57
|
+
class ConflictError extends DominusNodeError {
|
|
58
|
+
constructor(message = "Resource conflict") {
|
|
59
|
+
super(message, 409);
|
|
60
|
+
this.name = "ConflictError";
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.ConflictError = ConflictError;
|
|
64
|
+
class ServerError extends DominusNodeError {
|
|
65
|
+
constructor(message = "Server error") {
|
|
66
|
+
super(message, 500);
|
|
67
|
+
this.name = "ServerError";
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.ServerError = ServerError;
|
|
71
|
+
class NetworkError extends DominusNodeError {
|
|
72
|
+
constructor(message = "Network error") {
|
|
73
|
+
super(message);
|
|
74
|
+
this.name = "NetworkError";
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.NetworkError = NetworkError;
|
|
78
|
+
class ProxyError extends DominusNodeError {
|
|
79
|
+
proxyErrorCode;
|
|
80
|
+
constructor(message, proxyErrorCode) {
|
|
81
|
+
super(message);
|
|
82
|
+
this.name = "ProxyError";
|
|
83
|
+
this.proxyErrorCode = proxyErrorCode;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.ProxyError = ProxyError;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { TokenManager } from "./token-manager.js";
|
|
2
|
+
export interface HttpOptions {
|
|
3
|
+
method: string;
|
|
4
|
+
path: string;
|
|
5
|
+
body?: unknown;
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
requiresAuth?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare class HttpClient {
|
|
10
|
+
private baseUrl;
|
|
11
|
+
private tokenManager;
|
|
12
|
+
constructor(baseUrl: string, tokenManager: TokenManager);
|
|
13
|
+
request<T>(opts: HttpOptions): Promise<T>;
|
|
14
|
+
get<T>(path: string, requiresAuth?: boolean): Promise<T>;
|
|
15
|
+
post<T>(path: string, body?: unknown, requiresAuth?: boolean): Promise<T>;
|
|
16
|
+
put<T>(path: string, body?: unknown): Promise<T>;
|
|
17
|
+
patch<T>(path: string, body?: unknown): Promise<T>;
|
|
18
|
+
delete<T>(path: string): Promise<T>;
|
|
19
|
+
}
|