agentmail 0.0.46 → 0.0.48

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.
Files changed (120) hide show
  1. package/dist/cjs/Client.d.ts +3 -0
  2. package/dist/cjs/Client.js +11 -6
  3. package/dist/cjs/api/resources/drafts/types/CreateDraftRequest.d.ts +1 -0
  4. package/dist/cjs/api/resources/drafts/types/Draft.d.ts +2 -0
  5. package/dist/cjs/api/resources/drafts/types/DraftItem.d.ts +2 -0
  6. package/dist/cjs/api/resources/drafts/types/DraftSendAt.d.ts +7 -0
  7. package/dist/cjs/api/resources/drafts/types/DraftSendAt.js +5 -0
  8. package/dist/cjs/api/resources/drafts/types/DraftSendStatus.d.ts +12 -0
  9. package/dist/cjs/api/resources/drafts/types/DraftSendStatus.js +11 -0
  10. package/dist/cjs/api/resources/drafts/types/index.d.ts +2 -0
  11. package/dist/cjs/api/resources/drafts/types/index.js +2 -0
  12. package/dist/cjs/api/resources/inboxes/client/Client.d.ts +3 -0
  13. package/dist/cjs/api/resources/inboxes/client/Client.js +5 -0
  14. package/dist/cjs/api/resources/inboxes/resources/drafts/client/Client.d.ts +2 -1
  15. package/dist/cjs/api/resources/inboxes/resources/drafts/client/Client.js +2 -1
  16. package/dist/cjs/api/resources/inboxes/resources/index.d.ts +2 -0
  17. package/dist/cjs/api/resources/inboxes/resources/index.js +3 -1
  18. package/dist/cjs/api/resources/inboxes/resources/messages/client/Client.d.ts +2 -2
  19. package/dist/cjs/api/resources/inboxes/resources/messages/client/Client.js +3 -3
  20. package/dist/cjs/api/resources/inboxes/resources/metrics/client/Client.d.ts +47 -0
  21. package/dist/cjs/api/resources/inboxes/resources/metrics/client/Client.js +142 -0
  22. package/dist/cjs/api/resources/inboxes/resources/metrics/client/index.d.ts +2 -0
  23. package/dist/cjs/api/resources/inboxes/resources/metrics/client/index.js +17 -0
  24. package/dist/cjs/api/resources/inboxes/resources/metrics/client/requests/ListInboxMetricsRequest.d.ts +16 -0
  25. package/dist/cjs/api/resources/inboxes/resources/metrics/client/requests/ListInboxMetricsRequest.js +5 -0
  26. package/dist/cjs/api/resources/inboxes/resources/metrics/client/requests/index.d.ts +1 -0
  27. package/dist/cjs/api/resources/inboxes/resources/metrics/client/requests/index.js +2 -0
  28. package/dist/cjs/api/resources/inboxes/resources/metrics/index.d.ts +1 -0
  29. package/dist/cjs/api/resources/inboxes/resources/metrics/index.js +17 -0
  30. package/dist/cjs/api/resources/index.d.ts +3 -0
  31. package/dist/cjs/api/resources/index.js +4 -1
  32. package/dist/cjs/api/resources/metrics/client/Client.d.ts +45 -0
  33. package/dist/cjs/api/resources/metrics/client/Client.js +138 -0
  34. package/dist/cjs/api/resources/metrics/client/index.d.ts +2 -0
  35. package/dist/cjs/api/resources/metrics/client/index.js +17 -0
  36. package/dist/cjs/api/resources/metrics/client/requests/ListMetricsRequest.d.ts +16 -0
  37. package/dist/cjs/api/resources/metrics/client/requests/ListMetricsRequest.js +5 -0
  38. package/dist/cjs/api/resources/metrics/client/requests/index.d.ts +1 -0
  39. package/dist/cjs/api/resources/metrics/client/requests/index.js +2 -0
  40. package/dist/cjs/api/resources/metrics/index.d.ts +2 -0
  41. package/dist/cjs/api/resources/metrics/index.js +18 -0
  42. package/dist/cjs/api/resources/metrics/types/ListMetricsResponse.d.ts +8 -0
  43. package/dist/cjs/api/resources/metrics/types/ListMetricsResponse.js +5 -0
  44. package/dist/cjs/api/resources/metrics/types/MessageMetrics.d.ts +20 -0
  45. package/dist/cjs/api/resources/metrics/types/MessageMetrics.js +5 -0
  46. package/dist/cjs/api/resources/metrics/types/MetricEndTimestamp.d.ts +7 -0
  47. package/dist/cjs/api/resources/metrics/types/MetricEndTimestamp.js +5 -0
  48. package/dist/cjs/api/resources/metrics/types/MetricEventType.d.ts +16 -0
  49. package/dist/cjs/api/resources/metrics/types/MetricEventType.js +15 -0
  50. package/dist/cjs/api/resources/metrics/types/MetricEventTypes.d.ts +8 -0
  51. package/dist/cjs/api/resources/metrics/types/MetricEventTypes.js +5 -0
  52. package/dist/cjs/api/resources/metrics/types/MetricStartTimestamp.d.ts +7 -0
  53. package/dist/cjs/api/resources/metrics/types/MetricStartTimestamp.js +5 -0
  54. package/dist/cjs/api/resources/metrics/types/MetricTimestamp.d.ts +7 -0
  55. package/dist/cjs/api/resources/metrics/types/MetricTimestamp.js +5 -0
  56. package/dist/cjs/api/resources/metrics/types/index.d.ts +7 -0
  57. package/dist/cjs/api/resources/metrics/types/index.js +23 -0
  58. package/dist/cjs/version.d.ts +1 -1
  59. package/dist/cjs/version.js +1 -1
  60. package/dist/esm/Client.d.mts +3 -0
  61. package/dist/esm/Client.mjs +7 -2
  62. package/dist/esm/api/resources/drafts/types/CreateDraftRequest.d.mts +1 -0
  63. package/dist/esm/api/resources/drafts/types/Draft.d.mts +2 -0
  64. package/dist/esm/api/resources/drafts/types/DraftItem.d.mts +2 -0
  65. package/dist/esm/api/resources/drafts/types/DraftSendAt.d.mts +7 -0
  66. package/dist/esm/api/resources/drafts/types/DraftSendAt.mjs +4 -0
  67. package/dist/esm/api/resources/drafts/types/DraftSendStatus.d.mts +12 -0
  68. package/dist/esm/api/resources/drafts/types/DraftSendStatus.mjs +8 -0
  69. package/dist/esm/api/resources/drafts/types/index.d.mts +2 -0
  70. package/dist/esm/api/resources/drafts/types/index.mjs +2 -0
  71. package/dist/esm/api/resources/inboxes/client/Client.d.mts +3 -0
  72. package/dist/esm/api/resources/inboxes/client/Client.mjs +5 -0
  73. package/dist/esm/api/resources/inboxes/resources/drafts/client/Client.d.mts +2 -1
  74. package/dist/esm/api/resources/inboxes/resources/drafts/client/Client.mjs +2 -1
  75. package/dist/esm/api/resources/inboxes/resources/index.d.mts +2 -0
  76. package/dist/esm/api/resources/inboxes/resources/index.mjs +2 -0
  77. package/dist/esm/api/resources/inboxes/resources/messages/client/Client.d.mts +2 -2
  78. package/dist/esm/api/resources/inboxes/resources/messages/client/Client.mjs +3 -3
  79. package/dist/esm/api/resources/inboxes/resources/metrics/client/Client.d.mts +47 -0
  80. package/dist/esm/api/resources/inboxes/resources/metrics/client/Client.mjs +105 -0
  81. package/dist/esm/api/resources/inboxes/resources/metrics/client/index.d.mts +2 -0
  82. package/dist/esm/api/resources/inboxes/resources/metrics/client/index.mjs +1 -0
  83. package/dist/esm/api/resources/inboxes/resources/metrics/client/requests/ListInboxMetricsRequest.d.mts +16 -0
  84. package/dist/esm/api/resources/inboxes/resources/metrics/client/requests/ListInboxMetricsRequest.mjs +4 -0
  85. package/dist/esm/api/resources/inboxes/resources/metrics/client/requests/index.d.mts +1 -0
  86. package/dist/esm/api/resources/inboxes/resources/metrics/client/requests/index.mjs +1 -0
  87. package/dist/esm/api/resources/inboxes/resources/metrics/index.d.mts +1 -0
  88. package/dist/esm/api/resources/inboxes/resources/metrics/index.mjs +1 -0
  89. package/dist/esm/api/resources/index.d.mts +3 -0
  90. package/dist/esm/api/resources/index.mjs +3 -0
  91. package/dist/esm/api/resources/metrics/client/Client.d.mts +45 -0
  92. package/dist/esm/api/resources/metrics/client/Client.mjs +101 -0
  93. package/dist/esm/api/resources/metrics/client/index.d.mts +2 -0
  94. package/dist/esm/api/resources/metrics/client/index.mjs +1 -0
  95. package/dist/esm/api/resources/metrics/client/requests/ListMetricsRequest.d.mts +16 -0
  96. package/dist/esm/api/resources/metrics/client/requests/ListMetricsRequest.mjs +4 -0
  97. package/dist/esm/api/resources/metrics/client/requests/index.d.mts +1 -0
  98. package/dist/esm/api/resources/metrics/client/requests/index.mjs +1 -0
  99. package/dist/esm/api/resources/metrics/index.d.mts +2 -0
  100. package/dist/esm/api/resources/metrics/index.mjs +2 -0
  101. package/dist/esm/api/resources/metrics/types/ListMetricsResponse.d.mts +8 -0
  102. package/dist/esm/api/resources/metrics/types/ListMetricsResponse.mjs +4 -0
  103. package/dist/esm/api/resources/metrics/types/MessageMetrics.d.mts +20 -0
  104. package/dist/esm/api/resources/metrics/types/MessageMetrics.mjs +4 -0
  105. package/dist/esm/api/resources/metrics/types/MetricEndTimestamp.d.mts +7 -0
  106. package/dist/esm/api/resources/metrics/types/MetricEndTimestamp.mjs +4 -0
  107. package/dist/esm/api/resources/metrics/types/MetricEventType.d.mts +16 -0
  108. package/dist/esm/api/resources/metrics/types/MetricEventType.mjs +12 -0
  109. package/dist/esm/api/resources/metrics/types/MetricEventTypes.d.mts +8 -0
  110. package/dist/esm/api/resources/metrics/types/MetricEventTypes.mjs +4 -0
  111. package/dist/esm/api/resources/metrics/types/MetricStartTimestamp.d.mts +7 -0
  112. package/dist/esm/api/resources/metrics/types/MetricStartTimestamp.mjs +4 -0
  113. package/dist/esm/api/resources/metrics/types/MetricTimestamp.d.mts +7 -0
  114. package/dist/esm/api/resources/metrics/types/MetricTimestamp.mjs +4 -0
  115. package/dist/esm/api/resources/metrics/types/index.d.mts +7 -0
  116. package/dist/esm/api/resources/metrics/types/index.mjs +7 -0
  117. package/dist/esm/version.d.mts +1 -1
  118. package/dist/esm/version.mjs +1 -1
  119. package/package.json +1 -1
  120. package/reference.md +115 -0
@@ -59,8 +59,8 @@ export declare class Messages {
59
59
  /**
60
60
  * @throws {@link AgentMail.NotFoundError}
61
61
  */
62
- getRawMessage(inboxId: AgentMail.inboxes.InboxId, messageId: AgentMail.MessageId, requestOptions?: Messages.RequestOptions): core.HttpResponsePromise<core.BinaryResponse>;
63
- private __getRawMessage;
62
+ getRaw(inboxId: AgentMail.inboxes.InboxId, messageId: AgentMail.MessageId, requestOptions?: Messages.RequestOptions): core.HttpResponsePromise<core.BinaryResponse>;
63
+ private __getRaw;
64
64
  /**
65
65
  * @param {AgentMail.inboxes.InboxId} inboxId
66
66
  * @param {AgentMail.SendMessageRequest} request
@@ -200,10 +200,10 @@ export class Messages {
200
200
  /**
201
201
  * @throws {@link AgentMail.NotFoundError}
202
202
  */
203
- getRawMessage(inboxId, messageId, requestOptions) {
204
- return core.HttpResponsePromise.fromPromise(this.__getRawMessage(inboxId, messageId, requestOptions));
203
+ getRaw(inboxId, messageId, requestOptions) {
204
+ return core.HttpResponsePromise.fromPromise(this.__getRaw(inboxId, messageId, requestOptions));
205
205
  }
206
- __getRawMessage(inboxId, messageId, requestOptions) {
206
+ __getRaw(inboxId, messageId, requestOptions) {
207
207
  return __awaiter(this, void 0, void 0, function* () {
208
208
  var _a, _b, _c;
209
209
  const _response = yield core.fetcher({
@@ -0,0 +1,47 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ import * as environments from "../../../../../../environments.mjs";
5
+ import * as core from "../../../../../../core/index.mjs";
6
+ import * as AgentMail from "../../../../../index.mjs";
7
+ export declare namespace Metrics {
8
+ interface Options {
9
+ environment?: core.Supplier<environments.AgentMailEnvironment | environments.AgentMailEnvironmentUrls>;
10
+ /** Specify a custom URL to connect the client to. */
11
+ baseUrl?: core.Supplier<string>;
12
+ apiKey?: core.Supplier<core.BearerToken | undefined>;
13
+ /** Additional headers to include in requests. */
14
+ headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
15
+ }
16
+ interface RequestOptions {
17
+ /** The maximum time to wait for a response in seconds. */
18
+ timeoutInSeconds?: number;
19
+ /** The number of times to retry the request. Defaults to 2. */
20
+ maxRetries?: number;
21
+ /** A hook to abort the request. */
22
+ abortSignal?: AbortSignal;
23
+ /** Additional headers to include in the request. */
24
+ headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
25
+ }
26
+ }
27
+ export declare class Metrics {
28
+ protected readonly _options: Metrics.Options;
29
+ constructor(_options?: Metrics.Options);
30
+ /**
31
+ * @param {AgentMail.inboxes.InboxId} inboxId
32
+ * @param {AgentMail.inboxes.ListInboxMetricsRequest} request
33
+ * @param {Metrics.RequestOptions} requestOptions - Request-specific configuration.
34
+ *
35
+ * @throws {@link AgentMail.NotFoundError}
36
+ * @throws {@link AgentMail.ValidationError}
37
+ *
38
+ * @example
39
+ * await client.inboxes.metrics.get("inbox_id", {
40
+ * start_timestamp: "2024-01-15T09:30:00Z",
41
+ * end_timestamp: "2024-01-15T09:30:00Z"
42
+ * })
43
+ */
44
+ get(inboxId: AgentMail.inboxes.InboxId, request: AgentMail.inboxes.ListInboxMetricsRequest, requestOptions?: Metrics.RequestOptions): core.HttpResponsePromise<AgentMail.ListMetricsResponse>;
45
+ private __get;
46
+ protected _getAuthorizationHeader(): Promise<string>;
47
+ }
@@ -0,0 +1,105 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
5
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6
+ return new (P || (P = Promise))(function (resolve, reject) {
7
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
8
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
9
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
10
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
11
+ });
12
+ };
13
+ import * as environments from "../../../../../../environments.mjs";
14
+ import * as core from "../../../../../../core/index.mjs";
15
+ import * as AgentMail from "../../../../../index.mjs";
16
+ import { toJson } from "../../../../../../core/json.mjs";
17
+ import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../../../core/headers.mjs";
18
+ import * as errors from "../../../../../../errors/index.mjs";
19
+ export class Metrics {
20
+ constructor(_options = {}) {
21
+ this._options = _options;
22
+ }
23
+ /**
24
+ * @param {AgentMail.inboxes.InboxId} inboxId
25
+ * @param {AgentMail.inboxes.ListInboxMetricsRequest} request
26
+ * @param {Metrics.RequestOptions} requestOptions - Request-specific configuration.
27
+ *
28
+ * @throws {@link AgentMail.NotFoundError}
29
+ * @throws {@link AgentMail.ValidationError}
30
+ *
31
+ * @example
32
+ * await client.inboxes.metrics.get("inbox_id", {
33
+ * start_timestamp: "2024-01-15T09:30:00Z",
34
+ * end_timestamp: "2024-01-15T09:30:00Z"
35
+ * })
36
+ */
37
+ get(inboxId, request, requestOptions) {
38
+ return core.HttpResponsePromise.fromPromise(this.__get(inboxId, request, requestOptions));
39
+ }
40
+ __get(inboxId, request, requestOptions) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ var _a, _b, _c;
43
+ const { event_types: eventTypes, start_timestamp: startTimestamp, end_timestamp: endTimestamp } = request;
44
+ const _queryParams = {};
45
+ if (eventTypes != null) {
46
+ _queryParams["event_types"] = toJson(eventTypes);
47
+ }
48
+ _queryParams["start_timestamp"] = startTimestamp;
49
+ _queryParams["end_timestamp"] = endTimestamp;
50
+ const _response = yield core.fetcher({
51
+ 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).http, `/v0/inboxes/${encodeURIComponent(inboxId)}/metrics`),
52
+ method: "GET",
53
+ headers: mergeHeaders((_c = this._options) === null || _c === void 0 ? void 0 : _c.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
54
+ queryParameters: _queryParams,
55
+ timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
56
+ maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
57
+ abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
58
+ });
59
+ if (_response.ok) {
60
+ return { data: _response.body, rawResponse: _response.rawResponse };
61
+ }
62
+ if (_response.error.reason === "status-code") {
63
+ switch (_response.error.statusCode) {
64
+ case 404:
65
+ throw new AgentMail.NotFoundError(_response.error.body, _response.rawResponse);
66
+ case 400:
67
+ throw new AgentMail.ValidationError(_response.error.body, _response.rawResponse);
68
+ default:
69
+ throw new errors.AgentMailError({
70
+ statusCode: _response.error.statusCode,
71
+ body: _response.error.body,
72
+ rawResponse: _response.rawResponse,
73
+ });
74
+ }
75
+ }
76
+ switch (_response.error.reason) {
77
+ case "non-json":
78
+ throw new errors.AgentMailError({
79
+ statusCode: _response.error.statusCode,
80
+ body: _response.error.rawBody,
81
+ rawResponse: _response.rawResponse,
82
+ });
83
+ case "timeout":
84
+ throw new errors.AgentMailTimeoutError("Timeout exceeded when calling GET /v0/inboxes/{inbox_id}/metrics.");
85
+ case "unknown":
86
+ throw new errors.AgentMailError({
87
+ message: _response.error.errorMessage,
88
+ rawResponse: _response.rawResponse,
89
+ });
90
+ }
91
+ });
92
+ }
93
+ _getAuthorizationHeader() {
94
+ return __awaiter(this, void 0, void 0, function* () {
95
+ var _a;
96
+ 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"];
97
+ if (bearer == null) {
98
+ throw new errors.AgentMailError({
99
+ message: "Please specify a bearer by either passing it in to the constructor or initializing a AGENTMAIL_API_KEY environment variable",
100
+ });
101
+ }
102
+ return `Bearer ${bearer}`;
103
+ });
104
+ }
105
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ export * from "./requests/index.mjs";
@@ -0,0 +1 @@
1
+ export * from "./requests/index.mjs";
@@ -0,0 +1,16 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ import * as AgentMail from "../../../../../../index.mjs";
5
+ /**
6
+ * @example
7
+ * {
8
+ * start_timestamp: "2024-01-15T09:30:00Z",
9
+ * end_timestamp: "2024-01-15T09:30:00Z"
10
+ * }
11
+ */
12
+ export interface ListInboxMetricsRequest {
13
+ event_types?: AgentMail.MetricEventTypes;
14
+ start_timestamp: AgentMail.MetricStartTimestamp;
15
+ end_timestamp: AgentMail.MetricEndTimestamp;
16
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ export {};
@@ -0,0 +1 @@
1
+ export { type ListInboxMetricsRequest } from "./ListInboxMetricsRequest.mjs";
@@ -0,0 +1 @@
1
+ export * from "./client/index.mjs";
@@ -0,0 +1 @@
1
+ export * from "./client/index.mjs";
@@ -8,6 +8,8 @@ export * as drafts from "./drafts/index.mjs";
8
8
  export * from "./drafts/types/index.mjs";
9
9
  export * as messages from "./messages/index.mjs";
10
10
  export * from "./messages/types/index.mjs";
11
+ export * as metrics from "./metrics/index.mjs";
12
+ export * from "./metrics/types/index.mjs";
11
13
  export * as threads from "./threads/index.mjs";
12
14
  export * from "./threads/types/index.mjs";
13
15
  export * as websockets from "./websockets/index.mjs";
@@ -15,4 +17,5 @@ export * from "./websockets/types/index.mjs";
15
17
  export * from "./messages/errors/index.mjs";
16
18
  export * from "./domains/client/requests/index.mjs";
17
19
  export * from "./drafts/client/requests/index.mjs";
20
+ export * from "./metrics/client/requests/index.mjs";
18
21
  export * from "./threads/client/requests/index.mjs";
@@ -8,6 +8,8 @@ export * as drafts from "./drafts/index.mjs";
8
8
  export * from "./drafts/types/index.mjs";
9
9
  export * as messages from "./messages/index.mjs";
10
10
  export * from "./messages/types/index.mjs";
11
+ export * as metrics from "./metrics/index.mjs";
12
+ export * from "./metrics/types/index.mjs";
11
13
  export * as threads from "./threads/index.mjs";
12
14
  export * from "./threads/types/index.mjs";
13
15
  export * as websockets from "./websockets/index.mjs";
@@ -15,4 +17,5 @@ export * from "./websockets/types/index.mjs";
15
17
  export * from "./messages/errors/index.mjs";
16
18
  export * from "./domains/client/requests/index.mjs";
17
19
  export * from "./drafts/client/requests/index.mjs";
20
+ export * from "./metrics/client/requests/index.mjs";
18
21
  export * from "./threads/client/requests/index.mjs";
@@ -0,0 +1,45 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ import * as environments from "../../../../environments.mjs";
5
+ import * as core from "../../../../core/index.mjs";
6
+ import * as AgentMail from "../../../index.mjs";
7
+ export declare namespace Metrics {
8
+ interface Options {
9
+ environment?: core.Supplier<environments.AgentMailEnvironment | environments.AgentMailEnvironmentUrls>;
10
+ /** Specify a custom URL to connect the client to. */
11
+ baseUrl?: core.Supplier<string>;
12
+ apiKey?: core.Supplier<core.BearerToken | undefined>;
13
+ /** Additional headers to include in requests. */
14
+ headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
15
+ }
16
+ interface RequestOptions {
17
+ /** The maximum time to wait for a response in seconds. */
18
+ timeoutInSeconds?: number;
19
+ /** The number of times to retry the request. Defaults to 2. */
20
+ maxRetries?: number;
21
+ /** A hook to abort the request. */
22
+ abortSignal?: AbortSignal;
23
+ /** Additional headers to include in the request. */
24
+ headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
25
+ }
26
+ }
27
+ export declare class Metrics {
28
+ protected readonly _options: Metrics.Options;
29
+ constructor(_options?: Metrics.Options);
30
+ /**
31
+ * @param {AgentMail.ListMetricsRequest} request
32
+ * @param {Metrics.RequestOptions} requestOptions - Request-specific configuration.
33
+ *
34
+ * @throws {@link AgentMail.NotFoundError}
35
+ *
36
+ * @example
37
+ * await client.metrics.list({
38
+ * start_timestamp: "2024-01-15T09:30:00Z",
39
+ * end_timestamp: "2024-01-15T09:30:00Z"
40
+ * })
41
+ */
42
+ list(request: AgentMail.ListMetricsRequest, requestOptions?: Metrics.RequestOptions): core.HttpResponsePromise<AgentMail.ListMetricsResponse>;
43
+ private __list;
44
+ protected _getAuthorizationHeader(): Promise<string>;
45
+ }
@@ -0,0 +1,101 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
5
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6
+ return new (P || (P = Promise))(function (resolve, reject) {
7
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
8
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
9
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
10
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
11
+ });
12
+ };
13
+ import * as environments from "../../../../environments.mjs";
14
+ import * as core from "../../../../core/index.mjs";
15
+ import * as AgentMail from "../../../index.mjs";
16
+ import { toJson } from "../../../../core/json.mjs";
17
+ import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.mjs";
18
+ import * as errors from "../../../../errors/index.mjs";
19
+ export class Metrics {
20
+ constructor(_options = {}) {
21
+ this._options = _options;
22
+ }
23
+ /**
24
+ * @param {AgentMail.ListMetricsRequest} request
25
+ * @param {Metrics.RequestOptions} requestOptions - Request-specific configuration.
26
+ *
27
+ * @throws {@link AgentMail.NotFoundError}
28
+ *
29
+ * @example
30
+ * await client.metrics.list({
31
+ * start_timestamp: "2024-01-15T09:30:00Z",
32
+ * end_timestamp: "2024-01-15T09:30:00Z"
33
+ * })
34
+ */
35
+ list(request, requestOptions) {
36
+ return core.HttpResponsePromise.fromPromise(this.__list(request, requestOptions));
37
+ }
38
+ __list(request, requestOptions) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ var _a, _b, _c;
41
+ const { event_types: eventTypes, start_timestamp: startTimestamp, end_timestamp: endTimestamp } = request;
42
+ const _queryParams = {};
43
+ if (eventTypes != null) {
44
+ _queryParams["event_types"] = toJson(eventTypes);
45
+ }
46
+ _queryParams["start_timestamp"] = startTimestamp;
47
+ _queryParams["end_timestamp"] = endTimestamp;
48
+ const _response = yield core.fetcher({
49
+ 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).http, "/v0/metrics"),
50
+ method: "GET",
51
+ headers: mergeHeaders((_c = this._options) === null || _c === void 0 ? void 0 : _c.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
52
+ queryParameters: _queryParams,
53
+ timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
54
+ maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
55
+ abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
56
+ });
57
+ if (_response.ok) {
58
+ return { data: _response.body, rawResponse: _response.rawResponse };
59
+ }
60
+ if (_response.error.reason === "status-code") {
61
+ switch (_response.error.statusCode) {
62
+ case 404:
63
+ throw new AgentMail.NotFoundError(_response.error.body, _response.rawResponse);
64
+ default:
65
+ throw new errors.AgentMailError({
66
+ statusCode: _response.error.statusCode,
67
+ body: _response.error.body,
68
+ rawResponse: _response.rawResponse,
69
+ });
70
+ }
71
+ }
72
+ switch (_response.error.reason) {
73
+ case "non-json":
74
+ throw new errors.AgentMailError({
75
+ statusCode: _response.error.statusCode,
76
+ body: _response.error.rawBody,
77
+ rawResponse: _response.rawResponse,
78
+ });
79
+ case "timeout":
80
+ throw new errors.AgentMailTimeoutError("Timeout exceeded when calling GET /v0/metrics.");
81
+ case "unknown":
82
+ throw new errors.AgentMailError({
83
+ message: _response.error.errorMessage,
84
+ rawResponse: _response.rawResponse,
85
+ });
86
+ }
87
+ });
88
+ }
89
+ _getAuthorizationHeader() {
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ var _a;
92
+ 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"];
93
+ if (bearer == null) {
94
+ throw new errors.AgentMailError({
95
+ message: "Please specify a bearer by either passing it in to the constructor or initializing a AGENTMAIL_API_KEY environment variable",
96
+ });
97
+ }
98
+ return `Bearer ${bearer}`;
99
+ });
100
+ }
101
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ export * from "./requests/index.mjs";
@@ -0,0 +1 @@
1
+ export * from "./requests/index.mjs";
@@ -0,0 +1,16 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ import * as AgentMail from "../../../../index.mjs";
5
+ /**
6
+ * @example
7
+ * {
8
+ * start_timestamp: "2024-01-15T09:30:00Z",
9
+ * end_timestamp: "2024-01-15T09:30:00Z"
10
+ * }
11
+ */
12
+ export interface ListMetricsRequest {
13
+ event_types?: AgentMail.MetricEventTypes;
14
+ start_timestamp: AgentMail.MetricStartTimestamp;
15
+ end_timestamp: AgentMail.MetricEndTimestamp;
16
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ export {};
@@ -0,0 +1 @@
1
+ export { type ListMetricsRequest } from "./ListMetricsRequest.mjs";
@@ -0,0 +1,2 @@
1
+ export * from "./types/index.mjs";
2
+ export * from "./client/index.mjs";
@@ -0,0 +1,2 @@
1
+ export * from "./types/index.mjs";
2
+ export * from "./client/index.mjs";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ import * as AgentMail from "../../../index.mjs";
5
+ export interface ListMetricsResponse {
6
+ /** Message metrics grouped by event type. */
7
+ message?: AgentMail.MessageMetrics;
8
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ export {};
@@ -0,0 +1,20 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ import * as AgentMail from "../../../index.mjs";
5
+ export interface MessageMetrics {
6
+ /** Timestamps when messages were sent. */
7
+ sent?: AgentMail.MetricTimestamp[];
8
+ /** Timestamps when messages were delivered. */
9
+ delivered?: AgentMail.MetricTimestamp[];
10
+ /** Timestamps when messages bounced. */
11
+ bounced?: AgentMail.MetricTimestamp[];
12
+ /** Timestamps when messages were delayed. */
13
+ delayed?: AgentMail.MetricTimestamp[];
14
+ /** Timestamps when messages were rejected. */
15
+ rejected?: AgentMail.MetricTimestamp[];
16
+ /** Timestamps when messages received complaints. */
17
+ complained?: AgentMail.MetricTimestamp[];
18
+ /** Timestamps when messages were received. */
19
+ received?: AgentMail.MetricTimestamp[];
20
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ export {};
@@ -0,0 +1,7 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ /**
5
+ * End timestamp for the metrics query range.
6
+ */
7
+ export type MetricEndTimestamp = string;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ export {};
@@ -0,0 +1,16 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ /**
5
+ * Type of metric event.
6
+ */
7
+ export type MetricEventType = "message.sent" | "message.delivered" | "message.bounced" | "message.delayed" | "message.rejected" | "message.complained" | "message.received";
8
+ export declare const MetricEventType: {
9
+ readonly MessageSent: "message.sent";
10
+ readonly MessageDelivered: "message.delivered";
11
+ readonly MessageBounced: "message.bounced";
12
+ readonly MessageDelayed: "message.delayed";
13
+ readonly MessageRejected: "message.rejected";
14
+ readonly MessageComplained: "message.complained";
15
+ readonly MessageReceived: "message.received";
16
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ export const MetricEventType = {
5
+ MessageSent: "message.sent",
6
+ MessageDelivered: "message.delivered",
7
+ MessageBounced: "message.bounced",
8
+ MessageDelayed: "message.delayed",
9
+ MessageRejected: "message.rejected",
10
+ MessageComplained: "message.complained",
11
+ MessageReceived: "message.received",
12
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ import * as AgentMail from "../../../index.mjs";
5
+ /**
6
+ * List of metric event types to filter by.
7
+ */
8
+ export type MetricEventTypes = AgentMail.MetricEventType[];
@@ -0,0 +1,4 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ export {};
@@ -0,0 +1,7 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ /**
5
+ * Start timestamp for the metrics query range.
6
+ */
7
+ export type MetricStartTimestamp = string;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ export {};
@@ -0,0 +1,7 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ /**
5
+ * Timestamp when the metric event occurred.
6
+ */
7
+ export type MetricTimestamp = string;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ export {};
@@ -0,0 +1,7 @@
1
+ export * from "./MetricEventType.mjs";
2
+ export * from "./MetricTimestamp.mjs";
3
+ export * from "./MetricEventTypes.mjs";
4
+ export * from "./MetricStartTimestamp.mjs";
5
+ export * from "./MetricEndTimestamp.mjs";
6
+ export * from "./MessageMetrics.mjs";
7
+ export * from "./ListMetricsResponse.mjs";
@@ -0,0 +1,7 @@
1
+ export * from "./MetricEventType.mjs";
2
+ export * from "./MetricTimestamp.mjs";
3
+ export * from "./MetricEventTypes.mjs";
4
+ export * from "./MetricStartTimestamp.mjs";
5
+ export * from "./MetricEndTimestamp.mjs";
6
+ export * from "./MessageMetrics.mjs";
7
+ export * from "./ListMetricsResponse.mjs";
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.0.46";
1
+ export declare const SDK_VERSION = "0.0.48";
@@ -1 +1 @@
1
- export const SDK_VERSION = "0.0.46";
1
+ export const SDK_VERSION = "0.0.48";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentmail",
3
- "version": "0.0.46",
3
+ "version": "0.0.48",
4
4
  "private": false,
5
5
  "repository": "github:agentmail-to/agentmail-node",
6
6
  "type": "commonjs",