@nexusm/sdk 5.0.0 → 5.1.0

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/dist/index.d.mts CHANGED
@@ -457,6 +457,21 @@ declare class HttpClient {
457
457
  * @returns The parsed response body.
458
458
  */
459
459
  patch<T>(path: string, data?: unknown, signal?: AbortSignal): Promise<T>;
460
+ /**
461
+ * Send a GET request and return the raw response body as a string.
462
+ *
463
+ * Intended for file-download endpoints (e.g. `GET /dashboard/export`) that
464
+ * return `text/csv` or `application/json` as a raw file stream rather than a
465
+ * JSON-parsed object. The retry and auth interceptors still apply; the
466
+ * response cache is intentionally bypassed (export payloads are not cacheable
467
+ * at the SDK layer).
468
+ *
469
+ * @param path - URL path relative to the base URL (e.g. `/dashboard/export`).
470
+ * @param params - Optional query parameters.
471
+ * @param signal - Optional {@link AbortSignal} to cancel the request.
472
+ * @returns The raw response body as a string.
473
+ */
474
+ getText(path: string, params?: Record<string, unknown>, signal?: AbortSignal): Promise<string>;
460
475
  /**
461
476
  * Send a DELETE request.
462
477
  *
@@ -2305,6 +2320,133 @@ declare class ErrorService extends BaseService {
2305
2320
  submit(data: ErrorReportRequest, options?: RequestOptions): Promise<ErrorReportResponse>;
2306
2321
  }
2307
2322
 
2323
+ /**
2324
+ * @module types/dashboard
2325
+ * @description Dashboard Service type definitions.
2326
+ *
2327
+ * Mirrors the Nexus API dashboard export contract:
2328
+ * - GET /v1/dashboard/export — download a dataset as CSV or JSON
2329
+ *
2330
+ * The export endpoint returns raw file content (text/csv or application/json),
2331
+ * not a JSON-parsed object. The SDK therefore exposes these types only for
2332
+ * the _request_ side; the return value is `string`.
2333
+ */
2334
+ /**
2335
+ * The set of exportable dashboard datasets.
2336
+ *
2337
+ * Must stay in sync with the backend `DashboardExportDataset` Literal:
2338
+ * - `quality_distribution` — Quality score bucket distribution
2339
+ * - `feedback_trend` — Feedback rating trend over time
2340
+ * - `diagnosis_stats` — Diagnosis type statistics
2341
+ * - `feedback_health` — Overall feedback health metrics
2342
+ * - `error_heatmap` — Error frequency heatmap by endpoint / time
2343
+ * - `ab_distribution` — A/B experiment assignment distribution
2344
+ */
2345
+ type DashboardExportDataset = 'quality_distribution' | 'feedback_trend' | 'diagnosis_stats' | 'feedback_health' | 'error_heatmap' | 'ab_distribution';
2346
+ /**
2347
+ * Query parameters for `GET /v1/dashboard/export`.
2348
+ */
2349
+ interface DashboardExportParams {
2350
+ /**
2351
+ * The dataset to export. Required.
2352
+ *
2353
+ * Must be one of the six whitelisted values ({@link DashboardExportDataset}).
2354
+ * The backend returns HTTP 422 for unknown values.
2355
+ */
2356
+ dataset: DashboardExportDataset;
2357
+ /**
2358
+ * File format for the exported data.
2359
+ *
2360
+ * - `'csv'` — Comma-separated values (default when omitted).
2361
+ * - `'json'` — Raw JSON text (not parsed; returned as a string by the SDK).
2362
+ *
2363
+ * @default 'csv'
2364
+ */
2365
+ format?: 'csv' | 'json';
2366
+ /**
2367
+ * Filter results to a specific tenant.
2368
+ *
2369
+ * Only usable by API keys that carry the admin scope. The backend returns
2370
+ * HTTP 403 when this field is present but the caller lacks admin privileges,
2371
+ * and HTTP 400 when the value is not a valid UUID (it is normalized to
2372
+ * canonical form server-side).
2373
+ */
2374
+ target_tenant_id?: string;
2375
+ }
2376
+
2377
+ /**
2378
+ * @module services/dashboard
2379
+ * @description Dashboard Service — export analytics datasets.
2380
+ *
2381
+ * Wraps the Nexus Dashboard API:
2382
+ * - GET /v1/dashboard/export — download a dataset as raw CSV or JSON text
2383
+ *
2384
+ * The export endpoint is a file-download endpoint: the backend responds with
2385
+ * `Content-Disposition: attachment` and a raw file body (not a JSON envelope).
2386
+ * Accordingly, `export()` returns the raw response string rather than parsing
2387
+ * it into an object — callers receive exactly the bytes the server sent.
2388
+ *
2389
+ * ### WebSocket realtime subscriptions — deferred
2390
+ *
2391
+ * US-033b FU-3 scope is limited to the REST export method. A WebSocket
2392
+ * subscription helper (`subscribe()` / `DashboardSubscription`) was evaluated
2393
+ * for inclusion but is deferred to FU-4 (WS replay/catchup protocol decision).
2394
+ * Reasons:
2395
+ * 1. The WS message schema is not yet stabilised (FU-4 owns that contract).
2396
+ * 2. A proper WS abstraction requires a browser/Node `WebSocket` shim strategy
2397
+ * that is a non-trivial independent surface.
2398
+ * Track the WS helper in FU-4; this file should be extended there.
2399
+ *
2400
+ * @example
2401
+ * ```typescript
2402
+ * const nexus = new NexusClient({ apiKey: 'nx_test_abc123' });
2403
+ *
2404
+ * // Download quality distribution as CSV (default format)
2405
+ * const csv = await nexus.dashboard.export({ dataset: 'quality_distribution' });
2406
+ * // csv is a string like: "bucket,count\n0-1,12\n1-2,45\n..."
2407
+ *
2408
+ * // Download feedback trend as JSON
2409
+ * const json = await nexus.dashboard.export({
2410
+ * dataset: 'feedback_trend',
2411
+ * format: 'json',
2412
+ * });
2413
+ *
2414
+ * // Admin: export data scoped to a specific tenant
2415
+ * const tenantCsv = await nexus.dashboard.export({
2416
+ * dataset: 'error_heatmap',
2417
+ * format: 'csv',
2418
+ * target_tenant_id: 'tenant-abc',
2419
+ * });
2420
+ * ```
2421
+ */
2422
+
2423
+ /**
2424
+ * Service for exporting dashboard analytics datasets.
2425
+ *
2426
+ * Exposes `GET /v1/dashboard/export` as a typed method that returns the raw
2427
+ * file body (CSV or JSON text) as a string.
2428
+ */
2429
+ declare class DashboardService extends BaseService {
2430
+ /**
2431
+ * Export a dashboard dataset as raw file content.
2432
+ *
2433
+ * Sends `GET /dashboard/export` with the given query parameters and returns
2434
+ * the raw response body as a string. The string is exactly the file the
2435
+ * server would send for a browser download:
2436
+ * - `format: 'csv'` (default) → comma-separated text
2437
+ * - `format: 'json'` → JSON text (not parsed into an object)
2438
+ *
2439
+ * @param params - Dataset selection and format options.
2440
+ * @param options - Optional request options (e.g. AbortSignal).
2441
+ * @returns Raw file body string.
2442
+ *
2443
+ * @throws {ApiError} HTTP 401 — missing or invalid API key.
2444
+ * @throws {ApiError} HTTP 403 — `target_tenant_id` requires admin scope.
2445
+ * @throws {ApiError} HTTP 422 — `dataset` is not one of the six whitelisted values.
2446
+ */
2447
+ export(params: DashboardExportParams, options?: RequestOptions): Promise<string>;
2448
+ }
2449
+
2308
2450
  /**
2309
2451
  * @module client
2310
2452
  * @description Main entry point for the Nexus SDK.
@@ -2356,6 +2498,8 @@ declare class NexusClient {
2356
2498
  readonly feedback: FeedbackService;
2357
2499
  /** Error reporting — submit structured error reports (US-031). */
2358
2500
  readonly errors: ErrorService;
2501
+ /** Dashboard analytics — export datasets as CSV or JSON (US-033b FU-3). */
2502
+ readonly dashboard: DashboardService;
2359
2503
  /** @internal Shared HTTP transport. */
2360
2504
  private readonly http;
2361
2505
  /**
package/dist/index.d.ts CHANGED
@@ -457,6 +457,21 @@ declare class HttpClient {
457
457
  * @returns The parsed response body.
458
458
  */
459
459
  patch<T>(path: string, data?: unknown, signal?: AbortSignal): Promise<T>;
460
+ /**
461
+ * Send a GET request and return the raw response body as a string.
462
+ *
463
+ * Intended for file-download endpoints (e.g. `GET /dashboard/export`) that
464
+ * return `text/csv` or `application/json` as a raw file stream rather than a
465
+ * JSON-parsed object. The retry and auth interceptors still apply; the
466
+ * response cache is intentionally bypassed (export payloads are not cacheable
467
+ * at the SDK layer).
468
+ *
469
+ * @param path - URL path relative to the base URL (e.g. `/dashboard/export`).
470
+ * @param params - Optional query parameters.
471
+ * @param signal - Optional {@link AbortSignal} to cancel the request.
472
+ * @returns The raw response body as a string.
473
+ */
474
+ getText(path: string, params?: Record<string, unknown>, signal?: AbortSignal): Promise<string>;
460
475
  /**
461
476
  * Send a DELETE request.
462
477
  *
@@ -2305,6 +2320,133 @@ declare class ErrorService extends BaseService {
2305
2320
  submit(data: ErrorReportRequest, options?: RequestOptions): Promise<ErrorReportResponse>;
2306
2321
  }
2307
2322
 
2323
+ /**
2324
+ * @module types/dashboard
2325
+ * @description Dashboard Service type definitions.
2326
+ *
2327
+ * Mirrors the Nexus API dashboard export contract:
2328
+ * - GET /v1/dashboard/export — download a dataset as CSV or JSON
2329
+ *
2330
+ * The export endpoint returns raw file content (text/csv or application/json),
2331
+ * not a JSON-parsed object. The SDK therefore exposes these types only for
2332
+ * the _request_ side; the return value is `string`.
2333
+ */
2334
+ /**
2335
+ * The set of exportable dashboard datasets.
2336
+ *
2337
+ * Must stay in sync with the backend `DashboardExportDataset` Literal:
2338
+ * - `quality_distribution` — Quality score bucket distribution
2339
+ * - `feedback_trend` — Feedback rating trend over time
2340
+ * - `diagnosis_stats` — Diagnosis type statistics
2341
+ * - `feedback_health` — Overall feedback health metrics
2342
+ * - `error_heatmap` — Error frequency heatmap by endpoint / time
2343
+ * - `ab_distribution` — A/B experiment assignment distribution
2344
+ */
2345
+ type DashboardExportDataset = 'quality_distribution' | 'feedback_trend' | 'diagnosis_stats' | 'feedback_health' | 'error_heatmap' | 'ab_distribution';
2346
+ /**
2347
+ * Query parameters for `GET /v1/dashboard/export`.
2348
+ */
2349
+ interface DashboardExportParams {
2350
+ /**
2351
+ * The dataset to export. Required.
2352
+ *
2353
+ * Must be one of the six whitelisted values ({@link DashboardExportDataset}).
2354
+ * The backend returns HTTP 422 for unknown values.
2355
+ */
2356
+ dataset: DashboardExportDataset;
2357
+ /**
2358
+ * File format for the exported data.
2359
+ *
2360
+ * - `'csv'` — Comma-separated values (default when omitted).
2361
+ * - `'json'` — Raw JSON text (not parsed; returned as a string by the SDK).
2362
+ *
2363
+ * @default 'csv'
2364
+ */
2365
+ format?: 'csv' | 'json';
2366
+ /**
2367
+ * Filter results to a specific tenant.
2368
+ *
2369
+ * Only usable by API keys that carry the admin scope. The backend returns
2370
+ * HTTP 403 when this field is present but the caller lacks admin privileges,
2371
+ * and HTTP 400 when the value is not a valid UUID (it is normalized to
2372
+ * canonical form server-side).
2373
+ */
2374
+ target_tenant_id?: string;
2375
+ }
2376
+
2377
+ /**
2378
+ * @module services/dashboard
2379
+ * @description Dashboard Service — export analytics datasets.
2380
+ *
2381
+ * Wraps the Nexus Dashboard API:
2382
+ * - GET /v1/dashboard/export — download a dataset as raw CSV or JSON text
2383
+ *
2384
+ * The export endpoint is a file-download endpoint: the backend responds with
2385
+ * `Content-Disposition: attachment` and a raw file body (not a JSON envelope).
2386
+ * Accordingly, `export()` returns the raw response string rather than parsing
2387
+ * it into an object — callers receive exactly the bytes the server sent.
2388
+ *
2389
+ * ### WebSocket realtime subscriptions — deferred
2390
+ *
2391
+ * US-033b FU-3 scope is limited to the REST export method. A WebSocket
2392
+ * subscription helper (`subscribe()` / `DashboardSubscription`) was evaluated
2393
+ * for inclusion but is deferred to FU-4 (WS replay/catchup protocol decision).
2394
+ * Reasons:
2395
+ * 1. The WS message schema is not yet stabilised (FU-4 owns that contract).
2396
+ * 2. A proper WS abstraction requires a browser/Node `WebSocket` shim strategy
2397
+ * that is a non-trivial independent surface.
2398
+ * Track the WS helper in FU-4; this file should be extended there.
2399
+ *
2400
+ * @example
2401
+ * ```typescript
2402
+ * const nexus = new NexusClient({ apiKey: 'nx_test_abc123' });
2403
+ *
2404
+ * // Download quality distribution as CSV (default format)
2405
+ * const csv = await nexus.dashboard.export({ dataset: 'quality_distribution' });
2406
+ * // csv is a string like: "bucket,count\n0-1,12\n1-2,45\n..."
2407
+ *
2408
+ * // Download feedback trend as JSON
2409
+ * const json = await nexus.dashboard.export({
2410
+ * dataset: 'feedback_trend',
2411
+ * format: 'json',
2412
+ * });
2413
+ *
2414
+ * // Admin: export data scoped to a specific tenant
2415
+ * const tenantCsv = await nexus.dashboard.export({
2416
+ * dataset: 'error_heatmap',
2417
+ * format: 'csv',
2418
+ * target_tenant_id: 'tenant-abc',
2419
+ * });
2420
+ * ```
2421
+ */
2422
+
2423
+ /**
2424
+ * Service for exporting dashboard analytics datasets.
2425
+ *
2426
+ * Exposes `GET /v1/dashboard/export` as a typed method that returns the raw
2427
+ * file body (CSV or JSON text) as a string.
2428
+ */
2429
+ declare class DashboardService extends BaseService {
2430
+ /**
2431
+ * Export a dashboard dataset as raw file content.
2432
+ *
2433
+ * Sends `GET /dashboard/export` with the given query parameters and returns
2434
+ * the raw response body as a string. The string is exactly the file the
2435
+ * server would send for a browser download:
2436
+ * - `format: 'csv'` (default) → comma-separated text
2437
+ * - `format: 'json'` → JSON text (not parsed into an object)
2438
+ *
2439
+ * @param params - Dataset selection and format options.
2440
+ * @param options - Optional request options (e.g. AbortSignal).
2441
+ * @returns Raw file body string.
2442
+ *
2443
+ * @throws {ApiError} HTTP 401 — missing or invalid API key.
2444
+ * @throws {ApiError} HTTP 403 — `target_tenant_id` requires admin scope.
2445
+ * @throws {ApiError} HTTP 422 — `dataset` is not one of the six whitelisted values.
2446
+ */
2447
+ export(params: DashboardExportParams, options?: RequestOptions): Promise<string>;
2448
+ }
2449
+
2308
2450
  /**
2309
2451
  * @module client
2310
2452
  * @description Main entry point for the Nexus SDK.
@@ -2356,6 +2498,8 @@ declare class NexusClient {
2356
2498
  readonly feedback: FeedbackService;
2357
2499
  /** Error reporting — submit structured error reports (US-031). */
2358
2500
  readonly errors: ErrorService;
2501
+ /** Dashboard analytics — export datasets as CSV or JSON (US-033b FU-3). */
2502
+ readonly dashboard: DashboardService;
2359
2503
  /** @internal Shared HTTP transport. */
2360
2504
  private readonly http;
2361
2505
  /**
package/dist/index.js CHANGED
@@ -794,6 +794,30 @@ var HttpClient = class {
794
794
  this.cache.invalidate(path.split("/").filter(Boolean)[0] ?? path);
795
795
  return result;
796
796
  }
797
+ /**
798
+ * Send a GET request and return the raw response body as a string.
799
+ *
800
+ * Intended for file-download endpoints (e.g. `GET /dashboard/export`) that
801
+ * return `text/csv` or `application/json` as a raw file stream rather than a
802
+ * JSON-parsed object. The retry and auth interceptors still apply; the
803
+ * response cache is intentionally bypassed (export payloads are not cacheable
804
+ * at the SDK layer).
805
+ *
806
+ * @param path - URL path relative to the base URL (e.g. `/dashboard/export`).
807
+ * @param params - Optional query parameters.
808
+ * @param signal - Optional {@link AbortSignal} to cancel the request.
809
+ * @returns The raw response body as a string.
810
+ */
811
+ async getText(path, params, signal) {
812
+ return this.retry.execute(async () => {
813
+ const response = await this.axios.get(path, {
814
+ params,
815
+ signal,
816
+ responseType: "text"
817
+ });
818
+ return response.data;
819
+ });
820
+ }
797
821
  /**
798
822
  * Send a DELETE request.
799
823
  *
@@ -1410,6 +1434,35 @@ var ErrorService = class extends BaseService {
1410
1434
  }
1411
1435
  };
1412
1436
 
1437
+ // src/services/dashboard.ts
1438
+ var DashboardService = class extends BaseService {
1439
+ /**
1440
+ * Export a dashboard dataset as raw file content.
1441
+ *
1442
+ * Sends `GET /dashboard/export` with the given query parameters and returns
1443
+ * the raw response body as a string. The string is exactly the file the
1444
+ * server would send for a browser download:
1445
+ * - `format: 'csv'` (default) → comma-separated text
1446
+ * - `format: 'json'` → JSON text (not parsed into an object)
1447
+ *
1448
+ * @param params - Dataset selection and format options.
1449
+ * @param options - Optional request options (e.g. AbortSignal).
1450
+ * @returns Raw file body string.
1451
+ *
1452
+ * @throws {ApiError} HTTP 401 — missing or invalid API key.
1453
+ * @throws {ApiError} HTTP 403 — `target_tenant_id` requires admin scope.
1454
+ * @throws {ApiError} HTTP 422 — `dataset` is not one of the six whitelisted values.
1455
+ */
1456
+ async export(params, options) {
1457
+ const query = { dataset: params.dataset };
1458
+ if (params.format !== void 0) query["format"] = params.format;
1459
+ if (params.target_tenant_id !== void 0) {
1460
+ query["target_tenant_id"] = params.target_tenant_id;
1461
+ }
1462
+ return this.http.getText("/dashboard/export", query, options?.signal);
1463
+ }
1464
+ };
1465
+
1413
1466
  // src/client.ts
1414
1467
  var NexusClient = class {
1415
1468
  /**
@@ -1431,6 +1484,7 @@ var NexusClient = class {
1431
1484
  this.tenants = new TenantService(this.http);
1432
1485
  this.feedback = new FeedbackService(this.http);
1433
1486
  this.errors = new ErrorService(this.http);
1487
+ this.dashboard = new DashboardService(this.http);
1434
1488
  if (resolved.autoErrorReport) {
1435
1489
  this.http.onApiError = (statusCode, method, url, detail) => {
1436
1490
  this.errors.submit({