agentmail 0.1.5 → 0.1.7
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 +63 -0
- package/dist/cjs/BaseClient.d.ts +14 -1
- package/dist/cjs/BaseClient.js +59 -0
- package/dist/cjs/Client.d.ts +30 -29
- package/dist/cjs/Client.js +12 -53
- package/dist/cjs/api/resources/apiKeys/client/Client.d.ts +12 -12
- package/dist/cjs/api/resources/apiKeys/client/Client.js +29 -31
- package/dist/cjs/api/resources/domains/client/Client.d.ts +19 -19
- package/dist/cjs/api/resources/domains/client/Client.js +60 -53
- package/dist/cjs/api/resources/domains/types/Domain.d.ts +1 -0
- package/dist/cjs/api/resources/domains/types/DomainItem.d.ts +1 -0
- package/dist/cjs/api/resources/drafts/client/Client.d.ts +10 -10
- package/dist/cjs/api/resources/drafts/client/Client.js +23 -28
- package/dist/cjs/api/resources/events/types/DomainVerifiedEvent.d.ts +7 -0
- package/dist/cjs/api/resources/{webhooks → events}/types/EventType.d.ts +1 -0
- package/dist/cjs/api/resources/{webhooks → events}/types/EventType.js +1 -0
- package/dist/cjs/api/resources/events/types/EventTypes.d.ts +5 -0
- package/dist/cjs/api/resources/events/types/EventTypes.js +3 -0
- package/dist/cjs/api/resources/events/types/index.d.ts +3 -0
- package/dist/cjs/api/resources/events/types/index.js +3 -0
- package/dist/cjs/api/resources/inboxes/client/Client.d.ts +30 -30
- package/dist/cjs/api/resources/inboxes/client/Client.js +55 -51
- package/dist/cjs/api/resources/inboxes/resources/drafts/client/Client.d.ts +27 -27
- package/dist/cjs/api/resources/inboxes/resources/drafts/client/Client.js +77 -70
- package/dist/cjs/api/resources/inboxes/resources/messages/client/Client.d.ts +25 -25
- package/dist/cjs/api/resources/inboxes/resources/messages/client/Client.js +83 -73
- package/dist/cjs/api/resources/inboxes/resources/metrics/client/Client.d.ts +8 -8
- package/dist/cjs/api/resources/inboxes/resources/metrics/client/Client.js +17 -25
- package/dist/cjs/api/resources/inboxes/resources/threads/client/Client.d.ts +17 -17
- package/dist/cjs/api/resources/inboxes/resources/threads/client/Client.js +51 -50
- package/dist/cjs/api/resources/inboxes/types/Inbox.d.ts +1 -0
- package/dist/cjs/api/resources/messages/types/ReplyToMessageRequest.d.ts +1 -0
- package/dist/cjs/api/resources/messages/types/SendMessageHeaders.d.ts +4 -0
- package/dist/cjs/api/resources/messages/types/SendMessageHeaders.js +3 -0
- package/dist/cjs/api/resources/messages/types/SendMessageRequest.d.ts +1 -0
- package/dist/cjs/api/resources/messages/types/index.d.ts +1 -0
- package/dist/cjs/api/resources/messages/types/index.js +1 -0
- package/dist/cjs/api/resources/metrics/client/Client.d.ts +7 -7
- package/dist/cjs/api/resources/metrics/client/Client.js +12 -20
- package/dist/cjs/api/resources/pods/client/Client.d.ts +27 -27
- package/dist/cjs/api/resources/pods/client/Client.js +44 -43
- package/dist/cjs/api/resources/pods/resources/domains/client/Client.d.ts +15 -15
- package/dist/cjs/api/resources/pods/resources/domains/client/Client.js +41 -43
- package/dist/cjs/api/resources/pods/resources/drafts/client/Client.d.ts +12 -12
- package/dist/cjs/api/resources/pods/resources/drafts/client/Client.js +30 -35
- package/dist/cjs/api/resources/pods/resources/inboxes/client/Client.d.ts +19 -19
- package/dist/cjs/api/resources/pods/resources/inboxes/client/Client.js +53 -52
- package/dist/cjs/api/resources/pods/resources/threads/client/Client.d.ts +13 -13
- package/dist/cjs/api/resources/pods/resources/threads/client/Client.js +39 -41
- package/dist/cjs/api/resources/threads/client/Client.d.ts +11 -11
- package/dist/cjs/api/resources/threads/client/Client.js +32 -34
- package/dist/cjs/api/resources/webhooks/client/Client.d.ts +15 -15
- package/dist/cjs/api/resources/webhooks/client/Client.js +40 -39
- package/dist/cjs/api/resources/webhooks/types/CreateWebhookRequest.d.ts +1 -1
- package/dist/cjs/api/resources/webhooks/types/Webhook.d.ts +1 -1
- package/dist/cjs/api/resources/webhooks/types/index.d.ts +0 -2
- package/dist/cjs/api/resources/webhooks/types/index.js +0 -2
- package/dist/cjs/api/resources/websockets/client/Client.d.ts +6 -6
- package/dist/cjs/api/resources/websockets/client/Client.js +8 -19
- package/dist/cjs/api/resources/websockets/client/Socket.d.ts +1 -1
- package/dist/cjs/api/resources/websockets/types/Subscribe.d.ts +5 -1
- package/dist/cjs/api/resources/websockets/types/Subscribed.d.ts +5 -1
- package/dist/cjs/auth/BearerAuthProvider.d.ts +14 -0
- package/dist/cjs/auth/BearerAuthProvider.js +72 -0
- package/dist/cjs/auth/index.d.ts +1 -0
- package/dist/cjs/auth/index.js +5 -0
- package/dist/cjs/core/auth/AuthProvider.d.ts +4 -1
- package/dist/cjs/core/auth/BearerToken.d.ts +3 -1
- package/dist/cjs/core/auth/BearerToken.js +7 -6
- package/dist/cjs/core/auth/NoOpAuthProvider.d.ts +5 -0
- package/dist/cjs/core/auth/NoOpAuthProvider.js +9 -0
- package/dist/cjs/core/auth/index.d.ts +1 -0
- package/dist/cjs/core/auth/index.js +3 -1
- package/dist/cjs/core/exports.d.ts +1 -0
- package/dist/cjs/core/exports.js +1 -0
- package/dist/cjs/core/fetcher/Fetcher.d.ts +4 -1
- package/dist/cjs/core/fetcher/Fetcher.js +202 -9
- package/dist/cjs/core/fetcher/getRequestBody.d.ts +1 -1
- package/dist/cjs/core/fetcher/getRequestBody.js +4 -0
- package/dist/cjs/core/fetcher/makeRequest.d.ts +1 -1
- package/dist/cjs/core/fetcher/makeRequest.js +0 -2
- package/dist/cjs/core/fetcher/requestWithRetries.js +0 -9
- package/dist/cjs/core/fetcher/signals.d.ts +0 -6
- package/dist/cjs/core/fetcher/signals.js +0 -12
- package/dist/cjs/core/headers.js +6 -4
- package/dist/cjs/core/index.d.ts +1 -0
- package/dist/cjs/core/index.js +2 -1
- package/dist/cjs/core/logging/exports.d.ts +18 -0
- package/dist/cjs/core/logging/exports.js +45 -0
- package/dist/cjs/core/logging/index.d.ts +1 -0
- package/dist/cjs/core/logging/index.js +17 -0
- package/dist/cjs/core/logging/logger.d.ts +126 -0
- package/dist/cjs/core/logging/logger.js +144 -0
- package/dist/cjs/core/schemas/Schema.d.ts +1 -0
- package/dist/cjs/core/schemas/Schema.js +1 -0
- package/dist/cjs/core/schemas/builders/primitives/index.d.ts +1 -0
- package/dist/cjs/core/schemas/builders/primitives/index.js +3 -1
- package/dist/cjs/core/schemas/builders/primitives/never.d.ts +2 -0
- package/dist/cjs/core/schemas/builders/primitives/never.js +14 -0
- package/dist/cjs/core/url/join.js +0 -1
- package/dist/cjs/serialization/resources/domains/types/Domain.d.ts +2 -0
- package/dist/cjs/serialization/resources/domains/types/Domain.js +2 -0
- package/dist/cjs/serialization/resources/domains/types/DomainItem.d.ts +2 -0
- package/dist/cjs/serialization/resources/domains/types/DomainItem.js +2 -0
- package/dist/cjs/serialization/resources/events/types/DomainVerifiedEvent.d.ts +14 -0
- package/dist/cjs/serialization/resources/events/types/DomainVerifiedEvent.js +46 -0
- package/dist/cjs/serialization/resources/{webhooks → events}/types/EventType.d.ts +2 -2
- package/dist/cjs/serialization/resources/{webhooks → events}/types/EventType.js +1 -0
- package/dist/cjs/serialization/resources/{webhooks → events}/types/EventTypes.d.ts +1 -1
- package/dist/cjs/serialization/resources/events/types/index.d.ts +3 -0
- package/dist/cjs/serialization/resources/events/types/index.js +3 -0
- package/dist/cjs/serialization/resources/inboxes/types/Inbox.d.ts +2 -0
- package/dist/cjs/serialization/resources/inboxes/types/Inbox.js +2 -0
- package/dist/cjs/serialization/resources/messages/types/ReplyToMessageRequest.d.ts +2 -0
- package/dist/cjs/serialization/resources/messages/types/ReplyToMessageRequest.js +2 -0
- package/dist/cjs/serialization/resources/messages/types/SendMessageHeaders.d.ts +7 -0
- package/dist/cjs/serialization/resources/messages/types/SendMessageHeaders.js +39 -0
- package/dist/cjs/serialization/resources/messages/types/SendMessageRequest.d.ts +2 -0
- package/dist/cjs/serialization/resources/messages/types/SendMessageRequest.js +2 -0
- package/dist/cjs/serialization/resources/messages/types/index.d.ts +1 -0
- package/dist/cjs/serialization/resources/messages/types/index.js +1 -0
- package/dist/cjs/serialization/resources/webhooks/types/CreateWebhookRequest.d.ts +1 -1
- package/dist/cjs/serialization/resources/webhooks/types/CreateWebhookRequest.js +1 -1
- package/dist/cjs/serialization/resources/webhooks/types/Webhook.d.ts +1 -1
- package/dist/cjs/serialization/resources/webhooks/types/Webhook.js +1 -1
- package/dist/cjs/serialization/resources/webhooks/types/index.d.ts +0 -2
- package/dist/cjs/serialization/resources/webhooks/types/index.js +0 -2
- package/dist/cjs/serialization/resources/websockets/client/socket/WebsocketsSocketResponse.d.ts +3 -2
- package/dist/cjs/serialization/resources/websockets/client/socket/WebsocketsSocketResponse.js +2 -0
- package/dist/cjs/serialization/resources/websockets/types/Subscribe.d.ts +4 -1
- package/dist/cjs/serialization/resources/websockets/types/Subscribe.js +4 -1
- package/dist/cjs/serialization/resources/websockets/types/Subscribed.d.ts +4 -1
- package/dist/cjs/serialization/resources/websockets/types/Subscribed.js +4 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/BaseClient.d.mts +14 -1
- package/dist/esm/BaseClient.mjs +24 -1
- package/dist/esm/Client.d.mts +30 -29
- package/dist/esm/Client.mjs +21 -29
- package/dist/esm/api/resources/apiKeys/client/Client.d.mts +12 -12
- package/dist/esm/api/resources/apiKeys/client/Client.mjs +28 -30
- package/dist/esm/api/resources/domains/client/Client.d.mts +19 -19
- package/dist/esm/api/resources/domains/client/Client.mjs +59 -52
- package/dist/esm/api/resources/domains/types/Domain.d.mts +1 -0
- package/dist/esm/api/resources/domains/types/DomainItem.d.mts +1 -0
- package/dist/esm/api/resources/drafts/client/Client.d.mts +10 -10
- package/dist/esm/api/resources/drafts/client/Client.mjs +22 -27
- package/dist/esm/api/resources/events/types/DomainVerifiedEvent.d.mts +7 -0
- package/dist/esm/api/resources/{webhooks → events}/types/EventType.d.mts +1 -0
- package/dist/esm/api/resources/{webhooks → events}/types/EventType.mjs +1 -0
- package/dist/esm/api/resources/events/types/EventTypes.d.mts +5 -0
- package/dist/esm/api/resources/events/types/EventTypes.mjs +2 -0
- package/dist/esm/api/resources/events/types/index.d.mts +3 -0
- package/dist/esm/api/resources/events/types/index.mjs +3 -0
- package/dist/esm/api/resources/inboxes/client/Client.d.mts +30 -30
- package/dist/esm/api/resources/inboxes/client/Client.mjs +58 -54
- package/dist/esm/api/resources/inboxes/resources/drafts/client/Client.d.mts +27 -27
- package/dist/esm/api/resources/inboxes/resources/drafts/client/Client.mjs +76 -69
- package/dist/esm/api/resources/inboxes/resources/messages/client/Client.d.mts +25 -25
- package/dist/esm/api/resources/inboxes/resources/messages/client/Client.mjs +82 -72
- package/dist/esm/api/resources/inboxes/resources/metrics/client/Client.d.mts +8 -8
- package/dist/esm/api/resources/inboxes/resources/metrics/client/Client.mjs +16 -24
- package/dist/esm/api/resources/inboxes/resources/threads/client/Client.d.mts +17 -17
- package/dist/esm/api/resources/inboxes/resources/threads/client/Client.mjs +50 -49
- package/dist/esm/api/resources/inboxes/types/Inbox.d.mts +1 -0
- package/dist/esm/api/resources/messages/types/ReplyToMessageRequest.d.mts +1 -0
- package/dist/esm/api/resources/messages/types/SendMessageHeaders.d.mts +4 -0
- package/dist/esm/api/resources/messages/types/SendMessageHeaders.mjs +2 -0
- package/dist/esm/api/resources/messages/types/SendMessageRequest.d.mts +1 -0
- package/dist/esm/api/resources/messages/types/index.d.mts +1 -0
- package/dist/esm/api/resources/messages/types/index.mjs +1 -0
- package/dist/esm/api/resources/metrics/client/Client.d.mts +7 -7
- package/dist/esm/api/resources/metrics/client/Client.mjs +11 -19
- package/dist/esm/api/resources/pods/client/Client.d.mts +27 -27
- package/dist/esm/api/resources/pods/client/Client.mjs +47 -46
- package/dist/esm/api/resources/pods/resources/domains/client/Client.d.mts +15 -15
- package/dist/esm/api/resources/pods/resources/domains/client/Client.mjs +40 -42
- package/dist/esm/api/resources/pods/resources/drafts/client/Client.d.mts +12 -12
- package/dist/esm/api/resources/pods/resources/drafts/client/Client.mjs +29 -34
- package/dist/esm/api/resources/pods/resources/inboxes/client/Client.d.mts +19 -19
- package/dist/esm/api/resources/pods/resources/inboxes/client/Client.mjs +52 -51
- package/dist/esm/api/resources/pods/resources/threads/client/Client.d.mts +13 -13
- package/dist/esm/api/resources/pods/resources/threads/client/Client.mjs +38 -40
- package/dist/esm/api/resources/threads/client/Client.d.mts +11 -11
- package/dist/esm/api/resources/threads/client/Client.mjs +31 -33
- package/dist/esm/api/resources/webhooks/client/Client.d.mts +15 -15
- package/dist/esm/api/resources/webhooks/client/Client.mjs +39 -38
- package/dist/esm/api/resources/webhooks/types/CreateWebhookRequest.d.mts +1 -1
- package/dist/esm/api/resources/webhooks/types/Webhook.d.mts +1 -1
- package/dist/esm/api/resources/webhooks/types/index.d.mts +0 -2
- package/dist/esm/api/resources/webhooks/types/index.mjs +0 -2
- package/dist/esm/api/resources/websockets/client/Client.d.mts +6 -6
- package/dist/esm/api/resources/websockets/client/Client.mjs +7 -18
- package/dist/esm/api/resources/websockets/client/Socket.d.mts +1 -1
- package/dist/esm/api/resources/websockets/types/Subscribe.d.mts +5 -1
- package/dist/esm/api/resources/websockets/types/Subscribed.d.mts +5 -1
- package/dist/esm/auth/BearerAuthProvider.d.mts +14 -0
- package/dist/esm/auth/BearerAuthProvider.mjs +35 -0
- package/dist/esm/auth/index.d.mts +1 -0
- package/dist/esm/auth/index.mjs +1 -0
- package/dist/esm/core/auth/AuthProvider.d.mts +4 -1
- package/dist/esm/core/auth/BearerToken.d.mts +3 -1
- package/dist/esm/core/auth/BearerToken.mjs +7 -6
- package/dist/esm/core/auth/NoOpAuthProvider.d.mts +5 -0
- package/dist/esm/core/auth/NoOpAuthProvider.mjs +5 -0
- package/dist/esm/core/auth/index.d.mts +1 -0
- package/dist/esm/core/auth/index.mjs +1 -0
- package/dist/esm/core/exports.d.mts +1 -0
- package/dist/esm/core/exports.mjs +1 -0
- package/dist/esm/core/fetcher/Fetcher.d.mts +4 -1
- package/dist/esm/core/fetcher/Fetcher.mjs +202 -9
- package/dist/esm/core/fetcher/getRequestBody.d.mts +1 -1
- package/dist/esm/core/fetcher/getRequestBody.mjs +4 -0
- package/dist/esm/core/fetcher/makeRequest.d.mts +1 -1
- package/dist/esm/core/fetcher/makeRequest.mjs +0 -2
- package/dist/esm/core/fetcher/requestWithRetries.mjs +0 -9
- package/dist/esm/core/fetcher/signals.d.mts +0 -6
- package/dist/esm/core/fetcher/signals.mjs +0 -12
- package/dist/esm/core/headers.mjs +6 -4
- package/dist/esm/core/index.d.mts +1 -0
- package/dist/esm/core/index.mjs +1 -0
- package/dist/esm/core/logging/exports.d.mts +18 -0
- package/dist/esm/core/logging/exports.mjs +9 -0
- package/dist/esm/core/logging/index.d.mts +1 -0
- package/dist/esm/core/logging/index.mjs +1 -0
- package/dist/esm/core/logging/logger.d.mts +126 -0
- package/dist/esm/core/logging/logger.mjs +138 -0
- package/dist/esm/core/schemas/Schema.d.mts +1 -0
- package/dist/esm/core/schemas/Schema.mjs +1 -0
- package/dist/esm/core/schemas/builders/primitives/index.d.mts +1 -0
- package/dist/esm/core/schemas/builders/primitives/index.mjs +1 -0
- package/dist/esm/core/schemas/builders/primitives/never.d.mts +2 -0
- package/dist/esm/core/schemas/builders/primitives/never.mjs +11 -0
- package/dist/esm/core/url/join.mjs +0 -1
- package/dist/esm/serialization/resources/domains/types/Domain.d.mts +2 -0
- package/dist/esm/serialization/resources/domains/types/Domain.mjs +2 -0
- package/dist/esm/serialization/resources/domains/types/DomainItem.d.mts +2 -0
- package/dist/esm/serialization/resources/domains/types/DomainItem.mjs +2 -0
- package/dist/esm/serialization/resources/events/types/DomainVerifiedEvent.d.mts +14 -0
- package/dist/esm/serialization/resources/events/types/DomainVerifiedEvent.mjs +10 -0
- package/dist/esm/serialization/resources/{webhooks → events}/types/EventType.d.mts +2 -2
- package/dist/esm/serialization/resources/{webhooks → events}/types/EventType.mjs +1 -0
- package/dist/esm/serialization/resources/{webhooks → events}/types/EventTypes.d.mts +1 -1
- package/dist/esm/serialization/resources/events/types/index.d.mts +3 -0
- package/dist/esm/serialization/resources/events/types/index.mjs +3 -0
- package/dist/esm/serialization/resources/inboxes/types/Inbox.d.mts +2 -0
- package/dist/esm/serialization/resources/inboxes/types/Inbox.mjs +2 -0
- package/dist/esm/serialization/resources/messages/types/ReplyToMessageRequest.d.mts +2 -0
- package/dist/esm/serialization/resources/messages/types/ReplyToMessageRequest.mjs +2 -0
- package/dist/esm/serialization/resources/messages/types/SendMessageHeaders.d.mts +7 -0
- package/dist/esm/serialization/resources/messages/types/SendMessageHeaders.mjs +3 -0
- package/dist/esm/serialization/resources/messages/types/SendMessageRequest.d.mts +2 -0
- package/dist/esm/serialization/resources/messages/types/SendMessageRequest.mjs +2 -0
- package/dist/esm/serialization/resources/messages/types/index.d.mts +1 -0
- package/dist/esm/serialization/resources/messages/types/index.mjs +1 -0
- package/dist/esm/serialization/resources/webhooks/types/CreateWebhookRequest.d.mts +1 -1
- package/dist/esm/serialization/resources/webhooks/types/CreateWebhookRequest.mjs +1 -1
- package/dist/esm/serialization/resources/webhooks/types/Webhook.d.mts +1 -1
- package/dist/esm/serialization/resources/webhooks/types/Webhook.mjs +1 -1
- package/dist/esm/serialization/resources/webhooks/types/index.d.mts +0 -2
- package/dist/esm/serialization/resources/webhooks/types/index.mjs +0 -2
- package/dist/esm/serialization/resources/websockets/client/socket/WebsocketsSocketResponse.d.mts +3 -2
- package/dist/esm/serialization/resources/websockets/client/socket/WebsocketsSocketResponse.mjs +2 -0
- package/dist/esm/serialization/resources/websockets/types/Subscribe.d.mts +4 -1
- package/dist/esm/serialization/resources/websockets/types/Subscribe.mjs +4 -1
- package/dist/esm/serialization/resources/websockets/types/Subscribed.d.mts +4 -1
- package/dist/esm/serialization/resources/websockets/types/Subscribed.mjs +4 -1
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/dist/llms-full.txt +1241 -123
- package/dist/llms.txt +7 -1
- package/package.json +1 -1
- package/reference.md +170 -170
- package/dist/cjs/api/resources/webhooks/types/EventTypes.d.ts +0 -5
- package/dist/esm/api/resources/webhooks/types/EventTypes.d.mts +0 -5
- /package/dist/cjs/api/resources/{webhooks/types/EventTypes.js → events/types/DomainVerifiedEvent.js} +0 -0
- /package/dist/cjs/serialization/resources/{webhooks → events}/types/EventTypes.js +0 -0
- /package/dist/esm/api/resources/{webhooks/types/EventTypes.mjs → events/types/DomainVerifiedEvent.mjs} +0 -0
- /package/dist/esm/serialization/resources/{webhooks → events}/types/EventTypes.mjs +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type * as AgentMail from "../../../index.mjs";
|
|
2
2
|
export interface CreateWebhookRequest {
|
|
3
3
|
url: AgentMail.webhooks.Url;
|
|
4
|
-
eventTypes: AgentMail.
|
|
4
|
+
eventTypes: AgentMail.EventTypes;
|
|
5
5
|
inboxIds?: AgentMail.webhooks.InboxIds;
|
|
6
6
|
clientId?: AgentMail.webhooks.ClientId;
|
|
7
7
|
}
|
|
@@ -2,7 +2,7 @@ import type * as AgentMail from "../../../index.mjs";
|
|
|
2
2
|
export interface Webhook {
|
|
3
3
|
webhookId: AgentMail.webhooks.WebhookId;
|
|
4
4
|
url: AgentMail.webhooks.Url;
|
|
5
|
-
eventTypes?: AgentMail.
|
|
5
|
+
eventTypes?: AgentMail.EventTypes;
|
|
6
6
|
inboxIds?: AgentMail.webhooks.InboxIds;
|
|
7
7
|
/** Secret for webhook signature verification. */
|
|
8
8
|
secret: string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { BaseClientOptions } from "../../../../BaseClient.mjs";
|
|
2
|
+
import { type NormalizedClientOptionsWithAuth } from "../../../../BaseClient.mjs";
|
|
2
3
|
import { WebsocketsSocket } from "./Socket.mjs";
|
|
3
|
-
export declare namespace
|
|
4
|
+
export declare namespace WebsocketsClient {
|
|
4
5
|
interface Options extends BaseClientOptions {
|
|
5
6
|
}
|
|
6
7
|
interface ConnectArgs {
|
|
@@ -13,9 +14,8 @@ export declare namespace Websockets {
|
|
|
13
14
|
reconnectAttempts?: number;
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
|
-
export declare class
|
|
17
|
-
protected readonly _options:
|
|
18
|
-
constructor(
|
|
19
|
-
connect(args?:
|
|
20
|
-
protected _getAuthorizationHeader(): Promise<string>;
|
|
17
|
+
export declare class WebsocketsClient {
|
|
18
|
+
protected readonly _options: NormalizedClientOptionsWithAuth<WebsocketsClient.Options>;
|
|
19
|
+
constructor(options?: WebsocketsClient.Options);
|
|
20
|
+
connect(args?: WebsocketsClient.ConnectArgs): Promise<WebsocketsSocket>;
|
|
21
21
|
}
|
|
@@ -8,14 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
import {
|
|
11
|
+
import { normalizeClientOptionsWithAuth } from "../../../../BaseClient.mjs";
|
|
12
|
+
import { mergeHeaders } from "../../../../core/headers.mjs";
|
|
12
13
|
import * as core from "../../../../core/index.mjs";
|
|
13
14
|
import * as environments from "../../../../environments.mjs";
|
|
14
|
-
import * as errors from "../../../../errors/index.mjs";
|
|
15
15
|
import { WebsocketsSocket } from "./Socket.mjs";
|
|
16
|
-
export class
|
|
17
|
-
constructor(
|
|
18
|
-
this._options =
|
|
16
|
+
export class WebsocketsClient {
|
|
17
|
+
constructor(options = {}) {
|
|
18
|
+
this._options = normalizeClientOptionsWithAuth(options);
|
|
19
19
|
}
|
|
20
20
|
connect() {
|
|
21
21
|
return __awaiter(this, arguments, void 0, function* (args = {}) {
|
|
@@ -25,7 +25,8 @@ export class Websockets {
|
|
|
25
25
|
if (authToken != null) {
|
|
26
26
|
_queryParams.auth_token = authToken;
|
|
27
27
|
}
|
|
28
|
-
const
|
|
28
|
+
const _authRequest = yield this._options.authProvider.getAuthRequest();
|
|
29
|
+
const _headers = mergeHeaders(_authRequest.headers, headers);
|
|
29
30
|
const socket = new core.ReconnectingWebSocket({
|
|
30
31
|
url: 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.Production).websockets, "/v0"),
|
|
31
32
|
protocols: [],
|
|
@@ -36,16 +37,4 @@ export class Websockets {
|
|
|
36
37
|
return new WebsocketsSocket({ socket });
|
|
37
38
|
});
|
|
38
39
|
}
|
|
39
|
-
_getAuthorizationHeader() {
|
|
40
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
var _a;
|
|
42
|
-
const bearer = (_a = (yield core.Supplier.get(this._options.apiKey))) !== null && _a !== void 0 ? _a : process === null || process === void 0 ? void 0 : process.env.AGENTMAIL_API_KEY;
|
|
43
|
-
if (bearer == null) {
|
|
44
|
-
throw new errors.AgentMailError({
|
|
45
|
-
message: "Please specify a bearer by either passing it in to the constructor or initializing a AGENTMAIL_API_KEY environment variable",
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
return `Bearer ${bearer}`;
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
40
|
}
|
|
@@ -4,7 +4,7 @@ export declare namespace WebsocketsSocket {
|
|
|
4
4
|
interface Args {
|
|
5
5
|
socket: core.ReconnectingWebSocket;
|
|
6
6
|
}
|
|
7
|
-
type Response = AgentMail.Subscribed | AgentMail.MessageReceivedEvent | AgentMail.MessageSentEvent | AgentMail.MessageDeliveredEvent | AgentMail.MessageBouncedEvent | AgentMail.MessageComplainedEvent | AgentMail.MessageRejectedEvent;
|
|
7
|
+
type Response = AgentMail.Subscribed | AgentMail.MessageReceivedEvent | AgentMail.MessageSentEvent | AgentMail.MessageDeliveredEvent | AgentMail.MessageBouncedEvent | AgentMail.MessageComplainedEvent | AgentMail.MessageRejectedEvent | AgentMail.DomainVerifiedEvent;
|
|
8
8
|
type EventHandlers = {
|
|
9
9
|
open?: () => void;
|
|
10
10
|
message?: (message: Response) => void;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import type * as AgentMail from "../../../index.mjs";
|
|
1
2
|
export interface Subscribe {
|
|
2
3
|
type: "subscribe";
|
|
4
|
+
eventTypes?: AgentMail.EventTypes;
|
|
3
5
|
/** IDs of the inboxes to subscribe to. */
|
|
4
|
-
inboxIds
|
|
6
|
+
inboxIds?: string[];
|
|
7
|
+
/** IDs of the pods to subscribe to. */
|
|
8
|
+
podIds?: string[];
|
|
5
9
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import type * as AgentMail from "../../../index.mjs";
|
|
1
2
|
export interface Subscribed {
|
|
2
3
|
type: "subscribed";
|
|
4
|
+
eventTypes?: AgentMail.EventTypes;
|
|
3
5
|
/** IDs of the inboxes that have been subscribed to. */
|
|
4
|
-
inboxIds
|
|
6
|
+
inboxIds?: string[];
|
|
7
|
+
/** IDs of the pods that have been subscribed to. */
|
|
8
|
+
podIds?: string[];
|
|
5
9
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as core from "../core/index.mjs";
|
|
2
|
+
export declare namespace BearerAuthProvider {
|
|
3
|
+
interface Options {
|
|
4
|
+
apiKey?: core.Supplier<core.BearerToken | undefined>;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export declare class BearerAuthProvider implements core.AuthProvider {
|
|
8
|
+
private readonly token;
|
|
9
|
+
constructor(options: BearerAuthProvider.Options);
|
|
10
|
+
static canCreate(options: BearerAuthProvider.Options): boolean;
|
|
11
|
+
getAuthRequest(_arg?: {
|
|
12
|
+
endpointMetadata?: core.EndpointMetadata;
|
|
13
|
+
}): Promise<core.AuthRequest>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// This file was auto-generated by Fern from our API Definition.
|
|
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
|
+
import * as core from "../core/index.mjs";
|
|
12
|
+
import * as errors from "../errors/index.mjs";
|
|
13
|
+
export class BearerAuthProvider {
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.token = options.apiKey;
|
|
16
|
+
}
|
|
17
|
+
static canCreate(options) {
|
|
18
|
+
var _a;
|
|
19
|
+
return options.apiKey != null || ((_a = process.env) === null || _a === void 0 ? void 0 : _a.AGENTMAIL_API_KEY) != null;
|
|
20
|
+
}
|
|
21
|
+
getAuthRequest(_arg) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
const apiKey = (_a = (yield core.Supplier.get(this.token))) !== null && _a !== void 0 ? _a : (_b = process.env) === null || _b === void 0 ? void 0 : _b.AGENTMAIL_API_KEY;
|
|
25
|
+
if (apiKey == null) {
|
|
26
|
+
throw new errors.AgentMailError({
|
|
27
|
+
message: "Please specify a apiKey by either passing it in to the constructor or initializing a AGENTMAIL_API_KEY environment variable",
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
headers: { Authorization: `Bearer ${apiKey}` },
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BearerAuthProvider } from "./BearerAuthProvider.mjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BearerAuthProvider } from "./BearerAuthProvider.mjs";
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import type { EndpointMetadata } from "../fetcher/EndpointMetadata.mjs";
|
|
1
2
|
import type { AuthRequest } from "./AuthRequest.mjs";
|
|
2
3
|
export interface AuthProvider {
|
|
3
|
-
getAuthRequest(
|
|
4
|
+
getAuthRequest(arg?: {
|
|
5
|
+
endpointMetadata?: EndpointMetadata;
|
|
6
|
+
}): Promise<AuthRequest>;
|
|
4
7
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export type BearerToken = string;
|
|
2
|
+
declare function toAuthorizationHeader(token: string | undefined): string | undefined;
|
|
2
3
|
export declare const BearerToken: {
|
|
3
|
-
toAuthorizationHeader:
|
|
4
|
+
toAuthorizationHeader: typeof toAuthorizationHeader;
|
|
4
5
|
fromAuthorizationHeader: (header: string) => BearerToken;
|
|
5
6
|
};
|
|
7
|
+
export {};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
const BEARER_AUTH_HEADER_PREFIX = /^Bearer /i;
|
|
2
|
+
function toAuthorizationHeader(token) {
|
|
3
|
+
if (token == null) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
return `Bearer ${token}`;
|
|
7
|
+
}
|
|
2
8
|
export const BearerToken = {
|
|
3
|
-
toAuthorizationHeader:
|
|
4
|
-
if (token == null) {
|
|
5
|
-
return undefined;
|
|
6
|
-
}
|
|
7
|
-
return `Bearer ${token}`;
|
|
8
|
-
},
|
|
9
|
+
toAuthorizationHeader: toAuthorizationHeader,
|
|
9
10
|
fromAuthorizationHeader: (header) => {
|
|
10
11
|
return header.replace(BEARER_AUTH_HEADER_PREFIX, "").trim();
|
|
11
12
|
},
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type LogConfig, type Logger } from "../logging/logger.mjs";
|
|
1
2
|
import type { APIResponse } from "./APIResponse.mjs";
|
|
2
3
|
import type { EndpointMetadata } from "./EndpointMetadata.mjs";
|
|
3
4
|
import { EndpointSupplier } from "./EndpointSupplier.mjs";
|
|
@@ -14,10 +15,12 @@ export declare namespace Fetcher {
|
|
|
14
15
|
maxRetries?: number;
|
|
15
16
|
withCredentials?: boolean;
|
|
16
17
|
abortSignal?: AbortSignal;
|
|
17
|
-
requestType?: "json" | "file" | "bytes";
|
|
18
|
+
requestType?: "json" | "file" | "bytes" | "form" | "other";
|
|
18
19
|
responseType?: "json" | "blob" | "sse" | "streaming" | "text" | "arrayBuffer" | "binary-response";
|
|
19
20
|
duplex?: "half";
|
|
20
21
|
endpointMetadata?: EndpointMetadata;
|
|
22
|
+
fetchFn?: typeof fetch;
|
|
23
|
+
logging?: LogConfig | Logger;
|
|
21
24
|
}
|
|
22
25
|
type Error = FailedStatusCodeError | NonJsonError | TimeoutError | UnknownError;
|
|
23
26
|
interface FailedStatusCodeError {
|
|
@@ -8,21 +8,153 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { toJson } from "../json.mjs";
|
|
11
|
+
import { createLogger } from "../logging/logger.mjs";
|
|
11
12
|
import { createRequestUrl } from "./createRequestUrl.mjs";
|
|
12
13
|
import { EndpointSupplier } from "./EndpointSupplier.mjs";
|
|
13
14
|
import { getErrorResponseBody } from "./getErrorResponseBody.mjs";
|
|
14
15
|
import { getFetchFn } from "./getFetchFn.mjs";
|
|
15
16
|
import { getRequestBody } from "./getRequestBody.mjs";
|
|
16
17
|
import { getResponseBody } from "./getResponseBody.mjs";
|
|
18
|
+
import { Headers } from "./Headers.mjs";
|
|
17
19
|
import { makeRequest } from "./makeRequest.mjs";
|
|
18
20
|
import { abortRawResponse, toRawResponse, unknownRawResponse } from "./RawResponse.mjs";
|
|
19
21
|
import { requestWithRetries } from "./requestWithRetries.mjs";
|
|
22
|
+
const SENSITIVE_HEADERS = new Set([
|
|
23
|
+
"authorization",
|
|
24
|
+
"www-authenticate",
|
|
25
|
+
"x-api-key",
|
|
26
|
+
"api-key",
|
|
27
|
+
"apikey",
|
|
28
|
+
"x-api-token",
|
|
29
|
+
"x-auth-token",
|
|
30
|
+
"auth-token",
|
|
31
|
+
"cookie",
|
|
32
|
+
"set-cookie",
|
|
33
|
+
"proxy-authorization",
|
|
34
|
+
"proxy-authenticate",
|
|
35
|
+
"x-csrf-token",
|
|
36
|
+
"x-xsrf-token",
|
|
37
|
+
"x-session-token",
|
|
38
|
+
"x-access-token",
|
|
39
|
+
]);
|
|
40
|
+
function redactHeaders(headers) {
|
|
41
|
+
const filtered = {};
|
|
42
|
+
for (const [key, value] of headers instanceof Headers ? headers.entries() : Object.entries(headers)) {
|
|
43
|
+
if (SENSITIVE_HEADERS.has(key.toLowerCase())) {
|
|
44
|
+
filtered[key] = "[REDACTED]";
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
filtered[key] = value;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return filtered;
|
|
51
|
+
}
|
|
52
|
+
const SENSITIVE_QUERY_PARAMS = new Set([
|
|
53
|
+
"api_key",
|
|
54
|
+
"api-key",
|
|
55
|
+
"apikey",
|
|
56
|
+
"token",
|
|
57
|
+
"access_token",
|
|
58
|
+
"access-token",
|
|
59
|
+
"auth_token",
|
|
60
|
+
"auth-token",
|
|
61
|
+
"password",
|
|
62
|
+
"passwd",
|
|
63
|
+
"secret",
|
|
64
|
+
"api_secret",
|
|
65
|
+
"api-secret",
|
|
66
|
+
"apisecret",
|
|
67
|
+
"key",
|
|
68
|
+
"session",
|
|
69
|
+
"session_id",
|
|
70
|
+
"session-id",
|
|
71
|
+
]);
|
|
72
|
+
function redactQueryParameters(queryParameters) {
|
|
73
|
+
if (queryParameters == null) {
|
|
74
|
+
return queryParameters;
|
|
75
|
+
}
|
|
76
|
+
const redacted = {};
|
|
77
|
+
for (const [key, value] of Object.entries(queryParameters)) {
|
|
78
|
+
if (SENSITIVE_QUERY_PARAMS.has(key.toLowerCase())) {
|
|
79
|
+
redacted[key] = "[REDACTED]";
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
redacted[key] = value;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return redacted;
|
|
86
|
+
}
|
|
87
|
+
function redactUrl(url) {
|
|
88
|
+
const protocolIndex = url.indexOf("://");
|
|
89
|
+
if (protocolIndex === -1)
|
|
90
|
+
return url;
|
|
91
|
+
const afterProtocol = protocolIndex + 3;
|
|
92
|
+
// Find the first delimiter that marks the end of the authority section
|
|
93
|
+
const pathStart = url.indexOf("/", afterProtocol);
|
|
94
|
+
let queryStart = url.indexOf("?", afterProtocol);
|
|
95
|
+
let fragmentStart = url.indexOf("#", afterProtocol);
|
|
96
|
+
const firstDelimiter = Math.min(pathStart === -1 ? url.length : pathStart, queryStart === -1 ? url.length : queryStart, fragmentStart === -1 ? url.length : fragmentStart);
|
|
97
|
+
// Find the LAST @ before the delimiter (handles multiple @ in credentials)
|
|
98
|
+
let atIndex = -1;
|
|
99
|
+
for (let i = afterProtocol; i < firstDelimiter; i++) {
|
|
100
|
+
if (url[i] === "@") {
|
|
101
|
+
atIndex = i;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (atIndex !== -1) {
|
|
105
|
+
url = `${url.slice(0, afterProtocol)}[REDACTED]@${url.slice(atIndex + 1)}`;
|
|
106
|
+
}
|
|
107
|
+
// Recalculate queryStart since url might have changed
|
|
108
|
+
queryStart = url.indexOf("?");
|
|
109
|
+
if (queryStart === -1)
|
|
110
|
+
return url;
|
|
111
|
+
fragmentStart = url.indexOf("#", queryStart);
|
|
112
|
+
const queryEnd = fragmentStart !== -1 ? fragmentStart : url.length;
|
|
113
|
+
const queryString = url.slice(queryStart + 1, queryEnd);
|
|
114
|
+
if (queryString.length === 0)
|
|
115
|
+
return url;
|
|
116
|
+
// FAST PATH: Quick check if any sensitive keywords present
|
|
117
|
+
// Using indexOf is faster than regex for simple substring matching
|
|
118
|
+
const lower = queryString.toLowerCase();
|
|
119
|
+
const hasSensitive = lower.includes("token") ||
|
|
120
|
+
lower.includes("key") ||
|
|
121
|
+
lower.includes("password") ||
|
|
122
|
+
lower.includes("passwd") ||
|
|
123
|
+
lower.includes("secret") ||
|
|
124
|
+
lower.includes("session") ||
|
|
125
|
+
lower.includes("auth");
|
|
126
|
+
if (!hasSensitive) {
|
|
127
|
+
return url;
|
|
128
|
+
}
|
|
129
|
+
// SLOW PATH: Parse and redact
|
|
130
|
+
const redactedParams = [];
|
|
131
|
+
const params = queryString.split("&");
|
|
132
|
+
for (const param of params) {
|
|
133
|
+
const equalIndex = param.indexOf("=");
|
|
134
|
+
if (equalIndex === -1) {
|
|
135
|
+
redactedParams.push(param);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const key = param.slice(0, equalIndex);
|
|
139
|
+
let shouldRedact = SENSITIVE_QUERY_PARAMS.has(key.toLowerCase());
|
|
140
|
+
if (!shouldRedact && key.includes("%")) {
|
|
141
|
+
try {
|
|
142
|
+
const decodedKey = decodeURIComponent(key);
|
|
143
|
+
shouldRedact = SENSITIVE_QUERY_PARAMS.has(decodedKey.toLowerCase());
|
|
144
|
+
}
|
|
145
|
+
catch (_a) { }
|
|
146
|
+
}
|
|
147
|
+
redactedParams.push(shouldRedact ? `${key}=[REDACTED]` : param);
|
|
148
|
+
}
|
|
149
|
+
return url.slice(0, queryStart + 1) + redactedParams.join("&") + url.slice(queryEnd);
|
|
150
|
+
}
|
|
20
151
|
function getHeaders(args) {
|
|
21
152
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
153
|
var _a;
|
|
23
|
-
const newHeaders =
|
|
154
|
+
const newHeaders = new Headers();
|
|
155
|
+
newHeaders.set("Accept", args.responseType === "json" ? "application/json" : args.responseType === "text" ? "text/plain" : "*/*");
|
|
24
156
|
if (args.body !== undefined && args.contentType != null) {
|
|
25
|
-
newHeaders
|
|
157
|
+
newHeaders.set("Content-Type", args.contentType);
|
|
26
158
|
}
|
|
27
159
|
if (args.headers == null) {
|
|
28
160
|
return newHeaders;
|
|
@@ -30,31 +162,52 @@ function getHeaders(args) {
|
|
|
30
162
|
for (const [key, value] of Object.entries(args.headers)) {
|
|
31
163
|
const result = yield EndpointSupplier.get(value, { endpointMetadata: (_a = args.endpointMetadata) !== null && _a !== void 0 ? _a : {} });
|
|
32
164
|
if (typeof result === "string") {
|
|
33
|
-
newHeaders
|
|
165
|
+
newHeaders.set(key, result);
|
|
34
166
|
continue;
|
|
35
167
|
}
|
|
36
168
|
if (result == null) {
|
|
37
169
|
continue;
|
|
38
170
|
}
|
|
39
|
-
newHeaders
|
|
171
|
+
newHeaders.set(key, `${result}`);
|
|
40
172
|
}
|
|
41
173
|
return newHeaders;
|
|
42
174
|
});
|
|
43
175
|
}
|
|
44
176
|
export function fetcherImpl(args) {
|
|
45
177
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
var _a;
|
|
178
|
+
var _a, _b, _c;
|
|
47
179
|
const url = createRequestUrl(args.url, args.queryParameters);
|
|
48
180
|
const requestBody = yield getRequestBody({
|
|
49
181
|
body: args.body,
|
|
50
|
-
type: args.requestType
|
|
182
|
+
type: (_a = args.requestType) !== null && _a !== void 0 ? _a : "other",
|
|
51
183
|
});
|
|
52
|
-
const fetchFn = yield getFetchFn();
|
|
184
|
+
const fetchFn = (_b = args.fetchFn) !== null && _b !== void 0 ? _b : (yield getFetchFn());
|
|
185
|
+
const headers = yield getHeaders(args);
|
|
186
|
+
const logger = createLogger(args.logging);
|
|
187
|
+
if (logger.isDebug()) {
|
|
188
|
+
const metadata = {
|
|
189
|
+
method: args.method,
|
|
190
|
+
url: redactUrl(url),
|
|
191
|
+
headers: redactHeaders(headers),
|
|
192
|
+
queryParameters: redactQueryParameters(args.queryParameters),
|
|
193
|
+
hasBody: requestBody != null,
|
|
194
|
+
};
|
|
195
|
+
logger.debug("Making HTTP request", metadata);
|
|
196
|
+
}
|
|
53
197
|
try {
|
|
54
198
|
const response = yield requestWithRetries(() => __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
return makeRequest(fetchFn, url, args.method,
|
|
199
|
+
return makeRequest(fetchFn, url, args.method, headers, requestBody, args.timeoutMs, args.abortSignal, args.withCredentials, args.duplex);
|
|
56
200
|
}), args.maxRetries);
|
|
57
201
|
if (response.status >= 200 && response.status < 400) {
|
|
202
|
+
if (logger.isDebug()) {
|
|
203
|
+
const metadata = {
|
|
204
|
+
method: args.method,
|
|
205
|
+
url: redactUrl(url),
|
|
206
|
+
statusCode: response.status,
|
|
207
|
+
responseHeaders: redactHeaders(response.headers),
|
|
208
|
+
};
|
|
209
|
+
logger.debug("HTTP request succeeded", metadata);
|
|
210
|
+
}
|
|
58
211
|
return {
|
|
59
212
|
ok: true,
|
|
60
213
|
body: (yield getResponseBody(response, args.responseType)),
|
|
@@ -63,6 +216,15 @@ export function fetcherImpl(args) {
|
|
|
63
216
|
};
|
|
64
217
|
}
|
|
65
218
|
else {
|
|
219
|
+
if (logger.isError()) {
|
|
220
|
+
const metadata = {
|
|
221
|
+
method: args.method,
|
|
222
|
+
url: redactUrl(url),
|
|
223
|
+
statusCode: response.status,
|
|
224
|
+
responseHeaders: redactHeaders(Object.fromEntries(response.headers.entries())),
|
|
225
|
+
};
|
|
226
|
+
logger.error("HTTP request failed with error status", metadata);
|
|
227
|
+
}
|
|
66
228
|
return {
|
|
67
229
|
ok: false,
|
|
68
230
|
error: {
|
|
@@ -75,7 +237,14 @@ export function fetcherImpl(args) {
|
|
|
75
237
|
}
|
|
76
238
|
}
|
|
77
239
|
catch (error) {
|
|
78
|
-
if ((
|
|
240
|
+
if ((_c = args.abortSignal) === null || _c === void 0 ? void 0 : _c.aborted) {
|
|
241
|
+
if (logger.isError()) {
|
|
242
|
+
const metadata = {
|
|
243
|
+
method: args.method,
|
|
244
|
+
url: redactUrl(url),
|
|
245
|
+
};
|
|
246
|
+
logger.error("HTTP request was aborted", metadata);
|
|
247
|
+
}
|
|
79
248
|
return {
|
|
80
249
|
ok: false,
|
|
81
250
|
error: {
|
|
@@ -86,6 +255,14 @@ export function fetcherImpl(args) {
|
|
|
86
255
|
};
|
|
87
256
|
}
|
|
88
257
|
else if (error instanceof Error && error.name === "AbortError") {
|
|
258
|
+
if (logger.isError()) {
|
|
259
|
+
const metadata = {
|
|
260
|
+
method: args.method,
|
|
261
|
+
url: redactUrl(url),
|
|
262
|
+
timeoutMs: args.timeoutMs,
|
|
263
|
+
};
|
|
264
|
+
logger.error("HTTP request timed out", metadata);
|
|
265
|
+
}
|
|
89
266
|
return {
|
|
90
267
|
ok: false,
|
|
91
268
|
error: {
|
|
@@ -95,6 +272,14 @@ export function fetcherImpl(args) {
|
|
|
95
272
|
};
|
|
96
273
|
}
|
|
97
274
|
else if (error instanceof Error) {
|
|
275
|
+
if (logger.isError()) {
|
|
276
|
+
const metadata = {
|
|
277
|
+
method: args.method,
|
|
278
|
+
url: redactUrl(url),
|
|
279
|
+
errorMessage: error.message,
|
|
280
|
+
};
|
|
281
|
+
logger.error("HTTP request failed with error", metadata);
|
|
282
|
+
}
|
|
98
283
|
return {
|
|
99
284
|
ok: false,
|
|
100
285
|
error: {
|
|
@@ -104,6 +289,14 @@ export function fetcherImpl(args) {
|
|
|
104
289
|
rawResponse: unknownRawResponse,
|
|
105
290
|
};
|
|
106
291
|
}
|
|
292
|
+
if (logger.isError()) {
|
|
293
|
+
const metadata = {
|
|
294
|
+
method: args.method,
|
|
295
|
+
url: redactUrl(url),
|
|
296
|
+
error: toJson(error),
|
|
297
|
+
};
|
|
298
|
+
logger.error("HTTP request failed with unknown error", metadata);
|
|
299
|
+
}
|
|
107
300
|
return {
|
|
108
301
|
ok: false,
|
|
109
302
|
error: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare namespace GetRequestBody {
|
|
2
2
|
interface Args {
|
|
3
3
|
body: unknown;
|
|
4
|
-
type: "json" | "file" | "bytes" | "other";
|
|
4
|
+
type: "json" | "file" | "bytes" | "form" | "other";
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
7
|
export declare function getRequestBody({ body, type }: GetRequestBody.Args): Promise<BodyInit | undefined>;
|
|
@@ -8,8 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { toJson } from "../json.mjs";
|
|
11
|
+
import { toQueryString } from "../url/qs.mjs";
|
|
11
12
|
export function getRequestBody(_a) {
|
|
12
13
|
return __awaiter(this, arguments, void 0, function* ({ body, type }) {
|
|
14
|
+
if (type === "form") {
|
|
15
|
+
return toQueryString(body, { arrayFormat: "repeat", encode: true });
|
|
16
|
+
}
|
|
13
17
|
if (type.includes("json")) {
|
|
14
18
|
return toJson(body);
|
|
15
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const makeRequest: (fetchFn: (url: string, init: RequestInit) => Promise<Response>, url: string, method: string, headers: Record<string, string>, requestBody: BodyInit | undefined, timeoutMs?: number, abortSignal?: AbortSignal, withCredentials?: boolean, duplex?: "half") => Promise<Response>;
|
|
1
|
+
export declare const makeRequest: (fetchFn: (url: string, init: RequestInit) => Promise<Response>, url: string, method: string, headers: Headers | Record<string, string>, requestBody: BodyInit | undefined, timeoutMs?: number, abortSignal?: AbortSignal, withCredentials?: boolean, duplex?: "half") => Promise<Response>;
|
|
@@ -10,14 +10,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { anySignal, getTimeoutSignal } from "./signals.mjs";
|
|
11
11
|
export const makeRequest = (fetchFn, url, method, headers, requestBody, timeoutMs, abortSignal, withCredentials, duplex) => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
12
|
const signals = [];
|
|
13
|
-
// Add timeout signal
|
|
14
13
|
let timeoutAbortId;
|
|
15
14
|
if (timeoutMs != null) {
|
|
16
15
|
const { signal, abortId } = getTimeoutSignal(timeoutMs);
|
|
17
16
|
timeoutAbortId = abortId;
|
|
18
17
|
signals.push(signal);
|
|
19
18
|
}
|
|
20
|
-
// Add arbitrary signal
|
|
21
19
|
if (abortSignal != null) {
|
|
22
20
|
signals.push(abortSignal);
|
|
23
21
|
}
|