agentmail 0.1.19 → 0.2.3
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/README.md +30 -1
- package/dist/cjs/BaseClient.d.ts +7 -7
- package/dist/cjs/BaseClient.js +2 -2
- package/dist/cjs/Client.d.ts +1 -2
- package/dist/cjs/api/errors/IsTakenError.js +5 -1
- package/dist/cjs/api/errors/NotFoundError.js +5 -1
- package/dist/cjs/api/errors/ValidationError.js +5 -1
- package/dist/cjs/api/resources/apiKeys/client/Client.d.ts +1 -2
- package/dist/cjs/api/resources/apiKeys/client/Client.js +8 -52
- package/dist/cjs/api/resources/attachments/types/AttachmentResponse.d.ts +13 -0
- package/dist/cjs/api/resources/attachments/types/AttachmentResponse.js +3 -0
- package/dist/cjs/api/resources/attachments/types/index.d.ts +1 -0
- package/dist/cjs/api/resources/attachments/types/index.js +1 -0
- package/dist/cjs/api/resources/domains/client/Client.d.ts +1 -2
- package/dist/cjs/api/resources/domains/client/Client.js +11 -97
- package/dist/cjs/api/resources/drafts/client/Client.d.ts +1 -2
- package/dist/cjs/api/resources/drafts/client/Client.js +20 -49
- package/dist/cjs/api/resources/inboxes/client/Client.d.ts +1 -2
- package/dist/cjs/api/resources/inboxes/client/Client.js +10 -82
- package/dist/cjs/api/resources/inboxes/resources/drafts/client/Client.d.ts +1 -2
- package/dist/cjs/api/resources/inboxes/resources/drafts/client/Client.js +24 -109
- package/dist/cjs/api/resources/inboxes/resources/messages/client/Client.d.ts +10 -3
- package/dist/cjs/api/resources/inboxes/resources/messages/client/Client.js +45 -144
- package/dist/cjs/api/resources/inboxes/resources/metrics/client/Client.d.ts +1 -2
- package/dist/cjs/api/resources/inboxes/resources/metrics/client/Client.js +16 -22
- package/dist/cjs/api/resources/inboxes/resources/threads/client/Client.d.ts +10 -3
- package/dist/cjs/api/resources/inboxes/resources/threads/client/Client.js +41 -84
- package/dist/cjs/api/resources/messages/errors/MessageRejectedError.js +5 -1
- package/dist/cjs/api/resources/metrics/client/Client.d.ts +1 -2
- package/dist/cjs/api/resources/metrics/client/Client.js +16 -22
- package/dist/cjs/api/resources/organizations/client/Client.d.ts +1 -2
- package/dist/cjs/api/resources/organizations/client/Client.js +2 -15
- package/dist/cjs/api/resources/pods/client/Client.d.ts +1 -2
- package/dist/cjs/api/resources/pods/client/Client.js +9 -67
- package/dist/cjs/api/resources/pods/resources/domains/client/Client.d.ts +1 -2
- package/dist/cjs/api/resources/pods/resources/domains/client/Client.js +8 -52
- package/dist/cjs/api/resources/pods/resources/drafts/client/Client.d.ts +1 -2
- package/dist/cjs/api/resources/pods/resources/drafts/client/Client.js +20 -49
- package/dist/cjs/api/resources/pods/resources/inboxes/client/Client.d.ts +1 -2
- package/dist/cjs/api/resources/pods/resources/inboxes/client/Client.js +9 -67
- package/dist/cjs/api/resources/pods/resources/threads/client/Client.d.ts +10 -3
- package/dist/cjs/api/resources/pods/resources/threads/client/Client.js +40 -69
- package/dist/cjs/api/resources/threads/client/Client.d.ts +9 -3
- package/dist/cjs/api/resources/threads/client/Client.js +39 -69
- package/dist/cjs/api/resources/webhooks/client/Client.d.ts +1 -2
- package/dist/cjs/api/resources/webhooks/client/Client.js +9 -67
- package/dist/cjs/api/resources/websockets/client/Client.d.ts +2 -3
- package/dist/cjs/api/resources/websockets/client/Client.js +3 -4
- package/dist/cjs/auth/BearerAuthProvider.d.ts +14 -8
- package/dist/cjs/auth/BearerAuthProvider.js +16 -6
- package/dist/cjs/core/fetcher/BinaryResponse.d.ts +6 -7
- package/dist/cjs/core/fetcher/EndpointSupplier.d.ts +2 -2
- package/dist/cjs/core/fetcher/Fetcher.d.ts +6 -3
- package/dist/cjs/core/fetcher/Fetcher.js +2 -1
- package/dist/cjs/core/fetcher/getResponseBody.js +18 -4
- package/dist/cjs/core/fetcher/signals.d.ts +1 -1
- package/dist/cjs/core/headers.d.ts +2 -2
- package/dist/cjs/core/runtime/runtime.js +11 -10
- package/dist/cjs/core/schemas/builders/object/object.js +34 -3
- package/dist/cjs/core/websocket/ws.d.ts +1 -1
- package/dist/cjs/errors/AgentMailError.js +5 -1
- package/dist/cjs/errors/AgentMailTimeoutError.js +5 -1
- package/dist/cjs/errors/handleNonStatusCodeError.d.ts +2 -0
- package/dist/cjs/errors/handleNonStatusCodeError.js +65 -0
- package/dist/cjs/serialization/resources/attachments/types/AttachmentResponse.d.ts +22 -0
- package/dist/cjs/serialization/resources/attachments/types/AttachmentResponse.js +54 -0
- package/dist/cjs/serialization/resources/attachments/types/index.d.ts +1 -0
- package/dist/cjs/serialization/resources/attachments/types/index.js +1 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/BaseClient.d.mts +7 -7
- package/dist/esm/BaseClient.mjs +2 -2
- package/dist/esm/Client.d.mts +1 -2
- package/dist/esm/api/errors/IsTakenError.mjs +5 -1
- package/dist/esm/api/errors/NotFoundError.mjs +5 -1
- package/dist/esm/api/errors/ValidationError.mjs +5 -1
- package/dist/esm/api/resources/apiKeys/client/Client.d.mts +1 -2
- package/dist/esm/api/resources/apiKeys/client/Client.mjs +8 -52
- package/dist/esm/api/resources/attachments/types/AttachmentResponse.d.mts +13 -0
- package/dist/esm/api/resources/attachments/types/AttachmentResponse.mjs +2 -0
- package/dist/esm/api/resources/attachments/types/index.d.mts +1 -0
- package/dist/esm/api/resources/attachments/types/index.mjs +1 -0
- package/dist/esm/api/resources/domains/client/Client.d.mts +1 -2
- package/dist/esm/api/resources/domains/client/Client.mjs +11 -97
- package/dist/esm/api/resources/drafts/client/Client.d.mts +1 -2
- package/dist/esm/api/resources/drafts/client/Client.mjs +20 -49
- package/dist/esm/api/resources/inboxes/client/Client.d.mts +1 -2
- package/dist/esm/api/resources/inboxes/client/Client.mjs +10 -82
- package/dist/esm/api/resources/inboxes/resources/drafts/client/Client.d.mts +1 -2
- package/dist/esm/api/resources/inboxes/resources/drafts/client/Client.mjs +24 -109
- package/dist/esm/api/resources/inboxes/resources/messages/client/Client.d.mts +10 -3
- package/dist/esm/api/resources/inboxes/resources/messages/client/Client.mjs +45 -144
- package/dist/esm/api/resources/inboxes/resources/metrics/client/Client.d.mts +1 -2
- package/dist/esm/api/resources/inboxes/resources/metrics/client/Client.mjs +16 -22
- package/dist/esm/api/resources/inboxes/resources/threads/client/Client.d.mts +10 -3
- package/dist/esm/api/resources/inboxes/resources/threads/client/Client.mjs +41 -84
- package/dist/esm/api/resources/messages/errors/MessageRejectedError.mjs +5 -1
- package/dist/esm/api/resources/metrics/client/Client.d.mts +1 -2
- package/dist/esm/api/resources/metrics/client/Client.mjs +16 -22
- package/dist/esm/api/resources/organizations/client/Client.d.mts +1 -2
- package/dist/esm/api/resources/organizations/client/Client.mjs +2 -15
- package/dist/esm/api/resources/pods/client/Client.d.mts +1 -2
- package/dist/esm/api/resources/pods/client/Client.mjs +9 -67
- package/dist/esm/api/resources/pods/resources/domains/client/Client.d.mts +1 -2
- package/dist/esm/api/resources/pods/resources/domains/client/Client.mjs +8 -52
- package/dist/esm/api/resources/pods/resources/drafts/client/Client.d.mts +1 -2
- package/dist/esm/api/resources/pods/resources/drafts/client/Client.mjs +20 -49
- package/dist/esm/api/resources/pods/resources/inboxes/client/Client.d.mts +1 -2
- package/dist/esm/api/resources/pods/resources/inboxes/client/Client.mjs +9 -67
- package/dist/esm/api/resources/pods/resources/threads/client/Client.d.mts +10 -3
- package/dist/esm/api/resources/pods/resources/threads/client/Client.mjs +40 -69
- package/dist/esm/api/resources/threads/client/Client.d.mts +9 -3
- package/dist/esm/api/resources/threads/client/Client.mjs +39 -69
- package/dist/esm/api/resources/webhooks/client/Client.d.mts +1 -2
- package/dist/esm/api/resources/webhooks/client/Client.mjs +9 -67
- package/dist/esm/api/resources/websockets/client/Client.d.mts +2 -3
- package/dist/esm/api/resources/websockets/client/Client.mjs +3 -4
- package/dist/esm/auth/BearerAuthProvider.d.mts +14 -8
- package/dist/esm/auth/BearerAuthProvider.mjs +16 -6
- package/dist/esm/core/fetcher/BinaryResponse.d.mts +6 -7
- package/dist/esm/core/fetcher/EndpointSupplier.d.mts +2 -2
- package/dist/esm/core/fetcher/Fetcher.d.mts +6 -3
- package/dist/esm/core/fetcher/Fetcher.mjs +2 -1
- package/dist/esm/core/fetcher/getResponseBody.mjs +18 -4
- package/dist/esm/core/fetcher/signals.d.mts +1 -1
- package/dist/esm/core/headers.d.mts +2 -2
- package/dist/esm/core/runtime/runtime.mjs +11 -10
- package/dist/esm/core/schemas/builders/object/object.mjs +34 -3
- package/dist/esm/core/websocket/ws.d.mts +1 -1
- package/dist/esm/errors/AgentMailError.mjs +5 -1
- package/dist/esm/errors/AgentMailTimeoutError.mjs +5 -1
- package/dist/esm/errors/handleNonStatusCodeError.d.mts +2 -0
- package/dist/esm/errors/handleNonStatusCodeError.mjs +29 -0
- package/dist/esm/serialization/resources/attachments/types/AttachmentResponse.d.mts +22 -0
- package/dist/esm/serialization/resources/attachments/types/AttachmentResponse.mjs +18 -0
- package/dist/esm/serialization/resources/attachments/types/index.d.mts +1 -0
- package/dist/esm/serialization/resources/attachments/types/index.mjs +1 -0
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/dist/llms-full.txt +1905 -131
- package/dist/llms.txt +3 -0
- package/package.json +6 -3
- package/reference.md +4 -4
- package/dist/cjs/core/fetcher/ResponseWithBody.d.ts +0 -4
- package/dist/cjs/core/fetcher/ResponseWithBody.js +0 -6
- package/dist/esm/core/fetcher/ResponseWithBody.d.mts +0 -4
- package/dist/esm/core/fetcher/ResponseWithBody.mjs +0 -3
|
@@ -48,6 +48,7 @@ const BaseClient_js_1 = require("../../../../BaseClient.js");
|
|
|
48
48
|
const headers_js_1 = require("../../../../core/headers.js");
|
|
49
49
|
const core = __importStar(require("../../../../core/index.js"));
|
|
50
50
|
const environments = __importStar(require("../../../../environments.js"));
|
|
51
|
+
const handleNonStatusCodeError_js_1 = require("../../../../errors/handleNonStatusCodeError.js");
|
|
51
52
|
const errors = __importStar(require("../../../../errors/index.js"));
|
|
52
53
|
const serializers = __importStar(require("../../../../serialization/index.js"));
|
|
53
54
|
const AgentMail = __importStar(require("../../../index.js"));
|
|
@@ -69,13 +70,10 @@ class WebhooksClient {
|
|
|
69
70
|
return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) {
|
|
70
71
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
71
72
|
const { limit, pageToken } = request;
|
|
72
|
-
const _queryParams = {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
if (pageToken != null) {
|
|
77
|
-
_queryParams.page_token = pageToken;
|
|
78
|
-
}
|
|
73
|
+
const _queryParams = {
|
|
74
|
+
limit,
|
|
75
|
+
page_token: pageToken,
|
|
76
|
+
};
|
|
79
77
|
const _authRequest = yield this._options.authProvider.getAuthRequest();
|
|
80
78
|
const _headers = (0, headers_js_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
81
79
|
const _response = yield core.fetcher({
|
|
@@ -108,21 +106,7 @@ class WebhooksClient {
|
|
|
108
106
|
rawResponse: _response.rawResponse,
|
|
109
107
|
});
|
|
110
108
|
}
|
|
111
|
-
|
|
112
|
-
case "non-json":
|
|
113
|
-
throw new errors.AgentMailError({
|
|
114
|
-
statusCode: _response.error.statusCode,
|
|
115
|
-
body: _response.error.rawBody,
|
|
116
|
-
rawResponse: _response.rawResponse,
|
|
117
|
-
});
|
|
118
|
-
case "timeout":
|
|
119
|
-
throw new errors.AgentMailTimeoutError("Timeout exceeded when calling GET /v0/webhooks.");
|
|
120
|
-
case "unknown":
|
|
121
|
-
throw new errors.AgentMailError({
|
|
122
|
-
message: _response.error.errorMessage,
|
|
123
|
-
rawResponse: _response.rawResponse,
|
|
124
|
-
});
|
|
125
|
-
}
|
|
109
|
+
return (0, handleNonStatusCodeError_js_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "GET", "/v0/webhooks");
|
|
126
110
|
});
|
|
127
111
|
}
|
|
128
112
|
/**
|
|
@@ -183,21 +167,7 @@ class WebhooksClient {
|
|
|
183
167
|
});
|
|
184
168
|
}
|
|
185
169
|
}
|
|
186
|
-
|
|
187
|
-
case "non-json":
|
|
188
|
-
throw new errors.AgentMailError({
|
|
189
|
-
statusCode: _response.error.statusCode,
|
|
190
|
-
body: _response.error.rawBody,
|
|
191
|
-
rawResponse: _response.rawResponse,
|
|
192
|
-
});
|
|
193
|
-
case "timeout":
|
|
194
|
-
throw new errors.AgentMailTimeoutError("Timeout exceeded when calling GET /v0/webhooks/{webhook_id}.");
|
|
195
|
-
case "unknown":
|
|
196
|
-
throw new errors.AgentMailError({
|
|
197
|
-
message: _response.error.errorMessage,
|
|
198
|
-
rawResponse: _response.rawResponse,
|
|
199
|
-
});
|
|
200
|
-
}
|
|
170
|
+
return (0, handleNonStatusCodeError_js_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "GET", "/v0/webhooks/{webhook_id}");
|
|
201
171
|
});
|
|
202
172
|
}
|
|
203
173
|
/**
|
|
@@ -267,21 +237,7 @@ class WebhooksClient {
|
|
|
267
237
|
});
|
|
268
238
|
}
|
|
269
239
|
}
|
|
270
|
-
|
|
271
|
-
case "non-json":
|
|
272
|
-
throw new errors.AgentMailError({
|
|
273
|
-
statusCode: _response.error.statusCode,
|
|
274
|
-
body: _response.error.rawBody,
|
|
275
|
-
rawResponse: _response.rawResponse,
|
|
276
|
-
});
|
|
277
|
-
case "timeout":
|
|
278
|
-
throw new errors.AgentMailTimeoutError("Timeout exceeded when calling POST /v0/webhooks.");
|
|
279
|
-
case "unknown":
|
|
280
|
-
throw new errors.AgentMailError({
|
|
281
|
-
message: _response.error.errorMessage,
|
|
282
|
-
rawResponse: _response.rawResponse,
|
|
283
|
-
});
|
|
284
|
-
}
|
|
240
|
+
return (0, handleNonStatusCodeError_js_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "POST", "/v0/webhooks");
|
|
285
241
|
});
|
|
286
242
|
}
|
|
287
243
|
/**
|
|
@@ -333,21 +289,7 @@ class WebhooksClient {
|
|
|
333
289
|
});
|
|
334
290
|
}
|
|
335
291
|
}
|
|
336
|
-
|
|
337
|
-
case "non-json":
|
|
338
|
-
throw new errors.AgentMailError({
|
|
339
|
-
statusCode: _response.error.statusCode,
|
|
340
|
-
body: _response.error.rawBody,
|
|
341
|
-
rawResponse: _response.rawResponse,
|
|
342
|
-
});
|
|
343
|
-
case "timeout":
|
|
344
|
-
throw new errors.AgentMailTimeoutError("Timeout exceeded when calling DELETE /v0/webhooks/{webhook_id}.");
|
|
345
|
-
case "unknown":
|
|
346
|
-
throw new errors.AgentMailError({
|
|
347
|
-
message: _response.error.errorMessage,
|
|
348
|
-
rawResponse: _response.rawResponse,
|
|
349
|
-
});
|
|
350
|
-
}
|
|
292
|
+
return (0, handleNonStatusCodeError_js_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "DELETE", "/v0/webhooks/{webhook_id}");
|
|
351
293
|
});
|
|
352
294
|
}
|
|
353
295
|
}
|
|
@@ -2,10 +2,9 @@ import type { BaseClientOptions } from "../../../../BaseClient.js";
|
|
|
2
2
|
import { type NormalizedClientOptionsWithAuth } from "../../../../BaseClient.js";
|
|
3
3
|
import { WebsocketsSocket } from "./Socket.js";
|
|
4
4
|
export declare namespace WebsocketsClient {
|
|
5
|
-
|
|
6
|
-
}
|
|
5
|
+
type Options = BaseClientOptions;
|
|
7
6
|
interface ConnectArgs {
|
|
8
|
-
authToken?: string
|
|
7
|
+
authToken?: string;
|
|
9
8
|
/** Arbitrary headers to send with the websocket connect request. */
|
|
10
9
|
headers?: Record<string, string>;
|
|
11
10
|
/** Enable debug mode on the websocket. Defaults to false. */
|
|
@@ -57,10 +57,9 @@ class WebsocketsClient {
|
|
|
57
57
|
return __awaiter(this, arguments, void 0, function* (args = {}) {
|
|
58
58
|
var _a, _b;
|
|
59
59
|
const { authToken, headers, debug, reconnectAttempts } = args;
|
|
60
|
-
const _queryParams = {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
60
|
+
const _queryParams = {
|
|
61
|
+
auth_token: authToken,
|
|
62
|
+
};
|
|
64
63
|
const _authRequest = yield this._options.authProvider.getAuthRequest();
|
|
65
64
|
const _headers = (0, headers_js_1.mergeHeaders)(_authRequest.headers, headers);
|
|
66
65
|
const socket = new core.ReconnectingWebSocket({
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import * as core from "../core/index.js";
|
|
2
|
-
|
|
3
|
-
interface Options {
|
|
4
|
-
apiKey?: core.Supplier<core.BearerToken | undefined>;
|
|
5
|
-
}
|
|
6
|
-
}
|
|
2
|
+
declare const TOKEN_PARAM: "apiKey";
|
|
7
3
|
export declare class BearerAuthProvider implements core.AuthProvider {
|
|
8
|
-
private readonly
|
|
4
|
+
private readonly options;
|
|
9
5
|
constructor(options: BearerAuthProvider.Options);
|
|
10
|
-
static canCreate(options: BearerAuthProvider.Options): boolean;
|
|
11
|
-
getAuthRequest(
|
|
6
|
+
static canCreate(options: Partial<BearerAuthProvider.Options>): boolean;
|
|
7
|
+
getAuthRequest({ endpointMetadata, }?: {
|
|
12
8
|
endpointMetadata?: core.EndpointMetadata;
|
|
13
9
|
}): Promise<core.AuthRequest>;
|
|
14
10
|
}
|
|
11
|
+
export declare namespace BearerAuthProvider {
|
|
12
|
+
const AUTH_SCHEME: "Bearer";
|
|
13
|
+
const AUTH_CONFIG_ERROR_MESSAGE: string;
|
|
14
|
+
type Options = AuthOptions;
|
|
15
|
+
type AuthOptions = {
|
|
16
|
+
[TOKEN_PARAM]?: core.Supplier<core.BearerToken> | undefined;
|
|
17
|
+
};
|
|
18
|
+
function createInstance(options: Options): core.AuthProvider;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -46,21 +46,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
46
46
|
exports.BearerAuthProvider = void 0;
|
|
47
47
|
const core = __importStar(require("../core/index.js"));
|
|
48
48
|
const errors = __importStar(require("../errors/index.js"));
|
|
49
|
+
const TOKEN_PARAM = "apiKey";
|
|
50
|
+
const ENV_TOKEN = "AGENTMAIL_API_KEY";
|
|
49
51
|
class BearerAuthProvider {
|
|
50
52
|
constructor(options) {
|
|
51
|
-
this.
|
|
53
|
+
this.options = options;
|
|
52
54
|
}
|
|
53
55
|
static canCreate(options) {
|
|
54
56
|
var _a;
|
|
55
|
-
return options
|
|
57
|
+
return (options === null || options === void 0 ? void 0 : options[TOKEN_PARAM]) != null || ((_a = process.env) === null || _a === void 0 ? void 0 : _a[ENV_TOKEN]) != null;
|
|
56
58
|
}
|
|
57
|
-
getAuthRequest(
|
|
58
|
-
return __awaiter(this,
|
|
59
|
+
getAuthRequest() {
|
|
60
|
+
return __awaiter(this, arguments, void 0, function* ({ endpointMetadata, } = {}) {
|
|
59
61
|
var _a, _b;
|
|
60
|
-
const apiKey = (_a = (yield core.Supplier.get(this.
|
|
62
|
+
const apiKey = (_a = (yield core.Supplier.get(this.options[TOKEN_PARAM]))) !== null && _a !== void 0 ? _a : (_b = process.env) === null || _b === void 0 ? void 0 : _b[ENV_TOKEN];
|
|
61
63
|
if (apiKey == null) {
|
|
62
64
|
throw new errors.AgentMailError({
|
|
63
|
-
message:
|
|
65
|
+
message: BearerAuthProvider.AUTH_CONFIG_ERROR_MESSAGE,
|
|
64
66
|
});
|
|
65
67
|
}
|
|
66
68
|
return {
|
|
@@ -70,3 +72,11 @@ class BearerAuthProvider {
|
|
|
70
72
|
}
|
|
71
73
|
}
|
|
72
74
|
exports.BearerAuthProvider = BearerAuthProvider;
|
|
75
|
+
(function (BearerAuthProvider) {
|
|
76
|
+
BearerAuthProvider.AUTH_SCHEME = "Bearer";
|
|
77
|
+
BearerAuthProvider.AUTH_CONFIG_ERROR_MESSAGE = `Please provide '${TOKEN_PARAM}' when initializing the client, or set the '${ENV_TOKEN}' environment variable`;
|
|
78
|
+
function createInstance(options) {
|
|
79
|
+
return new BearerAuthProvider(options);
|
|
80
|
+
}
|
|
81
|
+
BearerAuthProvider.createInstance = createInstance;
|
|
82
|
+
})(BearerAuthProvider || (exports.BearerAuthProvider = BearerAuthProvider = {}));
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import type { ResponseWithBody } from "./ResponseWithBody.js";
|
|
2
1
|
export type BinaryResponse = {
|
|
3
2
|
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/bodyUsed) */
|
|
4
|
-
bodyUsed:
|
|
3
|
+
bodyUsed: Response["bodyUsed"];
|
|
5
4
|
/**
|
|
6
5
|
* Returns a ReadableStream of the response body.
|
|
7
6
|
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/body)
|
|
8
7
|
*/
|
|
9
|
-
stream: () =>
|
|
8
|
+
stream: () => Response["body"];
|
|
10
9
|
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/arrayBuffer) */
|
|
11
|
-
arrayBuffer: () =>
|
|
10
|
+
arrayBuffer: () => ReturnType<Response["arrayBuffer"]>;
|
|
12
11
|
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/blob) */
|
|
13
|
-
blob: () =>
|
|
12
|
+
blob: () => ReturnType<Response["blob"]>;
|
|
14
13
|
/**
|
|
15
14
|
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/bytes)
|
|
16
15
|
* Some versions of the Fetch API may not support this method.
|
|
17
16
|
*/
|
|
18
|
-
bytes?():
|
|
17
|
+
bytes?(): ReturnType<Response["bytes"]>;
|
|
19
18
|
};
|
|
20
|
-
export declare function getBinaryResponse(response:
|
|
19
|
+
export declare function getBinaryResponse(response: Response): BinaryResponse;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { EndpointMetadata } from "./EndpointMetadata.js";
|
|
2
2
|
import type { Supplier } from "./Supplier.js";
|
|
3
3
|
type EndpointSupplierFn<T> = (arg: {
|
|
4
|
-
endpointMetadata
|
|
4
|
+
endpointMetadata?: EndpointMetadata;
|
|
5
5
|
}) => T | Promise<T>;
|
|
6
6
|
export type EndpointSupplier<T> = Supplier<T> | EndpointSupplierFn<T>;
|
|
7
7
|
export declare const EndpointSupplier: {
|
|
8
8
|
get: <T>(supplier: EndpointSupplier<T>, arg: {
|
|
9
|
-
endpointMetadata
|
|
9
|
+
endpointMetadata?: EndpointMetadata;
|
|
10
10
|
}) => Promise<T>;
|
|
11
11
|
};
|
|
12
12
|
export {};
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { type LogConfig, type Logger } from "../logging/logger.js";
|
|
2
2
|
import type { APIResponse } from "./APIResponse.js";
|
|
3
3
|
import type { EndpointMetadata } from "./EndpointMetadata.js";
|
|
4
|
-
import { EndpointSupplier } from "./EndpointSupplier.js";
|
|
5
4
|
export type FetchFunction = <R = unknown>(args: Fetcher.Args) => Promise<APIResponse<R, Fetcher.Error>>;
|
|
6
5
|
export declare namespace Fetcher {
|
|
7
6
|
interface Args {
|
|
8
7
|
url: string;
|
|
9
8
|
method: string;
|
|
10
9
|
contentType?: string;
|
|
11
|
-
headers?: Record<string,
|
|
10
|
+
headers?: Record<string, unknown>;
|
|
12
11
|
queryParameters?: Record<string, unknown>;
|
|
13
12
|
body?: unknown;
|
|
14
13
|
timeoutMs?: number;
|
|
@@ -22,7 +21,7 @@ export declare namespace Fetcher {
|
|
|
22
21
|
fetchFn?: typeof fetch;
|
|
23
22
|
logging?: LogConfig | Logger;
|
|
24
23
|
}
|
|
25
|
-
type Error = FailedStatusCodeError | NonJsonError | TimeoutError | UnknownError;
|
|
24
|
+
type Error = FailedStatusCodeError | NonJsonError | BodyIsNullError | TimeoutError | UnknownError;
|
|
26
25
|
interface FailedStatusCodeError {
|
|
27
26
|
reason: "status-code";
|
|
28
27
|
statusCode: number;
|
|
@@ -33,6 +32,10 @@ export declare namespace Fetcher {
|
|
|
33
32
|
statusCode: number;
|
|
34
33
|
rawBody: string;
|
|
35
34
|
}
|
|
35
|
+
interface BodyIsNullError {
|
|
36
|
+
reason: "body-is-null";
|
|
37
|
+
statusCode: number;
|
|
38
|
+
}
|
|
36
39
|
interface TimeoutError {
|
|
37
40
|
reason: "timeout";
|
|
38
41
|
}
|
|
@@ -212,9 +212,10 @@ function fetcherImpl(args) {
|
|
|
212
212
|
};
|
|
213
213
|
logger.debug("HTTP request succeeded", metadata);
|
|
214
214
|
}
|
|
215
|
+
const body = yield (0, getResponseBody_js_1.getResponseBody)(response, args.responseType);
|
|
215
216
|
return {
|
|
216
217
|
ok: true,
|
|
217
|
-
body:
|
|
218
|
+
body: body,
|
|
218
219
|
headers: response.headers,
|
|
219
220
|
rawResponse: (0, RawResponse_js_1.toRawResponse)(response),
|
|
220
221
|
};
|
|
@@ -12,12 +12,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.getResponseBody = getResponseBody;
|
|
13
13
|
const json_js_1 = require("../json.js");
|
|
14
14
|
const BinaryResponse_js_1 = require("./BinaryResponse.js");
|
|
15
|
-
const ResponseWithBody_js_1 = require("./ResponseWithBody.js");
|
|
16
15
|
function getResponseBody(response, responseType) {
|
|
17
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
if (!(0, ResponseWithBody_js_1.isResponseWithBody)(response)) {
|
|
19
|
-
return undefined;
|
|
20
|
-
}
|
|
21
17
|
switch (responseType) {
|
|
22
18
|
case "binary-response":
|
|
23
19
|
return (0, BinaryResponse_js_1.getBinaryResponse)(response);
|
|
@@ -26,8 +22,26 @@ function getResponseBody(response, responseType) {
|
|
|
26
22
|
case "arrayBuffer":
|
|
27
23
|
return yield response.arrayBuffer();
|
|
28
24
|
case "sse":
|
|
25
|
+
if (response.body == null) {
|
|
26
|
+
return {
|
|
27
|
+
ok: false,
|
|
28
|
+
error: {
|
|
29
|
+
reason: "body-is-null",
|
|
30
|
+
statusCode: response.status,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
29
34
|
return response.body;
|
|
30
35
|
case "streaming":
|
|
36
|
+
if (response.body == null) {
|
|
37
|
+
return {
|
|
38
|
+
ok: false,
|
|
39
|
+
error: {
|
|
40
|
+
reason: "body-is-null",
|
|
41
|
+
statusCode: response.status,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
31
45
|
return response.body;
|
|
32
46
|
case "text":
|
|
33
47
|
return yield response.text();
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function mergeHeaders
|
|
2
|
-
export declare function mergeOnlyDefinedHeaders
|
|
1
|
+
export declare function mergeHeaders(...headersArray: (Record<string, unknown> | null | undefined)[]): Record<string, unknown>;
|
|
2
|
+
export declare function mergeOnlyDefinedHeaders(...headersArray: (Record<string, unknown> | null | undefined)[]): Record<string, unknown>;
|
|
@@ -71,6 +71,17 @@ function evaluateRuntime() {
|
|
|
71
71
|
version: Bun.version,
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* A constant that indicates whether the environment the code is running is in React-Native.
|
|
76
|
+
* This check should come before Node.js detection since React Native may have a process polyfill.
|
|
77
|
+
* https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Core/setUpNavigator.js
|
|
78
|
+
*/
|
|
79
|
+
const isReactNative = typeof navigator !== "undefined" && (navigator === null || navigator === void 0 ? void 0 : navigator.product) === "ReactNative";
|
|
80
|
+
if (isReactNative) {
|
|
81
|
+
return {
|
|
82
|
+
type: "react-native",
|
|
83
|
+
};
|
|
84
|
+
}
|
|
74
85
|
/**
|
|
75
86
|
* A constant that indicates whether the environment the code is running is Node.JS.
|
|
76
87
|
*/
|
|
@@ -86,16 +97,6 @@ function evaluateRuntime() {
|
|
|
86
97
|
parsedVersion: Number(process.versions.node.split(".")[0]),
|
|
87
98
|
};
|
|
88
99
|
}
|
|
89
|
-
/**
|
|
90
|
-
* A constant that indicates whether the environment the code is running is in React-Native.
|
|
91
|
-
* https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Core/setUpNavigator.js
|
|
92
|
-
*/
|
|
93
|
-
const isReactNative = typeof navigator !== "undefined" && (navigator === null || navigator === void 0 ? void 0 : navigator.product) === "ReactNative";
|
|
94
|
-
if (isReactNative) {
|
|
95
|
-
return {
|
|
96
|
-
type: "react-native",
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
100
|
return {
|
|
100
101
|
type: "unknown",
|
|
101
102
|
};
|
|
@@ -180,6 +180,7 @@ function getObjectUtils(schema) {
|
|
|
180
180
|
value: raw,
|
|
181
181
|
transformBase: (rawBase) => schema.parse(rawBase, opts),
|
|
182
182
|
transformExtension: (rawExtension) => extension.parse(rawExtension, opts),
|
|
183
|
+
breadcrumbsPrefix: opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix,
|
|
183
184
|
});
|
|
184
185
|
},
|
|
185
186
|
json: (parsed, opts) => {
|
|
@@ -188,6 +189,7 @@ function getObjectUtils(schema) {
|
|
|
188
189
|
value: parsed,
|
|
189
190
|
transformBase: (parsedBase) => schema.json(parsedBase, opts),
|
|
190
191
|
transformExtension: (parsedExtension) => extension.json(parsedExtension, opts),
|
|
192
|
+
breadcrumbsPrefix: opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix,
|
|
191
193
|
});
|
|
192
194
|
},
|
|
193
195
|
getType: () => Schema_js_1.SchemaType.OBJECT,
|
|
@@ -195,6 +197,8 @@ function getObjectUtils(schema) {
|
|
|
195
197
|
return Object.assign(Object.assign(Object.assign(Object.assign({}, baseSchema), (0, index_js_2.getSchemaUtils)(baseSchema)), (0, index_js_1.getObjectLikeUtils)(baseSchema)), getObjectUtils(baseSchema));
|
|
196
198
|
},
|
|
197
199
|
passthrough: () => {
|
|
200
|
+
const knownRawKeys = new Set(schema._getRawProperties());
|
|
201
|
+
const knownParsedKeys = new Set(schema._getParsedProperties());
|
|
198
202
|
const baseSchema = {
|
|
199
203
|
_getParsedProperties: () => schema._getParsedProperties(),
|
|
200
204
|
_getRawProperties: () => schema._getRawProperties(),
|
|
@@ -203,9 +207,17 @@ function getObjectUtils(schema) {
|
|
|
203
207
|
if (!transformed.ok) {
|
|
204
208
|
return transformed;
|
|
205
209
|
}
|
|
210
|
+
const extraProperties = {};
|
|
211
|
+
if (typeof raw === "object" && raw != null) {
|
|
212
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
213
|
+
if (!knownRawKeys.has(key)) {
|
|
214
|
+
extraProperties[key] = value;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
206
218
|
return {
|
|
207
219
|
ok: true,
|
|
208
|
-
value: Object.assign(Object.assign({},
|
|
220
|
+
value: Object.assign(Object.assign({}, extraProperties), transformed.value),
|
|
209
221
|
};
|
|
210
222
|
},
|
|
211
223
|
json: (parsed, opts) => {
|
|
@@ -213,9 +225,17 @@ function getObjectUtils(schema) {
|
|
|
213
225
|
if (!transformed.ok) {
|
|
214
226
|
return transformed;
|
|
215
227
|
}
|
|
228
|
+
const extraProperties = {};
|
|
229
|
+
if (typeof parsed === "object" && parsed != null) {
|
|
230
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
231
|
+
if (!knownParsedKeys.has(key)) {
|
|
232
|
+
extraProperties[key] = value;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
216
236
|
return {
|
|
217
237
|
ok: true,
|
|
218
|
-
value: Object.assign(Object.assign({},
|
|
238
|
+
value: Object.assign(Object.assign({}, extraProperties), transformed.value),
|
|
219
239
|
};
|
|
220
240
|
},
|
|
221
241
|
getType: () => Schema_js_1.SchemaType.OBJECT,
|
|
@@ -224,7 +244,18 @@ function getObjectUtils(schema) {
|
|
|
224
244
|
},
|
|
225
245
|
};
|
|
226
246
|
}
|
|
227
|
-
function validateAndTransformExtendedObject({ extensionKeys, value, transformBase, transformExtension, }) {
|
|
247
|
+
function validateAndTransformExtendedObject({ extensionKeys, value, transformBase, transformExtension, breadcrumbsPrefix = [], }) {
|
|
248
|
+
if (!(0, isPlainObject_js_1.isPlainObject)(value)) {
|
|
249
|
+
return {
|
|
250
|
+
ok: false,
|
|
251
|
+
errors: [
|
|
252
|
+
{
|
|
253
|
+
path: breadcrumbsPrefix,
|
|
254
|
+
message: (0, getErrorMessageForIncorrectType_js_1.getErrorMessageForIncorrectType)(value, "object"),
|
|
255
|
+
},
|
|
256
|
+
],
|
|
257
|
+
};
|
|
258
|
+
}
|
|
228
259
|
const extensionPropertiesSet = new Set(extensionKeys);
|
|
229
260
|
const [extensionProperties, baseProperties] = (0, partition_js_1.partition)((0, keys_js_1.keys)(value), (key) => extensionPropertiesSet.has(key));
|
|
230
261
|
const transformedBase = transformBase((0, filterObject_js_1.filterObject)(value, baseProperties));
|
|
@@ -8,7 +8,7 @@ export declare namespace ReconnectingWebSocket {
|
|
|
8
8
|
protocols?: string | string[];
|
|
9
9
|
options?: ReconnectingWebSocket.Options;
|
|
10
10
|
headers?: Record<string, unknown>;
|
|
11
|
-
queryParameters?: Record<string,
|
|
11
|
+
queryParameters?: Record<string, unknown>;
|
|
12
12
|
}
|
|
13
13
|
type Options = {
|
|
14
14
|
WebSocket?: any;
|
|
@@ -6,7 +6,11 @@ const json_js_1 = require("../core/json.js");
|
|
|
6
6
|
class AgentMailError extends Error {
|
|
7
7
|
constructor({ message, statusCode, body, rawResponse, }) {
|
|
8
8
|
super(buildMessage({ message, statusCode, body }));
|
|
9
|
-
Object.setPrototypeOf(this,
|
|
9
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
10
|
+
if (Error.captureStackTrace) {
|
|
11
|
+
Error.captureStackTrace(this, this.constructor);
|
|
12
|
+
}
|
|
13
|
+
this.name = this.constructor.name;
|
|
10
14
|
this.statusCode = statusCode;
|
|
11
15
|
this.body = body;
|
|
12
16
|
this.rawResponse = rawResponse;
|
|
@@ -5,7 +5,11 @@ exports.AgentMailTimeoutError = void 0;
|
|
|
5
5
|
class AgentMailTimeoutError extends Error {
|
|
6
6
|
constructor(message) {
|
|
7
7
|
super(message);
|
|
8
|
-
Object.setPrototypeOf(this,
|
|
8
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
9
|
+
if (Error.captureStackTrace) {
|
|
10
|
+
Error.captureStackTrace(this, this.constructor);
|
|
11
|
+
}
|
|
12
|
+
this.name = this.constructor.name;
|
|
9
13
|
}
|
|
10
14
|
}
|
|
11
15
|
exports.AgentMailTimeoutError = AgentMailTimeoutError;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This file was auto-generated by Fern from our API Definition.
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.handleNonStatusCodeError = handleNonStatusCodeError;
|
|
38
|
+
const errors = __importStar(require("./index.js"));
|
|
39
|
+
function handleNonStatusCodeError(error, rawResponse, method, path) {
|
|
40
|
+
switch (error.reason) {
|
|
41
|
+
case "non-json":
|
|
42
|
+
throw new errors.AgentMailError({
|
|
43
|
+
statusCode: error.statusCode,
|
|
44
|
+
body: error.rawBody,
|
|
45
|
+
rawResponse: rawResponse,
|
|
46
|
+
});
|
|
47
|
+
case "body-is-null":
|
|
48
|
+
throw new errors.AgentMailError({
|
|
49
|
+
statusCode: error.statusCode,
|
|
50
|
+
rawResponse: rawResponse,
|
|
51
|
+
});
|
|
52
|
+
case "timeout":
|
|
53
|
+
throw new errors.AgentMailTimeoutError(`Timeout exceeded when calling ${method} ${path}.`);
|
|
54
|
+
case "unknown":
|
|
55
|
+
throw new errors.AgentMailError({
|
|
56
|
+
message: error.errorMessage,
|
|
57
|
+
rawResponse: rawResponse,
|
|
58
|
+
});
|
|
59
|
+
default:
|
|
60
|
+
throw new errors.AgentMailError({
|
|
61
|
+
message: "Unknown error",
|
|
62
|
+
rawResponse: rawResponse,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type * as AgentMail from "../../../../api/index.js";
|
|
2
|
+
import * as core from "../../../../core/index.js";
|
|
3
|
+
import type * as serializers from "../../../index.js";
|
|
4
|
+
import { AttachmentContentDisposition } from "./AttachmentContentDisposition.js";
|
|
5
|
+
import { AttachmentContentId } from "./AttachmentContentId.js";
|
|
6
|
+
import { AttachmentContentType } from "./AttachmentContentType.js";
|
|
7
|
+
import { AttachmentFilename } from "./AttachmentFilename.js";
|
|
8
|
+
import { AttachmentId } from "./AttachmentId.js";
|
|
9
|
+
import { AttachmentSize } from "./AttachmentSize.js";
|
|
10
|
+
export declare const AttachmentResponse: core.serialization.ObjectSchema<serializers.AttachmentResponse.Raw, AgentMail.AttachmentResponse>;
|
|
11
|
+
export declare namespace AttachmentResponse {
|
|
12
|
+
interface Raw {
|
|
13
|
+
attachment_id: AttachmentId.Raw;
|
|
14
|
+
filename?: AttachmentFilename.Raw | null;
|
|
15
|
+
size: AttachmentSize.Raw;
|
|
16
|
+
content_type?: AttachmentContentType.Raw | null;
|
|
17
|
+
content_disposition?: AttachmentContentDisposition.Raw | null;
|
|
18
|
+
content_id?: AttachmentContentId.Raw | null;
|
|
19
|
+
download_url: string;
|
|
20
|
+
expires_at: string;
|
|
21
|
+
}
|
|
22
|
+
}
|