@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,93 @@
|
|
|
1
|
+
import type { HttpClient } from "../http.js";
|
|
2
|
+
export interface Team {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
ownerId: string;
|
|
6
|
+
maxMembers: number;
|
|
7
|
+
status: string;
|
|
8
|
+
balanceCents: number;
|
|
9
|
+
createdAt: string;
|
|
10
|
+
}
|
|
11
|
+
export interface TeamMember {
|
|
12
|
+
id: string;
|
|
13
|
+
teamId: string;
|
|
14
|
+
userId: string;
|
|
15
|
+
email: string;
|
|
16
|
+
role: string;
|
|
17
|
+
joinedAt: string;
|
|
18
|
+
}
|
|
19
|
+
export interface TeamInvite {
|
|
20
|
+
id: string;
|
|
21
|
+
teamId: string;
|
|
22
|
+
email: string;
|
|
23
|
+
role: string;
|
|
24
|
+
token: string;
|
|
25
|
+
expiresAt: string;
|
|
26
|
+
createdAt: string;
|
|
27
|
+
}
|
|
28
|
+
export interface TeamKey {
|
|
29
|
+
id: string;
|
|
30
|
+
keyPrefix: string;
|
|
31
|
+
label: string;
|
|
32
|
+
createdAt: string;
|
|
33
|
+
}
|
|
34
|
+
export interface TeamKeyCreateResponse {
|
|
35
|
+
id: string;
|
|
36
|
+
key: string;
|
|
37
|
+
keyPrefix: string;
|
|
38
|
+
label: string;
|
|
39
|
+
}
|
|
40
|
+
export interface TeamListResponse {
|
|
41
|
+
teams: Team[];
|
|
42
|
+
}
|
|
43
|
+
export interface TeamDeleteResponse {
|
|
44
|
+
refundedCents: number;
|
|
45
|
+
}
|
|
46
|
+
export interface TeamFundResponse {
|
|
47
|
+
transaction: TeamTransaction;
|
|
48
|
+
}
|
|
49
|
+
export interface TeamTransaction {
|
|
50
|
+
id: string;
|
|
51
|
+
teamId: string;
|
|
52
|
+
type: string;
|
|
53
|
+
amountCents: number;
|
|
54
|
+
description: string;
|
|
55
|
+
createdAt: string;
|
|
56
|
+
}
|
|
57
|
+
export interface TeamTransactionsResponse {
|
|
58
|
+
transactions: TeamTransaction[];
|
|
59
|
+
}
|
|
60
|
+
export interface TeamMembersResponse {
|
|
61
|
+
members: TeamMember[];
|
|
62
|
+
}
|
|
63
|
+
export interface TeamInvitesResponse {
|
|
64
|
+
invites: TeamInvite[];
|
|
65
|
+
}
|
|
66
|
+
export interface TeamKeysResponse {
|
|
67
|
+
keys: TeamKey[];
|
|
68
|
+
}
|
|
69
|
+
export declare class TeamsResource {
|
|
70
|
+
private http;
|
|
71
|
+
constructor(http: HttpClient);
|
|
72
|
+
create(name: string, maxMembers?: number): Promise<Team>;
|
|
73
|
+
list(): Promise<Team[]>;
|
|
74
|
+
get(teamId: string): Promise<Team>;
|
|
75
|
+
update(teamId: string, updates: {
|
|
76
|
+
name?: string;
|
|
77
|
+
maxMembers?: number;
|
|
78
|
+
}): Promise<Team>;
|
|
79
|
+
delete(teamId: string): Promise<TeamDeleteResponse>;
|
|
80
|
+
fundWallet(teamId: string, amountCents: number): Promise<TeamFundResponse>;
|
|
81
|
+
getTransactions(teamId: string, limit?: number, offset?: number): Promise<TeamTransactionsResponse>;
|
|
82
|
+
listMembers(teamId: string): Promise<TeamMembersResponse>;
|
|
83
|
+
addMember(teamId: string, email: string, role?: string): Promise<TeamMember>;
|
|
84
|
+
updateMemberRole(teamId: string, userId: string, role: string): Promise<TeamMember>;
|
|
85
|
+
removeMember(teamId: string, userId: string): Promise<void>;
|
|
86
|
+
createInvite(teamId: string, email: string, role?: string): Promise<TeamInvite>;
|
|
87
|
+
listInvites(teamId: string): Promise<TeamInvitesResponse>;
|
|
88
|
+
cancelInvite(teamId: string, inviteId: string): Promise<void>;
|
|
89
|
+
acceptInvite(token: string): Promise<TeamMember>;
|
|
90
|
+
createKey(teamId: string, label: string): Promise<TeamKeyCreateResponse>;
|
|
91
|
+
listKeys(teamId: string): Promise<TeamKeysResponse>;
|
|
92
|
+
revokeKey(teamId: string, keyId: string): Promise<void>;
|
|
93
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TeamsResource = void 0;
|
|
4
|
+
class TeamsResource {
|
|
5
|
+
http;
|
|
6
|
+
constructor(http) {
|
|
7
|
+
this.http = http;
|
|
8
|
+
}
|
|
9
|
+
async create(name, maxMembers) {
|
|
10
|
+
const body = { name };
|
|
11
|
+
if (maxMembers !== undefined)
|
|
12
|
+
body.maxMembers = maxMembers;
|
|
13
|
+
return this.http.post("/api/teams", body);
|
|
14
|
+
}
|
|
15
|
+
async list() {
|
|
16
|
+
return this.http.get("/api/teams");
|
|
17
|
+
}
|
|
18
|
+
async get(teamId) {
|
|
19
|
+
return this.http.get(`/api/teams/${encodeURIComponent(teamId)}`);
|
|
20
|
+
}
|
|
21
|
+
async update(teamId, updates) {
|
|
22
|
+
return this.http.patch(`/api/teams/${encodeURIComponent(teamId)}`, updates);
|
|
23
|
+
}
|
|
24
|
+
async delete(teamId) {
|
|
25
|
+
return this.http.delete(`/api/teams/${encodeURIComponent(teamId)}`);
|
|
26
|
+
}
|
|
27
|
+
async fundWallet(teamId, amountCents) {
|
|
28
|
+
if (!Number.isInteger(amountCents) || amountCents <= 0 || amountCents > 2_147_483_647) {
|
|
29
|
+
throw new Error("amountCents must be a positive integer <= 2,147,483,647");
|
|
30
|
+
}
|
|
31
|
+
return this.http.post(`/api/teams/${encodeURIComponent(teamId)}/wallet/fund`, { amountCents });
|
|
32
|
+
}
|
|
33
|
+
async getTransactions(teamId, limit, offset) {
|
|
34
|
+
const params = new URLSearchParams();
|
|
35
|
+
if (limit !== undefined)
|
|
36
|
+
params.set("limit", String(limit));
|
|
37
|
+
if (offset !== undefined)
|
|
38
|
+
params.set("offset", String(offset));
|
|
39
|
+
const qs = params.toString();
|
|
40
|
+
return this.http.get(`/api/teams/${encodeURIComponent(teamId)}/wallet/transactions${qs ? `?${qs}` : ""}`);
|
|
41
|
+
}
|
|
42
|
+
async listMembers(teamId) {
|
|
43
|
+
return this.http.get(`/api/teams/${encodeURIComponent(teamId)}/members`);
|
|
44
|
+
}
|
|
45
|
+
async addMember(teamId, email, role) {
|
|
46
|
+
const body = { email };
|
|
47
|
+
if (role !== undefined)
|
|
48
|
+
body.role = role;
|
|
49
|
+
return this.http.post(`/api/teams/${encodeURIComponent(teamId)}/members`, body);
|
|
50
|
+
}
|
|
51
|
+
async updateMemberRole(teamId, userId, role) {
|
|
52
|
+
return this.http.patch(`/api/teams/${encodeURIComponent(teamId)}/members/${encodeURIComponent(userId)}`, { role });
|
|
53
|
+
}
|
|
54
|
+
async removeMember(teamId, userId) {
|
|
55
|
+
await this.http.delete(`/api/teams/${encodeURIComponent(teamId)}/members/${encodeURIComponent(userId)}`);
|
|
56
|
+
}
|
|
57
|
+
async createInvite(teamId, email, role) {
|
|
58
|
+
const body = { email };
|
|
59
|
+
if (role !== undefined)
|
|
60
|
+
body.role = role;
|
|
61
|
+
return this.http.post(`/api/teams/${encodeURIComponent(teamId)}/invites`, body);
|
|
62
|
+
}
|
|
63
|
+
async listInvites(teamId) {
|
|
64
|
+
return this.http.get(`/api/teams/${encodeURIComponent(teamId)}/invites`);
|
|
65
|
+
}
|
|
66
|
+
async cancelInvite(teamId, inviteId) {
|
|
67
|
+
await this.http.delete(`/api/teams/${encodeURIComponent(teamId)}/invites/${encodeURIComponent(inviteId)}`);
|
|
68
|
+
}
|
|
69
|
+
async acceptInvite(token) {
|
|
70
|
+
return this.http.post(`/api/teams/invites/${encodeURIComponent(token)}/accept`, {});
|
|
71
|
+
}
|
|
72
|
+
async createKey(teamId, label) {
|
|
73
|
+
return this.http.post(`/api/teams/${encodeURIComponent(teamId)}/keys`, { label });
|
|
74
|
+
}
|
|
75
|
+
async listKeys(teamId) {
|
|
76
|
+
return this.http.get(`/api/teams/${encodeURIComponent(teamId)}/keys`);
|
|
77
|
+
}
|
|
78
|
+
async revokeKey(teamId, keyId) {
|
|
79
|
+
await this.http.delete(`/api/teams/${encodeURIComponent(teamId)}/keys/${encodeURIComponent(keyId)}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.TeamsResource = TeamsResource;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { HttpClient } from "../http.js";
|
|
2
|
+
import type { TokenManager } from "../token-manager.js";
|
|
3
|
+
import type { User } from "../types.js";
|
|
4
|
+
export interface WalletChallenge {
|
|
5
|
+
challenge: string;
|
|
6
|
+
expiresAt: string;
|
|
7
|
+
}
|
|
8
|
+
export interface WalletVerifyResult {
|
|
9
|
+
token: string;
|
|
10
|
+
refreshToken: string;
|
|
11
|
+
user: User;
|
|
12
|
+
/** When true, the user must complete MFA before authentication is granted. */
|
|
13
|
+
mfaRequired?: boolean;
|
|
14
|
+
/** Challenge token to pass to auth.verifyMfa() when mfaRequired is true. */
|
|
15
|
+
mfaChallengeToken?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface WalletLinkResult {
|
|
18
|
+
success: boolean;
|
|
19
|
+
walletAddress: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Wallet-based authentication using EIP-191 signed messages.
|
|
23
|
+
*
|
|
24
|
+
* Allows Ethereum wallet holders to authenticate by signing a server-issued
|
|
25
|
+
* challenge message. Supports account creation, login, and linking a wallet
|
|
26
|
+
* to an existing account.
|
|
27
|
+
*/
|
|
28
|
+
export declare class WalletAuthResource {
|
|
29
|
+
private http;
|
|
30
|
+
private tokenManager;
|
|
31
|
+
constructor(http: HttpClient, tokenManager: TokenManager);
|
|
32
|
+
/**
|
|
33
|
+
* Request a signature challenge for the given Ethereum address.
|
|
34
|
+
*
|
|
35
|
+
* The returned challenge must be signed with the wallet's private key
|
|
36
|
+
* and submitted via `verify()` to complete authentication.
|
|
37
|
+
*
|
|
38
|
+
* This endpoint does not require authentication.
|
|
39
|
+
*/
|
|
40
|
+
challenge(address: string): Promise<WalletChallenge>;
|
|
41
|
+
/**
|
|
42
|
+
* Submit a signed challenge to create an account or log in.
|
|
43
|
+
*
|
|
44
|
+
* If the address is not yet associated with an account, a new one is created.
|
|
45
|
+
* Returns JWT tokens and user information on success.
|
|
46
|
+
* Tokens are automatically stored for subsequent authenticated requests.
|
|
47
|
+
*
|
|
48
|
+
* This endpoint does not require authentication.
|
|
49
|
+
*
|
|
50
|
+
* @param address - Ethereum address (0x-prefixed, 40 hex chars)
|
|
51
|
+
* @param signature - EIP-191 signature of the challenge message
|
|
52
|
+
* @param challenge - Optional: the challenge string (server looks up internally)
|
|
53
|
+
*/
|
|
54
|
+
verify(address: string, signature: string, challenge?: string): Promise<WalletVerifyResult>;
|
|
55
|
+
/**
|
|
56
|
+
* Link an Ethereum wallet to the currently authenticated account.
|
|
57
|
+
*
|
|
58
|
+
* Requires JWT authentication. The challenge must have been previously
|
|
59
|
+
* obtained via `challenge()` and signed with the wallet.
|
|
60
|
+
*
|
|
61
|
+
* @param address - Ethereum address
|
|
62
|
+
* @param signature - EIP-191 signature
|
|
63
|
+
* @param challenge - Optional: the challenge string
|
|
64
|
+
*/
|
|
65
|
+
link(address: string, signature: string, challenge?: string): Promise<WalletLinkResult>;
|
|
66
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WalletAuthResource = void 0;
|
|
4
|
+
// Ethereum address validation: 0x followed by 40 hex characters
|
|
5
|
+
const ETH_ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
|
|
6
|
+
// EIP-191 signature format: 0x prefix + 130 hex chars (65 bytes)
|
|
7
|
+
const EIP191_SIGNATURE_RE = /^0x[0-9a-fA-F]{130}$/;
|
|
8
|
+
const MAX_SIGNATURE_LENGTH = 200;
|
|
9
|
+
function validateAddress(address) {
|
|
10
|
+
if (!address || typeof address !== "string") {
|
|
11
|
+
throw new Error("address is required and must be a string");
|
|
12
|
+
}
|
|
13
|
+
if (!ETH_ADDRESS_RE.test(address)) {
|
|
14
|
+
throw new Error("address must be a valid Ethereum address (0x followed by 40 hex characters)");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function validateSignature(signature) {
|
|
18
|
+
if (!signature || typeof signature !== "string") {
|
|
19
|
+
throw new Error("signature is required and must be a string");
|
|
20
|
+
}
|
|
21
|
+
// Max length check before regex
|
|
22
|
+
if (signature.length > MAX_SIGNATURE_LENGTH) {
|
|
23
|
+
throw new Error(`signature must not exceed ${MAX_SIGNATURE_LENGTH} characters`);
|
|
24
|
+
}
|
|
25
|
+
// EIP-191 format validation
|
|
26
|
+
if (!EIP191_SIGNATURE_RE.test(signature)) {
|
|
27
|
+
throw new Error("signature must be a valid EIP-191 signature (0x followed by 130 hex characters)");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Wallet-based authentication using EIP-191 signed messages.
|
|
32
|
+
*
|
|
33
|
+
* Allows Ethereum wallet holders to authenticate by signing a server-issued
|
|
34
|
+
* challenge message. Supports account creation, login, and linking a wallet
|
|
35
|
+
* to an existing account.
|
|
36
|
+
*/
|
|
37
|
+
class WalletAuthResource {
|
|
38
|
+
http;
|
|
39
|
+
tokenManager;
|
|
40
|
+
constructor(http, tokenManager) {
|
|
41
|
+
this.http = http;
|
|
42
|
+
this.tokenManager = tokenManager;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Request a signature challenge for the given Ethereum address.
|
|
46
|
+
*
|
|
47
|
+
* The returned challenge must be signed with the wallet's private key
|
|
48
|
+
* and submitted via `verify()` to complete authentication.
|
|
49
|
+
*
|
|
50
|
+
* This endpoint does not require authentication.
|
|
51
|
+
*/
|
|
52
|
+
async challenge(address) {
|
|
53
|
+
validateAddress(address);
|
|
54
|
+
return this.http.post("/api/auth/wallet/challenge", { address }, false);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Submit a signed challenge to create an account or log in.
|
|
58
|
+
*
|
|
59
|
+
* If the address is not yet associated with an account, a new one is created.
|
|
60
|
+
* Returns JWT tokens and user information on success.
|
|
61
|
+
* Tokens are automatically stored for subsequent authenticated requests.
|
|
62
|
+
*
|
|
63
|
+
* This endpoint does not require authentication.
|
|
64
|
+
*
|
|
65
|
+
* @param address - Ethereum address (0x-prefixed, 40 hex chars)
|
|
66
|
+
* @param signature - EIP-191 signature of the challenge message
|
|
67
|
+
* @param challenge - Optional: the challenge string (server looks up internally)
|
|
68
|
+
*/
|
|
69
|
+
async verify(address, signature, challenge) {
|
|
70
|
+
validateAddress(address);
|
|
71
|
+
validateSignature(signature);
|
|
72
|
+
const body = { address, signature };
|
|
73
|
+
if (challenge)
|
|
74
|
+
body.challenge = challenge;
|
|
75
|
+
const result = await this.http.post("/api/auth/wallet/verify", body, false);
|
|
76
|
+
// Detect MFA-required response — don't store tokens, surface to caller
|
|
77
|
+
if (result.mfaRequired) {
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
// Store tokens after verify (matching Python/Go/Java SDKs)
|
|
81
|
+
if (result.token && result.refreshToken) {
|
|
82
|
+
this.tokenManager.setTokens(result.token, result.refreshToken);
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Link an Ethereum wallet to the currently authenticated account.
|
|
88
|
+
*
|
|
89
|
+
* Requires JWT authentication. The challenge must have been previously
|
|
90
|
+
* obtained via `challenge()` and signed with the wallet.
|
|
91
|
+
*
|
|
92
|
+
* @param address - Ethereum address
|
|
93
|
+
* @param signature - EIP-191 signature
|
|
94
|
+
* @param challenge - Optional: the challenge string
|
|
95
|
+
*/
|
|
96
|
+
async link(address, signature, challenge) {
|
|
97
|
+
validateAddress(address);
|
|
98
|
+
validateSignature(signature);
|
|
99
|
+
const body = { address, signature };
|
|
100
|
+
if (challenge)
|
|
101
|
+
body.challenge = challenge;
|
|
102
|
+
return this.http.post("/api/auth/wallet/link", body);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.WalletAuthResource = WalletAuthResource;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { HttpClient } from "../http.js";
|
|
2
|
+
export interface X402Facilitator {
|
|
3
|
+
address: string;
|
|
4
|
+
chain: string;
|
|
5
|
+
network: string;
|
|
6
|
+
}
|
|
7
|
+
export interface X402Pricing {
|
|
8
|
+
perRequestCents: number;
|
|
9
|
+
perGbCents: number;
|
|
10
|
+
currency: string;
|
|
11
|
+
}
|
|
12
|
+
export interface X402Info {
|
|
13
|
+
supported: boolean;
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
protocol: string;
|
|
16
|
+
version: string;
|
|
17
|
+
facilitators: X402Facilitator[];
|
|
18
|
+
pricing: X402Pricing;
|
|
19
|
+
currencies: string[];
|
|
20
|
+
walletType: string;
|
|
21
|
+
agenticWallets: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* x402 (HTTP 402 Payment Required) protocol information.
|
|
25
|
+
*
|
|
26
|
+
* Provides details about x402 micropayment support, facilitator addresses,
|
|
27
|
+
* pricing, and supported chains/currencies for AI agent payments.
|
|
28
|
+
*/
|
|
29
|
+
export declare class X402Resource {
|
|
30
|
+
private http;
|
|
31
|
+
constructor(http: HttpClient);
|
|
32
|
+
/**
|
|
33
|
+
* Get x402 protocol information including facilitator details,
|
|
34
|
+
* pricing, supported chains, and currencies.
|
|
35
|
+
*
|
|
36
|
+
* This endpoint does not require authentication.
|
|
37
|
+
*/
|
|
38
|
+
getInfo(): Promise<X402Info>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.X402Resource = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* x402 (HTTP 402 Payment Required) protocol information.
|
|
6
|
+
*
|
|
7
|
+
* Provides details about x402 micropayment support, facilitator addresses,
|
|
8
|
+
* pricing, and supported chains/currencies for AI agent payments.
|
|
9
|
+
*/
|
|
10
|
+
class X402Resource {
|
|
11
|
+
http;
|
|
12
|
+
constructor(http) {
|
|
13
|
+
this.http = http;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get x402 protocol information including facilitator details,
|
|
17
|
+
* pricing, supported chains, and currencies.
|
|
18
|
+
*
|
|
19
|
+
* This endpoint does not require authentication.
|
|
20
|
+
*/
|
|
21
|
+
async getInfo() {
|
|
22
|
+
return this.http.get("/api/x402/info", false);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.X402Resource = X402Resource;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { HttpClient } from "./http.js";
|
|
2
|
+
export interface ActiveSessionEntry {
|
|
3
|
+
id: string;
|
|
4
|
+
startedAt: string;
|
|
5
|
+
status: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ActiveSessionsResponse {
|
|
8
|
+
sessions: ActiveSessionEntry[];
|
|
9
|
+
}
|
|
10
|
+
export declare class SessionsResource {
|
|
11
|
+
private http;
|
|
12
|
+
constructor(http: HttpClient);
|
|
13
|
+
/** Get all active proxy sessions for the authenticated user. */
|
|
14
|
+
getActive(): Promise<ActiveSessionsResponse>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SessionsResource = void 0;
|
|
4
|
+
class SessionsResource {
|
|
5
|
+
http;
|
|
6
|
+
constructor(http) {
|
|
7
|
+
this.http = http;
|
|
8
|
+
}
|
|
9
|
+
/** Get all active proxy sessions for the authenticated user. */
|
|
10
|
+
async getActive() {
|
|
11
|
+
return this.http.get("/api/sessions/active");
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.SessionsResource = SessionsResource;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HttpClient } from "./http.js";
|
|
2
|
+
import type { SlotsInfo, WaitlistJoinResult, WaitlistCount } from "./types.js";
|
|
3
|
+
export declare class SlotsResource {
|
|
4
|
+
private http;
|
|
5
|
+
constructor(http: HttpClient);
|
|
6
|
+
getSlots(): Promise<SlotsInfo>;
|
|
7
|
+
joinWaitlist(email: string): Promise<WaitlistJoinResult>;
|
|
8
|
+
getWaitlistCount(): Promise<WaitlistCount>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SlotsResource = void 0;
|
|
4
|
+
class SlotsResource {
|
|
5
|
+
http;
|
|
6
|
+
constructor(http) {
|
|
7
|
+
this.http = http;
|
|
8
|
+
}
|
|
9
|
+
async getSlots() {
|
|
10
|
+
return this.http.get("/api/slots", false);
|
|
11
|
+
}
|
|
12
|
+
async joinWaitlist(email) {
|
|
13
|
+
return this.http.post("/api/waitlist/join", { email }, false);
|
|
14
|
+
}
|
|
15
|
+
async getWaitlistCount() {
|
|
16
|
+
return this.http.get("/api/waitlist/count", false);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.SlotsResource = SlotsResource;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare class TokenManager {
|
|
2
|
+
private accessToken;
|
|
3
|
+
private refreshTokenValue;
|
|
4
|
+
private refreshPromise;
|
|
5
|
+
private refreshFn;
|
|
6
|
+
setTokens(access: string, refresh?: string): void;
|
|
7
|
+
setRefreshFunction(fn: (refreshToken: string) => Promise<{
|
|
8
|
+
accessToken: string;
|
|
9
|
+
refreshToken?: string;
|
|
10
|
+
}>): void;
|
|
11
|
+
getAccessToken(): string | null;
|
|
12
|
+
getRefreshToken(): string | null;
|
|
13
|
+
isExpired(token: string): boolean;
|
|
14
|
+
getValidToken(): Promise<string>;
|
|
15
|
+
/**
|
|
16
|
+
* Force a token refresh regardless of expiry state.
|
|
17
|
+
* Used after a 401 response to avoid re-using a rejected token.
|
|
18
|
+
*/
|
|
19
|
+
forceRefresh(): Promise<string>;
|
|
20
|
+
clear(): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TokenManager = void 0;
|
|
4
|
+
const constants_js_1 = require("./constants.js");
|
|
5
|
+
const errors_js_1 = require("./errors.js");
|
|
6
|
+
class TokenManager {
|
|
7
|
+
accessToken = null;
|
|
8
|
+
refreshTokenValue = null;
|
|
9
|
+
refreshPromise = null;
|
|
10
|
+
refreshFn = null;
|
|
11
|
+
setTokens(access, refresh) {
|
|
12
|
+
this.accessToken = access;
|
|
13
|
+
if (refresh)
|
|
14
|
+
this.refreshTokenValue = refresh;
|
|
15
|
+
}
|
|
16
|
+
setRefreshFunction(fn) {
|
|
17
|
+
this.refreshFn = fn;
|
|
18
|
+
}
|
|
19
|
+
getAccessToken() {
|
|
20
|
+
return this.accessToken;
|
|
21
|
+
}
|
|
22
|
+
getRefreshToken() {
|
|
23
|
+
return this.refreshTokenValue;
|
|
24
|
+
}
|
|
25
|
+
isExpired(token) {
|
|
26
|
+
try {
|
|
27
|
+
const parts = token.split(".");
|
|
28
|
+
if (parts.length !== 3)
|
|
29
|
+
return true;
|
|
30
|
+
const payload = JSON.parse(Buffer.from(parts[1].replace(/-/g, "+").replace(/_/g, "/"), "base64").toString());
|
|
31
|
+
return payload.exp * 1000 < Date.now() + constants_js_1.TOKEN_REFRESH_BUFFER_MS;
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async getValidToken() {
|
|
38
|
+
if (this.accessToken && !this.isExpired(this.accessToken)) {
|
|
39
|
+
return this.accessToken;
|
|
40
|
+
}
|
|
41
|
+
if (!this.refreshTokenValue || !this.refreshFn) {
|
|
42
|
+
throw new errors_js_1.AuthenticationError("No valid token and cannot refresh");
|
|
43
|
+
}
|
|
44
|
+
// Singleton refresh
|
|
45
|
+
if (this.refreshPromise)
|
|
46
|
+
return this.refreshPromise;
|
|
47
|
+
this.refreshPromise = (async () => {
|
|
48
|
+
try {
|
|
49
|
+
const result = await this.refreshFn(this.refreshTokenValue);
|
|
50
|
+
this.accessToken = result.accessToken;
|
|
51
|
+
if (result.refreshToken) {
|
|
52
|
+
this.refreshTokenValue = result.refreshToken;
|
|
53
|
+
}
|
|
54
|
+
return this.accessToken;
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
// Clear tokens on refresh failure to prevent rapid-fire retry loops
|
|
58
|
+
this.accessToken = null;
|
|
59
|
+
this.refreshTokenValue = null;
|
|
60
|
+
throw err;
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
this.refreshPromise = null;
|
|
64
|
+
}
|
|
65
|
+
})();
|
|
66
|
+
return this.refreshPromise;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Force a token refresh regardless of expiry state.
|
|
70
|
+
* Used after a 401 response to avoid re-using a rejected token.
|
|
71
|
+
*/
|
|
72
|
+
async forceRefresh() {
|
|
73
|
+
if (!this.refreshTokenValue || !this.refreshFn) {
|
|
74
|
+
throw new errors_js_1.AuthenticationError("No valid token and cannot refresh");
|
|
75
|
+
}
|
|
76
|
+
// Singleton refresh (reuse in-flight refresh if one is already happening)
|
|
77
|
+
if (this.refreshPromise)
|
|
78
|
+
return this.refreshPromise;
|
|
79
|
+
this.refreshPromise = (async () => {
|
|
80
|
+
try {
|
|
81
|
+
const result = await this.refreshFn(this.refreshTokenValue);
|
|
82
|
+
this.accessToken = result.accessToken;
|
|
83
|
+
if (result.refreshToken) {
|
|
84
|
+
this.refreshTokenValue = result.refreshToken;
|
|
85
|
+
}
|
|
86
|
+
return this.accessToken;
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
this.accessToken = null;
|
|
90
|
+
this.refreshTokenValue = null;
|
|
91
|
+
throw err;
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
this.refreshPromise = null;
|
|
95
|
+
}
|
|
96
|
+
})();
|
|
97
|
+
return this.refreshPromise;
|
|
98
|
+
}
|
|
99
|
+
clear() {
|
|
100
|
+
this.accessToken = null;
|
|
101
|
+
this.refreshTokenValue = null;
|
|
102
|
+
this.refreshPromise = null;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.TokenManager = TokenManager;
|