@salesforce/b2c-tooling-sdk 1.18.0 → 1.19.1

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 (37) hide show
  1. package/dist/esm/clients/index.d.ts +2 -0
  2. package/dist/esm/clients/index.js +1 -0
  3. package/dist/esm/clients/index.js.map +1 -1
  4. package/dist/esm/clients/metrics.d.ts +123 -0
  5. package/dist/esm/clients/metrics.generated.d.ts +1016 -0
  6. package/dist/esm/clients/metrics.generated.js +6 -0
  7. package/dist/esm/clients/metrics.generated.js.map +1 -0
  8. package/dist/esm/clients/metrics.js +65 -0
  9. package/dist/esm/clients/metrics.js.map +1 -0
  10. package/dist/esm/clients/middleware-registry.d.ts +1 -1
  11. package/dist/esm/clients/middleware-registry.js.map +1 -1
  12. package/dist/esm/discovery/detector.d.ts +1 -0
  13. package/dist/esm/discovery/detector.js +3 -1
  14. package/dist/esm/discovery/detector.js.map +1 -1
  15. package/dist/esm/discovery/index.d.ts +1 -1
  16. package/dist/esm/discovery/patterns/cartridges.js +4 -2
  17. package/dist/esm/discovery/patterns/cartridges.js.map +1 -1
  18. package/dist/esm/discovery/patterns/sfra.js +10 -5
  19. package/dist/esm/discovery/patterns/sfra.js.map +1 -1
  20. package/dist/esm/discovery/types.d.ts +20 -1
  21. package/dist/esm/index.d.ts +4 -2
  22. package/dist/esm/index.js +3 -1
  23. package/dist/esm/index.js.map +1 -1
  24. package/dist/esm/operations/code/cartridges.d.ts +18 -0
  25. package/dist/esm/operations/code/cartridges.js +31 -20
  26. package/dist/esm/operations/code/cartridges.js.map +1 -1
  27. package/dist/esm/operations/logs/filter.d.ts +6 -1
  28. package/dist/esm/operations/logs/filter.js +7 -2
  29. package/dist/esm/operations/logs/filter.js.map +1 -1
  30. package/dist/esm/operations/metrics/index.d.ts +371 -0
  31. package/dist/esm/operations/metrics/index.js +478 -0
  32. package/dist/esm/operations/metrics/index.js.map +1 -0
  33. package/dist/esm/operations/metrics/tags.d.ts +148 -0
  34. package/dist/esm/operations/metrics/tags.js +235 -0
  35. package/dist/esm/operations/metrics/tags.js.map +1 -0
  36. package/package.json +6 -2
  37. package/specs/metrics-v1.json +1713 -0
@@ -0,0 +1,371 @@
1
+ /**
2
+ * Metrics operations for B2C Commerce (Observability).
3
+ *
4
+ * This module provides typed, high-level functions for retrieving operational
5
+ * time-series metrics from the SCAPI Observability Metrics API
6
+ * (`observability/metrics/v1`). Each metric *category* has its own function; all
7
+ * return the same {@link MetricsDataResponse} envelope.
8
+ *
9
+ * ## Categories
10
+ *
11
+ * - {@link getOverallMetrics} — overall application metrics
12
+ * - {@link getSalesMetrics} — sales metrics
13
+ * - {@link getEcdnMetrics} — embedded CDN metrics
14
+ * - {@link getThirdPartyMetrics} — third-party service call metrics (filterable by service)
15
+ * - {@link getScapiMetrics} — SCAPI request metrics (filterable by API family/name)
16
+ * - {@link getScapiHooksMetrics} — SCAPI hook execution metrics
17
+ * - {@link getMrtMetrics} — Managed Runtime metrics
18
+ * - {@link getControllerMetrics} — controller/pipeline metrics
19
+ * - {@link getOcapiMetrics} — OCAPI request metrics (filterable by category/api)
20
+ *
21
+ * {@link getMetricsByCategory} dispatches to the correct function by category
22
+ * name — convenient for CLIs and tools that take a category as input.
23
+ *
24
+ * ## Usage
25
+ *
26
+ * ```typescript
27
+ * import {createMetricsClient} from '@salesforce/b2c-tooling-sdk/clients';
28
+ * import {getOverallMetrics} from '@salesforce/b2c-tooling-sdk/operations/metrics';
29
+ *
30
+ * const client = createMetricsClient({shortCode, tenantId}, auth);
31
+ * const result = await getOverallMetrics(client, tenantId, {from, to});
32
+ * for (const metric of result.data) {
33
+ * console.log(metric.title, metric.dataSeries.length);
34
+ * }
35
+ * ```
36
+ *
37
+ * ## Authentication
38
+ *
39
+ * Requires OAuth client-credentials with the `sfcc.metrics` admin scope. The
40
+ * {@link createMetricsClient} factory attaches this scope plus the tenant scope
41
+ * automatically.
42
+ *
43
+ * @module operations/metrics
44
+ */
45
+ import type { MetricsClient, MetricsDataResponse } from '../../clients/metrics.js';
46
+ export type { MetricsClient, MetricsClientConfig, MetricsDataResponse, Metric, MetricDataSeries, MetricDataPoint, MetricsError, } from '../../clients/metrics.js';
47
+ /**
48
+ * All metric categories exposed by the Metrics API, in a stable, documented order.
49
+ *
50
+ * Values match the API path segments (e.g. `overall` → `/metrics/overall`).
51
+ */
52
+ export declare const METRIC_CATEGORIES: readonly ["overall", "sales", "ecdn", "third-party", "scapi", "scapi-hooks", "mrt", "controller", "ocapi"];
53
+ /**
54
+ * A metric category name. One of {@link METRIC_CATEGORIES}.
55
+ */
56
+ export type MetricCategory = (typeof METRIC_CATEGORIES)[number];
57
+ /**
58
+ * Time-window options common to every metrics operation.
59
+ *
60
+ * Accepts either a {@link Date} or a number of **epoch milliseconds** (the same
61
+ * unit as `Date.now()`), for both `from` and `to`. Both are optional; when
62
+ * omitted the API applies its default window. When both are supplied, `from`
63
+ * must be before `to` or the API returns a 400.
64
+ *
65
+ * > **Note:** The Metrics API wire format is epoch **seconds**, and the data
66
+ * > points it returns are timestamped in **seconds**. These operations convert
67
+ * > millisecond inputs to seconds on the way out and normalize response
68
+ * > timestamps back to **milliseconds** on the way in, so callers work in
69
+ * > JS-native millisecond time throughout (e.g. `new Date(point.timestamp)`).
70
+ */
71
+ export interface MetricsTimeWindow {
72
+ /** Start of the window — a {@link Date} or epoch milliseconds (inclusive). */
73
+ from?: Date | number;
74
+ /** End of the window — a {@link Date} or epoch milliseconds (inclusive). */
75
+ to?: Date | number;
76
+ }
77
+ /**
78
+ * Options for {@link getThirdPartyMetrics}: time window plus an optional
79
+ * third-party service filter.
80
+ */
81
+ export interface ThirdPartyMetricsOptions extends MetricsTimeWindow {
82
+ /** Restrict results to a single third-party service by its id. */
83
+ thirdPartyServiceId?: string;
84
+ }
85
+ /**
86
+ * Options for {@link getScapiMetrics}: time window plus optional SCAPI filters.
87
+ */
88
+ export interface ScapiMetricsOptions extends MetricsTimeWindow {
89
+ /** Restrict results to a SCAPI API family (e.g. `product`, `checkout`). */
90
+ apiFamily?: string;
91
+ /** Restrict results to a SCAPI API name (e.g. `shopper-products`). */
92
+ apiName?: string;
93
+ }
94
+ /**
95
+ * Options for {@link getOcapiMetrics}: time window plus optional OCAPI filters.
96
+ */
97
+ export interface OcapiMetricsOptions extends MetricsTimeWindow {
98
+ /** Restrict results to an OCAPI category (e.g. `shop`, `data`). */
99
+ ocapiCategory?: string;
100
+ /** Restrict results to a specific OCAPI API. */
101
+ ocapiApi?: string;
102
+ }
103
+ /**
104
+ * Union of every option shape accepted by {@link getMetricsByCategory}.
105
+ */
106
+ export type MetricsQueryOptions = MetricsTimeWindow & Partial<Pick<ThirdPartyMetricsOptions, 'thirdPartyServiceId'>> & Partial<Pick<ScapiMetricsOptions, 'apiFamily' | 'apiName'>> & Partial<Pick<OcapiMetricsOptions, 'ocapiCategory' | 'ocapiApi'>>;
107
+ /**
108
+ * How far back the Metrics API retains data: `from` must be no older than
109
+ * `serverNow - 30 days`, or the API returns 400.
110
+ */
111
+ export declare const METRICS_RETENTION_MS: number;
112
+ /**
113
+ * Default (and maximum) width of a metrics time window: 24 hours.
114
+ *
115
+ * The Metrics API pairs a request that omits `to` with its own `now` and then
116
+ * enforces a maximum window of `to - from ≤ 24h`, rejecting anything wider with a
117
+ * 400. An open-ended `from` older than 24h therefore always fails. To make the
118
+ * behavior predictable, {@link resolveMetricsWindow} fills in a 24-hour window
119
+ * (clamped so `to` never exceeds `now`) for any bound the caller leaves open, and
120
+ * always sends both `from` and `to`. This is only a *default* for derivation — an
121
+ * explicit `from`+`to` range wider than 24h is still sent as-is, letting the API
122
+ * remain authoritative and return its own error.
123
+ */
124
+ export declare const METRICS_DEFAULT_WINDOW_MS: number;
125
+ /**
126
+ * Safety margin kept *inside* the retention window when clamping `from`. Because
127
+ * the server evaluates retention against its own clock at request time, a `from`
128
+ * computed as exactly "30 days ago" on the client is reliably rejected once
129
+ * request latency and client/server clock skew are added. {@link resolveMetricsWindow}
130
+ * therefore clamps a `from` that lands within this margin of the retention floor
131
+ * up to `now - 30 days + margin`, so edge requests (e.g. `--from 30d`) succeed.
132
+ * 5 minutes comfortably covers latency and typical skew while costing a
133
+ * negligible fraction of the 30-day window.
134
+ */
135
+ export declare const METRICS_RETENTION_SAFETY_MARGIN_MS: number;
136
+ /**
137
+ * A metrics bound as accepted from a CLI flag or MCP argument: a {@link Date},
138
+ * epoch **milliseconds**, or a human string — a relative duration (`5m`, `1h`,
139
+ * `2d`, interpreted as "ago") or an ISO 8601 timestamp.
140
+ */
141
+ export type MetricsBoundInput = Date | number | string;
142
+ /**
143
+ * Parses a single metrics time bound (`from` or `to`) into a {@link Date}.
144
+ *
145
+ * This is the shared bound parser for the CLI `metrics get` command and the MCP
146
+ * `metrics_get` tool. It resolves a single bound in isolation; deriving the
147
+ * companion bound and applying the 24-hour default window is the job of
148
+ * {@link resolveMetricsWindow}.
149
+ *
150
+ * @param value - The bound: a Date, epoch milliseconds, a relative duration
151
+ * (`5m`/`1h`/`2d`, relative to `now`), or an ISO 8601 timestamp
152
+ * @param now - Reference time for relative durations (defaults to the current
153
+ * time; injectable for deterministic tests)
154
+ * @returns The resolved {@link Date}
155
+ * @throws TypeError if a string value is neither a valid relative duration nor
156
+ * a parseable ISO 8601 timestamp
157
+ *
158
+ * @example
159
+ * ```typescript
160
+ * const from = parseMetricsBound('2d'); // 2 days ago
161
+ * const to = parseMetricsBound('2026-01-25T12:00:00Z');
162
+ * await getSalesMetrics(client, tenantId, {from, to});
163
+ * ```
164
+ */
165
+ export declare function parseMetricsBound(value: MetricsBoundInput, now?: Date): Date;
166
+ /**
167
+ * Raw `from`/`to`/`window` inputs, as accepted from CLI flags or MCP arguments,
168
+ * before resolution. Any subset may be provided.
169
+ */
170
+ export interface MetricsWindowInput {
171
+ /** Start bound (Date, epoch ms, relative like `7d`, or ISO 8601). */
172
+ from?: MetricsBoundInput;
173
+ /** End bound (Date, epoch ms, relative like `6h`, or ISO 8601). */
174
+ to?: MetricsBoundInput;
175
+ /**
176
+ * Window duration as a relative string (`1h`, `30m`, `2d`) or a number of
177
+ * **milliseconds**. Combined with exactly one of `from`/`to` it derives the
178
+ * other bound; supplied alone it means "the last {window}".
179
+ */
180
+ window?: number | string;
181
+ }
182
+ /**
183
+ * A resolved metrics window. Both `from` and `to` are always present: the
184
+ * resolver derives whichever bound the caller left open using the 24-hour
185
+ * default window (see {@link METRICS_DEFAULT_WINDOW_MS}) and always sends an
186
+ * explicit range, so the request never depends on the server's implicit `to`.
187
+ * Epoch-second echoes are included for reporting.
188
+ */
189
+ export interface ResolvedMetricsWindow {
190
+ /** Resolved start bound. */
191
+ from: Date;
192
+ /** Resolved end bound. */
193
+ to: Date;
194
+ /** ISO 8601 form of {@link from}. */
195
+ fromIso: string;
196
+ /** ISO 8601 form of {@link to}. */
197
+ toIso: string;
198
+ /** Epoch **seconds** form of {@link from} (the API wire unit). */
199
+ fromEpochSeconds: number;
200
+ /** Epoch **seconds** form of {@link to} (the API wire unit). */
201
+ toEpochSeconds: number;
202
+ /**
203
+ * True when `from` was clamped forward to stay inside the retention window
204
+ * (see {@link METRICS_RETENTION_SAFETY_MARGIN_MS}). Surfaced so callers can
205
+ * report that the effective start differs slightly from what was requested.
206
+ */
207
+ clampedFrom: boolean;
208
+ /**
209
+ * True when a bound was derived from the 24-hour default window rather than
210
+ * supplied by the caller (e.g. `from` alone, `to` alone, or nothing at all).
211
+ * Surfaced so callers can note that the effective range was defaulted.
212
+ */
213
+ defaultedWindow: boolean;
214
+ }
215
+ /**
216
+ * Resolves `from`/`to`/`window` inputs into the concrete bounds to send to the
217
+ * Metrics API. This is the shared resolver for the CLI `metrics get` command and
218
+ * the MCP `metrics_get` tool, so both share identical, tested semantics.
219
+ *
220
+ * The resolver always produces an explicit `from`+`to` pair. The Metrics API
221
+ * pairs a request that omits `to` with its own `now` and enforces a 24-hour
222
+ * maximum window, so an open-ended `from` older than 24 hours always fails; to
223
+ * make the behavior predictable, any bound the caller leaves open is filled from
224
+ * the 24-hour default window (see {@link METRICS_DEFAULT_WINDOW_MS}) rather than
225
+ * relying on the server's implicit end.
226
+ *
227
+ * The `window` duration makes fixed-width lookbacks easy without hand-computing
228
+ * a second timestamp — e.g. "a 1-hour window starting 7 days ago" is
229
+ * `{from: '7d', window: '1h'}`. Resolution rules:
230
+ *
231
+ * - `from` + `to` — used as given; `window` must NOT also be set. An explicit
232
+ * range wider than the 24-hour maximum is still sent as-is, leaving the API to
233
+ * return its own error.
234
+ * - `from` + `window` — `to = from + window`.
235
+ * - `to` + `window` — `from = to - window`.
236
+ * - `window` only — the last `window`: `to = now`, `from = now - window`.
237
+ * - `from` only — a 24-hour window forward from `from`: `to = min(from + 24h, now)`.
238
+ * - `to` only — a 24-hour window back from `to`: `from = to - 24h`.
239
+ * - nothing — the last 24 hours: `to = now`, `from = now - 24h`.
240
+ *
241
+ * Bounds filled from the 24-hour default (the last three rules) set
242
+ * {@link ResolvedMetricsWindow.defaultedWindow}. Validation is structural
243
+ * (over-specification and `from` after `to`). Additionally, a `from` that lands
244
+ * at or beyond the 30-day retention floor is clamped *forward* to
245
+ * `now - 30 days + margin` (see {@link METRICS_RETENTION_SAFETY_MARGIN_MS}) so
246
+ * requests like `--from 30d` are not rejected by the server's own slightly-later
247
+ * clock; the clamp is applied before deriving the companion bound so the window
248
+ * width is preserved, only ever moves `from` toward `now`, and is reported via
249
+ * {@link ResolvedMetricsWindow.clampedFrom}.
250
+ *
251
+ * @param input - The raw `from`/`to`/`window` inputs
252
+ * @param now - Reference time for relative bounds, default/window modes, and the
253
+ * retention clamp (defaults to the current time; injectable for deterministic tests)
254
+ * @returns The resolved bounds plus ISO/epoch-second echoes and clamp/default flags
255
+ * @throws TypeError if a bound or the window string is unparseable
256
+ * @throws RangeError if all three are supplied, or the resolved `from` is after `to`
257
+ *
258
+ * @example
259
+ * ```typescript
260
+ * // A 1-hour window starting 7 days ago:
261
+ * const w = resolveMetricsWindow({from: '7d', window: '1h'});
262
+ * await getScapiMetrics(client, tenantId, {from: w.from, to: w.to});
263
+ * ```
264
+ */
265
+ export declare function resolveMetricsWindow(input?: MetricsWindowInput, now?: Date): ResolvedMetricsWindow;
266
+ /**
267
+ * Retrieves overall application metrics for an organization.
268
+ *
269
+ * @param client - Metrics API client from {@link createMetricsClient}
270
+ * @param tenantId - Tenant ID (with or without the `f_ecom_` prefix)
271
+ * @param options - Optional time window (epoch milliseconds)
272
+ * @returns The metrics data response
273
+ * @throws Error if the request fails
274
+ */
275
+ export declare function getOverallMetrics(client: MetricsClient, tenantId: string, options?: MetricsTimeWindow): Promise<MetricsDataResponse>;
276
+ /**
277
+ * Retrieves sales metrics for an organization.
278
+ *
279
+ * @param client - Metrics API client from {@link createMetricsClient}
280
+ * @param tenantId - Tenant ID (with or without the `f_ecom_` prefix)
281
+ * @param options - Optional time window (epoch milliseconds)
282
+ * @returns The metrics data response
283
+ * @throws Error if the request fails
284
+ */
285
+ export declare function getSalesMetrics(client: MetricsClient, tenantId: string, options?: MetricsTimeWindow): Promise<MetricsDataResponse>;
286
+ /**
287
+ * Retrieves embedded CDN (eCDN) metrics for an organization.
288
+ *
289
+ * @param client - Metrics API client from {@link createMetricsClient}
290
+ * @param tenantId - Tenant ID (with or without the `f_ecom_` prefix)
291
+ * @param options - Optional time window (epoch milliseconds)
292
+ * @returns The metrics data response
293
+ * @throws Error if the request fails
294
+ */
295
+ export declare function getEcdnMetrics(client: MetricsClient, tenantId: string, options?: MetricsTimeWindow): Promise<MetricsDataResponse>;
296
+ /**
297
+ * Retrieves third-party service call metrics for an organization.
298
+ *
299
+ * @param client - Metrics API client from {@link createMetricsClient}
300
+ * @param tenantId - Tenant ID (with or without the `f_ecom_` prefix)
301
+ * @param options - Optional time window and `thirdPartyServiceId` filter
302
+ * @returns The metrics data response
303
+ * @throws Error if the request fails
304
+ */
305
+ export declare function getThirdPartyMetrics(client: MetricsClient, tenantId: string, options?: ThirdPartyMetricsOptions): Promise<MetricsDataResponse>;
306
+ /**
307
+ * Retrieves SCAPI request metrics for an organization.
308
+ *
309
+ * @param client - Metrics API client from {@link createMetricsClient}
310
+ * @param tenantId - Tenant ID (with or without the `f_ecom_` prefix)
311
+ * @param options - Optional time window and `apiFamily`/`apiName` filters
312
+ * @returns The metrics data response
313
+ * @throws Error if the request fails
314
+ */
315
+ export declare function getScapiMetrics(client: MetricsClient, tenantId: string, options?: ScapiMetricsOptions): Promise<MetricsDataResponse>;
316
+ /**
317
+ * Retrieves SCAPI hook execution metrics for an organization.
318
+ *
319
+ * @param client - Metrics API client from {@link createMetricsClient}
320
+ * @param tenantId - Tenant ID (with or without the `f_ecom_` prefix)
321
+ * @param options - Optional time window (epoch milliseconds)
322
+ * @returns The metrics data response
323
+ * @throws Error if the request fails
324
+ */
325
+ export declare function getScapiHooksMetrics(client: MetricsClient, tenantId: string, options?: MetricsTimeWindow): Promise<MetricsDataResponse>;
326
+ /**
327
+ * Retrieves Managed Runtime (MRT) metrics for an organization.
328
+ *
329
+ * @param client - Metrics API client from {@link createMetricsClient}
330
+ * @param tenantId - Tenant ID (with or without the `f_ecom_` prefix)
331
+ * @param options - Optional time window (epoch milliseconds)
332
+ * @returns The metrics data response
333
+ * @throws Error if the request fails
334
+ */
335
+ export declare function getMrtMetrics(client: MetricsClient, tenantId: string, options?: MetricsTimeWindow): Promise<MetricsDataResponse>;
336
+ /**
337
+ * Retrieves controller/pipeline metrics for an organization.
338
+ *
339
+ * @param client - Metrics API client from {@link createMetricsClient}
340
+ * @param tenantId - Tenant ID (with or without the `f_ecom_` prefix)
341
+ * @param options - Optional time window (epoch milliseconds)
342
+ * @returns The metrics data response
343
+ * @throws Error if the request fails
344
+ */
345
+ export declare function getControllerMetrics(client: MetricsClient, tenantId: string, options?: MetricsTimeWindow): Promise<MetricsDataResponse>;
346
+ /**
347
+ * Retrieves OCAPI request metrics for an organization.
348
+ *
349
+ * @param client - Metrics API client from {@link createMetricsClient}
350
+ * @param tenantId - Tenant ID (with or without the `f_ecom_` prefix)
351
+ * @param options - Optional time window and `ocapiCategory`/`ocapiApi` filters
352
+ * @returns The metrics data response
353
+ * @throws Error if the request fails
354
+ */
355
+ export declare function getOcapiMetrics(client: MetricsClient, tenantId: string, options?: OcapiMetricsOptions): Promise<MetricsDataResponse>;
356
+ /**
357
+ * Retrieves metrics for a category by name, dispatching to the category-specific
358
+ * function. Category-specific filters (`thirdPartyServiceId`, `apiFamily`,
359
+ * `apiName`, `ocapiCategory`, `ocapiApi`) are applied only for the categories
360
+ * that support them and ignored otherwise.
361
+ *
362
+ * @param client - Metrics API client from {@link createMetricsClient}
363
+ * @param tenantId - Tenant ID (with or without the `f_ecom_` prefix)
364
+ * @param category - One of {@link METRIC_CATEGORIES}
365
+ * @param options - Optional time window and category-specific filters
366
+ * @returns The metrics data response
367
+ * @throws Error if the request fails or the category is unknown
368
+ */
369
+ export declare function getMetricsByCategory(client: MetricsClient, tenantId: string, category: MetricCategory, options?: MetricsQueryOptions): Promise<MetricsDataResponse>;
370
+ export { parseSeriesTags, enrichMetricsTags } from './tags.js';
371
+ export type { MetricSeriesTags, MetricsTagContext, MetricsTaggedResponse } from './tags.js';