agentmail 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/BaseClient.js +2 -2
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/wrapper/Client.d.ts +9 -2
- package/dist/cjs/wrapper/Client.js +19 -7
- package/dist/cjs/wrapper/WebsocketsClient.d.ts +3 -3
- package/dist/cjs/wrapper/WebsocketsClient.js +5 -6
- package/dist/cjs/wrapper/index.d.ts +0 -1
- package/dist/cjs/wrapper/index.js +1 -3
- package/dist/cjs/wrapper/mpp.d.ts +2 -0
- package/dist/cjs/wrapper/mpp.js +25 -0
- package/dist/cjs/wrapper/probe402.d.ts +1 -0
- package/dist/cjs/wrapper/probe402.js +22 -0
- package/dist/cjs/wrapper/x402.d.ts +1 -1
- package/dist/cjs/wrapper/x402.js +4 -7
- package/dist/esm/BaseClient.mjs +2 -2
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/dist/esm/wrapper/Client.d.mts +9 -2
- package/dist/esm/wrapper/Client.mjs +19 -7
- package/dist/esm/wrapper/WebsocketsClient.d.mts +3 -3
- package/dist/esm/wrapper/WebsocketsClient.mjs +5 -6
- package/dist/esm/wrapper/index.d.mts +0 -1
- package/dist/esm/wrapper/index.mjs +0 -1
- package/dist/esm/wrapper/mpp.d.mts +2 -0
- package/dist/esm/wrapper/mpp.mjs +22 -0
- package/dist/esm/wrapper/probe402.d.mts +1 -0
- package/dist/esm/wrapper/probe402.mjs +19 -0
- package/dist/esm/wrapper/x402.d.mts +1 -1
- package/dist/esm/wrapper/x402.mjs +3 -6
- package/package.json +1 -1
package/dist/cjs/BaseClient.js
CHANGED
|
@@ -43,8 +43,8 @@ function normalizeClientOptions(options) {
|
|
|
43
43
|
const headers = (0, headers_js_1.mergeHeaders)({
|
|
44
44
|
"X-Fern-Language": "JavaScript",
|
|
45
45
|
"X-Fern-SDK-Name": "agentmail",
|
|
46
|
-
"X-Fern-SDK-Version": "0.3.
|
|
47
|
-
"User-Agent": "agentmail/0.3.
|
|
46
|
+
"X-Fern-SDK-Version": "0.3.2",
|
|
47
|
+
"User-Agent": "agentmail/0.3.2",
|
|
48
48
|
"X-Fern-Runtime": core.RUNTIME.type,
|
|
49
49
|
"X-Fern-Runtime-Version": core.RUNTIME.version,
|
|
50
50
|
}, options === null || options === void 0 ? void 0 : options.headers);
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.3.
|
|
1
|
+
export declare const SDK_VERSION = "0.3.2";
|
package/dist/cjs/version.js
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
import type { x402Client } from "@x402/fetch";
|
|
2
|
-
import {
|
|
2
|
+
import type { Mppx } from "mppx/client";
|
|
3
3
|
import { Supplier } from "../core/index.js";
|
|
4
|
+
import { AgentMailClient as FernAgentMailClient } from "../Client.js";
|
|
4
5
|
import { WebsocketsClient } from "./WebsocketsClient.js";
|
|
5
6
|
type SharedOptions = Omit<FernAgentMailClient.Options, "apiKey">;
|
|
6
7
|
export declare namespace AgentMailClient {
|
|
7
8
|
type Options = SharedOptions & ({
|
|
8
9
|
x402: x402Client;
|
|
10
|
+
mpp?: never;
|
|
11
|
+
apiKey?: never;
|
|
12
|
+
} | {
|
|
13
|
+
mpp: Mppx.Mppx;
|
|
14
|
+
x402?: never;
|
|
9
15
|
apiKey?: never;
|
|
10
16
|
} | {
|
|
11
17
|
apiKey?: Supplier<string>;
|
|
12
18
|
x402?: never;
|
|
19
|
+
mpp?: never;
|
|
13
20
|
});
|
|
14
21
|
type RequestOptions = FernAgentMailClient.RequestOptions;
|
|
15
22
|
}
|
|
16
23
|
export declare class AgentMailClient extends FernAgentMailClient {
|
|
17
24
|
protected _websockets: WebsocketsClient | undefined;
|
|
18
|
-
private readonly
|
|
25
|
+
private readonly _getPaymentCredentials;
|
|
19
26
|
get websockets(): WebsocketsClient;
|
|
20
27
|
constructor(options?: AgentMailClient.Options);
|
|
21
28
|
}
|
|
@@ -54,23 +54,26 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
54
54
|
};
|
|
55
55
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
56
56
|
exports.AgentMailClient = void 0;
|
|
57
|
-
const Client_js_1 = require("../Client.js");
|
|
58
57
|
const index_js_1 = require("../core/index.js");
|
|
58
|
+
const NoOpAuthProvider_js_1 = require("../core/auth/NoOpAuthProvider.js");
|
|
59
59
|
const environments_js_1 = require("../environments.js");
|
|
60
|
+
const Client_js_1 = require("../Client.js");
|
|
60
61
|
const WebsocketsClient_js_1 = require("./WebsocketsClient.js");
|
|
62
|
+
const x402_js_1 = require("./x402.js");
|
|
63
|
+
const mpp_js_1 = require("./mpp.js");
|
|
61
64
|
class AgentMailClient extends Client_js_1.AgentMailClient {
|
|
62
65
|
get websockets() {
|
|
63
66
|
var _a;
|
|
64
|
-
return ((_a = this._websockets) !== null && _a !== void 0 ? _a : (this._websockets = new WebsocketsClient_js_1.WebsocketsClient(this._options, this.
|
|
67
|
+
return ((_a = this._websockets) !== null && _a !== void 0 ? _a : (this._websockets = new WebsocketsClient_js_1.WebsocketsClient(this._options, this._getPaymentCredentials)));
|
|
65
68
|
}
|
|
66
69
|
constructor(options = {}) {
|
|
67
70
|
if (options.x402) {
|
|
68
71
|
const { x402 } = options, rest = __rest(options, ["x402"]);
|
|
69
72
|
let wrappedFetch;
|
|
70
|
-
const fernOptions = Object.assign(Object.assign({}, rest), { fetch: (input, init) => __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
const fernOptions = Object.assign(Object.assign({}, rest), { authProvider: new NoOpAuthProvider_js_1.NoOpAuthProvider(), fetch: (input, init) => __awaiter(this, void 0, void 0, function* () {
|
|
71
74
|
if (!wrappedFetch) {
|
|
72
|
-
const
|
|
73
|
-
wrappedFetch = wrapFetchWithPayment(fetch, x402);
|
|
75
|
+
const mod = yield Promise.resolve().then(() => __importStar(require("@x402/fetch")));
|
|
76
|
+
wrappedFetch = mod.wrapFetchWithPayment(fetch, x402);
|
|
74
77
|
}
|
|
75
78
|
return wrappedFetch(input, init);
|
|
76
79
|
}) });
|
|
@@ -78,7 +81,16 @@ class AgentMailClient extends Client_js_1.AgentMailClient {
|
|
|
78
81
|
fernOptions.environment = environments_js_1.AgentMailEnvironment.ProdX402;
|
|
79
82
|
}
|
|
80
83
|
super(fernOptions);
|
|
81
|
-
this.
|
|
84
|
+
this._getPaymentCredentials = (wsUrl) => (0, x402_js_1.getPaymentCredentials)(wsUrl, x402);
|
|
85
|
+
}
|
|
86
|
+
else if (options.mpp) {
|
|
87
|
+
const { mpp } = options, rest = __rest(options, ["mpp"]);
|
|
88
|
+
const fernOptions = Object.assign(Object.assign({}, rest), { authProvider: new NoOpAuthProvider_js_1.NoOpAuthProvider(), fetch: mpp.fetch });
|
|
89
|
+
if (!fernOptions.environment && !fernOptions.baseUrl) {
|
|
90
|
+
fernOptions.environment = environments_js_1.AgentMailEnvironment.ProdMpp;
|
|
91
|
+
}
|
|
92
|
+
super(fernOptions);
|
|
93
|
+
this._getPaymentCredentials = (wsUrl) => (0, mpp_js_1.getPaymentCredentials)(wsUrl, mpp);
|
|
82
94
|
}
|
|
83
95
|
else {
|
|
84
96
|
let fernOptions = options;
|
|
@@ -92,7 +104,7 @@ class AgentMailClient extends Client_js_1.AgentMailClient {
|
|
|
92
104
|
}) });
|
|
93
105
|
}
|
|
94
106
|
super(fernOptions);
|
|
95
|
-
this.
|
|
107
|
+
this._getPaymentCredentials = undefined;
|
|
96
108
|
}
|
|
97
109
|
}
|
|
98
110
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { x402Client } from "@x402/fetch";
|
|
2
1
|
import { WebsocketsClient as FernWebsocketsClient } from "../api/resources/websockets/client/Client.js";
|
|
3
2
|
import type { WebsocketsSocket } from "../api/resources/websockets/client/Socket.js";
|
|
3
|
+
export type GetPaymentCredentials = (wsUrl: string) => Promise<Record<string, string>>;
|
|
4
4
|
export declare class WebsocketsClient extends FernWebsocketsClient {
|
|
5
|
-
private readonly
|
|
6
|
-
constructor(options: FernWebsocketsClient.Options,
|
|
5
|
+
private readonly _getPaymentCredentials;
|
|
6
|
+
constructor(options: FernWebsocketsClient.Options, getPaymentCredentials?: GetPaymentCredentials);
|
|
7
7
|
connect(args?: FernWebsocketsClient.ConnectArgs): Promise<WebsocketsSocket>;
|
|
8
8
|
}
|
|
@@ -46,11 +46,10 @@ exports.WebsocketsClient = void 0;
|
|
|
46
46
|
const Client_js_1 = require("../api/resources/websockets/client/Client.js");
|
|
47
47
|
const core = __importStar(require("../core/index.js"));
|
|
48
48
|
const environments = __importStar(require("../environments.js"));
|
|
49
|
-
const x402_js_1 = require("./x402.js");
|
|
50
49
|
class WebsocketsClient extends Client_js_1.WebsocketsClient {
|
|
51
|
-
constructor(options,
|
|
50
|
+
constructor(options, getPaymentCredentials) {
|
|
52
51
|
super(options);
|
|
53
|
-
this.
|
|
52
|
+
this._getPaymentCredentials = getPaymentCredentials;
|
|
54
53
|
}
|
|
55
54
|
connect() {
|
|
56
55
|
const _super = Object.create(null, {
|
|
@@ -58,11 +57,11 @@ class WebsocketsClient extends Client_js_1.WebsocketsClient {
|
|
|
58
57
|
});
|
|
59
58
|
return __awaiter(this, arguments, void 0, function* (args = {}) {
|
|
60
59
|
var _a, _b, _c;
|
|
61
|
-
if (this.
|
|
60
|
+
if (this._getPaymentCredentials) {
|
|
62
61
|
const wsUrl = core.url.join((_a = (yield core.Supplier.get(this._options.baseUrl))) !== null && _a !== void 0 ? _a : ((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.AgentMailEnvironment.Prod)
|
|
63
62
|
.websockets, "/v0");
|
|
64
|
-
const
|
|
65
|
-
return _super.connect.call(this, Object.assign(Object.assign({}, args), {
|
|
63
|
+
const credentials = yield this._getPaymentCredentials(wsUrl);
|
|
64
|
+
return _super.connect.call(this, Object.assign(Object.assign({}, args), { queryParams: Object.assign(Object.assign({}, credentials), args.queryParams) }));
|
|
66
65
|
}
|
|
67
66
|
if (!args.apiKey) {
|
|
68
67
|
const apiKey = (_c = (yield core.Supplier.get(this._options.apiKey))) !== null && _c !== void 0 ? _c : process.env.AGENTMAIL_API_KEY;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.AgentMailClient = void 0;
|
|
4
4
|
var Client_js_1 = require("./Client.js");
|
|
5
5
|
Object.defineProperty(exports, "AgentMailClient", { enumerable: true, get: function () { return Client_js_1.AgentMailClient; } });
|
|
6
|
-
var WebsocketsClient_js_1 = require("./WebsocketsClient.js");
|
|
7
|
-
Object.defineProperty(exports, "WebsocketsClient", { enumerable: true, get: function () { return WebsocketsClient_js_1.WebsocketsClient; } });
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getPaymentCredentials = getPaymentCredentials;
|
|
13
|
+
const probe402_js_1 = require("./probe402.js");
|
|
14
|
+
function getPaymentCredentials(wsUrl, mpp) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const response = yield (0, probe402_js_1.probe402)(wsUrl);
|
|
17
|
+
const credential = yield mpp.createCredential(response);
|
|
18
|
+
const signed = mpp.transport.setCredential(new Request(wsUrl), credential);
|
|
19
|
+
const headers = {};
|
|
20
|
+
signed.headers.forEach((value, key) => {
|
|
21
|
+
headers[key] = value;
|
|
22
|
+
});
|
|
23
|
+
return headers;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function probe402(wsUrl: string): Promise<Response>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.probe402 = probe402;
|
|
13
|
+
function probe402(wsUrl) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const httpUrl = wsUrl.replace(/^wss:\/\//, "https://").replace(/^ws:\/\//, "http://");
|
|
16
|
+
const response = yield fetch(httpUrl);
|
|
17
|
+
if (response.status !== 402) {
|
|
18
|
+
throw new Error(`Expected 402 from ${httpUrl} but got ${response.status}`);
|
|
19
|
+
}
|
|
20
|
+
return response;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { x402Client } from "@x402/fetch";
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function getPaymentCredentials(wsUrl: string, client: x402Client): Promise<Record<string, string>>;
|
package/dist/cjs/wrapper/x402.js
CHANGED
|
@@ -42,16 +42,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
42
42
|
});
|
|
43
43
|
};
|
|
44
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
-
exports.
|
|
46
|
-
|
|
45
|
+
exports.getPaymentCredentials = getPaymentCredentials;
|
|
46
|
+
const probe402_js_1 = require("./probe402.js");
|
|
47
|
+
function getPaymentCredentials(wsUrl, client) {
|
|
47
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
49
|
const { x402HTTPClient } = yield Promise.resolve().then(() => __importStar(require("@x402/fetch")));
|
|
49
50
|
const httpClient = new x402HTTPClient(client);
|
|
50
|
-
const
|
|
51
|
-
const response = yield fetch(httpUrl);
|
|
52
|
-
if (response.status !== 402) {
|
|
53
|
-
throw new Error(`x402: expected 402 from ${httpUrl} but got ${response.status}`);
|
|
54
|
-
}
|
|
51
|
+
const response = yield (0, probe402_js_1.probe402)(wsUrl);
|
|
55
52
|
let body;
|
|
56
53
|
try {
|
|
57
54
|
body = JSON.parse(yield response.text());
|
package/dist/esm/BaseClient.mjs
CHANGED
|
@@ -6,8 +6,8 @@ export function normalizeClientOptions(options) {
|
|
|
6
6
|
const headers = mergeHeaders({
|
|
7
7
|
"X-Fern-Language": "JavaScript",
|
|
8
8
|
"X-Fern-SDK-Name": "agentmail",
|
|
9
|
-
"X-Fern-SDK-Version": "0.3.
|
|
10
|
-
"User-Agent": "agentmail/0.3.
|
|
9
|
+
"X-Fern-SDK-Version": "0.3.2",
|
|
10
|
+
"User-Agent": "agentmail/0.3.2",
|
|
11
11
|
"X-Fern-Runtime": core.RUNTIME.type,
|
|
12
12
|
"X-Fern-Runtime-Version": core.RUNTIME.version,
|
|
13
13
|
}, options === null || options === void 0 ? void 0 : options.headers);
|
package/dist/esm/version.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.3.
|
|
1
|
+
export declare const SDK_VERSION = "0.3.2";
|
package/dist/esm/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.3.
|
|
1
|
+
export const SDK_VERSION = "0.3.2";
|
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
import type { x402Client } from "@x402/fetch";
|
|
2
|
-
import {
|
|
2
|
+
import type { Mppx } from "mppx/client";
|
|
3
3
|
import { Supplier } from "../core/index.mjs";
|
|
4
|
+
import { AgentMailClient as FernAgentMailClient } from "../Client.mjs";
|
|
4
5
|
import { WebsocketsClient } from "./WebsocketsClient.mjs";
|
|
5
6
|
type SharedOptions = Omit<FernAgentMailClient.Options, "apiKey">;
|
|
6
7
|
export declare namespace AgentMailClient {
|
|
7
8
|
type Options = SharedOptions & ({
|
|
8
9
|
x402: x402Client;
|
|
10
|
+
mpp?: never;
|
|
11
|
+
apiKey?: never;
|
|
12
|
+
} | {
|
|
13
|
+
mpp: Mppx.Mppx;
|
|
14
|
+
x402?: never;
|
|
9
15
|
apiKey?: never;
|
|
10
16
|
} | {
|
|
11
17
|
apiKey?: Supplier<string>;
|
|
12
18
|
x402?: never;
|
|
19
|
+
mpp?: never;
|
|
13
20
|
});
|
|
14
21
|
type RequestOptions = FernAgentMailClient.RequestOptions;
|
|
15
22
|
}
|
|
16
23
|
export declare class AgentMailClient extends FernAgentMailClient {
|
|
17
24
|
protected _websockets: WebsocketsClient | undefined;
|
|
18
|
-
private readonly
|
|
25
|
+
private readonly _getPaymentCredentials;
|
|
19
26
|
get websockets(): WebsocketsClient;
|
|
20
27
|
constructor(options?: AgentMailClient.Options);
|
|
21
28
|
}
|
|
@@ -18,23 +18,26 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
18
18
|
}
|
|
19
19
|
return t;
|
|
20
20
|
};
|
|
21
|
-
import { AgentMailClient as FernAgentMailClient } from "../Client.mjs";
|
|
22
21
|
import { Supplier } from "../core/index.mjs";
|
|
22
|
+
import { NoOpAuthProvider } from "../core/auth/NoOpAuthProvider.mjs";
|
|
23
23
|
import { AgentMailEnvironment } from "../environments.mjs";
|
|
24
|
+
import { AgentMailClient as FernAgentMailClient } from "../Client.mjs";
|
|
24
25
|
import { WebsocketsClient } from "./WebsocketsClient.mjs";
|
|
26
|
+
import { getPaymentCredentials as getX402Credentials } from "./x402.mjs";
|
|
27
|
+
import { getPaymentCredentials as getMppCredentials } from "./mpp.mjs";
|
|
25
28
|
export class AgentMailClient extends FernAgentMailClient {
|
|
26
29
|
get websockets() {
|
|
27
30
|
var _a;
|
|
28
|
-
return ((_a = this._websockets) !== null && _a !== void 0 ? _a : (this._websockets = new WebsocketsClient(this._options, this.
|
|
31
|
+
return ((_a = this._websockets) !== null && _a !== void 0 ? _a : (this._websockets = new WebsocketsClient(this._options, this._getPaymentCredentials)));
|
|
29
32
|
}
|
|
30
33
|
constructor(options = {}) {
|
|
31
34
|
if (options.x402) {
|
|
32
35
|
const { x402 } = options, rest = __rest(options, ["x402"]);
|
|
33
36
|
let wrappedFetch;
|
|
34
|
-
const fernOptions = Object.assign(Object.assign({}, rest), { fetch: (input, init) => __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const fernOptions = Object.assign(Object.assign({}, rest), { authProvider: new NoOpAuthProvider(), fetch: (input, init) => __awaiter(this, void 0, void 0, function* () {
|
|
35
38
|
if (!wrappedFetch) {
|
|
36
|
-
const
|
|
37
|
-
wrappedFetch = wrapFetchWithPayment(fetch, x402);
|
|
39
|
+
const mod = yield import("@x402/fetch");
|
|
40
|
+
wrappedFetch = mod.wrapFetchWithPayment(fetch, x402);
|
|
38
41
|
}
|
|
39
42
|
return wrappedFetch(input, init);
|
|
40
43
|
}) });
|
|
@@ -42,7 +45,16 @@ export class AgentMailClient extends FernAgentMailClient {
|
|
|
42
45
|
fernOptions.environment = AgentMailEnvironment.ProdX402;
|
|
43
46
|
}
|
|
44
47
|
super(fernOptions);
|
|
45
|
-
this.
|
|
48
|
+
this._getPaymentCredentials = (wsUrl) => getX402Credentials(wsUrl, x402);
|
|
49
|
+
}
|
|
50
|
+
else if (options.mpp) {
|
|
51
|
+
const { mpp } = options, rest = __rest(options, ["mpp"]);
|
|
52
|
+
const fernOptions = Object.assign(Object.assign({}, rest), { authProvider: new NoOpAuthProvider(), fetch: mpp.fetch });
|
|
53
|
+
if (!fernOptions.environment && !fernOptions.baseUrl) {
|
|
54
|
+
fernOptions.environment = AgentMailEnvironment.ProdMpp;
|
|
55
|
+
}
|
|
56
|
+
super(fernOptions);
|
|
57
|
+
this._getPaymentCredentials = (wsUrl) => getMppCredentials(wsUrl, mpp);
|
|
46
58
|
}
|
|
47
59
|
else {
|
|
48
60
|
let fernOptions = options;
|
|
@@ -56,7 +68,7 @@ export class AgentMailClient extends FernAgentMailClient {
|
|
|
56
68
|
}) });
|
|
57
69
|
}
|
|
58
70
|
super(fernOptions);
|
|
59
|
-
this.
|
|
71
|
+
this._getPaymentCredentials = undefined;
|
|
60
72
|
}
|
|
61
73
|
}
|
|
62
74
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { x402Client } from "@x402/fetch";
|
|
2
1
|
import { WebsocketsClient as FernWebsocketsClient } from "../api/resources/websockets/client/Client.mjs";
|
|
3
2
|
import type { WebsocketsSocket } from "../api/resources/websockets/client/Socket.mjs";
|
|
3
|
+
export type GetPaymentCredentials = (wsUrl: string) => Promise<Record<string, string>>;
|
|
4
4
|
export declare class WebsocketsClient extends FernWebsocketsClient {
|
|
5
|
-
private readonly
|
|
6
|
-
constructor(options: FernWebsocketsClient.Options,
|
|
5
|
+
private readonly _getPaymentCredentials;
|
|
6
|
+
constructor(options: FernWebsocketsClient.Options, getPaymentCredentials?: GetPaymentCredentials);
|
|
7
7
|
connect(args?: FernWebsocketsClient.ConnectArgs): Promise<WebsocketsSocket>;
|
|
8
8
|
}
|
|
@@ -10,11 +10,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { WebsocketsClient as FernWebsocketsClient } from "../api/resources/websockets/client/Client.mjs";
|
|
11
11
|
import * as core from "../core/index.mjs";
|
|
12
12
|
import * as environments from "../environments.mjs";
|
|
13
|
-
import { getPaymentHeaders } from "./x402.mjs";
|
|
14
13
|
export class WebsocketsClient extends FernWebsocketsClient {
|
|
15
|
-
constructor(options,
|
|
14
|
+
constructor(options, getPaymentCredentials) {
|
|
16
15
|
super(options);
|
|
17
|
-
this.
|
|
16
|
+
this._getPaymentCredentials = getPaymentCredentials;
|
|
18
17
|
}
|
|
19
18
|
connect() {
|
|
20
19
|
const _super = Object.create(null, {
|
|
@@ -22,11 +21,11 @@ export class WebsocketsClient extends FernWebsocketsClient {
|
|
|
22
21
|
});
|
|
23
22
|
return __awaiter(this, arguments, void 0, function* (args = {}) {
|
|
24
23
|
var _a, _b, _c;
|
|
25
|
-
if (this.
|
|
24
|
+
if (this._getPaymentCredentials) {
|
|
26
25
|
const wsUrl = core.url.join((_a = (yield core.Supplier.get(this._options.baseUrl))) !== null && _a !== void 0 ? _a : ((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.AgentMailEnvironment.Prod)
|
|
27
26
|
.websockets, "/v0");
|
|
28
|
-
const
|
|
29
|
-
return _super.connect.call(this, Object.assign(Object.assign({}, args), {
|
|
27
|
+
const credentials = yield this._getPaymentCredentials(wsUrl);
|
|
28
|
+
return _super.connect.call(this, Object.assign(Object.assign({}, args), { queryParams: Object.assign(Object.assign({}, credentials), args.queryParams) }));
|
|
30
29
|
}
|
|
31
30
|
if (!args.apiKey) {
|
|
32
31
|
const apiKey = (_c = (yield core.Supplier.get(this._options.apiKey))) !== null && _c !== void 0 ? _c : process.env.AGENTMAIL_API_KEY;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { probe402 } from "./probe402.mjs";
|
|
11
|
+
export function getPaymentCredentials(wsUrl, mpp) {
|
|
12
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
const response = yield probe402(wsUrl);
|
|
14
|
+
const credential = yield mpp.createCredential(response);
|
|
15
|
+
const signed = mpp.transport.setCredential(new Request(wsUrl), credential);
|
|
16
|
+
const headers = {};
|
|
17
|
+
signed.headers.forEach((value, key) => {
|
|
18
|
+
headers[key] = value;
|
|
19
|
+
});
|
|
20
|
+
return headers;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function probe402(wsUrl: string): Promise<Response>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export function probe402(wsUrl) {
|
|
11
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
const httpUrl = wsUrl.replace(/^wss:\/\//, "https://").replace(/^ws:\/\//, "http://");
|
|
13
|
+
const response = yield fetch(httpUrl);
|
|
14
|
+
if (response.status !== 402) {
|
|
15
|
+
throw new Error(`Expected 402 from ${httpUrl} but got ${response.status}`);
|
|
16
|
+
}
|
|
17
|
+
return response;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { x402Client } from "@x402/fetch";
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function getPaymentCredentials(wsUrl: string, client: x402Client): Promise<Record<string, string>>;
|
|
@@ -7,15 +7,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
import { probe402 } from "./probe402.mjs";
|
|
11
|
+
export function getPaymentCredentials(wsUrl, client) {
|
|
11
12
|
return __awaiter(this, void 0, void 0, function* () {
|
|
12
13
|
const { x402HTTPClient } = yield import("@x402/fetch");
|
|
13
14
|
const httpClient = new x402HTTPClient(client);
|
|
14
|
-
const
|
|
15
|
-
const response = yield fetch(httpUrl);
|
|
16
|
-
if (response.status !== 402) {
|
|
17
|
-
throw new Error(`x402: expected 402 from ${httpUrl} but got ${response.status}`);
|
|
18
|
-
}
|
|
15
|
+
const response = yield probe402(wsUrl);
|
|
19
16
|
let body;
|
|
20
17
|
try {
|
|
21
18
|
body = JSON.parse(yield response.text());
|