@mappa-ai/mappa-node 1.2.1 → 1.2.3

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.cts CHANGED
@@ -119,6 +119,44 @@ declare class JobCanceledError extends MappaError {
119
119
  });
120
120
  toString(): string;
121
121
  }
122
+ /**
123
+ * Error thrown when SSE streaming fails after all retries.
124
+ *
125
+ * Includes recovery metadata to allow callers to resume or retry:
126
+ * - `jobId`: The job being streamed (when known)
127
+ * - `lastEventId`: Last successfully received event ID for resumption
128
+ * - `url`: The stream URL that failed
129
+ * - `retryCount`: Number of retries attempted
130
+ *
131
+ * @example
132
+ * ```typescript
133
+ * try {
134
+ * for await (const event of mappa.jobs.stream(jobId)) { ... }
135
+ * } catch (err) {
136
+ * if (err instanceof StreamError) {
137
+ * console.log(`Stream failed for job ${err.jobId}`);
138
+ * console.log(`Last event ID: ${err.lastEventId}`);
139
+ * // Can retry with: mappa.jobs.stream(err.jobId)
140
+ * }
141
+ * }
142
+ * ```
143
+ */
144
+ declare class StreamError extends MappaError {
145
+ name: string;
146
+ jobId?: string;
147
+ lastEventId?: string;
148
+ url?: string;
149
+ retryCount: number;
150
+ constructor(message: string, opts: {
151
+ jobId?: string;
152
+ lastEventId?: string;
153
+ url?: string;
154
+ retryCount: number;
155
+ requestId?: string;
156
+ cause?: unknown;
157
+ });
158
+ toString(): string;
159
+ }
122
160
  //#endregion
123
161
  //#region src/resources/transport.d.ts
124
162
  /**
@@ -152,6 +190,8 @@ type Telemetry = {
152
190
  url: string;
153
191
  requestId?: string;
154
192
  error: unknown;
193
+ /** Additional context for SSE streaming errors. */
194
+ context?: Record<string, unknown>;
155
195
  }) => void;
156
196
  };
157
197
  type TransportOptions = {
@@ -190,6 +230,9 @@ declare class Transport {
190
230
  *
191
231
  * Uses native `fetch` with streaming response body (not browser-only `EventSource`).
192
232
  * Parses SSE format manually from the `ReadableStream`.
233
+ *
234
+ * Automatically retries on network failures (socket errors, DNS failures, etc.)
235
+ * up to `maxRetries` times with exponential backoff.
193
236
  */
194
237
  streamSSE<T>(path: string, opts?: SSEStreamOptions): AsyncGenerator<SSEEvent<T>>;
195
238
  /**
@@ -260,6 +303,18 @@ type ReportOutputEntry<OutputType extends ReportOutputType, Template extends Rep
260
303
  };
261
304
  type ReportOutputForType<OutputType extends ReportOutputType> = ReportOutputEntry<OutputType, "sales_playbook"> | ReportOutputEntry<OutputType, "general_report"> | ReportOutputEntry<OutputType, "hiring_report"> | ReportOutputEntry<OutputType, "profile_alignment">;
262
305
  type ReportOutput = ReportOutputForType<"markdown"> | ReportOutputForType<"json"> | ReportOutputForType<"pdf"> | ReportOutputForType<"url">;
306
+ /**
307
+ * Report output configuration constrained to a specific output type.
308
+ * When T is a specific literal like "markdown", only markdown output configs are allowed.
309
+ * When T is the full union (ReportOutputType), all output configs are allowed.
310
+ *
311
+ * @example
312
+ * ```typescript
313
+ * type MarkdownOutput = ReportOutputFor<"markdown">; // Only markdown configs
314
+ * type AnyOutput = ReportOutputFor<ReportOutputType>; // All configs (same as ReportOutput)
315
+ * ```
316
+ */
317
+ type ReportOutputFor<T extends ReportOutputType> = T extends "markdown" ? ReportOutputForType<"markdown"> : T extends "json" ? ReportOutputForType<"json"> : T extends "pdf" ? ReportOutputForType<"pdf"> : T extends "url" ? ReportOutputForType<"url"> : ReportOutput;
263
318
  type TargetStrategy = "dominant" | "timerange" | "entity_id" | "magic_hint";
264
319
  type TargetOnMiss = "fallback_dominant" | "error";
265
320
  type TargetTimeRange = {
@@ -378,7 +433,7 @@ type WebhookConfig = {
378
433
  url: string;
379
434
  headers?: Record<string, string>;
380
435
  };
381
- type ReportCreateJobRequest = {
436
+ type ReportCreateJobRequest<T extends ReportOutputType = ReportOutputType> = {
382
437
  subject?: Subject;
383
438
  /**
384
439
  * Reference to already-uploaded media.
@@ -387,7 +442,7 @@ type ReportCreateJobRequest = {
387
442
  * use helper methods like `reports.createJobFromUrl()` / `reports.createJobFromFile()`.
388
443
  */
389
444
  media: MediaIdRef;
390
- output: ReportOutput;
445
+ output: ReportOutputFor<T>;
391
446
  /**
392
447
  * Select the target entity for analysis.
393
448
  *
@@ -468,13 +523,25 @@ type UrlReport = ReportBase & {
468
523
  reportUrl: string;
469
524
  };
470
525
  type Report = MarkdownReport | JsonReport | PdfReport | UrlReport;
471
- type ReportJobReceipt = {
526
+ /**
527
+ * Maps an output type to its corresponding report type.
528
+ * Used for type-safe inference in generate methods.
529
+ *
530
+ * @example
531
+ * ```typescript
532
+ * type R = ReportForOutputType<"markdown">; // MarkdownReport
533
+ * type R = ReportForOutputType<"json">; // JsonReport
534
+ * type R = ReportForOutputType<ReportOutputType>; // Report (union)
535
+ * ```
536
+ */
537
+ type ReportForOutputType<T extends ReportOutputType> = T extends "markdown" ? MarkdownReport : T extends "json" ? JsonReport : T extends "pdf" ? PdfReport : T extends "url" ? UrlReport : Report;
538
+ type ReportJobReceipt<T extends ReportOutputType = ReportOutputType> = {
472
539
  jobId: string;
473
540
  status: "queued" | "running";
474
541
  stage?: JobStage;
475
542
  estimatedWaitSec?: number;
476
543
  requestId?: string;
477
- handle?: ReportRunHandle;
544
+ handle?: ReportRunHandle<T>;
478
545
  };
479
546
  type FeedbackReceipt = {
480
547
  id: string;
@@ -594,16 +661,16 @@ type WaitOptions = {
594
661
  */
595
662
  signal?: AbortSignal;
596
663
  };
597
- type ReportRunHandle = {
664
+ type ReportRunHandle<T extends ReportOutputType = ReportOutputType> = {
598
665
  jobId: string;
599
666
  stream(opts?: {
600
667
  signal?: AbortSignal;
601
668
  onEvent?: (e: JobEvent) => void;
602
669
  }): AsyncIterable<JobEvent>;
603
- wait(opts?: WaitOptions): Promise<Report>;
670
+ wait(opts?: WaitOptions): Promise<ReportForOutputType<T>>;
604
671
  cancel(): Promise<Job>;
605
672
  job(): Promise<Job>;
606
- report(): Promise<Report | null>;
673
+ report(): Promise<ReportForOutputType<T> | null>;
607
674
  };
608
675
  /**
609
676
  * Type guard for MarkdownReport.
@@ -1102,7 +1169,7 @@ declare class JobsResource {
1102
1169
  * - `signal` (from {@link UploadRequest}) is applied to the upload request.
1103
1170
  * Job creation only runs after a successful upload.
1104
1171
  */
1105
- type ReportCreateJobFromFileRequest = Omit<ReportCreateJobRequest, "media" | "idempotencyKey" | "requestId"> & Omit<UploadRequest, "filename"> & {
1172
+ type ReportCreateJobFromFileRequest<T extends ReportOutputType = ReportOutputType> = Omit<ReportCreateJobRequest<T>, "media" | "idempotencyKey" | "requestId"> & Omit<UploadRequest, "filename"> & {
1106
1173
  /**
1107
1174
  * Optional filename to attach to the upload.
1108
1175
  *
@@ -1130,7 +1197,7 @@ type ReportCreateJobFromFileRequest = Omit<ReportCreateJobRequest, "media" | "id
1130
1197
  * - `idempotencyKey` applies to the *whole* download + upload + create-job sequence.
1131
1198
  * - `requestId` is forwarded to both upload and job creation calls.
1132
1199
  */
1133
- type ReportCreateJobFromUrlRequest = Omit<ReportCreateJobRequest, "media" | "idempotencyKey" | "requestId"> & {
1200
+ type ReportCreateJobFromUrlRequest<T extends ReportOutputType = ReportOutputType> = Omit<ReportCreateJobRequest<T>, "media" | "idempotencyKey" | "requestId"> & {
1134
1201
  url: string;
1135
1202
  contentType?: string;
1136
1203
  filename?: string;
@@ -1176,14 +1243,14 @@ declare class ReportsResource {
1176
1243
  * - wait for completion and fetch the final report
1177
1244
  * - cancel the job, or fetch job/report metadata
1178
1245
  */
1179
- createJob(req: ReportCreateJobRequest): Promise<ReportJobReceipt>;
1246
+ createJob<T extends ReportOutputType = ReportOutputType>(req: ReportCreateJobRequest<T>): Promise<ReportJobReceipt<T>>;
1180
1247
  /**
1181
1248
  * Upload a file and create a report job in one call.
1182
1249
  *
1183
1250
  * Keeps `createJob()` strict about `media: { mediaId }` while offering a
1184
1251
  * convenient helper when you start from raw bytes.
1185
1252
  */
1186
- createJobFromFile(req: ReportCreateJobFromFileRequest): Promise<ReportJobReceipt>;
1253
+ createJobFromFile<T extends ReportOutputType = ReportOutputType>(req: ReportCreateJobFromFileRequest<T>): Promise<ReportJobReceipt<T>>;
1187
1254
  /**
1188
1255
  * Download a file from a URL, upload it, and create a report job.
1189
1256
  *
@@ -1200,7 +1267,7 @@ declare class ReportsResource {
1200
1267
  * - Only allows `http:` and `https:` URLs.
1201
1268
  * - Requires a resolvable `contentType` (from `req.contentType` or response header).
1202
1269
  */
1203
- createJobFromUrl(req: ReportCreateJobFromUrlRequest): Promise<ReportJobReceipt>;
1270
+ createJobFromUrl<T extends ReportOutputType = ReportOutputType>(req: ReportCreateJobFromUrlRequest<T>): Promise<ReportJobReceipt<T>>;
1204
1271
  get(reportId: string, opts?: {
1205
1272
  requestId?: string;
1206
1273
  signal?: AbortSignal;
@@ -1213,24 +1280,24 @@ declare class ReportsResource {
1213
1280
  * Convenience wrapper: createJob + wait + get
1214
1281
  * Use for scripts; for production prefer createJob + webhooks/stream.
1215
1282
  */
1216
- generate(req: ReportCreateJobRequest, opts?: {
1283
+ generate<T extends ReportOutputType = ReportOutputType>(req: ReportCreateJobRequest<T>, opts?: {
1217
1284
  wait?: WaitOptions;
1218
- }): Promise<Report>;
1285
+ }): Promise<ReportForOutputType<T>>;
1219
1286
  /**
1220
1287
  * Convenience wrapper: createJobFromFile + wait + get.
1221
1288
  * Use for scripts; for production prefer createJobFromFile + webhooks/stream.
1222
1289
  */
1223
- generateFromFile(req: ReportCreateJobFromFileRequest, opts?: {
1290
+ generateFromFile<T extends ReportOutputType = ReportOutputType>(req: ReportCreateJobFromFileRequest<T>, opts?: {
1224
1291
  wait?: WaitOptions;
1225
- }): Promise<Report>;
1292
+ }): Promise<ReportForOutputType<T>>;
1226
1293
  /**
1227
1294
  * Convenience wrapper: createJobFromUrl + wait + get.
1228
1295
  * Use for scripts; for production prefer createJobFromUrl + webhooks/stream.
1229
1296
  */
1230
- generateFromUrl(req: ReportCreateJobFromUrlRequest, opts?: {
1297
+ generateFromUrl<T extends ReportOutputType = ReportOutputType>(req: ReportCreateJobFromUrlRequest<T>, opts?: {
1231
1298
  wait?: WaitOptions;
1232
- }): Promise<Report>;
1233
- makeHandle(jobId: string): ReportRunHandle;
1299
+ }): Promise<ReportForOutputType<T>>;
1300
+ makeHandle<T extends ReportOutputType = ReportOutputType>(jobId: string): ReportRunHandle<T>;
1234
1301
  private defaultIdempotencyKey;
1235
1302
  private normalizeJobRequest;
1236
1303
  }
@@ -1349,6 +1416,26 @@ declare function isMappaError(err: unknown): err is MappaError;
1349
1416
  * ```
1350
1417
  */
1351
1418
  declare function isInsufficientCreditsError(err: unknown): err is InsufficientCreditsError;
1419
+ /**
1420
+ * Type guard for stream connection errors.
1421
+ *
1422
+ * Use this to detect streaming failures and access recovery metadata
1423
+ * like `jobId`, `lastEventId`, and `retryCount`.
1424
+ *
1425
+ * @example
1426
+ * ```typescript
1427
+ * try {
1428
+ * await mappa.reports.generate({ ... });
1429
+ * } catch (err) {
1430
+ * if (isStreamError(err)) {
1431
+ * console.log(`Stream failed for job ${err.jobId}`);
1432
+ * console.log(`Last event ID: ${err.lastEventId}`);
1433
+ * console.log(`Retries attempted: ${err.retryCount}`);
1434
+ * }
1435
+ * }
1436
+ * ```
1437
+ */
1438
+ declare function isStreamError(err: unknown): err is StreamError;
1352
1439
  //#endregion
1353
- export { ApiError, AuthError, CreditBalance, CreditTransaction, CreditTransactionType, CreditUsage, CursorPage, CursorPaginationParams, Entity, EntityTagsResult, FeedbackReceipt, FileDeleteReceipt, InsufficientCreditsError, Job, JobCanceledError, JobCreditReservation, JobEvent, JobFailedError, JobStage, JobStatus, JsonReport, JsonValue, ListEntitiesOptions, ListEntitiesResponse, Mappa, MappaError, MarkdownReport, MediaFile, MediaIdRef, MediaObject, MediaProcessingStatus, MediaRef, MediaRetention, OffsetPage, OffsetPaginationParams, PdfReport, RateLimitError, Report, ReportBase, ReportCreateJobRequest, ReportJobReceipt, ReportOutput, ReportOutputType, ReportRunHandle, ReportTemplateId, ReportTemplateParamsMap, RetentionLockResult, Subject, TargetDominant, TargetEntityId, TargetFor, TargetMagicHint, TargetOnMiss, TargetSelector, TargetStrategy, TargetStrategyMap, TargetTimeRange, TargetTimeRangeStrategy, UrlReport, Usage, ValidationError, WaitOptions, WebhookConfig, hasEntity, isInsufficientCreditsError, isJsonReport, isMappaError, isMarkdownReport, isPdfReport, isUrlReport };
1440
+ export { ApiError, AuthError, CreditBalance, CreditTransaction, CreditTransactionType, CreditUsage, CursorPage, CursorPaginationParams, Entity, EntityTagsResult, FeedbackReceipt, FileDeleteReceipt, InsufficientCreditsError, Job, JobCanceledError, JobCreditReservation, JobEvent, JobFailedError, JobStage, JobStatus, JsonReport, JsonValue, ListEntitiesOptions, ListEntitiesResponse, Mappa, MappaError, MarkdownReport, MediaFile, MediaIdRef, MediaObject, MediaProcessingStatus, MediaRef, MediaRetention, OffsetPage, OffsetPaginationParams, PdfReport, RateLimitError, Report, ReportBase, ReportCreateJobRequest, ReportForOutputType, ReportJobReceipt, ReportOutput, ReportOutputFor, ReportOutputType, ReportRunHandle, ReportTemplateId, ReportTemplateParamsMap, RetentionLockResult, StreamError, Subject, TargetDominant, TargetEntityId, TargetFor, TargetMagicHint, TargetOnMiss, TargetSelector, TargetStrategy, TargetStrategyMap, TargetTimeRange, TargetTimeRangeStrategy, UrlReport, Usage, ValidationError, WaitOptions, WebhookConfig, hasEntity, isInsufficientCreditsError, isJsonReport, isMappaError, isMarkdownReport, isPdfReport, isStreamError, isUrlReport };
1354
1441
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.mts CHANGED
@@ -119,6 +119,44 @@ declare class JobCanceledError extends MappaError {
119
119
  });
120
120
  toString(): string;
121
121
  }
122
+ /**
123
+ * Error thrown when SSE streaming fails after all retries.
124
+ *
125
+ * Includes recovery metadata to allow callers to resume or retry:
126
+ * - `jobId`: The job being streamed (when known)
127
+ * - `lastEventId`: Last successfully received event ID for resumption
128
+ * - `url`: The stream URL that failed
129
+ * - `retryCount`: Number of retries attempted
130
+ *
131
+ * @example
132
+ * ```typescript
133
+ * try {
134
+ * for await (const event of mappa.jobs.stream(jobId)) { ... }
135
+ * } catch (err) {
136
+ * if (err instanceof StreamError) {
137
+ * console.log(`Stream failed for job ${err.jobId}`);
138
+ * console.log(`Last event ID: ${err.lastEventId}`);
139
+ * // Can retry with: mappa.jobs.stream(err.jobId)
140
+ * }
141
+ * }
142
+ * ```
143
+ */
144
+ declare class StreamError extends MappaError {
145
+ name: string;
146
+ jobId?: string;
147
+ lastEventId?: string;
148
+ url?: string;
149
+ retryCount: number;
150
+ constructor(message: string, opts: {
151
+ jobId?: string;
152
+ lastEventId?: string;
153
+ url?: string;
154
+ retryCount: number;
155
+ requestId?: string;
156
+ cause?: unknown;
157
+ });
158
+ toString(): string;
159
+ }
122
160
  //#endregion
123
161
  //#region src/resources/transport.d.ts
124
162
  /**
@@ -152,6 +190,8 @@ type Telemetry = {
152
190
  url: string;
153
191
  requestId?: string;
154
192
  error: unknown;
193
+ /** Additional context for SSE streaming errors. */
194
+ context?: Record<string, unknown>;
155
195
  }) => void;
156
196
  };
157
197
  type TransportOptions = {
@@ -190,6 +230,9 @@ declare class Transport {
190
230
  *
191
231
  * Uses native `fetch` with streaming response body (not browser-only `EventSource`).
192
232
  * Parses SSE format manually from the `ReadableStream`.
233
+ *
234
+ * Automatically retries on network failures (socket errors, DNS failures, etc.)
235
+ * up to `maxRetries` times with exponential backoff.
193
236
  */
194
237
  streamSSE<T>(path: string, opts?: SSEStreamOptions): AsyncGenerator<SSEEvent<T>>;
195
238
  /**
@@ -260,6 +303,18 @@ type ReportOutputEntry<OutputType extends ReportOutputType, Template extends Rep
260
303
  };
261
304
  type ReportOutputForType<OutputType extends ReportOutputType> = ReportOutputEntry<OutputType, "sales_playbook"> | ReportOutputEntry<OutputType, "general_report"> | ReportOutputEntry<OutputType, "hiring_report"> | ReportOutputEntry<OutputType, "profile_alignment">;
262
305
  type ReportOutput = ReportOutputForType<"markdown"> | ReportOutputForType<"json"> | ReportOutputForType<"pdf"> | ReportOutputForType<"url">;
306
+ /**
307
+ * Report output configuration constrained to a specific output type.
308
+ * When T is a specific literal like "markdown", only markdown output configs are allowed.
309
+ * When T is the full union (ReportOutputType), all output configs are allowed.
310
+ *
311
+ * @example
312
+ * ```typescript
313
+ * type MarkdownOutput = ReportOutputFor<"markdown">; // Only markdown configs
314
+ * type AnyOutput = ReportOutputFor<ReportOutputType>; // All configs (same as ReportOutput)
315
+ * ```
316
+ */
317
+ type ReportOutputFor<T extends ReportOutputType> = T extends "markdown" ? ReportOutputForType<"markdown"> : T extends "json" ? ReportOutputForType<"json"> : T extends "pdf" ? ReportOutputForType<"pdf"> : T extends "url" ? ReportOutputForType<"url"> : ReportOutput;
263
318
  type TargetStrategy = "dominant" | "timerange" | "entity_id" | "magic_hint";
264
319
  type TargetOnMiss = "fallback_dominant" | "error";
265
320
  type TargetTimeRange = {
@@ -378,7 +433,7 @@ type WebhookConfig = {
378
433
  url: string;
379
434
  headers?: Record<string, string>;
380
435
  };
381
- type ReportCreateJobRequest = {
436
+ type ReportCreateJobRequest<T extends ReportOutputType = ReportOutputType> = {
382
437
  subject?: Subject;
383
438
  /**
384
439
  * Reference to already-uploaded media.
@@ -387,7 +442,7 @@ type ReportCreateJobRequest = {
387
442
  * use helper methods like `reports.createJobFromUrl()` / `reports.createJobFromFile()`.
388
443
  */
389
444
  media: MediaIdRef;
390
- output: ReportOutput;
445
+ output: ReportOutputFor<T>;
391
446
  /**
392
447
  * Select the target entity for analysis.
393
448
  *
@@ -468,13 +523,25 @@ type UrlReport = ReportBase & {
468
523
  reportUrl: string;
469
524
  };
470
525
  type Report = MarkdownReport | JsonReport | PdfReport | UrlReport;
471
- type ReportJobReceipt = {
526
+ /**
527
+ * Maps an output type to its corresponding report type.
528
+ * Used for type-safe inference in generate methods.
529
+ *
530
+ * @example
531
+ * ```typescript
532
+ * type R = ReportForOutputType<"markdown">; // MarkdownReport
533
+ * type R = ReportForOutputType<"json">; // JsonReport
534
+ * type R = ReportForOutputType<ReportOutputType>; // Report (union)
535
+ * ```
536
+ */
537
+ type ReportForOutputType<T extends ReportOutputType> = T extends "markdown" ? MarkdownReport : T extends "json" ? JsonReport : T extends "pdf" ? PdfReport : T extends "url" ? UrlReport : Report;
538
+ type ReportJobReceipt<T extends ReportOutputType = ReportOutputType> = {
472
539
  jobId: string;
473
540
  status: "queued" | "running";
474
541
  stage?: JobStage;
475
542
  estimatedWaitSec?: number;
476
543
  requestId?: string;
477
- handle?: ReportRunHandle;
544
+ handle?: ReportRunHandle<T>;
478
545
  };
479
546
  type FeedbackReceipt = {
480
547
  id: string;
@@ -594,16 +661,16 @@ type WaitOptions = {
594
661
  */
595
662
  signal?: AbortSignal;
596
663
  };
597
- type ReportRunHandle = {
664
+ type ReportRunHandle<T extends ReportOutputType = ReportOutputType> = {
598
665
  jobId: string;
599
666
  stream(opts?: {
600
667
  signal?: AbortSignal;
601
668
  onEvent?: (e: JobEvent) => void;
602
669
  }): AsyncIterable<JobEvent>;
603
- wait(opts?: WaitOptions): Promise<Report>;
670
+ wait(opts?: WaitOptions): Promise<ReportForOutputType<T>>;
604
671
  cancel(): Promise<Job>;
605
672
  job(): Promise<Job>;
606
- report(): Promise<Report | null>;
673
+ report(): Promise<ReportForOutputType<T> | null>;
607
674
  };
608
675
  /**
609
676
  * Type guard for MarkdownReport.
@@ -1102,7 +1169,7 @@ declare class JobsResource {
1102
1169
  * - `signal` (from {@link UploadRequest}) is applied to the upload request.
1103
1170
  * Job creation only runs after a successful upload.
1104
1171
  */
1105
- type ReportCreateJobFromFileRequest = Omit<ReportCreateJobRequest, "media" | "idempotencyKey" | "requestId"> & Omit<UploadRequest, "filename"> & {
1172
+ type ReportCreateJobFromFileRequest<T extends ReportOutputType = ReportOutputType> = Omit<ReportCreateJobRequest<T>, "media" | "idempotencyKey" | "requestId"> & Omit<UploadRequest, "filename"> & {
1106
1173
  /**
1107
1174
  * Optional filename to attach to the upload.
1108
1175
  *
@@ -1130,7 +1197,7 @@ type ReportCreateJobFromFileRequest = Omit<ReportCreateJobRequest, "media" | "id
1130
1197
  * - `idempotencyKey` applies to the *whole* download + upload + create-job sequence.
1131
1198
  * - `requestId` is forwarded to both upload and job creation calls.
1132
1199
  */
1133
- type ReportCreateJobFromUrlRequest = Omit<ReportCreateJobRequest, "media" | "idempotencyKey" | "requestId"> & {
1200
+ type ReportCreateJobFromUrlRequest<T extends ReportOutputType = ReportOutputType> = Omit<ReportCreateJobRequest<T>, "media" | "idempotencyKey" | "requestId"> & {
1134
1201
  url: string;
1135
1202
  contentType?: string;
1136
1203
  filename?: string;
@@ -1176,14 +1243,14 @@ declare class ReportsResource {
1176
1243
  * - wait for completion and fetch the final report
1177
1244
  * - cancel the job, or fetch job/report metadata
1178
1245
  */
1179
- createJob(req: ReportCreateJobRequest): Promise<ReportJobReceipt>;
1246
+ createJob<T extends ReportOutputType = ReportOutputType>(req: ReportCreateJobRequest<T>): Promise<ReportJobReceipt<T>>;
1180
1247
  /**
1181
1248
  * Upload a file and create a report job in one call.
1182
1249
  *
1183
1250
  * Keeps `createJob()` strict about `media: { mediaId }` while offering a
1184
1251
  * convenient helper when you start from raw bytes.
1185
1252
  */
1186
- createJobFromFile(req: ReportCreateJobFromFileRequest): Promise<ReportJobReceipt>;
1253
+ createJobFromFile<T extends ReportOutputType = ReportOutputType>(req: ReportCreateJobFromFileRequest<T>): Promise<ReportJobReceipt<T>>;
1187
1254
  /**
1188
1255
  * Download a file from a URL, upload it, and create a report job.
1189
1256
  *
@@ -1200,7 +1267,7 @@ declare class ReportsResource {
1200
1267
  * - Only allows `http:` and `https:` URLs.
1201
1268
  * - Requires a resolvable `contentType` (from `req.contentType` or response header).
1202
1269
  */
1203
- createJobFromUrl(req: ReportCreateJobFromUrlRequest): Promise<ReportJobReceipt>;
1270
+ createJobFromUrl<T extends ReportOutputType = ReportOutputType>(req: ReportCreateJobFromUrlRequest<T>): Promise<ReportJobReceipt<T>>;
1204
1271
  get(reportId: string, opts?: {
1205
1272
  requestId?: string;
1206
1273
  signal?: AbortSignal;
@@ -1213,24 +1280,24 @@ declare class ReportsResource {
1213
1280
  * Convenience wrapper: createJob + wait + get
1214
1281
  * Use for scripts; for production prefer createJob + webhooks/stream.
1215
1282
  */
1216
- generate(req: ReportCreateJobRequest, opts?: {
1283
+ generate<T extends ReportOutputType = ReportOutputType>(req: ReportCreateJobRequest<T>, opts?: {
1217
1284
  wait?: WaitOptions;
1218
- }): Promise<Report>;
1285
+ }): Promise<ReportForOutputType<T>>;
1219
1286
  /**
1220
1287
  * Convenience wrapper: createJobFromFile + wait + get.
1221
1288
  * Use for scripts; for production prefer createJobFromFile + webhooks/stream.
1222
1289
  */
1223
- generateFromFile(req: ReportCreateJobFromFileRequest, opts?: {
1290
+ generateFromFile<T extends ReportOutputType = ReportOutputType>(req: ReportCreateJobFromFileRequest<T>, opts?: {
1224
1291
  wait?: WaitOptions;
1225
- }): Promise<Report>;
1292
+ }): Promise<ReportForOutputType<T>>;
1226
1293
  /**
1227
1294
  * Convenience wrapper: createJobFromUrl + wait + get.
1228
1295
  * Use for scripts; for production prefer createJobFromUrl + webhooks/stream.
1229
1296
  */
1230
- generateFromUrl(req: ReportCreateJobFromUrlRequest, opts?: {
1297
+ generateFromUrl<T extends ReportOutputType = ReportOutputType>(req: ReportCreateJobFromUrlRequest<T>, opts?: {
1231
1298
  wait?: WaitOptions;
1232
- }): Promise<Report>;
1233
- makeHandle(jobId: string): ReportRunHandle;
1299
+ }): Promise<ReportForOutputType<T>>;
1300
+ makeHandle<T extends ReportOutputType = ReportOutputType>(jobId: string): ReportRunHandle<T>;
1234
1301
  private defaultIdempotencyKey;
1235
1302
  private normalizeJobRequest;
1236
1303
  }
@@ -1349,6 +1416,26 @@ declare function isMappaError(err: unknown): err is MappaError;
1349
1416
  * ```
1350
1417
  */
1351
1418
  declare function isInsufficientCreditsError(err: unknown): err is InsufficientCreditsError;
1419
+ /**
1420
+ * Type guard for stream connection errors.
1421
+ *
1422
+ * Use this to detect streaming failures and access recovery metadata
1423
+ * like `jobId`, `lastEventId`, and `retryCount`.
1424
+ *
1425
+ * @example
1426
+ * ```typescript
1427
+ * try {
1428
+ * await mappa.reports.generate({ ... });
1429
+ * } catch (err) {
1430
+ * if (isStreamError(err)) {
1431
+ * console.log(`Stream failed for job ${err.jobId}`);
1432
+ * console.log(`Last event ID: ${err.lastEventId}`);
1433
+ * console.log(`Retries attempted: ${err.retryCount}`);
1434
+ * }
1435
+ * }
1436
+ * ```
1437
+ */
1438
+ declare function isStreamError(err: unknown): err is StreamError;
1352
1439
  //#endregion
1353
- export { ApiError, AuthError, CreditBalance, CreditTransaction, CreditTransactionType, CreditUsage, CursorPage, CursorPaginationParams, Entity, EntityTagsResult, FeedbackReceipt, FileDeleteReceipt, InsufficientCreditsError, Job, JobCanceledError, JobCreditReservation, JobEvent, JobFailedError, JobStage, JobStatus, JsonReport, JsonValue, ListEntitiesOptions, ListEntitiesResponse, Mappa, MappaError, MarkdownReport, MediaFile, MediaIdRef, MediaObject, MediaProcessingStatus, MediaRef, MediaRetention, OffsetPage, OffsetPaginationParams, PdfReport, RateLimitError, Report, ReportBase, ReportCreateJobRequest, ReportJobReceipt, ReportOutput, ReportOutputType, ReportRunHandle, ReportTemplateId, ReportTemplateParamsMap, RetentionLockResult, Subject, TargetDominant, TargetEntityId, TargetFor, TargetMagicHint, TargetOnMiss, TargetSelector, TargetStrategy, TargetStrategyMap, TargetTimeRange, TargetTimeRangeStrategy, UrlReport, Usage, ValidationError, WaitOptions, WebhookConfig, hasEntity, isInsufficientCreditsError, isJsonReport, isMappaError, isMarkdownReport, isPdfReport, isUrlReport };
1440
+ export { ApiError, AuthError, CreditBalance, CreditTransaction, CreditTransactionType, CreditUsage, CursorPage, CursorPaginationParams, Entity, EntityTagsResult, FeedbackReceipt, FileDeleteReceipt, InsufficientCreditsError, Job, JobCanceledError, JobCreditReservation, JobEvent, JobFailedError, JobStage, JobStatus, JsonReport, JsonValue, ListEntitiesOptions, ListEntitiesResponse, Mappa, MappaError, MarkdownReport, MediaFile, MediaIdRef, MediaObject, MediaProcessingStatus, MediaRef, MediaRetention, OffsetPage, OffsetPaginationParams, PdfReport, RateLimitError, Report, ReportBase, ReportCreateJobRequest, ReportForOutputType, ReportJobReceipt, ReportOutput, ReportOutputFor, ReportOutputType, ReportRunHandle, ReportTemplateId, ReportTemplateParamsMap, RetentionLockResult, StreamError, Subject, TargetDominant, TargetEntityId, TargetFor, TargetMagicHint, TargetOnMiss, TargetSelector, TargetStrategy, TargetStrategyMap, TargetTimeRange, TargetTimeRangeStrategy, UrlReport, Usage, ValidationError, WaitOptions, WebhookConfig, hasEntity, isInsufficientCreditsError, isJsonReport, isMappaError, isMarkdownReport, isPdfReport, isStreamError, isUrlReport };
1354
1441
  //# sourceMappingURL=index.d.mts.map