agentmail 0.5.11 → 0.5.12

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 (104) hide show
  1. package/dist/cjs/BaseClient.js +2 -2
  2. package/dist/cjs/api/resources/inboxes/resources/metrics/client/Client.d.ts +30 -4
  3. package/dist/cjs/api/resources/inboxes/resources/metrics/client/Client.js +102 -7
  4. package/dist/cjs/api/resources/inboxes/resources/metrics/client/requests/{QueryMetricsRequest.d.ts → QueryEventsRequest.d.ts} +1 -1
  5. package/dist/cjs/api/resources/inboxes/resources/metrics/client/requests/QueryUsageRequest.d.ts +13 -0
  6. package/dist/cjs/api/resources/inboxes/resources/metrics/client/requests/index.d.ts +2 -1
  7. package/dist/cjs/api/resources/metrics/client/Client.d.ts +27 -4
  8. package/dist/cjs/api/resources/metrics/client/Client.js +99 -7
  9. package/dist/cjs/api/resources/metrics/client/requests/{QueryMetricsRequest.d.ts → QueryEventsRequest.d.ts} +1 -1
  10. package/dist/cjs/api/resources/metrics/client/requests/QueryUsageRequest.d.ts +13 -0
  11. package/dist/cjs/api/resources/metrics/client/requests/QueryUsageRequest.js +3 -0
  12. package/dist/cjs/api/resources/metrics/client/requests/index.d.ts +2 -1
  13. package/dist/cjs/api/resources/metrics/types/MetricEventType.d.ts +6 -3
  14. package/dist/cjs/api/resources/metrics/types/MetricEventType.js +6 -3
  15. package/dist/cjs/api/resources/metrics/types/Period.d.ts +2 -2
  16. package/dist/cjs/api/resources/metrics/types/QueryUsageResponse.d.ts +5 -0
  17. package/dist/cjs/api/resources/metrics/types/QueryUsageResponse.js +3 -0
  18. package/dist/cjs/api/resources/metrics/types/UsagePoint.d.ts +6 -0
  19. package/dist/cjs/api/resources/metrics/types/UsagePoint.js +3 -0
  20. package/dist/cjs/api/resources/metrics/types/UsageType.d.ts +14 -0
  21. package/dist/cjs/api/resources/metrics/types/UsageType.js +17 -0
  22. package/dist/cjs/api/resources/metrics/types/UsageTypes.d.ts +5 -0
  23. package/dist/cjs/api/resources/metrics/types/UsageTypes.js +3 -0
  24. package/dist/cjs/api/resources/metrics/types/index.d.ts +4 -0
  25. package/dist/cjs/api/resources/metrics/types/index.js +4 -0
  26. package/dist/cjs/api/resources/pods/resources/metrics/client/Client.d.ts +30 -4
  27. package/dist/cjs/api/resources/pods/resources/metrics/client/Client.js +102 -7
  28. package/dist/cjs/api/resources/pods/resources/metrics/client/requests/{QueryMetricsRequest.d.ts → QueryEventsRequest.d.ts} +1 -1
  29. package/dist/cjs/api/resources/pods/resources/metrics/client/requests/QueryEventsRequest.js +3 -0
  30. package/dist/cjs/api/resources/pods/resources/metrics/client/requests/QueryUsageRequest.d.ts +13 -0
  31. package/dist/cjs/api/resources/pods/resources/metrics/client/requests/QueryUsageRequest.js +3 -0
  32. package/dist/cjs/api/resources/pods/resources/metrics/client/requests/index.d.ts +2 -1
  33. package/dist/cjs/serialization/resources/metrics/types/MetricEventType.d.ts +1 -1
  34. package/dist/cjs/serialization/resources/metrics/types/MetricEventType.js +6 -3
  35. package/dist/cjs/serialization/resources/metrics/types/Period.d.ts +1 -1
  36. package/dist/cjs/serialization/resources/metrics/types/Period.js +1 -1
  37. package/dist/cjs/serialization/resources/metrics/types/QueryUsageResponse.d.ts +9 -0
  38. package/dist/cjs/serialization/resources/metrics/types/QueryUsageResponse.js +41 -0
  39. package/dist/cjs/serialization/resources/metrics/types/UsagePoint.d.ts +10 -0
  40. package/dist/cjs/serialization/resources/metrics/types/UsagePoint.js +42 -0
  41. package/dist/cjs/serialization/resources/metrics/types/UsageType.d.ts +7 -0
  42. package/dist/cjs/serialization/resources/metrics/types/UsageType.js +46 -0
  43. package/dist/cjs/serialization/resources/metrics/types/UsageTypes.d.ts +8 -0
  44. package/dist/cjs/serialization/resources/metrics/types/UsageTypes.js +40 -0
  45. package/dist/cjs/serialization/resources/metrics/types/index.d.ts +4 -0
  46. package/dist/cjs/serialization/resources/metrics/types/index.js +4 -0
  47. package/dist/cjs/version.d.ts +1 -1
  48. package/dist/cjs/version.js +1 -1
  49. package/dist/esm/BaseClient.mjs +2 -2
  50. package/dist/esm/api/resources/inboxes/resources/metrics/client/Client.d.mts +30 -4
  51. package/dist/esm/api/resources/inboxes/resources/metrics/client/Client.mjs +102 -7
  52. package/dist/esm/api/resources/{pods/resources/metrics/client/requests/QueryMetricsRequest.d.mts → inboxes/resources/metrics/client/requests/QueryEventsRequest.d.mts} +1 -1
  53. package/dist/esm/api/resources/inboxes/resources/metrics/client/requests/QueryUsageRequest.d.mts +13 -0
  54. package/dist/esm/api/resources/inboxes/resources/metrics/client/requests/index.d.mts +2 -1
  55. package/dist/esm/api/resources/metrics/client/Client.d.mts +27 -4
  56. package/dist/esm/api/resources/metrics/client/Client.mjs +99 -7
  57. package/dist/esm/api/resources/metrics/client/requests/{QueryMetricsRequest.d.mts → QueryEventsRequest.d.mts} +1 -1
  58. package/dist/esm/api/resources/metrics/client/requests/QueryUsageRequest.d.mts +13 -0
  59. package/dist/esm/api/resources/metrics/client/requests/QueryUsageRequest.mjs +2 -0
  60. package/dist/esm/api/resources/metrics/client/requests/index.d.mts +2 -1
  61. package/dist/esm/api/resources/metrics/types/MetricEventType.d.mts +6 -3
  62. package/dist/esm/api/resources/metrics/types/MetricEventType.mjs +6 -3
  63. package/dist/esm/api/resources/metrics/types/Period.d.mts +2 -2
  64. package/dist/esm/api/resources/metrics/types/QueryUsageResponse.d.mts +5 -0
  65. package/dist/esm/api/resources/metrics/types/QueryUsageResponse.mjs +2 -0
  66. package/dist/esm/api/resources/metrics/types/UsagePoint.d.mts +6 -0
  67. package/dist/esm/api/resources/metrics/types/UsagePoint.mjs +2 -0
  68. package/dist/esm/api/resources/metrics/types/UsageType.d.mts +14 -0
  69. package/dist/esm/api/resources/metrics/types/UsageType.mjs +14 -0
  70. package/dist/esm/api/resources/metrics/types/UsageTypes.d.mts +5 -0
  71. package/dist/esm/api/resources/metrics/types/UsageTypes.mjs +2 -0
  72. package/dist/esm/api/resources/metrics/types/index.d.mts +4 -0
  73. package/dist/esm/api/resources/metrics/types/index.mjs +4 -0
  74. package/dist/esm/api/resources/pods/resources/metrics/client/Client.d.mts +30 -4
  75. package/dist/esm/api/resources/pods/resources/metrics/client/Client.mjs +102 -7
  76. package/dist/esm/api/resources/{inboxes/resources/metrics/client/requests/QueryMetricsRequest.d.mts → pods/resources/metrics/client/requests/QueryEventsRequest.d.mts} +1 -1
  77. package/dist/esm/api/resources/pods/resources/metrics/client/requests/QueryEventsRequest.mjs +2 -0
  78. package/dist/esm/api/resources/pods/resources/metrics/client/requests/QueryUsageRequest.d.mts +13 -0
  79. package/dist/esm/api/resources/pods/resources/metrics/client/requests/QueryUsageRequest.mjs +2 -0
  80. package/dist/esm/api/resources/pods/resources/metrics/client/requests/index.d.mts +2 -1
  81. package/dist/esm/serialization/resources/metrics/types/MetricEventType.d.mts +1 -1
  82. package/dist/esm/serialization/resources/metrics/types/MetricEventType.mjs +6 -3
  83. package/dist/esm/serialization/resources/metrics/types/Period.d.mts +1 -1
  84. package/dist/esm/serialization/resources/metrics/types/Period.mjs +1 -1
  85. package/dist/esm/serialization/resources/metrics/types/QueryUsageResponse.d.mts +9 -0
  86. package/dist/esm/serialization/resources/metrics/types/QueryUsageResponse.mjs +5 -0
  87. package/dist/esm/serialization/resources/metrics/types/UsagePoint.d.mts +10 -0
  88. package/dist/esm/serialization/resources/metrics/types/UsagePoint.mjs +6 -0
  89. package/dist/esm/serialization/resources/metrics/types/UsageType.d.mts +7 -0
  90. package/dist/esm/serialization/resources/metrics/types/UsageType.mjs +10 -0
  91. package/dist/esm/serialization/resources/metrics/types/UsageTypes.d.mts +8 -0
  92. package/dist/esm/serialization/resources/metrics/types/UsageTypes.mjs +4 -0
  93. package/dist/esm/serialization/resources/metrics/types/index.d.mts +4 -0
  94. package/dist/esm/serialization/resources/metrics/types/index.mjs +4 -0
  95. package/dist/esm/version.d.mts +1 -1
  96. package/dist/esm/version.mjs +1 -1
  97. package/package.json +1 -1
  98. package/reference.md +248 -9
  99. /package/dist/cjs/api/resources/inboxes/resources/metrics/client/requests/{QueryMetricsRequest.js → QueryEventsRequest.js} +0 -0
  100. /package/dist/cjs/api/resources/{metrics/client/requests/QueryMetricsRequest.js → inboxes/resources/metrics/client/requests/QueryUsageRequest.js} +0 -0
  101. /package/dist/cjs/api/resources/{pods/resources/metrics/client/requests/QueryMetricsRequest.js → metrics/client/requests/QueryEventsRequest.js} +0 -0
  102. /package/dist/esm/api/resources/inboxes/resources/metrics/client/requests/{QueryMetricsRequest.mjs → QueryEventsRequest.mjs} +0 -0
  103. /package/dist/esm/api/resources/{metrics/client/requests/QueryMetricsRequest.mjs → inboxes/resources/metrics/client/requests/QueryUsageRequest.mjs} +0 -0
  104. /package/dist/esm/api/resources/{pods/resources/metrics/client/requests/QueryMetricsRequest.mjs → metrics/client/requests/QueryEventsRequest.mjs} +0 -0
@@ -22,24 +22,30 @@ export class MetricsClient {
22
22
  this._options = normalizeClientOptionsWithAuth(options);
23
23
  }
24
24
  /**
25
+ * Counts of email events (sent, delivered, bounced, etc.) over time for
26
+ * the inbox. Defaults to the last 24 hours; `start` must be within the
27
+ * last 90 days, and a future `end` is clamped to now. Omit `period` for
28
+ * individual event counts, or set it to sum counts into buckets of that
29
+ * many seconds.
30
+ *
25
31
  * **CLI:**
26
32
  * ```bash
27
33
  * agentmail inboxes:metrics query --inbox-id <inbox_id>
28
34
  * ```
29
35
  *
30
36
  * @param {AgentMail.inboxes.InboxId} inbox_id
31
- * @param {AgentMail.inboxes.QueryMetricsRequest} request
37
+ * @param {AgentMail.inboxes.QueryEventsRequest} request
32
38
  * @param {MetricsClient.RequestOptions} requestOptions - Request-specific configuration.
33
39
  *
34
40
  * @throws {@link AgentMail.ValidationError}
35
41
  *
36
42
  * @example
37
- * await client.inboxes.metrics.query("inbox_id")
43
+ * await client.inboxes.metrics.queryEvents("inbox_id")
38
44
  */
39
- query(inbox_id, request = {}, requestOptions) {
40
- return core.HttpResponsePromise.fromPromise(this.__query(inbox_id, request, requestOptions));
45
+ queryEvents(inbox_id, request = {}, requestOptions) {
46
+ return core.HttpResponsePromise.fromPromise(this.__queryEvents(inbox_id, request, requestOptions));
41
47
  }
42
- __query(inbox_id_1) {
48
+ __queryEvents(inbox_id_1) {
43
49
  return __awaiter(this, arguments, void 0, function* (inbox_id, request = {}, requestOptions) {
44
50
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
45
51
  const { eventTypes, start, end, period, limit, descending } = request;
@@ -64,7 +70,7 @@ export class MetricsClient {
64
70
  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);
65
71
  const _response = yield core.fetcher({
66
72
  url: core.url.join((_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : ((_c = (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.AgentMailEnvironment.Prod)
67
- .http, `/v0/inboxes/${core.url.encodePathParam(serializers.inboxes.InboxId.jsonOrThrow(inbox_id, { omitUndefined: true }))}/metrics`),
73
+ .http, `/v0/inboxes/${core.url.encodePathParam(serializers.inboxes.InboxId.jsonOrThrow(inbox_id, { omitUndefined: true }))}/metrics/events`),
68
74
  method: "GET",
69
75
  headers: _headers,
70
76
  queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
@@ -104,7 +110,96 @@ export class MetricsClient {
104
110
  });
105
111
  }
106
112
  }
107
- return handleNonStatusCodeError(_response.error, _response.rawResponse, "GET", "/v0/inboxes/{inbox_id}/metrics");
113
+ return handleNonStatusCodeError(_response.error, _response.rawResponse, "GET", "/v0/inboxes/{inbox_id}/metrics/events");
114
+ });
115
+ }
116
+ /**
117
+ * Cumulative usage series for the inbox. Each point is the running total
118
+ * of the usage type at that timestamp, not the change within the bucket.
119
+ * Inbox-scoped queries carry `storage_bytes`, `message_count`, and
120
+ * `thread_count`; requested types that don't apply to the scope are
121
+ * ignored. Defaults to the last 24 hours; `start` must be within the
122
+ * last 90 days, and a future `end` is clamped to now. The range divided
123
+ * by `period` must not exceed 1000 buckets.
124
+ *
125
+ * @param {AgentMail.inboxes.InboxId} inbox_id
126
+ * @param {AgentMail.inboxes.QueryUsageRequest} request
127
+ * @param {MetricsClient.RequestOptions} requestOptions - Request-specific configuration.
128
+ *
129
+ * @throws {@link AgentMail.ValidationError}
130
+ *
131
+ * @example
132
+ * await client.inboxes.metrics.queryUsage("inbox_id")
133
+ */
134
+ queryUsage(inbox_id, request = {}, requestOptions) {
135
+ return core.HttpResponsePromise.fromPromise(this.__queryUsage(inbox_id, request, requestOptions));
136
+ }
137
+ __queryUsage(inbox_id_1) {
138
+ return __awaiter(this, arguments, void 0, function* (inbox_id, request = {}, requestOptions) {
139
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
140
+ const { usageTypes, start, end, period, limit, descending } = request;
141
+ const _queryParams = {
142
+ usage_types: usageTypes != null
143
+ ? toJson(serializers.UsageTypes.jsonOrThrow(usageTypes, {
144
+ unrecognizedObjectKeys: "strip",
145
+ omitUndefined: true,
146
+ }))
147
+ : undefined,
148
+ start: start != null
149
+ ? serializers.Start.jsonOrThrow(start, { unrecognizedObjectKeys: "strip", omitUndefined: true })
150
+ : undefined,
151
+ end: end != null
152
+ ? serializers.End.jsonOrThrow(end, { unrecognizedObjectKeys: "strip", omitUndefined: true })
153
+ : undefined,
154
+ period,
155
+ limit,
156
+ descending,
157
+ };
158
+ const _authRequest = yield this._options.authProvider.getAuthRequest();
159
+ 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);
160
+ const _response = yield core.fetcher({
161
+ url: core.url.join((_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : ((_c = (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.AgentMailEnvironment.Prod)
162
+ .http, `/v0/inboxes/${core.url.encodePathParam(serializers.inboxes.InboxId.jsonOrThrow(inbox_id, { omitUndefined: true }))}/metrics/usage`),
163
+ method: "GET",
164
+ headers: _headers,
165
+ queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
166
+ timeoutMs: ((_f = (_d = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _d !== void 0 ? _d : (_e = this._options) === null || _e === void 0 ? void 0 : _e.timeoutInSeconds) !== null && _f !== void 0 ? _f : 60) * 1000,
167
+ maxRetries: (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.maxRetries,
168
+ abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
169
+ fetchFn: (_j = this._options) === null || _j === void 0 ? void 0 : _j.fetch,
170
+ logging: this._options.logging,
171
+ });
172
+ if (_response.ok) {
173
+ return {
174
+ data: serializers.QueryUsageResponse.parseOrThrow(_response.body, {
175
+ unrecognizedObjectKeys: "passthrough",
176
+ allowUnrecognizedUnionMembers: true,
177
+ allowUnrecognizedEnumValues: true,
178
+ skipValidation: true,
179
+ breadcrumbsPrefix: ["response"],
180
+ }),
181
+ rawResponse: _response.rawResponse,
182
+ };
183
+ }
184
+ if (_response.error.reason === "status-code") {
185
+ switch (_response.error.statusCode) {
186
+ case 400:
187
+ throw new AgentMail.ValidationError(serializers.ValidationErrorResponse.parseOrThrow(_response.error.body, {
188
+ unrecognizedObjectKeys: "passthrough",
189
+ allowUnrecognizedUnionMembers: true,
190
+ allowUnrecognizedEnumValues: true,
191
+ skipValidation: true,
192
+ breadcrumbsPrefix: ["response"],
193
+ }), _response.rawResponse);
194
+ default:
195
+ throw new errors.AgentMailError({
196
+ statusCode: _response.error.statusCode,
197
+ body: _response.error.body,
198
+ rawResponse: _response.rawResponse,
199
+ });
200
+ }
201
+ }
202
+ return handleNonStatusCodeError(_response.error, _response.rawResponse, "GET", "/v0/inboxes/{inbox_id}/metrics/usage");
108
203
  });
109
204
  }
110
205
  }
@@ -3,7 +3,7 @@ import type * as AgentMail from "../../../../../../index.mjs";
3
3
  * @example
4
4
  * {}
5
5
  */
6
- export interface QueryMetricsRequest {
6
+ export interface QueryEventsRequest {
7
7
  eventTypes?: AgentMail.MetricEventTypes;
8
8
  start?: AgentMail.Start;
9
9
  end?: AgentMail.End;
@@ -0,0 +1,13 @@
1
+ import type * as AgentMail from "../../../../../../index.mjs";
2
+ /**
3
+ * @example
4
+ * {}
5
+ */
6
+ export interface QueryUsageRequest {
7
+ usageTypes?: AgentMail.UsageTypes;
8
+ start?: AgentMail.Start;
9
+ end?: AgentMail.End;
10
+ period?: AgentMail.Period;
11
+ limit?: AgentMail.MetricLimit;
12
+ descending?: AgentMail.Descending;
13
+ }
@@ -1 +1,2 @@
1
- export type { QueryMetricsRequest } from "./QueryMetricsRequest.mjs";
1
+ export type { QueryEventsRequest } from "./QueryEventsRequest.mjs";
2
+ export type { QueryUsageRequest } from "./QueryUsageRequest.mjs";
@@ -11,19 +11,42 @@ export declare class MetricsClient {
11
11
  protected readonly _options: NormalizedClientOptionsWithAuth<MetricsClient.Options>;
12
12
  constructor(options?: MetricsClient.Options);
13
13
  /**
14
+ * Counts of email events (sent, delivered, bounced, etc.) over time for
15
+ * the organization. Defaults to the last 24 hours; `start` must be within
16
+ * the last 90 days, and a future `end` is clamped to now. Omit `period`
17
+ * for individual event counts, or set it to sum counts into buckets of
18
+ * that many seconds.
19
+ *
14
20
  * **CLI:**
15
21
  * ```bash
16
22
  * agentmail metrics list
17
23
  * ```
18
24
  *
19
- * @param {AgentMail.QueryMetricsRequest} request
25
+ * @param {AgentMail.QueryEventsRequest} request
26
+ * @param {MetricsClient.RequestOptions} requestOptions - Request-specific configuration.
27
+ *
28
+ * @throws {@link AgentMail.ValidationError}
29
+ *
30
+ * @example
31
+ * await client.metrics.queryEvents()
32
+ */
33
+ queryEvents(request?: AgentMail.QueryEventsRequest, requestOptions?: MetricsClient.RequestOptions): core.HttpResponsePromise<AgentMail.QueryMetricsResponse>;
34
+ private __queryEvents;
35
+ /**
36
+ * Cumulative usage series for the organization. Each point is the running
37
+ * total of the usage type at that timestamp, not the change within the
38
+ * bucket. Defaults to the last 24 hours; `start` must be within the last
39
+ * 90 days, and a future `end` is clamped to now. The range divided by
40
+ * `period` must not exceed 1000 buckets.
41
+ *
42
+ * @param {AgentMail.QueryUsageRequest} request
20
43
  * @param {MetricsClient.RequestOptions} requestOptions - Request-specific configuration.
21
44
  *
22
45
  * @throws {@link AgentMail.ValidationError}
23
46
  *
24
47
  * @example
25
- * await client.metrics.query()
48
+ * await client.metrics.queryUsage()
26
49
  */
27
- query(request?: AgentMail.QueryMetricsRequest, requestOptions?: MetricsClient.RequestOptions): core.HttpResponsePromise<AgentMail.QueryMetricsResponse>;
28
- private __query;
50
+ queryUsage(request?: AgentMail.QueryUsageRequest, requestOptions?: MetricsClient.RequestOptions): core.HttpResponsePromise<AgentMail.QueryUsageResponse>;
51
+ private __queryUsage;
29
52
  }
@@ -22,23 +22,29 @@ export class MetricsClient {
22
22
  this._options = normalizeClientOptionsWithAuth(options);
23
23
  }
24
24
  /**
25
+ * Counts of email events (sent, delivered, bounced, etc.) over time for
26
+ * the organization. Defaults to the last 24 hours; `start` must be within
27
+ * the last 90 days, and a future `end` is clamped to now. Omit `period`
28
+ * for individual event counts, or set it to sum counts into buckets of
29
+ * that many seconds.
30
+ *
25
31
  * **CLI:**
26
32
  * ```bash
27
33
  * agentmail metrics list
28
34
  * ```
29
35
  *
30
- * @param {AgentMail.QueryMetricsRequest} request
36
+ * @param {AgentMail.QueryEventsRequest} request
31
37
  * @param {MetricsClient.RequestOptions} requestOptions - Request-specific configuration.
32
38
  *
33
39
  * @throws {@link AgentMail.ValidationError}
34
40
  *
35
41
  * @example
36
- * await client.metrics.query()
42
+ * await client.metrics.queryEvents()
37
43
  */
38
- query(request = {}, requestOptions) {
39
- return core.HttpResponsePromise.fromPromise(this.__query(request, requestOptions));
44
+ queryEvents(request = {}, requestOptions) {
45
+ return core.HttpResponsePromise.fromPromise(this.__queryEvents(request, requestOptions));
40
46
  }
41
- __query() {
47
+ __queryEvents() {
42
48
  return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) {
43
49
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
44
50
  const { eventTypes, start, end, period, limit, descending } = request;
@@ -63,7 +69,7 @@ export class MetricsClient {
63
69
  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);
64
70
  const _response = yield core.fetcher({
65
71
  url: core.url.join((_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : ((_c = (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.AgentMailEnvironment.Prod)
66
- .http, "/v0/metrics"),
72
+ .http, "/v0/metrics/events"),
67
73
  method: "GET",
68
74
  headers: _headers,
69
75
  queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
@@ -103,7 +109,93 @@ export class MetricsClient {
103
109
  });
104
110
  }
105
111
  }
106
- return handleNonStatusCodeError(_response.error, _response.rawResponse, "GET", "/v0/metrics");
112
+ return handleNonStatusCodeError(_response.error, _response.rawResponse, "GET", "/v0/metrics/events");
113
+ });
114
+ }
115
+ /**
116
+ * Cumulative usage series for the organization. Each point is the running
117
+ * total of the usage type at that timestamp, not the change within the
118
+ * bucket. Defaults to the last 24 hours; `start` must be within the last
119
+ * 90 days, and a future `end` is clamped to now. The range divided by
120
+ * `period` must not exceed 1000 buckets.
121
+ *
122
+ * @param {AgentMail.QueryUsageRequest} request
123
+ * @param {MetricsClient.RequestOptions} requestOptions - Request-specific configuration.
124
+ *
125
+ * @throws {@link AgentMail.ValidationError}
126
+ *
127
+ * @example
128
+ * await client.metrics.queryUsage()
129
+ */
130
+ queryUsage(request = {}, requestOptions) {
131
+ return core.HttpResponsePromise.fromPromise(this.__queryUsage(request, requestOptions));
132
+ }
133
+ __queryUsage() {
134
+ return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) {
135
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
136
+ const { usageTypes, start, end, period, limit, descending } = request;
137
+ const _queryParams = {
138
+ usage_types: usageTypes != null
139
+ ? toJson(serializers.UsageTypes.jsonOrThrow(usageTypes, {
140
+ unrecognizedObjectKeys: "strip",
141
+ omitUndefined: true,
142
+ }))
143
+ : undefined,
144
+ start: start != null
145
+ ? serializers.Start.jsonOrThrow(start, { unrecognizedObjectKeys: "strip", omitUndefined: true })
146
+ : undefined,
147
+ end: end != null
148
+ ? serializers.End.jsonOrThrow(end, { unrecognizedObjectKeys: "strip", omitUndefined: true })
149
+ : undefined,
150
+ period,
151
+ limit,
152
+ descending,
153
+ };
154
+ const _authRequest = yield this._options.authProvider.getAuthRequest();
155
+ 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);
156
+ const _response = yield core.fetcher({
157
+ url: core.url.join((_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : ((_c = (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.AgentMailEnvironment.Prod)
158
+ .http, "/v0/metrics/usage"),
159
+ method: "GET",
160
+ headers: _headers,
161
+ queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
162
+ timeoutMs: ((_f = (_d = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _d !== void 0 ? _d : (_e = this._options) === null || _e === void 0 ? void 0 : _e.timeoutInSeconds) !== null && _f !== void 0 ? _f : 60) * 1000,
163
+ maxRetries: (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.maxRetries,
164
+ abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
165
+ fetchFn: (_j = this._options) === null || _j === void 0 ? void 0 : _j.fetch,
166
+ logging: this._options.logging,
167
+ });
168
+ if (_response.ok) {
169
+ return {
170
+ data: serializers.QueryUsageResponse.parseOrThrow(_response.body, {
171
+ unrecognizedObjectKeys: "passthrough",
172
+ allowUnrecognizedUnionMembers: true,
173
+ allowUnrecognizedEnumValues: true,
174
+ skipValidation: true,
175
+ breadcrumbsPrefix: ["response"],
176
+ }),
177
+ rawResponse: _response.rawResponse,
178
+ };
179
+ }
180
+ if (_response.error.reason === "status-code") {
181
+ switch (_response.error.statusCode) {
182
+ case 400:
183
+ throw new AgentMail.ValidationError(serializers.ValidationErrorResponse.parseOrThrow(_response.error.body, {
184
+ unrecognizedObjectKeys: "passthrough",
185
+ allowUnrecognizedUnionMembers: true,
186
+ allowUnrecognizedEnumValues: true,
187
+ skipValidation: true,
188
+ breadcrumbsPrefix: ["response"],
189
+ }), _response.rawResponse);
190
+ default:
191
+ throw new errors.AgentMailError({
192
+ statusCode: _response.error.statusCode,
193
+ body: _response.error.body,
194
+ rawResponse: _response.rawResponse,
195
+ });
196
+ }
197
+ }
198
+ return handleNonStatusCodeError(_response.error, _response.rawResponse, "GET", "/v0/metrics/usage");
107
199
  });
108
200
  }
109
201
  }
@@ -3,7 +3,7 @@ import type * as AgentMail from "../../../../index.mjs";
3
3
  * @example
4
4
  * {}
5
5
  */
6
- export interface QueryMetricsRequest {
6
+ export interface QueryEventsRequest {
7
7
  eventTypes?: AgentMail.MetricEventTypes;
8
8
  start?: AgentMail.Start;
9
9
  end?: AgentMail.End;
@@ -0,0 +1,13 @@
1
+ import type * as AgentMail from "../../../../index.mjs";
2
+ /**
3
+ * @example
4
+ * {}
5
+ */
6
+ export interface QueryUsageRequest {
7
+ usageTypes?: AgentMail.UsageTypes;
8
+ start?: AgentMail.Start;
9
+ end?: AgentMail.End;
10
+ period?: AgentMail.Period;
11
+ limit?: AgentMail.MetricLimit;
12
+ descending?: AgentMail.Descending;
13
+ }
@@ -0,0 +1,2 @@
1
+ // This file was auto-generated by Fern from our API Definition.
2
+ export {};
@@ -1 +1,2 @@
1
- export type { QueryMetricsRequest } from "./QueryMetricsRequest.mjs";
1
+ export type { QueryEventsRequest } from "./QueryEventsRequest.mjs";
2
+ export type { QueryUsageRequest } from "./QueryUsageRequest.mjs";
@@ -1,11 +1,14 @@
1
1
  /** Type of metric event. */
2
2
  export declare const MetricEventType: {
3
+ readonly MessageReceived: "message.received";
4
+ readonly MessageReceivedSpam: "message.received.spam";
5
+ readonly MessageReceivedBlocked: "message.received.blocked";
6
+ readonly MessageReceivedUnauthenticated: "message.received.unauthenticated";
3
7
  readonly MessageSent: "message.sent";
4
8
  readonly MessageDelivered: "message.delivered";
5
9
  readonly MessageBounced: "message.bounced";
6
- readonly MessageDelayed: "message.delayed";
7
- readonly MessageRejected: "message.rejected";
8
10
  readonly MessageComplained: "message.complained";
9
- readonly MessageReceived: "message.received";
11
+ readonly MessageRejected: "message.rejected";
12
+ readonly DomainVerified: "domain.verified";
10
13
  };
11
14
  export type MetricEventType = (typeof MetricEventType)[keyof typeof MetricEventType];
@@ -1,11 +1,14 @@
1
1
  // This file was auto-generated by Fern from our API Definition.
2
2
  /** Type of metric event. */
3
3
  export const MetricEventType = {
4
+ MessageReceived: "message.received",
5
+ MessageReceivedSpam: "message.received.spam",
6
+ MessageReceivedBlocked: "message.received.blocked",
7
+ MessageReceivedUnauthenticated: "message.received.unauthenticated",
4
8
  MessageSent: "message.sent",
5
9
  MessageDelivered: "message.delivered",
6
10
  MessageBounced: "message.bounced",
7
- MessageDelayed: "message.delayed",
8
- MessageRejected: "message.rejected",
9
11
  MessageComplained: "message.complained",
10
- MessageReceived: "message.received",
12
+ MessageRejected: "message.rejected",
13
+ DomainVerified: "domain.verified",
11
14
  };
@@ -1,4 +1,4 @@
1
1
  /**
2
- * Period in number of seconds for the query.
2
+ * Size of each time bucket as a whole number of seconds, between 1 and 86400.
3
3
  */
4
- export type Period = string;
4
+ export type Period = number;
@@ -0,0 +1,5 @@
1
+ import type * as AgentMail from "../../../index.mjs";
2
+ /**
3
+ * Cumulative usage series grouped by usage type.
4
+ */
5
+ export type QueryUsageResponse = Partial<Record<AgentMail.UsageType, AgentMail.UsagePoint[]>>;
@@ -0,0 +1,2 @@
1
+ // This file was auto-generated by Fern from our API Definition.
2
+ export {};
@@ -0,0 +1,6 @@
1
+ export interface UsagePoint {
2
+ /** Timestamp of the point. */
3
+ timestamp: Date;
4
+ /** Cumulative value of the usage metric at the timestamp. */
5
+ value: number;
6
+ }
@@ -0,0 +1,2 @@
1
+ // This file was auto-generated by Fern from our API Definition.
2
+ export {};
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Type of usage metric. Inbox-scoped queries carry `storage_bytes`,
3
+ * `message_count`, and `thread_count`; pod-scoped queries add `inbox_count`
4
+ * and `domain_count`; organization-scoped queries add `pod_count`.
5
+ */
6
+ export declare const UsageType: {
7
+ readonly StorageBytes: "storage_bytes";
8
+ readonly MessageCount: "message_count";
9
+ readonly ThreadCount: "thread_count";
10
+ readonly InboxCount: "inbox_count";
11
+ readonly PodCount: "pod_count";
12
+ readonly DomainCount: "domain_count";
13
+ };
14
+ export type UsageType = (typeof UsageType)[keyof typeof UsageType];
@@ -0,0 +1,14 @@
1
+ // This file was auto-generated by Fern from our API Definition.
2
+ /**
3
+ * Type of usage metric. Inbox-scoped queries carry `storage_bytes`,
4
+ * `message_count`, and `thread_count`; pod-scoped queries add `inbox_count`
5
+ * and `domain_count`; organization-scoped queries add `pod_count`.
6
+ */
7
+ export const UsageType = {
8
+ StorageBytes: "storage_bytes",
9
+ MessageCount: "message_count",
10
+ ThreadCount: "thread_count",
11
+ InboxCount: "inbox_count",
12
+ PodCount: "pod_count",
13
+ DomainCount: "domain_count",
14
+ };
@@ -0,0 +1,5 @@
1
+ import type * as AgentMail from "../../../index.mjs";
2
+ /**
3
+ * List of usage metric types to query. Omit to query every type valid for the scope.
4
+ */
5
+ export type UsageTypes = AgentMail.UsageType[];
@@ -0,0 +1,2 @@
1
+ // This file was auto-generated by Fern from our API Definition.
2
+ export {};
@@ -6,4 +6,8 @@ export * from "./MetricEventTypes.mjs";
6
6
  export * from "./MetricLimit.mjs";
7
7
  export * from "./Period.mjs";
8
8
  export * from "./QueryMetricsResponse.mjs";
9
+ export * from "./QueryUsageResponse.mjs";
9
10
  export * from "./Start.mjs";
11
+ export * from "./UsagePoint.mjs";
12
+ export * from "./UsageType.mjs";
13
+ export * from "./UsageTypes.mjs";
@@ -6,4 +6,8 @@ export * from "./MetricEventTypes.mjs";
6
6
  export * from "./MetricLimit.mjs";
7
7
  export * from "./Period.mjs";
8
8
  export * from "./QueryMetricsResponse.mjs";
9
+ export * from "./QueryUsageResponse.mjs";
9
10
  export * from "./Start.mjs";
11
+ export * from "./UsagePoint.mjs";
12
+ export * from "./UsageType.mjs";
13
+ export * from "./UsageTypes.mjs";
@@ -11,20 +11,46 @@ export declare class MetricsClient {
11
11
  protected readonly _options: NormalizedClientOptionsWithAuth<MetricsClient.Options>;
12
12
  constructor(options?: MetricsClient.Options);
13
13
  /**
14
+ * Counts of email events (sent, delivered, bounced, etc.) over time for
15
+ * the pod. Defaults to the last 24 hours; `start` must be within the last
16
+ * 90 days, and a future `end` is clamped to now. Omit `period` for
17
+ * individual event counts, or set it to sum counts into buckets of that
18
+ * many seconds.
19
+ *
14
20
  * **CLI:**
15
21
  * ```bash
16
22
  * agentmail pods:metrics query --pod-id <pod_id>
17
23
  * ```
18
24
  *
19
25
  * @param {AgentMail.pods.PodId} pod_id
20
- * @param {AgentMail.pods.QueryMetricsRequest} request
26
+ * @param {AgentMail.pods.QueryEventsRequest} request
27
+ * @param {MetricsClient.RequestOptions} requestOptions - Request-specific configuration.
28
+ *
29
+ * @throws {@link AgentMail.ValidationError}
30
+ *
31
+ * @example
32
+ * await client.pods.metrics.queryEvents("pod_id")
33
+ */
34
+ queryEvents(pod_id: AgentMail.pods.PodId, request?: AgentMail.pods.QueryEventsRequest, requestOptions?: MetricsClient.RequestOptions): core.HttpResponsePromise<AgentMail.QueryMetricsResponse>;
35
+ private __queryEvents;
36
+ /**
37
+ * Cumulative usage series for the pod. Each point is the running total of
38
+ * the usage type at that timestamp, not the change within the bucket.
39
+ * Pod-scoped queries carry every usage type except `pod_count`; requested
40
+ * types that don't apply to the scope are ignored. Defaults to the last
41
+ * 24 hours; `start` must be within the last 90 days, and a future `end`
42
+ * is clamped to now. The range divided by `period` must not exceed 1000
43
+ * buckets.
44
+ *
45
+ * @param {AgentMail.pods.PodId} pod_id
46
+ * @param {AgentMail.pods.QueryUsageRequest} request
21
47
  * @param {MetricsClient.RequestOptions} requestOptions - Request-specific configuration.
22
48
  *
23
49
  * @throws {@link AgentMail.ValidationError}
24
50
  *
25
51
  * @example
26
- * await client.pods.metrics.query("pod_id")
52
+ * await client.pods.metrics.queryUsage("pod_id")
27
53
  */
28
- query(pod_id: AgentMail.pods.PodId, request?: AgentMail.pods.QueryMetricsRequest, requestOptions?: MetricsClient.RequestOptions): core.HttpResponsePromise<AgentMail.QueryMetricsResponse>;
29
- private __query;
54
+ queryUsage(pod_id: AgentMail.pods.PodId, request?: AgentMail.pods.QueryUsageRequest, requestOptions?: MetricsClient.RequestOptions): core.HttpResponsePromise<AgentMail.QueryUsageResponse>;
55
+ private __queryUsage;
30
56
  }