@mappa-ai/mappa-node 1.2.0 → 1.2.2

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
@@ -1,4 +1,9 @@
1
1
  //#region src/errors.d.ts
2
+ /**
3
+ * Symbol for custom Node.js inspect formatting.
4
+ * Ensures errors display nicely in console.log, REPL, and debuggers.
5
+ */
6
+ declare const customInspect: unique symbol;
2
7
  /**
3
8
  * Base error type for all SDK-raised errors.
4
9
  *
@@ -14,6 +19,8 @@ declare class MappaError extends Error {
14
19
  code?: string;
15
20
  cause?: unknown;
16
21
  });
22
+ toString(): string;
23
+ [customInspect](): string;
17
24
  }
18
25
  /**
19
26
  * Error returned when the API responds with a non-2xx status.
@@ -28,6 +35,7 @@ declare class ApiError extends MappaError {
28
35
  code?: string;
29
36
  details?: unknown;
30
37
  });
38
+ toString(): string;
31
39
  }
32
40
  /**
33
41
  * Error returned for HTTP 429 responses.
@@ -38,6 +46,7 @@ declare class ApiError extends MappaError {
38
46
  declare class RateLimitError extends ApiError {
39
47
  name: string;
40
48
  retryAfterMs?: number;
49
+ toString(): string;
41
50
  }
42
51
  /**
43
52
  * Error returned for authentication/authorization failures (typically 401/403).
@@ -51,6 +60,40 @@ declare class AuthError extends ApiError {
51
60
  declare class ValidationError extends ApiError {
52
61
  name: string;
53
62
  }
63
+ /**
64
+ * Error returned when the account lacks sufficient credits (HTTP 402).
65
+ *
66
+ * Use {@link InsufficientCreditsError.required} and {@link InsufficientCreditsError.available}
67
+ * to inform users how many credits are needed.
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * try {
72
+ * await mappa.reports.createJob({ ... });
73
+ * } catch (err) {
74
+ * if (err instanceof InsufficientCreditsError) {
75
+ * console.log(`Need ${err.required} credits, have ${err.available}`);
76
+ * }
77
+ * }
78
+ * ```
79
+ */
80
+ declare class InsufficientCreditsError extends ApiError {
81
+ name: string;
82
+ /** Credits required for the operation */
83
+ required: number;
84
+ /** Credits currently available */
85
+ available: number;
86
+ constructor(message: string, opts: {
87
+ status: number;
88
+ requestId?: string;
89
+ code?: string;
90
+ details?: {
91
+ required?: number;
92
+ available?: number;
93
+ };
94
+ });
95
+ toString(): string;
96
+ }
54
97
  /**
55
98
  * Error thrown by polling helpers when a job reaches the "failed" terminal state.
56
99
  */
@@ -62,6 +105,7 @@ declare class JobFailedError extends MappaError {
62
105
  code?: string;
63
106
  cause?: unknown;
64
107
  });
108
+ toString(): string;
65
109
  }
66
110
  /**
67
111
  * Error thrown by polling helpers when a job reaches the "canceled" terminal state.
@@ -73,6 +117,7 @@ declare class JobCanceledError extends MappaError {
73
117
  requestId?: string;
74
118
  cause?: unknown;
75
119
  });
120
+ toString(): string;
76
121
  }
77
122
  //#endregion
78
123
  //#region src/resources/transport.d.ts
@@ -215,6 +260,18 @@ type ReportOutputEntry<OutputType extends ReportOutputType, Template extends Rep
215
260
  };
216
261
  type ReportOutputForType<OutputType extends ReportOutputType> = ReportOutputEntry<OutputType, "sales_playbook"> | ReportOutputEntry<OutputType, "general_report"> | ReportOutputEntry<OutputType, "hiring_report"> | ReportOutputEntry<OutputType, "profile_alignment">;
217
262
  type ReportOutput = ReportOutputForType<"markdown"> | ReportOutputForType<"json"> | ReportOutputForType<"pdf"> | ReportOutputForType<"url">;
263
+ /**
264
+ * Report output configuration constrained to a specific output type.
265
+ * When T is a specific literal like "markdown", only markdown output configs are allowed.
266
+ * When T is the full union (ReportOutputType), all output configs are allowed.
267
+ *
268
+ * @example
269
+ * ```typescript
270
+ * type MarkdownOutput = ReportOutputFor<"markdown">; // Only markdown configs
271
+ * type AnyOutput = ReportOutputFor<ReportOutputType>; // All configs (same as ReportOutput)
272
+ * ```
273
+ */
274
+ 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;
218
275
  type TargetStrategy = "dominant" | "timerange" | "entity_id" | "magic_hint";
219
276
  type TargetOnMiss = "fallback_dominant" | "error";
220
277
  type TargetTimeRange = {
@@ -333,7 +390,7 @@ type WebhookConfig = {
333
390
  url: string;
334
391
  headers?: Record<string, string>;
335
392
  };
336
- type ReportCreateJobRequest = {
393
+ type ReportCreateJobRequest<T extends ReportOutputType = ReportOutputType> = {
337
394
  subject?: Subject;
338
395
  /**
339
396
  * Reference to already-uploaded media.
@@ -342,11 +399,11 @@ type ReportCreateJobRequest = {
342
399
  * use helper methods like `reports.createJobFromUrl()` / `reports.createJobFromFile()`.
343
400
  */
344
401
  media: MediaIdRef;
345
- output: ReportOutput;
402
+ output: ReportOutputFor<T>;
346
403
  /**
347
404
  * Select the target entity for analysis.
348
405
  *
349
- * When omitted, the API defaults to the dominant speaker.
406
+ * @defaultValue `{ strategy: "dominant" }` - analyzes the dominant speaker
350
407
  */
351
408
  target?: TargetSelector;
352
409
  options?: {
@@ -371,6 +428,7 @@ type ReportCreateJobRequest = {
371
428
  type ReportBase = {
372
429
  id: string;
373
430
  createdAt: string;
431
+ jobId?: string;
374
432
  subject?: Subject;
375
433
  media: {
376
434
  url?: string;
@@ -387,12 +445,14 @@ type ReportBase = {
387
445
  type MarkdownReport = ReportBase & {
388
446
  output: {
389
447
  type: "markdown";
448
+ template: ReportTemplateId;
390
449
  };
391
450
  markdown: string;
392
451
  };
393
452
  type JsonReport = ReportBase & {
394
453
  output: {
395
454
  type: "json";
455
+ template: ReportTemplateId;
396
456
  };
397
457
  sections: Array<{
398
458
  section_title: string;
@@ -402,7 +462,7 @@ type JsonReport = ReportBase & {
402
462
  type PdfReport = ReportBase & {
403
463
  output: {
404
464
  type: "pdf";
405
- template: string;
465
+ template: ReportTemplateId;
406
466
  };
407
467
  markdown: string;
408
468
  pdfUrl: string;
@@ -410,23 +470,35 @@ type PdfReport = ReportBase & {
410
470
  type UrlReport = ReportBase & {
411
471
  output: {
412
472
  type: "url";
413
- template: string;
473
+ template: ReportTemplateId;
414
474
  };
415
- markdown?: string;
416
- sections?: Array<{
475
+ markdown: string;
476
+ sections: Array<{
417
477
  section_title: string;
418
478
  section_content: JsonValue;
419
479
  }>;
420
480
  reportUrl: string;
421
481
  };
422
482
  type Report = MarkdownReport | JsonReport | PdfReport | UrlReport;
423
- type ReportJobReceipt = {
483
+ /**
484
+ * Maps an output type to its corresponding report type.
485
+ * Used for type-safe inference in generate methods.
486
+ *
487
+ * @example
488
+ * ```typescript
489
+ * type R = ReportForOutputType<"markdown">; // MarkdownReport
490
+ * type R = ReportForOutputType<"json">; // JsonReport
491
+ * type R = ReportForOutputType<ReportOutputType>; // Report (union)
492
+ * ```
493
+ */
494
+ type ReportForOutputType<T extends ReportOutputType> = T extends "markdown" ? MarkdownReport : T extends "json" ? JsonReport : T extends "pdf" ? PdfReport : T extends "url" ? UrlReport : Report;
495
+ type ReportJobReceipt<T extends ReportOutputType = ReportOutputType> = {
424
496
  jobId: string;
425
497
  status: "queued" | "running";
426
498
  stage?: JobStage;
427
499
  estimatedWaitSec?: number;
428
500
  requestId?: string;
429
- handle?: ReportRunHandle;
501
+ handle?: ReportRunHandle<T>;
430
502
  };
431
503
  type FeedbackReceipt = {
432
504
  id: string;
@@ -546,16 +618,16 @@ type WaitOptions = {
546
618
  */
547
619
  signal?: AbortSignal;
548
620
  };
549
- type ReportRunHandle = {
621
+ type ReportRunHandle<T extends ReportOutputType = ReportOutputType> = {
550
622
  jobId: string;
551
623
  stream(opts?: {
552
624
  signal?: AbortSignal;
553
625
  onEvent?: (e: JobEvent) => void;
554
626
  }): AsyncIterable<JobEvent>;
555
- wait(opts?: WaitOptions): Promise<Report>;
627
+ wait(opts?: WaitOptions): Promise<ReportForOutputType<T>>;
556
628
  cancel(): Promise<Job>;
557
629
  job(): Promise<Job>;
558
- report(): Promise<Report | null>;
630
+ report(): Promise<ReportForOutputType<T> | null>;
559
631
  };
560
632
  /**
561
633
  * Type guard for MarkdownReport.
@@ -1054,7 +1126,7 @@ declare class JobsResource {
1054
1126
  * - `signal` (from {@link UploadRequest}) is applied to the upload request.
1055
1127
  * Job creation only runs after a successful upload.
1056
1128
  */
1057
- type ReportCreateJobFromFileRequest = Omit<ReportCreateJobRequest, "media" | "idempotencyKey" | "requestId"> & Omit<UploadRequest, "filename"> & {
1129
+ type ReportCreateJobFromFileRequest<T extends ReportOutputType = ReportOutputType> = Omit<ReportCreateJobRequest<T>, "media" | "idempotencyKey" | "requestId"> & Omit<UploadRequest, "filename"> & {
1058
1130
  /**
1059
1131
  * Optional filename to attach to the upload.
1060
1132
  *
@@ -1082,7 +1154,7 @@ type ReportCreateJobFromFileRequest = Omit<ReportCreateJobRequest, "media" | "id
1082
1154
  * - `idempotencyKey` applies to the *whole* download + upload + create-job sequence.
1083
1155
  * - `requestId` is forwarded to both upload and job creation calls.
1084
1156
  */
1085
- type ReportCreateJobFromUrlRequest = Omit<ReportCreateJobRequest, "media" | "idempotencyKey" | "requestId"> & {
1157
+ type ReportCreateJobFromUrlRequest<T extends ReportOutputType = ReportOutputType> = Omit<ReportCreateJobRequest<T>, "media" | "idempotencyKey" | "requestId"> & {
1086
1158
  url: string;
1087
1159
  contentType?: string;
1088
1160
  filename?: string;
@@ -1119,6 +1191,7 @@ declare class ReportsResource {
1119
1191
  *
1120
1192
  * Behavior:
1121
1193
  * - Validates {@link MediaIdRef} at runtime (must provide `{ mediaId }`).
1194
+ * - Defaults to `{ strategy: "dominant" }` when `target` is omitted.
1122
1195
  * - Applies an idempotency key: uses `req.idempotencyKey` when provided; otherwise generates a best-effort default.
1123
1196
  * - Forwards `req.requestId` to the transport for end-to-end correlation.
1124
1197
  *
@@ -1127,14 +1200,14 @@ declare class ReportsResource {
1127
1200
  * - wait for completion and fetch the final report
1128
1201
  * - cancel the job, or fetch job/report metadata
1129
1202
  */
1130
- createJob(req: ReportCreateJobRequest): Promise<ReportJobReceipt>;
1203
+ createJob<T extends ReportOutputType = ReportOutputType>(req: ReportCreateJobRequest<T>): Promise<ReportJobReceipt<T>>;
1131
1204
  /**
1132
1205
  * Upload a file and create a report job in one call.
1133
1206
  *
1134
1207
  * Keeps `createJob()` strict about `media: { mediaId }` while offering a
1135
1208
  * convenient helper when you start from raw bytes.
1136
1209
  */
1137
- createJobFromFile(req: ReportCreateJobFromFileRequest): Promise<ReportJobReceipt>;
1210
+ createJobFromFile<T extends ReportOutputType = ReportOutputType>(req: ReportCreateJobFromFileRequest<T>): Promise<ReportJobReceipt<T>>;
1138
1211
  /**
1139
1212
  * Download a file from a URL, upload it, and create a report job.
1140
1213
  *
@@ -1151,7 +1224,7 @@ declare class ReportsResource {
1151
1224
  * - Only allows `http:` and `https:` URLs.
1152
1225
  * - Requires a resolvable `contentType` (from `req.contentType` or response header).
1153
1226
  */
1154
- createJobFromUrl(req: ReportCreateJobFromUrlRequest): Promise<ReportJobReceipt>;
1227
+ createJobFromUrl<T extends ReportOutputType = ReportOutputType>(req: ReportCreateJobFromUrlRequest<T>): Promise<ReportJobReceipt<T>>;
1155
1228
  get(reportId: string, opts?: {
1156
1229
  requestId?: string;
1157
1230
  signal?: AbortSignal;
@@ -1164,24 +1237,24 @@ declare class ReportsResource {
1164
1237
  * Convenience wrapper: createJob + wait + get
1165
1238
  * Use for scripts; for production prefer createJob + webhooks/stream.
1166
1239
  */
1167
- generate(req: ReportCreateJobRequest, opts?: {
1240
+ generate<T extends ReportOutputType = ReportOutputType>(req: ReportCreateJobRequest<T>, opts?: {
1168
1241
  wait?: WaitOptions;
1169
- }): Promise<Report>;
1242
+ }): Promise<ReportForOutputType<T>>;
1170
1243
  /**
1171
1244
  * Convenience wrapper: createJobFromFile + wait + get.
1172
1245
  * Use for scripts; for production prefer createJobFromFile + webhooks/stream.
1173
1246
  */
1174
- generateFromFile(req: ReportCreateJobFromFileRequest, opts?: {
1247
+ generateFromFile<T extends ReportOutputType = ReportOutputType>(req: ReportCreateJobFromFileRequest<T>, opts?: {
1175
1248
  wait?: WaitOptions;
1176
- }): Promise<Report>;
1249
+ }): Promise<ReportForOutputType<T>>;
1177
1250
  /**
1178
1251
  * Convenience wrapper: createJobFromUrl + wait + get.
1179
1252
  * Use for scripts; for production prefer createJobFromUrl + webhooks/stream.
1180
1253
  */
1181
- generateFromUrl(req: ReportCreateJobFromUrlRequest, opts?: {
1254
+ generateFromUrl<T extends ReportOutputType = ReportOutputType>(req: ReportCreateJobFromUrlRequest<T>, opts?: {
1182
1255
  wait?: WaitOptions;
1183
- }): Promise<Report>;
1184
- makeHandle(jobId: string): ReportRunHandle;
1256
+ }): Promise<ReportForOutputType<T>>;
1257
+ makeHandle<T extends ReportOutputType = ReportOutputType>(jobId: string): ReportRunHandle<T>;
1185
1258
  private defaultIdempotencyKey;
1186
1259
  private normalizeJobRequest;
1187
1260
  }
@@ -1285,5 +1358,21 @@ declare class Mappa {
1285
1358
  * Type guard for catching SDK errors.
1286
1359
  */
1287
1360
  declare function isMappaError(err: unknown): err is MappaError;
1361
+ /**
1362
+ * Type guard for insufficient credits errors.
1363
+ *
1364
+ * @example
1365
+ * ```typescript
1366
+ * try {
1367
+ * await mappa.reports.createJob({ ... });
1368
+ * } catch (err) {
1369
+ * if (isInsufficientCreditsError(err)) {
1370
+ * console.log(`Need ${err.required} credits, have ${err.available}`);
1371
+ * }
1372
+ * }
1373
+ * ```
1374
+ */
1375
+ declare function isInsufficientCreditsError(err: unknown): err is InsufficientCreditsError;
1288
1376
  //#endregion
1289
- export { ApiError, AuthError, CreditBalance, CreditTransaction, CreditTransactionType, CreditUsage, CursorPage, CursorPaginationParams, Entity, EntityTagsResult, FeedbackReceipt, FileDeleteReceipt, 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, isJsonReport, isMappaError, isMarkdownReport, isPdfReport, isUrlReport };
1377
+ 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, Subject, TargetDominant, TargetEntityId, TargetFor, TargetMagicHint, TargetOnMiss, TargetSelector, TargetStrategy, TargetStrategyMap, TargetTimeRange, TargetTimeRangeStrategy, UrlReport, Usage, ValidationError, WaitOptions, WebhookConfig, hasEntity, isInsufficientCreditsError, isJsonReport, isMappaError, isMarkdownReport, isPdfReport, isUrlReport };
1378
+ //# sourceMappingURL=index.d.mts.map