agentmail 0.2.1 → 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 +10 -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/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 +1 -2
- package/dist/cjs/api/resources/inboxes/resources/messages/client/Client.js +27 -142
- 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 +1 -2
- package/dist/cjs/api/resources/inboxes/resources/threads/client/Client.js +23 -82
- 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 +1 -2
- package/dist/cjs/api/resources/pods/resources/threads/client/Client.js +22 -67
- package/dist/cjs/api/resources/threads/client/Client.d.ts +1 -2
- package/dist/cjs/api/resources/threads/client/Client.js +22 -67
- 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/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/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 +1 -2
- package/dist/esm/api/resources/inboxes/resources/messages/client/Client.mjs +27 -142
- 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 +1 -2
- package/dist/esm/api/resources/inboxes/resources/threads/client/Client.mjs +23 -82
- 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 +1 -2
- package/dist/esm/api/resources/pods/resources/threads/client/Client.mjs +22 -67
- package/dist/esm/api/resources/threads/client/Client.d.mts +1 -2
- package/dist/esm/api/resources/threads/client/Client.mjs +22 -67
- 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/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +6 -3
- 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
|
@@ -13,6 +13,7 @@ import { mergeHeaders } from "../../../../core/headers.mjs";
|
|
|
13
13
|
import * as core from "../../../../core/index.mjs";
|
|
14
14
|
import { toJson } from "../../../../core/json.mjs";
|
|
15
15
|
import * as environments from "../../../../environments.mjs";
|
|
16
|
+
import { handleNonStatusCodeError } from "../../../../errors/handleNonStatusCodeError.mjs";
|
|
16
17
|
import * as errors from "../../../../errors/index.mjs";
|
|
17
18
|
import * as serializers from "../../../../serialization/index.mjs";
|
|
18
19
|
import * as AgentMail from "../../../index.mjs";
|
|
@@ -36,28 +37,24 @@ export class ThreadsClient {
|
|
|
36
37
|
return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) {
|
|
37
38
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
38
39
|
const { limit, pageToken, labels, before, after, ascending, includeSpam } = request;
|
|
39
|
-
const _queryParams = {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
if (includeSpam != null) {
|
|
59
|
-
_queryParams.include_spam = includeSpam.toString();
|
|
60
|
-
}
|
|
40
|
+
const _queryParams = {
|
|
41
|
+
limit,
|
|
42
|
+
page_token: pageToken,
|
|
43
|
+
labels: labels != null
|
|
44
|
+
? toJson(serializers.Labels.jsonOrThrow(labels, {
|
|
45
|
+
unrecognizedObjectKeys: "strip",
|
|
46
|
+
omitUndefined: true,
|
|
47
|
+
}))
|
|
48
|
+
: undefined,
|
|
49
|
+
before: before != null
|
|
50
|
+
? serializers.Before.jsonOrThrow(before, { unrecognizedObjectKeys: "strip", omitUndefined: true })
|
|
51
|
+
: undefined,
|
|
52
|
+
after: after != null
|
|
53
|
+
? serializers.After.jsonOrThrow(after, { unrecognizedObjectKeys: "strip", omitUndefined: true })
|
|
54
|
+
: undefined,
|
|
55
|
+
ascending,
|
|
56
|
+
include_spam: includeSpam,
|
|
57
|
+
};
|
|
61
58
|
const _authRequest = yield this._options.authProvider.getAuthRequest();
|
|
62
59
|
const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
63
60
|
const _response = yield core.fetcher({
|
|
@@ -101,21 +98,7 @@ export class ThreadsClient {
|
|
|
101
98
|
});
|
|
102
99
|
}
|
|
103
100
|
}
|
|
104
|
-
|
|
105
|
-
case "non-json":
|
|
106
|
-
throw new errors.AgentMailError({
|
|
107
|
-
statusCode: _response.error.statusCode,
|
|
108
|
-
body: _response.error.rawBody,
|
|
109
|
-
rawResponse: _response.rawResponse,
|
|
110
|
-
});
|
|
111
|
-
case "timeout":
|
|
112
|
-
throw new errors.AgentMailTimeoutError("Timeout exceeded when calling GET /v0/threads.");
|
|
113
|
-
case "unknown":
|
|
114
|
-
throw new errors.AgentMailError({
|
|
115
|
-
message: _response.error.errorMessage,
|
|
116
|
-
rawResponse: _response.rawResponse,
|
|
117
|
-
});
|
|
118
|
-
}
|
|
101
|
+
return handleNonStatusCodeError(_response.error, _response.rawResponse, "GET", "/v0/threads");
|
|
119
102
|
});
|
|
120
103
|
}
|
|
121
104
|
/**
|
|
@@ -176,21 +159,7 @@ export class ThreadsClient {
|
|
|
176
159
|
});
|
|
177
160
|
}
|
|
178
161
|
}
|
|
179
|
-
|
|
180
|
-
case "non-json":
|
|
181
|
-
throw new errors.AgentMailError({
|
|
182
|
-
statusCode: _response.error.statusCode,
|
|
183
|
-
body: _response.error.rawBody,
|
|
184
|
-
rawResponse: _response.rawResponse,
|
|
185
|
-
});
|
|
186
|
-
case "timeout":
|
|
187
|
-
throw new errors.AgentMailTimeoutError("Timeout exceeded when calling GET /v0/threads/{thread_id}.");
|
|
188
|
-
case "unknown":
|
|
189
|
-
throw new errors.AgentMailError({
|
|
190
|
-
message: _response.error.errorMessage,
|
|
191
|
-
rawResponse: _response.rawResponse,
|
|
192
|
-
});
|
|
193
|
-
}
|
|
162
|
+
return handleNonStatusCodeError(_response.error, _response.rawResponse, "GET", "/v0/threads/{thread_id}");
|
|
194
163
|
});
|
|
195
164
|
}
|
|
196
165
|
/**
|
|
@@ -252,21 +221,7 @@ export class ThreadsClient {
|
|
|
252
221
|
});
|
|
253
222
|
}
|
|
254
223
|
}
|
|
255
|
-
|
|
256
|
-
case "non-json":
|
|
257
|
-
throw new errors.AgentMailError({
|
|
258
|
-
statusCode: _response.error.statusCode,
|
|
259
|
-
body: _response.error.rawBody,
|
|
260
|
-
rawResponse: _response.rawResponse,
|
|
261
|
-
});
|
|
262
|
-
case "timeout":
|
|
263
|
-
throw new errors.AgentMailTimeoutError("Timeout exceeded when calling GET /v0/threads/{thread_id}/attachments/{attachment_id}.");
|
|
264
|
-
case "unknown":
|
|
265
|
-
throw new errors.AgentMailError({
|
|
266
|
-
message: _response.error.errorMessage,
|
|
267
|
-
rawResponse: _response.rawResponse,
|
|
268
|
-
});
|
|
269
|
-
}
|
|
224
|
+
return handleNonStatusCodeError(_response.error, _response.rawResponse, "GET", "/v0/threads/{thread_id}/attachments/{attachment_id}");
|
|
270
225
|
});
|
|
271
226
|
}
|
|
272
227
|
}
|
|
@@ -3,8 +3,7 @@ import { type NormalizedClientOptionsWithAuth } from "../../../../BaseClient.mjs
|
|
|
3
3
|
import * as core from "../../../../core/index.mjs";
|
|
4
4
|
import * as AgentMail from "../../../index.mjs";
|
|
5
5
|
export declare namespace WebhooksClient {
|
|
6
|
-
|
|
7
|
-
}
|
|
6
|
+
type Options = BaseClientOptions;
|
|
8
7
|
interface RequestOptions extends BaseRequestOptions {
|
|
9
8
|
}
|
|
10
9
|
}
|
|
@@ -12,6 +12,7 @@ import { normalizeClientOptionsWithAuth } from "../../../../BaseClient.mjs";
|
|
|
12
12
|
import { mergeHeaders } from "../../../../core/headers.mjs";
|
|
13
13
|
import * as core from "../../../../core/index.mjs";
|
|
14
14
|
import * as environments from "../../../../environments.mjs";
|
|
15
|
+
import { handleNonStatusCodeError } from "../../../../errors/handleNonStatusCodeError.mjs";
|
|
15
16
|
import * as errors from "../../../../errors/index.mjs";
|
|
16
17
|
import * as serializers from "../../../../serialization/index.mjs";
|
|
17
18
|
import * as AgentMail from "../../../index.mjs";
|
|
@@ -33,13 +34,10 @@ export class WebhooksClient {
|
|
|
33
34
|
return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) {
|
|
34
35
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
35
36
|
const { limit, pageToken } = request;
|
|
36
|
-
const _queryParams = {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
if (pageToken != null) {
|
|
41
|
-
_queryParams.page_token = pageToken;
|
|
42
|
-
}
|
|
37
|
+
const _queryParams = {
|
|
38
|
+
limit,
|
|
39
|
+
page_token: pageToken,
|
|
40
|
+
};
|
|
43
41
|
const _authRequest = yield this._options.authProvider.getAuthRequest();
|
|
44
42
|
const _headers = mergeHeaders(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
45
43
|
const _response = yield core.fetcher({
|
|
@@ -72,21 +70,7 @@ export class WebhooksClient {
|
|
|
72
70
|
rawResponse: _response.rawResponse,
|
|
73
71
|
});
|
|
74
72
|
}
|
|
75
|
-
|
|
76
|
-
case "non-json":
|
|
77
|
-
throw new errors.AgentMailError({
|
|
78
|
-
statusCode: _response.error.statusCode,
|
|
79
|
-
body: _response.error.rawBody,
|
|
80
|
-
rawResponse: _response.rawResponse,
|
|
81
|
-
});
|
|
82
|
-
case "timeout":
|
|
83
|
-
throw new errors.AgentMailTimeoutError("Timeout exceeded when calling GET /v0/webhooks.");
|
|
84
|
-
case "unknown":
|
|
85
|
-
throw new errors.AgentMailError({
|
|
86
|
-
message: _response.error.errorMessage,
|
|
87
|
-
rawResponse: _response.rawResponse,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
73
|
+
return handleNonStatusCodeError(_response.error, _response.rawResponse, "GET", "/v0/webhooks");
|
|
90
74
|
});
|
|
91
75
|
}
|
|
92
76
|
/**
|
|
@@ -147,21 +131,7 @@ export class WebhooksClient {
|
|
|
147
131
|
});
|
|
148
132
|
}
|
|
149
133
|
}
|
|
150
|
-
|
|
151
|
-
case "non-json":
|
|
152
|
-
throw new errors.AgentMailError({
|
|
153
|
-
statusCode: _response.error.statusCode,
|
|
154
|
-
body: _response.error.rawBody,
|
|
155
|
-
rawResponse: _response.rawResponse,
|
|
156
|
-
});
|
|
157
|
-
case "timeout":
|
|
158
|
-
throw new errors.AgentMailTimeoutError("Timeout exceeded when calling GET /v0/webhooks/{webhook_id}.");
|
|
159
|
-
case "unknown":
|
|
160
|
-
throw new errors.AgentMailError({
|
|
161
|
-
message: _response.error.errorMessage,
|
|
162
|
-
rawResponse: _response.rawResponse,
|
|
163
|
-
});
|
|
164
|
-
}
|
|
134
|
+
return handleNonStatusCodeError(_response.error, _response.rawResponse, "GET", "/v0/webhooks/{webhook_id}");
|
|
165
135
|
});
|
|
166
136
|
}
|
|
167
137
|
/**
|
|
@@ -231,21 +201,7 @@ export class WebhooksClient {
|
|
|
231
201
|
});
|
|
232
202
|
}
|
|
233
203
|
}
|
|
234
|
-
|
|
235
|
-
case "non-json":
|
|
236
|
-
throw new errors.AgentMailError({
|
|
237
|
-
statusCode: _response.error.statusCode,
|
|
238
|
-
body: _response.error.rawBody,
|
|
239
|
-
rawResponse: _response.rawResponse,
|
|
240
|
-
});
|
|
241
|
-
case "timeout":
|
|
242
|
-
throw new errors.AgentMailTimeoutError("Timeout exceeded when calling POST /v0/webhooks.");
|
|
243
|
-
case "unknown":
|
|
244
|
-
throw new errors.AgentMailError({
|
|
245
|
-
message: _response.error.errorMessage,
|
|
246
|
-
rawResponse: _response.rawResponse,
|
|
247
|
-
});
|
|
248
|
-
}
|
|
204
|
+
return handleNonStatusCodeError(_response.error, _response.rawResponse, "POST", "/v0/webhooks");
|
|
249
205
|
});
|
|
250
206
|
}
|
|
251
207
|
/**
|
|
@@ -297,21 +253,7 @@ export class WebhooksClient {
|
|
|
297
253
|
});
|
|
298
254
|
}
|
|
299
255
|
}
|
|
300
|
-
|
|
301
|
-
case "non-json":
|
|
302
|
-
throw new errors.AgentMailError({
|
|
303
|
-
statusCode: _response.error.statusCode,
|
|
304
|
-
body: _response.error.rawBody,
|
|
305
|
-
rawResponse: _response.rawResponse,
|
|
306
|
-
});
|
|
307
|
-
case "timeout":
|
|
308
|
-
throw new errors.AgentMailTimeoutError("Timeout exceeded when calling DELETE /v0/webhooks/{webhook_id}.");
|
|
309
|
-
case "unknown":
|
|
310
|
-
throw new errors.AgentMailError({
|
|
311
|
-
message: _response.error.errorMessage,
|
|
312
|
-
rawResponse: _response.rawResponse,
|
|
313
|
-
});
|
|
314
|
-
}
|
|
256
|
+
return handleNonStatusCodeError(_response.error, _response.rawResponse, "DELETE", "/v0/webhooks/{webhook_id}");
|
|
315
257
|
});
|
|
316
258
|
}
|
|
317
259
|
}
|
|
@@ -2,10 +2,9 @@ import type { BaseClientOptions } from "../../../../BaseClient.mjs";
|
|
|
2
2
|
import { type NormalizedClientOptionsWithAuth } from "../../../../BaseClient.mjs";
|
|
3
3
|
import { WebsocketsSocket } from "./Socket.mjs";
|
|
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. */
|
|
@@ -21,10 +21,9 @@ export class WebsocketsClient {
|
|
|
21
21
|
return __awaiter(this, arguments, void 0, function* (args = {}) {
|
|
22
22
|
var _a, _b;
|
|
23
23
|
const { authToken, headers, debug, reconnectAttempts } = args;
|
|
24
|
-
const _queryParams = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
24
|
+
const _queryParams = {
|
|
25
|
+
auth_token: authToken,
|
|
26
|
+
};
|
|
28
27
|
const _authRequest = yield this._options.authProvider.getAuthRequest();
|
|
29
28
|
const _headers = mergeHeaders(_authRequest.headers, headers);
|
|
30
29
|
const socket = new core.ReconnectingWebSocket({
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import * as core from "../core/index.mjs";
|
|
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 {};
|
|
@@ -10,21 +10,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
import * as core from "../core/index.mjs";
|
|
12
12
|
import * as errors from "../errors/index.mjs";
|
|
13
|
+
const TOKEN_PARAM = "apiKey";
|
|
14
|
+
const ENV_TOKEN = "AGENTMAIL_API_KEY";
|
|
13
15
|
export class BearerAuthProvider {
|
|
14
16
|
constructor(options) {
|
|
15
|
-
this.
|
|
17
|
+
this.options = options;
|
|
16
18
|
}
|
|
17
19
|
static canCreate(options) {
|
|
18
20
|
var _a;
|
|
19
|
-
return options
|
|
21
|
+
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;
|
|
20
22
|
}
|
|
21
|
-
getAuthRequest(
|
|
22
|
-
return __awaiter(this,
|
|
23
|
+
getAuthRequest() {
|
|
24
|
+
return __awaiter(this, arguments, void 0, function* ({ endpointMetadata, } = {}) {
|
|
23
25
|
var _a, _b;
|
|
24
|
-
const apiKey = (_a = (yield core.Supplier.get(this.
|
|
26
|
+
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];
|
|
25
27
|
if (apiKey == null) {
|
|
26
28
|
throw new errors.AgentMailError({
|
|
27
|
-
message:
|
|
29
|
+
message: BearerAuthProvider.AUTH_CONFIG_ERROR_MESSAGE,
|
|
28
30
|
});
|
|
29
31
|
}
|
|
30
32
|
return {
|
|
@@ -33,3 +35,11 @@ export class BearerAuthProvider {
|
|
|
33
35
|
});
|
|
34
36
|
}
|
|
35
37
|
}
|
|
38
|
+
(function (BearerAuthProvider) {
|
|
39
|
+
BearerAuthProvider.AUTH_SCHEME = "Bearer";
|
|
40
|
+
BearerAuthProvider.AUTH_CONFIG_ERROR_MESSAGE = `Please provide '${TOKEN_PARAM}' when initializing the client, or set the '${ENV_TOKEN}' environment variable`;
|
|
41
|
+
function createInstance(options) {
|
|
42
|
+
return new BearerAuthProvider(options);
|
|
43
|
+
}
|
|
44
|
+
BearerAuthProvider.createInstance = createInstance;
|
|
45
|
+
})(BearerAuthProvider || (BearerAuthProvider = {}));
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import type { ResponseWithBody } from "./ResponseWithBody.mjs";
|
|
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.mjs";
|
|
2
2
|
import type { Supplier } from "./Supplier.mjs";
|
|
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.mjs";
|
|
2
2
|
import type { APIResponse } from "./APIResponse.mjs";
|
|
3
3
|
import type { EndpointMetadata } from "./EndpointMetadata.mjs";
|
|
4
|
-
import { EndpointSupplier } from "./EndpointSupplier.mjs";
|
|
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
|
}
|
|
@@ -208,9 +208,10 @@ export function fetcherImpl(args) {
|
|
|
208
208
|
};
|
|
209
209
|
logger.debug("HTTP request succeeded", metadata);
|
|
210
210
|
}
|
|
211
|
+
const body = yield getResponseBody(response, args.responseType);
|
|
211
212
|
return {
|
|
212
213
|
ok: true,
|
|
213
|
-
body:
|
|
214
|
+
body: body,
|
|
214
215
|
headers: response.headers,
|
|
215
216
|
rawResponse: toRawResponse(response),
|
|
216
217
|
};
|
|
@@ -9,12 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { fromJson } from "../json.mjs";
|
|
11
11
|
import { getBinaryResponse } from "./BinaryResponse.mjs";
|
|
12
|
-
import { isResponseWithBody } from "./ResponseWithBody.mjs";
|
|
13
12
|
export function getResponseBody(response, responseType) {
|
|
14
13
|
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
-
if (!isResponseWithBody(response)) {
|
|
16
|
-
return undefined;
|
|
17
|
-
}
|
|
18
14
|
switch (responseType) {
|
|
19
15
|
case "binary-response":
|
|
20
16
|
return getBinaryResponse(response);
|
|
@@ -23,8 +19,26 @@ export function getResponseBody(response, responseType) {
|
|
|
23
19
|
case "arrayBuffer":
|
|
24
20
|
return yield response.arrayBuffer();
|
|
25
21
|
case "sse":
|
|
22
|
+
if (response.body == null) {
|
|
23
|
+
return {
|
|
24
|
+
ok: false,
|
|
25
|
+
error: {
|
|
26
|
+
reason: "body-is-null",
|
|
27
|
+
statusCode: response.status,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
26
31
|
return response.body;
|
|
27
32
|
case "streaming":
|
|
33
|
+
if (response.body == null) {
|
|
34
|
+
return {
|
|
35
|
+
ok: false,
|
|
36
|
+
error: {
|
|
37
|
+
reason: "body-is-null",
|
|
38
|
+
statusCode: response.status,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
28
42
|
return response.body;
|
|
29
43
|
case "text":
|
|
30
44
|
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>;
|
|
@@ -68,6 +68,17 @@ function evaluateRuntime() {
|
|
|
68
68
|
version: Bun.version,
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* A constant that indicates whether the environment the code is running is in React-Native.
|
|
73
|
+
* This check should come before Node.js detection since React Native may have a process polyfill.
|
|
74
|
+
* https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Core/setUpNavigator.js
|
|
75
|
+
*/
|
|
76
|
+
const isReactNative = typeof navigator !== "undefined" && (navigator === null || navigator === void 0 ? void 0 : navigator.product) === "ReactNative";
|
|
77
|
+
if (isReactNative) {
|
|
78
|
+
return {
|
|
79
|
+
type: "react-native",
|
|
80
|
+
};
|
|
81
|
+
}
|
|
71
82
|
/**
|
|
72
83
|
* A constant that indicates whether the environment the code is running is Node.JS.
|
|
73
84
|
*/
|
|
@@ -83,16 +94,6 @@ function evaluateRuntime() {
|
|
|
83
94
|
parsedVersion: Number(process.versions.node.split(".")[0]),
|
|
84
95
|
};
|
|
85
96
|
}
|
|
86
|
-
/**
|
|
87
|
-
* A constant that indicates whether the environment the code is running is in React-Native.
|
|
88
|
-
* https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Core/setUpNavigator.js
|
|
89
|
-
*/
|
|
90
|
-
const isReactNative = typeof navigator !== "undefined" && (navigator === null || navigator === void 0 ? void 0 : navigator.product) === "ReactNative";
|
|
91
|
-
if (isReactNative) {
|
|
92
|
-
return {
|
|
93
|
-
type: "react-native",
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
97
|
return {
|
|
97
98
|
type: "unknown",
|
|
98
99
|
};
|
|
@@ -176,6 +176,7 @@ export function getObjectUtils(schema) {
|
|
|
176
176
|
value: raw,
|
|
177
177
|
transformBase: (rawBase) => schema.parse(rawBase, opts),
|
|
178
178
|
transformExtension: (rawExtension) => extension.parse(rawExtension, opts),
|
|
179
|
+
breadcrumbsPrefix: opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix,
|
|
179
180
|
});
|
|
180
181
|
},
|
|
181
182
|
json: (parsed, opts) => {
|
|
@@ -184,6 +185,7 @@ export function getObjectUtils(schema) {
|
|
|
184
185
|
value: parsed,
|
|
185
186
|
transformBase: (parsedBase) => schema.json(parsedBase, opts),
|
|
186
187
|
transformExtension: (parsedExtension) => extension.json(parsedExtension, opts),
|
|
188
|
+
breadcrumbsPrefix: opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix,
|
|
187
189
|
});
|
|
188
190
|
},
|
|
189
191
|
getType: () => SchemaType.OBJECT,
|
|
@@ -191,6 +193,8 @@ export function getObjectUtils(schema) {
|
|
|
191
193
|
return Object.assign(Object.assign(Object.assign(Object.assign({}, baseSchema), getSchemaUtils(baseSchema)), getObjectLikeUtils(baseSchema)), getObjectUtils(baseSchema));
|
|
192
194
|
},
|
|
193
195
|
passthrough: () => {
|
|
196
|
+
const knownRawKeys = new Set(schema._getRawProperties());
|
|
197
|
+
const knownParsedKeys = new Set(schema._getParsedProperties());
|
|
194
198
|
const baseSchema = {
|
|
195
199
|
_getParsedProperties: () => schema._getParsedProperties(),
|
|
196
200
|
_getRawProperties: () => schema._getRawProperties(),
|
|
@@ -199,9 +203,17 @@ export function getObjectUtils(schema) {
|
|
|
199
203
|
if (!transformed.ok) {
|
|
200
204
|
return transformed;
|
|
201
205
|
}
|
|
206
|
+
const extraProperties = {};
|
|
207
|
+
if (typeof raw === "object" && raw != null) {
|
|
208
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
209
|
+
if (!knownRawKeys.has(key)) {
|
|
210
|
+
extraProperties[key] = value;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
202
214
|
return {
|
|
203
215
|
ok: true,
|
|
204
|
-
value: Object.assign(Object.assign({},
|
|
216
|
+
value: Object.assign(Object.assign({}, extraProperties), transformed.value),
|
|
205
217
|
};
|
|
206
218
|
},
|
|
207
219
|
json: (parsed, opts) => {
|
|
@@ -209,9 +221,17 @@ export function getObjectUtils(schema) {
|
|
|
209
221
|
if (!transformed.ok) {
|
|
210
222
|
return transformed;
|
|
211
223
|
}
|
|
224
|
+
const extraProperties = {};
|
|
225
|
+
if (typeof parsed === "object" && parsed != null) {
|
|
226
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
227
|
+
if (!knownParsedKeys.has(key)) {
|
|
228
|
+
extraProperties[key] = value;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
212
232
|
return {
|
|
213
233
|
ok: true,
|
|
214
|
-
value: Object.assign(Object.assign({},
|
|
234
|
+
value: Object.assign(Object.assign({}, extraProperties), transformed.value),
|
|
215
235
|
};
|
|
216
236
|
},
|
|
217
237
|
getType: () => SchemaType.OBJECT,
|
|
@@ -220,7 +240,18 @@ export function getObjectUtils(schema) {
|
|
|
220
240
|
},
|
|
221
241
|
};
|
|
222
242
|
}
|
|
223
|
-
function validateAndTransformExtendedObject({ extensionKeys, value, transformBase, transformExtension, }) {
|
|
243
|
+
function validateAndTransformExtendedObject({ extensionKeys, value, transformBase, transformExtension, breadcrumbsPrefix = [], }) {
|
|
244
|
+
if (!isPlainObject(value)) {
|
|
245
|
+
return {
|
|
246
|
+
ok: false,
|
|
247
|
+
errors: [
|
|
248
|
+
{
|
|
249
|
+
path: breadcrumbsPrefix,
|
|
250
|
+
message: getErrorMessageForIncorrectType(value, "object"),
|
|
251
|
+
},
|
|
252
|
+
],
|
|
253
|
+
};
|
|
254
|
+
}
|
|
224
255
|
const extensionPropertiesSet = new Set(extensionKeys);
|
|
225
256
|
const [extensionProperties, baseProperties] = partition(keys(value), (key) => extensionPropertiesSet.has(key));
|
|
226
257
|
const transformedBase = transformBase(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;
|
|
@@ -3,7 +3,11 @@ import { toJson } from "../core/json.mjs";
|
|
|
3
3
|
export class AgentMailError extends Error {
|
|
4
4
|
constructor({ message, statusCode, body, rawResponse, }) {
|
|
5
5
|
super(buildMessage({ message, statusCode, body }));
|
|
6
|
-
Object.setPrototypeOf(this,
|
|
6
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
7
|
+
if (Error.captureStackTrace) {
|
|
8
|
+
Error.captureStackTrace(this, this.constructor);
|
|
9
|
+
}
|
|
10
|
+
this.name = this.constructor.name;
|
|
7
11
|
this.statusCode = statusCode;
|
|
8
12
|
this.body = body;
|
|
9
13
|
this.rawResponse = rawResponse;
|