@mappa-ai/mappa-node 0.1.2 → 1.1.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.
- package/README.md +420 -31
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1235 -54
- package/dist/index.d.mts +1235 -54
- package/dist/index.mjs +1 -1
- package/package.json +4 -4
package/dist/index.d.cts
CHANGED
|
@@ -1,67 +1,1248 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
//#region src/errors.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Base error type for all SDK-raised errors.
|
|
4
|
+
*
|
|
5
|
+
* When available, {@link MappaError.requestId} can be used to correlate a failure
|
|
6
|
+
* with server logs/support.
|
|
7
|
+
*/
|
|
8
|
+
declare class MappaError extends Error {
|
|
9
|
+
name: string;
|
|
10
|
+
requestId?: string;
|
|
11
|
+
code?: string;
|
|
12
|
+
constructor(message: string, opts?: {
|
|
13
|
+
requestId?: string;
|
|
14
|
+
code?: string;
|
|
15
|
+
cause?: unknown;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Error returned when the API responds with a non-2xx status.
|
|
20
|
+
*/
|
|
21
|
+
declare class ApiError extends MappaError {
|
|
22
|
+
name: string;
|
|
23
|
+
status: number;
|
|
24
|
+
details?: unknown;
|
|
25
|
+
constructor(message: string, opts: {
|
|
26
|
+
status: number;
|
|
27
|
+
requestId?: string;
|
|
28
|
+
code?: string;
|
|
29
|
+
details?: unknown;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Error returned for HTTP 429 responses.
|
|
34
|
+
*
|
|
35
|
+
* If provided by the server, {@link RateLimitError.retryAfterMs} indicates when
|
|
36
|
+
* it is safe to retry.
|
|
37
|
+
*/
|
|
38
|
+
declare class RateLimitError extends ApiError {
|
|
39
|
+
name: string;
|
|
40
|
+
retryAfterMs?: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Error returned for authentication/authorization failures (typically 401/403).
|
|
44
|
+
*/
|
|
45
|
+
declare class AuthError extends ApiError {
|
|
46
|
+
name: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Error returned when the server rejects a request as invalid (typically 422).
|
|
50
|
+
*/
|
|
51
|
+
declare class ValidationError extends ApiError {
|
|
52
|
+
name: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Error thrown by polling helpers when a job reaches the "failed" terminal state.
|
|
56
|
+
*/
|
|
57
|
+
declare class JobFailedError extends MappaError {
|
|
58
|
+
name: string;
|
|
59
|
+
jobId: string;
|
|
60
|
+
constructor(jobId: string, message: string, opts?: {
|
|
61
|
+
requestId?: string;
|
|
62
|
+
code?: string;
|
|
63
|
+
cause?: unknown;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Error thrown by polling helpers when a job reaches the "canceled" terminal state.
|
|
68
|
+
*/
|
|
69
|
+
declare class JobCanceledError extends MappaError {
|
|
70
|
+
name: string;
|
|
71
|
+
jobId: string;
|
|
72
|
+
constructor(jobId: string, message: string, opts?: {
|
|
73
|
+
requestId?: string;
|
|
74
|
+
cause?: unknown;
|
|
75
|
+
});
|
|
6
76
|
}
|
|
7
77
|
//#endregion
|
|
8
|
-
//#region src/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
78
|
+
//#region src/resources/transport.d.ts
|
|
79
|
+
type Telemetry = {
|
|
80
|
+
onRequest?: (ctx: {
|
|
81
|
+
method: string;
|
|
82
|
+
url: string;
|
|
83
|
+
requestId?: string;
|
|
84
|
+
}) => void;
|
|
85
|
+
onResponse?: (ctx: {
|
|
86
|
+
status: number;
|
|
87
|
+
url: string;
|
|
88
|
+
requestId?: string;
|
|
89
|
+
durationMs: number;
|
|
90
|
+
}) => void;
|
|
91
|
+
onError?: (ctx: {
|
|
92
|
+
url: string;
|
|
93
|
+
requestId?: string;
|
|
94
|
+
error: unknown;
|
|
95
|
+
}) => void;
|
|
96
|
+
};
|
|
97
|
+
type TransportOptions = {
|
|
98
|
+
apiKey: string;
|
|
99
|
+
baseUrl: string;
|
|
100
|
+
timeoutMs: number;
|
|
101
|
+
maxRetries: number;
|
|
102
|
+
defaultHeaders?: Record<string, string>;
|
|
103
|
+
fetch?: typeof fetch;
|
|
104
|
+
telemetry?: Telemetry;
|
|
105
|
+
userAgent?: string;
|
|
106
|
+
};
|
|
107
|
+
type RequestOptions = {
|
|
108
|
+
method: "GET" | "POST" | "DELETE" | "PUT" | "PATCH";
|
|
109
|
+
path: string;
|
|
110
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
111
|
+
headers?: Record<string, string | undefined>;
|
|
112
|
+
body?: unknown;
|
|
113
|
+
idempotencyKey?: string;
|
|
114
|
+
requestId?: string;
|
|
115
|
+
signal?: AbortSignal;
|
|
116
|
+
retryable?: boolean;
|
|
117
|
+
};
|
|
118
|
+
type TransportResponse<T> = {
|
|
119
|
+
data: T;
|
|
120
|
+
status: number;
|
|
121
|
+
requestId?: string;
|
|
122
|
+
headers: Headers;
|
|
123
|
+
};
|
|
124
|
+
declare class Transport {
|
|
125
|
+
private readonly opts;
|
|
126
|
+
private readonly fetchImpl;
|
|
127
|
+
constructor(opts: TransportOptions);
|
|
128
|
+
request<T>(req: RequestOptions): Promise<TransportResponse<T>>;
|
|
42
129
|
}
|
|
43
130
|
//#endregion
|
|
44
|
-
//#region src/
|
|
131
|
+
//#region src/types.d.ts
|
|
45
132
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
133
|
+
* JSON-serializable value.
|
|
134
|
+
*
|
|
135
|
+
* Used throughout the SDK for message payloads, webhook data, and server-provided
|
|
136
|
+
* metadata where the exact shape is not known at compile time.
|
|
48
137
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
138
|
+
type JsonValue = string | number | boolean | null | {
|
|
139
|
+
[k: string]: JsonValue;
|
|
140
|
+
} | JsonValue[];
|
|
141
|
+
type MediaRef = {
|
|
142
|
+
url: string;
|
|
143
|
+
contentType?: string;
|
|
144
|
+
filename?: string;
|
|
145
|
+
} | {
|
|
146
|
+
mediaId: string;
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* A reference to an already-uploaded media object.
|
|
150
|
+
*/
|
|
151
|
+
type MediaIdRef = {
|
|
152
|
+
mediaId: string;
|
|
153
|
+
};
|
|
154
|
+
type ReportTemplateId = "sales_playbook" | "general_report" | "hiring_report" | "profile_alignment";
|
|
155
|
+
type ReportTemplateParamsMap = {
|
|
156
|
+
sales_playbook: Record<string, never>;
|
|
157
|
+
general_report: Record<string, never>;
|
|
158
|
+
hiring_report: {
|
|
159
|
+
roleTitle: string;
|
|
160
|
+
roleDescription: string;
|
|
161
|
+
companyCulture: string;
|
|
162
|
+
};
|
|
163
|
+
profile_alignment: {
|
|
164
|
+
idealProfile: string;
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
type ReportOutputType = "markdown" | "json" | "pdf" | "url";
|
|
168
|
+
type ReportOutputEntry<OutputType extends ReportOutputType, Template extends ReportTemplateId> = ReportTemplateParamsMap[Template] extends Record<string, never> ? {
|
|
169
|
+
type: OutputType;
|
|
170
|
+
template: Template;
|
|
171
|
+
templateParams?: ReportTemplateParamsMap[Template];
|
|
172
|
+
} : {
|
|
173
|
+
type: OutputType;
|
|
174
|
+
template: Template;
|
|
175
|
+
templateParams: ReportTemplateParamsMap[Template];
|
|
176
|
+
};
|
|
177
|
+
type ReportOutputForType<OutputType extends ReportOutputType> = ReportOutputEntry<OutputType, "sales_playbook"> | ReportOutputEntry<OutputType, "general_report"> | ReportOutputEntry<OutputType, "hiring_report"> | ReportOutputEntry<OutputType, "profile_alignment">;
|
|
178
|
+
type ReportOutput = ReportOutputForType<"markdown"> | ReportOutputForType<"json"> | ReportOutputForType<"pdf"> | ReportOutputForType<"url">;
|
|
179
|
+
type TargetStrategy = "dominant" | "timerange" | "entity_id" | "magic_hint";
|
|
180
|
+
type TargetOnMiss = "fallback_dominant" | "error";
|
|
181
|
+
type TargetTimeRange = {
|
|
182
|
+
/**
|
|
183
|
+
* Start time in seconds.
|
|
184
|
+
* When omitted, starts from the beginning.
|
|
185
|
+
*/
|
|
186
|
+
startSeconds?: number;
|
|
187
|
+
/**
|
|
188
|
+
* End time in seconds.
|
|
189
|
+
* When omitted, goes until the end.
|
|
190
|
+
*/
|
|
191
|
+
endSeconds?: number;
|
|
192
|
+
};
|
|
193
|
+
type TargetBase = {
|
|
194
|
+
/**
|
|
195
|
+
* Behavior when the entity is not found.
|
|
196
|
+
*/
|
|
197
|
+
onMiss?: TargetOnMiss;
|
|
198
|
+
/**
|
|
199
|
+
* Tags to apply to the selected entity after job completion.
|
|
200
|
+
*
|
|
201
|
+
* Tags must be 1-64 characters, alphanumeric with underscores and hyphens only.
|
|
202
|
+
* Maximum 10 tags per request.
|
|
203
|
+
*
|
|
204
|
+
* @example ["interviewer", "sales-rep", "round-1"]
|
|
205
|
+
*/
|
|
206
|
+
tags?: string[];
|
|
207
|
+
/**
|
|
208
|
+
* Exclude speakers whose entities have ANY of these tags from selection.
|
|
209
|
+
*
|
|
210
|
+
* Useful for filtering out known interviewers, hosts, etc.
|
|
211
|
+
*
|
|
212
|
+
* @example ["interviewer", "host"]
|
|
213
|
+
*/
|
|
214
|
+
excludeTags?: string[];
|
|
215
|
+
};
|
|
216
|
+
type TargetDominant = TargetBase & {
|
|
217
|
+
strategy: "dominant";
|
|
218
|
+
};
|
|
219
|
+
type TargetTimeRangeStrategy = TargetBase & {
|
|
220
|
+
strategy: "timerange";
|
|
221
|
+
timeRange: TargetTimeRange;
|
|
222
|
+
};
|
|
223
|
+
type TargetEntityId = TargetBase & {
|
|
224
|
+
strategy: "entity_id";
|
|
225
|
+
entityId: string;
|
|
226
|
+
};
|
|
227
|
+
type TargetMagicHint = TargetBase & {
|
|
228
|
+
strategy: "magic_hint";
|
|
229
|
+
hint: string;
|
|
230
|
+
};
|
|
231
|
+
type TargetSelector = TargetDominant | TargetTimeRangeStrategy | TargetEntityId | TargetMagicHint;
|
|
232
|
+
type TargetStrategyMap = {
|
|
233
|
+
dominant: TargetDominant;
|
|
234
|
+
timerange: TargetTimeRangeStrategy;
|
|
235
|
+
entity_id: TargetEntityId;
|
|
236
|
+
magic_hint: TargetMagicHint;
|
|
237
|
+
};
|
|
238
|
+
type TargetFor<Strategy extends TargetStrategy> = TargetStrategyMap[Strategy];
|
|
239
|
+
type Usage = {
|
|
240
|
+
creditsUsed: number;
|
|
241
|
+
creditsDiscounted?: number;
|
|
242
|
+
creditsNetUsed: number;
|
|
243
|
+
durationMs?: number;
|
|
244
|
+
modelVersion?: string;
|
|
245
|
+
};
|
|
246
|
+
type JobStage = "uploaded" | "queued" | "transcoding" | "extracting" | "scoring" | "rendering" | "finalizing";
|
|
247
|
+
type JobStatus = "queued" | "running" | "succeeded" | "failed" | "canceled";
|
|
248
|
+
type JobCreditReservation = {
|
|
249
|
+
reservedCredits: number | null;
|
|
250
|
+
reservationStatus: "active" | "released" | "applied" | null;
|
|
251
|
+
};
|
|
252
|
+
type Job = {
|
|
253
|
+
id: string;
|
|
254
|
+
type: "report.generate";
|
|
255
|
+
status: JobStatus;
|
|
256
|
+
stage?: JobStage;
|
|
257
|
+
progress?: number;
|
|
258
|
+
createdAt: string;
|
|
259
|
+
updatedAt: string;
|
|
260
|
+
reportId?: string;
|
|
261
|
+
usage?: Usage;
|
|
262
|
+
credits?: JobCreditReservation;
|
|
263
|
+
releasedCredits?: number | null;
|
|
264
|
+
error?: {
|
|
265
|
+
code: string;
|
|
266
|
+
message: string;
|
|
267
|
+
details?: JsonValue;
|
|
268
|
+
retryable?: boolean;
|
|
269
|
+
};
|
|
270
|
+
requestId?: string;
|
|
271
|
+
};
|
|
272
|
+
type JobEvent = {
|
|
273
|
+
type: "status";
|
|
274
|
+
job: Job;
|
|
275
|
+
} | {
|
|
276
|
+
type: "stage";
|
|
277
|
+
stage: JobStage;
|
|
278
|
+
progress?: number;
|
|
279
|
+
job: Job;
|
|
280
|
+
} | {
|
|
281
|
+
type: "log";
|
|
282
|
+
message: string;
|
|
283
|
+
ts: string;
|
|
284
|
+
} | {
|
|
285
|
+
type: "terminal";
|
|
286
|
+
job: Job;
|
|
287
|
+
};
|
|
288
|
+
type Subject = {
|
|
289
|
+
id?: string;
|
|
290
|
+
externalRef?: string;
|
|
291
|
+
metadata?: Record<string, JsonValue>;
|
|
292
|
+
};
|
|
293
|
+
type WebhookConfig = {
|
|
294
|
+
url: string;
|
|
295
|
+
headers?: Record<string, string>;
|
|
296
|
+
};
|
|
297
|
+
type ReportCreateJobRequest = {
|
|
298
|
+
subject?: Subject;
|
|
299
|
+
/**
|
|
300
|
+
* Reference to already-uploaded media.
|
|
301
|
+
*
|
|
302
|
+
* Note: Report job creation requires a `mediaId`. To start from a remote URL or local bytes,
|
|
303
|
+
* use helper methods like `reports.createJobFromUrl()` / `reports.createJobFromFile()`.
|
|
304
|
+
*/
|
|
305
|
+
media: MediaIdRef;
|
|
306
|
+
output: ReportOutput;
|
|
307
|
+
/**
|
|
308
|
+
* Select the target entity for analysis.
|
|
309
|
+
*
|
|
310
|
+
* When omitted, the API defaults to the dominant speaker.
|
|
311
|
+
*/
|
|
312
|
+
target?: TargetSelector;
|
|
313
|
+
options?: {
|
|
314
|
+
language?: string;
|
|
315
|
+
timezone?: string;
|
|
316
|
+
includeMetrics?: boolean;
|
|
317
|
+
includeRawModelOutput?: boolean;
|
|
318
|
+
};
|
|
319
|
+
/**
|
|
320
|
+
* Webhook to call when the job completes or fails.
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* webhook: {
|
|
324
|
+
* url: "https://example.com/webhooks/mappa",
|
|
325
|
+
* headers: { "X-Custom-Header": "value" }
|
|
326
|
+
* }
|
|
327
|
+
*/
|
|
328
|
+
webhook?: WebhookConfig;
|
|
329
|
+
idempotencyKey?: string;
|
|
330
|
+
requestId?: string;
|
|
331
|
+
};
|
|
332
|
+
type ReportBase = {
|
|
333
|
+
id: string;
|
|
334
|
+
createdAt: string;
|
|
335
|
+
subject?: Subject;
|
|
336
|
+
media: {
|
|
337
|
+
url?: string;
|
|
338
|
+
mediaId?: string;
|
|
339
|
+
};
|
|
340
|
+
entity: {
|
|
341
|
+
id: string;
|
|
342
|
+
tags: string[];
|
|
343
|
+
};
|
|
344
|
+
usage?: Usage;
|
|
345
|
+
metrics?: Record<string, JsonValue>;
|
|
346
|
+
raw?: JsonValue;
|
|
347
|
+
};
|
|
348
|
+
type MarkdownReport = ReportBase & {
|
|
349
|
+
output: {
|
|
350
|
+
type: "markdown";
|
|
351
|
+
};
|
|
352
|
+
markdown: string;
|
|
353
|
+
};
|
|
354
|
+
type JsonReport = ReportBase & {
|
|
355
|
+
output: {
|
|
356
|
+
type: "json";
|
|
357
|
+
};
|
|
358
|
+
sections: Array<{
|
|
359
|
+
section_title: string;
|
|
360
|
+
section_content: JsonValue;
|
|
361
|
+
}>;
|
|
362
|
+
};
|
|
363
|
+
type PdfReport = ReportBase & {
|
|
364
|
+
output: {
|
|
365
|
+
type: "pdf";
|
|
366
|
+
template: string;
|
|
367
|
+
};
|
|
368
|
+
markdown: string;
|
|
369
|
+
pdfUrl: string;
|
|
370
|
+
};
|
|
371
|
+
type UrlReport = ReportBase & {
|
|
372
|
+
output: {
|
|
373
|
+
type: "url";
|
|
374
|
+
template: string;
|
|
375
|
+
};
|
|
376
|
+
markdown?: string;
|
|
377
|
+
sections?: Array<{
|
|
378
|
+
section_title: string;
|
|
379
|
+
section_content: JsonValue;
|
|
380
|
+
}>;
|
|
381
|
+
reportUrl: string;
|
|
382
|
+
};
|
|
383
|
+
type Report = MarkdownReport | JsonReport | PdfReport | UrlReport;
|
|
384
|
+
type ReportJobReceipt = {
|
|
385
|
+
jobId: string;
|
|
386
|
+
status: "queued" | "running";
|
|
387
|
+
stage?: JobStage;
|
|
388
|
+
estimatedWaitSec?: number;
|
|
389
|
+
requestId?: string;
|
|
390
|
+
handle?: ReportRunHandle;
|
|
391
|
+
};
|
|
392
|
+
type FeedbackReceipt = {
|
|
393
|
+
id: string;
|
|
394
|
+
createdAt: string;
|
|
395
|
+
target: {
|
|
396
|
+
reportId?: string;
|
|
397
|
+
jobId?: string;
|
|
398
|
+
};
|
|
399
|
+
rating: "thumbs_up" | "thumbs_down" | "1" | "2" | "3" | "4" | "5";
|
|
400
|
+
tags?: string[];
|
|
401
|
+
comment?: string;
|
|
402
|
+
credits: {
|
|
403
|
+
eligible: boolean;
|
|
404
|
+
reason?: string;
|
|
405
|
+
discountApplied: number;
|
|
406
|
+
netUsed: number;
|
|
407
|
+
};
|
|
408
|
+
};
|
|
409
|
+
type MediaObject = {
|
|
410
|
+
mediaId: string;
|
|
411
|
+
createdAt: string;
|
|
412
|
+
contentType: string;
|
|
413
|
+
filename?: string;
|
|
414
|
+
sizeBytes?: number;
|
|
415
|
+
};
|
|
416
|
+
type MediaProcessingStatus = "PENDING" | "PROCESSING" | "COMPLETED" | "FAILED";
|
|
417
|
+
type MediaRetention = {
|
|
418
|
+
expiresAt: string | null;
|
|
419
|
+
daysRemaining: number | null;
|
|
420
|
+
locked: boolean;
|
|
421
|
+
};
|
|
422
|
+
type MediaFile = {
|
|
423
|
+
mediaId: string;
|
|
424
|
+
createdAt: string;
|
|
425
|
+
contentType: string;
|
|
426
|
+
filename: string | null;
|
|
427
|
+
sizeBytes: number | null;
|
|
428
|
+
durationSeconds: number | null;
|
|
429
|
+
processingStatus: MediaProcessingStatus;
|
|
430
|
+
lastUsedAt: string | null;
|
|
431
|
+
retention: MediaRetention;
|
|
432
|
+
};
|
|
433
|
+
type FileDeleteReceipt = {
|
|
434
|
+
mediaId: string;
|
|
435
|
+
deleted: true;
|
|
436
|
+
};
|
|
437
|
+
type RetentionLockResult = {
|
|
438
|
+
mediaId: string;
|
|
439
|
+
retentionLock: boolean;
|
|
440
|
+
message: string;
|
|
441
|
+
};
|
|
442
|
+
type CursorPaginationParams = {
|
|
443
|
+
limit?: number;
|
|
444
|
+
cursor?: string;
|
|
445
|
+
};
|
|
446
|
+
type OffsetPaginationParams = {
|
|
447
|
+
limit?: number;
|
|
448
|
+
offset?: number;
|
|
449
|
+
};
|
|
450
|
+
type CursorPage<T> = {
|
|
451
|
+
data: T[];
|
|
452
|
+
cursor?: string;
|
|
453
|
+
hasMore: boolean;
|
|
454
|
+
};
|
|
455
|
+
type OffsetPage<T> = {
|
|
456
|
+
data: T[];
|
|
457
|
+
pagination: {
|
|
458
|
+
limit: number;
|
|
459
|
+
offset: number;
|
|
460
|
+
total: number;
|
|
461
|
+
};
|
|
462
|
+
};
|
|
463
|
+
type CreditBalance = {
|
|
464
|
+
balance: number;
|
|
465
|
+
reserved: number;
|
|
466
|
+
available: number;
|
|
467
|
+
};
|
|
468
|
+
type CreditTransactionType = "PURCHASE" | "SUBSCRIPTION_GRANT" | "PROMO_GRANT" | "USAGE" | "REFUND" | "FEEDBACK_DISCOUNT" | "ADJUSTMENT" | "EXPIRATION";
|
|
469
|
+
type CreditTransaction = {
|
|
470
|
+
id: string;
|
|
471
|
+
type: CreditTransactionType;
|
|
472
|
+
amount: number;
|
|
473
|
+
createdAt: string;
|
|
474
|
+
effectiveAt: string;
|
|
475
|
+
expiresAt: string | null;
|
|
476
|
+
jobId: string | null;
|
|
477
|
+
job?: {
|
|
478
|
+
id: string;
|
|
479
|
+
status: string;
|
|
480
|
+
createdAt: string;
|
|
481
|
+
};
|
|
482
|
+
};
|
|
483
|
+
type CreditUsage = {
|
|
484
|
+
jobId: string;
|
|
485
|
+
creditsUsed: number;
|
|
486
|
+
creditsDiscounted?: number;
|
|
487
|
+
creditsNetUsed: number;
|
|
488
|
+
durationMs?: number;
|
|
489
|
+
modelVersion?: string;
|
|
490
|
+
};
|
|
491
|
+
/**
|
|
492
|
+
* Options for long-polling job completion.
|
|
493
|
+
*/
|
|
494
|
+
type WaitOptions = {
|
|
495
|
+
/**
|
|
496
|
+
* Maximum time to wait before failing.
|
|
497
|
+
*
|
|
498
|
+
* @defaultValue 300000
|
|
499
|
+
*/
|
|
500
|
+
timeoutMs?: number;
|
|
501
|
+
/**
|
|
502
|
+
* Initial polling interval.
|
|
503
|
+
*
|
|
504
|
+
* @defaultValue 1000
|
|
505
|
+
*/
|
|
506
|
+
pollIntervalMs?: number;
|
|
507
|
+
/**
|
|
508
|
+
* Maximum polling interval used with exponential backoff.
|
|
509
|
+
*
|
|
510
|
+
* @defaultValue 10000
|
|
511
|
+
*/
|
|
512
|
+
maxPollIntervalMs?: number;
|
|
513
|
+
/**
|
|
514
|
+
* Optional callback invoked on meaningful job state transitions.
|
|
515
|
+
*/
|
|
516
|
+
onEvent?: (event: JobEvent) => void;
|
|
517
|
+
/**
|
|
518
|
+
* Abort signal used to cancel waiting.
|
|
519
|
+
*/
|
|
520
|
+
signal?: AbortSignal;
|
|
521
|
+
};
|
|
522
|
+
type ReportRunHandle = {
|
|
523
|
+
jobId: string;
|
|
524
|
+
stream(opts?: {
|
|
525
|
+
signal?: AbortSignal;
|
|
526
|
+
onEvent?: (e: JobEvent) => void;
|
|
527
|
+
}): AsyncIterable<JobEvent>;
|
|
528
|
+
wait(opts?: WaitOptions): Promise<Report>;
|
|
529
|
+
cancel(): Promise<Job>;
|
|
530
|
+
job(): Promise<Job>;
|
|
531
|
+
report(): Promise<Report | null>;
|
|
532
|
+
};
|
|
533
|
+
/**
|
|
534
|
+
* Type guard for MarkdownReport.
|
|
535
|
+
*/
|
|
536
|
+
declare function isMarkdownReport(report: Report): report is MarkdownReport;
|
|
537
|
+
/**
|
|
538
|
+
* Type guard for JsonReport.
|
|
539
|
+
*/
|
|
540
|
+
declare function isJsonReport(report: Report): report is JsonReport;
|
|
541
|
+
/**
|
|
542
|
+
* Type guard for PdfReport.
|
|
543
|
+
*/
|
|
544
|
+
declare function isPdfReport(report: Report): report is PdfReport;
|
|
545
|
+
/**
|
|
546
|
+
* Type guard for UrlReport.
|
|
547
|
+
*/
|
|
548
|
+
declare function isUrlReport(report: Report): report is UrlReport;
|
|
549
|
+
type Entity = {
|
|
550
|
+
id: string;
|
|
551
|
+
tags: string[];
|
|
552
|
+
createdAt: string;
|
|
553
|
+
mediaCount: number;
|
|
554
|
+
lastSeenAt: string | null;
|
|
555
|
+
};
|
|
556
|
+
type EntityTagsResult = {
|
|
557
|
+
entityId: string;
|
|
558
|
+
tags: string[];
|
|
559
|
+
};
|
|
560
|
+
type ListEntitiesOptions = CursorPaginationParams & {
|
|
561
|
+
/**
|
|
562
|
+
* Filter entities by tags.
|
|
563
|
+
* Entities must have ALL specified tags (AND logic).
|
|
564
|
+
*/
|
|
565
|
+
tags?: string[];
|
|
566
|
+
};
|
|
567
|
+
type ListEntitiesResponse = {
|
|
568
|
+
entities: Entity[];
|
|
569
|
+
cursor?: string;
|
|
570
|
+
hasMore: boolean;
|
|
571
|
+
};
|
|
572
|
+
/**
|
|
573
|
+
* Type guard to check if a report has entity information.
|
|
574
|
+
* Always returns true since entity is always present in reports.
|
|
575
|
+
*/
|
|
576
|
+
declare function hasEntity(report: Report): report is Report & {
|
|
577
|
+
entity: {
|
|
578
|
+
id: string;
|
|
579
|
+
tags: string[];
|
|
580
|
+
};
|
|
581
|
+
};
|
|
582
|
+
//#endregion
|
|
583
|
+
//#region src/resources/credits.d.ts
|
|
584
|
+
type ListTransactionsOptions = {
|
|
585
|
+
/** Max transactions per page (1-100, default 50) */
|
|
586
|
+
limit?: number;
|
|
587
|
+
/** Offset for pagination (default 0) */
|
|
588
|
+
offset?: number;
|
|
589
|
+
requestId?: string;
|
|
590
|
+
signal?: AbortSignal;
|
|
591
|
+
};
|
|
592
|
+
type ListTransactionsResponse = {
|
|
593
|
+
transactions: CreditTransaction[];
|
|
594
|
+
pagination: {
|
|
595
|
+
limit: number;
|
|
596
|
+
offset: number;
|
|
597
|
+
total: number;
|
|
598
|
+
};
|
|
599
|
+
};
|
|
600
|
+
/**
|
|
601
|
+
* Credits API resource.
|
|
602
|
+
*
|
|
603
|
+
* Provides methods to manage and query credit balances, transaction history,
|
|
604
|
+
* and job-specific credit usage.
|
|
605
|
+
*/
|
|
606
|
+
declare class CreditsResource {
|
|
607
|
+
private readonly transport;
|
|
608
|
+
constructor(transport: Transport);
|
|
609
|
+
/**
|
|
610
|
+
* Get the current credit balance for your team.
|
|
611
|
+
*
|
|
612
|
+
* @example
|
|
613
|
+
* const balance = await mappa.credits.getBalance();
|
|
614
|
+
* console.log(`Available: ${balance.available} credits`);
|
|
615
|
+
*/
|
|
616
|
+
getBalance(opts?: {
|
|
617
|
+
requestId?: string;
|
|
618
|
+
signal?: AbortSignal;
|
|
619
|
+
}): Promise<CreditBalance>;
|
|
620
|
+
/**
|
|
621
|
+
* List credit transactions with offset pagination.
|
|
622
|
+
*
|
|
623
|
+
* @example
|
|
624
|
+
* const { transactions, pagination } = await mappa.credits.listTransactions({ limit: 25 });
|
|
625
|
+
* console.log(`Showing ${transactions.length} of ${pagination.total}`);
|
|
626
|
+
*/
|
|
627
|
+
listTransactions(opts?: ListTransactionsOptions): Promise<ListTransactionsResponse>;
|
|
628
|
+
/**
|
|
629
|
+
* Iterate over all transactions, automatically handling pagination.
|
|
630
|
+
*
|
|
631
|
+
* @example
|
|
632
|
+
* for await (const tx of mappa.credits.listAllTransactions()) {
|
|
633
|
+
* console.log(`${tx.type}: ${tx.amount}`);
|
|
634
|
+
* }
|
|
635
|
+
*/
|
|
636
|
+
listAllTransactions(opts?: Omit<ListTransactionsOptions, "offset">): AsyncIterable<CreditTransaction>;
|
|
637
|
+
/**
|
|
638
|
+
* Get credit usage details for a completed job.
|
|
639
|
+
*
|
|
640
|
+
* @example
|
|
641
|
+
* const usage = await mappa.credits.getJobUsage("job_xyz");
|
|
642
|
+
* console.log(`Net credits used: ${usage.creditsNetUsed}`);
|
|
643
|
+
*/
|
|
644
|
+
getJobUsage(jobId: string, opts?: {
|
|
645
|
+
requestId?: string;
|
|
646
|
+
signal?: AbortSignal;
|
|
647
|
+
}): Promise<CreditUsage>;
|
|
648
|
+
/**
|
|
649
|
+
* Check if the team has enough available credits for an operation.
|
|
650
|
+
*
|
|
651
|
+
* @example
|
|
652
|
+
* if (await mappa.credits.hasEnough(100)) {
|
|
653
|
+
* await mappa.reports.createJob(...);
|
|
654
|
+
* }
|
|
655
|
+
*/
|
|
656
|
+
hasEnough(credits: number, opts?: {
|
|
657
|
+
requestId?: string;
|
|
658
|
+
signal?: AbortSignal;
|
|
659
|
+
}): Promise<boolean>;
|
|
660
|
+
/**
|
|
661
|
+
* Get the number of available credits (balance - reserved).
|
|
662
|
+
*
|
|
663
|
+
* @example
|
|
664
|
+
* const available = await mappa.credits.getAvailable();
|
|
665
|
+
* console.log(`You can spend ${available} credits`);
|
|
666
|
+
*/
|
|
667
|
+
getAvailable(opts?: {
|
|
668
|
+
requestId?: string;
|
|
669
|
+
signal?: AbortSignal;
|
|
670
|
+
}): Promise<number>;
|
|
671
|
+
}
|
|
672
|
+
//#endregion
|
|
673
|
+
//#region src/resources/entities.d.ts
|
|
674
|
+
/**
|
|
675
|
+
* Entities API resource.
|
|
676
|
+
*
|
|
677
|
+
* Responsibilities:
|
|
678
|
+
* - List entities with optional tag filtering (`GET /v1/entities`)
|
|
679
|
+
* - Get single entity details (`GET /v1/entities/:entityId`)
|
|
680
|
+
* - Add tags to entities (`POST /v1/entities/:entityId/tags`)
|
|
681
|
+
* - Remove tags from entities (`DELETE /v1/entities/:entityId/tags`)
|
|
682
|
+
* - Replace all entity tags (`PUT /v1/entities/:entityId/tags`)
|
|
683
|
+
*
|
|
684
|
+
* Entities represent analyzed speakers identified by voice fingerprints.
|
|
685
|
+
* Tags allow you to label entities (e.g., "interviewer", "sales-rep") for easier
|
|
686
|
+
* filtering and identification across multiple reports.
|
|
687
|
+
*/
|
|
688
|
+
declare class EntitiesResource {
|
|
689
|
+
private readonly transport;
|
|
690
|
+
constructor(transport: Transport);
|
|
691
|
+
/**
|
|
692
|
+
* Get a single entity by ID.
|
|
693
|
+
*
|
|
694
|
+
* Returns entity metadata including tags, creation time, and usage statistics.
|
|
695
|
+
*
|
|
696
|
+
* @param entityId - The entity ID to retrieve
|
|
697
|
+
* @param opts - Optional request options (requestId, signal)
|
|
698
|
+
* @returns Entity details with tags and metadata
|
|
699
|
+
*
|
|
700
|
+
* @example
|
|
701
|
+
* ```typescript
|
|
702
|
+
* const entity = await mappa.entities.get("entity_abc123");
|
|
703
|
+
* console.log(entity.tags); // ["interviewer", "john"]
|
|
704
|
+
* ```
|
|
705
|
+
*/
|
|
706
|
+
get(entityId: string, opts?: {
|
|
707
|
+
requestId?: string;
|
|
708
|
+
signal?: AbortSignal;
|
|
709
|
+
}): Promise<Entity>;
|
|
710
|
+
/**
|
|
711
|
+
* List entities with optional tag filtering.
|
|
712
|
+
*
|
|
713
|
+
* Supports cursor-based pagination. Use the returned `cursor` for fetching
|
|
714
|
+
* subsequent pages, or use {@link listAll} for automatic pagination.
|
|
715
|
+
*
|
|
716
|
+
* When `tags` is provided, only entities with ALL specified tags are returned (AND logic).
|
|
717
|
+
*
|
|
718
|
+
* @param opts - List options: tags filter, cursor, limit
|
|
719
|
+
* @returns Paginated list of entities
|
|
720
|
+
*
|
|
721
|
+
* @example
|
|
722
|
+
* ```typescript
|
|
723
|
+
* // List all entities
|
|
724
|
+
* const page1 = await mappa.entities.list({ limit: 20 });
|
|
725
|
+
*
|
|
726
|
+
* // Filter by tags (must have both "interviewer" AND "sales")
|
|
727
|
+
* const filtered = await mappa.entities.list({
|
|
728
|
+
* tags: ["interviewer", "sales"],
|
|
729
|
+
* limit: 50
|
|
730
|
+
* });
|
|
731
|
+
*
|
|
732
|
+
* // Pagination
|
|
733
|
+
* const page2 = await mappa.entities.list({
|
|
734
|
+
* cursor: page1.cursor,
|
|
735
|
+
* limit: 20
|
|
736
|
+
* });
|
|
737
|
+
* ```
|
|
738
|
+
*/
|
|
739
|
+
list(opts?: ListEntitiesOptions & {
|
|
740
|
+
requestId?: string;
|
|
741
|
+
signal?: AbortSignal;
|
|
742
|
+
}): Promise<ListEntitiesResponse>;
|
|
54
743
|
/**
|
|
55
|
-
*
|
|
744
|
+
* Async iterator that automatically paginates through all entities.
|
|
745
|
+
*
|
|
746
|
+
* Useful for processing large entity sets without manual pagination management.
|
|
747
|
+
*
|
|
748
|
+
* @param opts - List options: tags filter, limit per page
|
|
749
|
+
* @yields Individual entities
|
|
750
|
+
*
|
|
751
|
+
* @example
|
|
752
|
+
* ```typescript
|
|
753
|
+
* // Process all entities with "interviewer" tag
|
|
754
|
+
* for await (const entity of mappa.entities.listAll({ tags: ["interviewer"] })) {
|
|
755
|
+
* console.log(`${entity.id}: ${entity.tags.join(", ")}`);
|
|
756
|
+
* }
|
|
757
|
+
* ```
|
|
56
758
|
*/
|
|
57
|
-
|
|
759
|
+
listAll(opts?: Omit<ListEntitiesOptions, "cursor"> & {
|
|
760
|
+
requestId?: string;
|
|
761
|
+
signal?: AbortSignal;
|
|
762
|
+
}): AsyncIterable<Entity>;
|
|
58
763
|
/**
|
|
59
|
-
*
|
|
764
|
+
* Get all entities with a specific tag.
|
|
765
|
+
*
|
|
766
|
+
* Convenience wrapper around {@link list} for single-tag filtering.
|
|
767
|
+
*
|
|
768
|
+
* @param tag - The tag to filter by
|
|
769
|
+
* @param opts - Optional pagination and request options
|
|
770
|
+
* @returns Paginated list of entities with the specified tag
|
|
771
|
+
*
|
|
772
|
+
* @example
|
|
773
|
+
* ```typescript
|
|
774
|
+
* const interviewers = await mappa.entities.getByTag("interviewer");
|
|
775
|
+
* ```
|
|
60
776
|
*/
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
777
|
+
getByTag(tag: string, opts?: Omit<ListEntitiesOptions, "tags"> & {
|
|
778
|
+
requestId?: string;
|
|
779
|
+
signal?: AbortSignal;
|
|
780
|
+
}): Promise<ListEntitiesResponse>;
|
|
781
|
+
/**
|
|
782
|
+
* Add tags to an entity.
|
|
783
|
+
*
|
|
784
|
+
* Idempotent: existing tags are preserved, duplicates are ignored.
|
|
785
|
+
*
|
|
786
|
+
* @param entityId - The entity ID to tag
|
|
787
|
+
* @param tags - Array of tags to add (1-10 tags, each 1-64 chars)
|
|
788
|
+
* @param opts - Optional request options
|
|
789
|
+
* @returns Updated tags for the entity
|
|
790
|
+
*
|
|
791
|
+
* @example
|
|
792
|
+
* ```typescript
|
|
793
|
+
* await mappa.entities.addTags("entity_abc123", ["interviewer", "john"]);
|
|
794
|
+
* ```
|
|
795
|
+
*/
|
|
796
|
+
addTags(entityId: string, tags: string[], opts?: {
|
|
797
|
+
requestId?: string;
|
|
798
|
+
signal?: AbortSignal;
|
|
799
|
+
}): Promise<EntityTagsResult>;
|
|
800
|
+
/**
|
|
801
|
+
* Remove tags from an entity.
|
|
802
|
+
*
|
|
803
|
+
* Idempotent: missing tags are silently ignored.
|
|
804
|
+
*
|
|
805
|
+
* @param entityId - The entity ID to update
|
|
806
|
+
* @param tags - Array of tags to remove
|
|
807
|
+
* @param opts - Optional request options
|
|
808
|
+
* @returns Updated tags for the entity
|
|
809
|
+
*
|
|
810
|
+
* @example
|
|
811
|
+
* ```typescript
|
|
812
|
+
* await mappa.entities.removeTags("entity_abc123", ["interviewer"]);
|
|
813
|
+
* ```
|
|
814
|
+
*/
|
|
815
|
+
removeTags(entityId: string, tags: string[], opts?: {
|
|
816
|
+
requestId?: string;
|
|
817
|
+
signal?: AbortSignal;
|
|
818
|
+
}): Promise<EntityTagsResult>;
|
|
819
|
+
/**
|
|
820
|
+
* Replace all tags on an entity.
|
|
821
|
+
*
|
|
822
|
+
* Sets the complete tag list, removing any tags not in the provided array.
|
|
823
|
+
* Pass an empty array to remove all tags.
|
|
824
|
+
*
|
|
825
|
+
* @param entityId - The entity ID to update
|
|
826
|
+
* @param tags - New complete tag list (0-10 tags)
|
|
827
|
+
* @param opts - Optional request options
|
|
828
|
+
* @returns Updated tags for the entity
|
|
829
|
+
*
|
|
830
|
+
* @example
|
|
831
|
+
* ```typescript
|
|
832
|
+
* // Replace all tags
|
|
833
|
+
* await mappa.entities.setTags("entity_abc123", ["sales-rep", "john"]);
|
|
834
|
+
*
|
|
835
|
+
* // Remove all tags
|
|
836
|
+
* await mappa.entities.setTags("entity_abc123", []);
|
|
837
|
+
* ```
|
|
838
|
+
*/
|
|
839
|
+
setTags(entityId: string, tags: string[], opts?: {
|
|
840
|
+
requestId?: string;
|
|
841
|
+
signal?: AbortSignal;
|
|
842
|
+
}): Promise<EntityTagsResult>;
|
|
843
|
+
}
|
|
844
|
+
//#endregion
|
|
845
|
+
//#region src/resources/feedback.d.ts
|
|
846
|
+
type FeedbackCreateRequest = {
|
|
847
|
+
reportId?: string;
|
|
848
|
+
jobId?: string;
|
|
849
|
+
rating: "thumbs_up" | "thumbs_down" | "1" | "2" | "3" | "4" | "5";
|
|
850
|
+
tags?: string[];
|
|
851
|
+
comment?: string;
|
|
852
|
+
corrections?: Array<{
|
|
853
|
+
path: string;
|
|
854
|
+
expected?: unknown;
|
|
855
|
+
observed?: unknown;
|
|
856
|
+
}>;
|
|
857
|
+
idempotencyKey?: string;
|
|
858
|
+
requestId?: string;
|
|
859
|
+
signal?: AbortSignal;
|
|
860
|
+
};
|
|
861
|
+
declare class FeedbackResource {
|
|
862
|
+
private readonly transport;
|
|
863
|
+
constructor(transport: Transport);
|
|
864
|
+
/**
|
|
865
|
+
* Create feedback for a report or job. Provide exactly one of `reportId` or `jobId`.
|
|
866
|
+
*/
|
|
867
|
+
create(req: FeedbackCreateRequest): Promise<FeedbackReceipt>;
|
|
868
|
+
}
|
|
869
|
+
//#endregion
|
|
870
|
+
//#region src/resources/files.d.ts
|
|
871
|
+
type UploadRequest = {
|
|
872
|
+
file: Blob | ArrayBuffer | Uint8Array | ReadableStream<Uint8Array>;
|
|
873
|
+
/**
|
|
874
|
+
* Optional override.
|
|
875
|
+
* If omitted, the SDK will try to infer it from `file.type` (Blob) and then from `filename`.
|
|
876
|
+
*/
|
|
877
|
+
contentType?: string;
|
|
878
|
+
filename?: string;
|
|
879
|
+
idempotencyKey?: string;
|
|
880
|
+
requestId?: string;
|
|
881
|
+
signal?: AbortSignal;
|
|
882
|
+
};
|
|
883
|
+
type ListFilesOptions = {
|
|
884
|
+
/** Max files per page (1-100, default 20) */
|
|
885
|
+
limit?: number;
|
|
886
|
+
/** Pagination cursor from previous response */
|
|
887
|
+
cursor?: string;
|
|
888
|
+
/** Include soft-deleted files (default false) */
|
|
889
|
+
includeDeleted?: boolean;
|
|
890
|
+
requestId?: string;
|
|
891
|
+
signal?: AbortSignal;
|
|
892
|
+
};
|
|
893
|
+
type ListFilesResponse = {
|
|
894
|
+
files: MediaFile[];
|
|
895
|
+
cursor?: string;
|
|
896
|
+
hasMore: boolean;
|
|
897
|
+
};
|
|
898
|
+
/**
|
|
899
|
+
* Uses multipart/form-data for uploads.
|
|
900
|
+
*
|
|
901
|
+
* If you need resumable uploads, add a dedicated resumable protocol.
|
|
902
|
+
*/
|
|
903
|
+
declare class FilesResource {
|
|
904
|
+
private readonly transport;
|
|
905
|
+
constructor(transport: Transport);
|
|
906
|
+
upload(req: UploadRequest): Promise<MediaObject>;
|
|
907
|
+
/**
|
|
908
|
+
* Retrieve metadata for a single uploaded file.
|
|
909
|
+
*
|
|
910
|
+
* @example
|
|
911
|
+
* const file = await mappa.files.get("media_abc123");
|
|
912
|
+
* console.log(file.processingStatus); // "COMPLETED"
|
|
913
|
+
*/
|
|
914
|
+
get(mediaId: string, opts?: {
|
|
915
|
+
requestId?: string;
|
|
916
|
+
signal?: AbortSignal;
|
|
917
|
+
}): Promise<MediaFile>;
|
|
918
|
+
/**
|
|
919
|
+
* List uploaded files with cursor pagination.
|
|
920
|
+
*
|
|
921
|
+
* @example
|
|
922
|
+
* const page1 = await mappa.files.list({ limit: 10 });
|
|
923
|
+
* if (page1.hasMore) {
|
|
924
|
+
* const page2 = await mappa.files.list({ limit: 10, cursor: page1.cursor });
|
|
925
|
+
* }
|
|
926
|
+
*/
|
|
927
|
+
list(opts?: ListFilesOptions): Promise<ListFilesResponse>;
|
|
928
|
+
/**
|
|
929
|
+
* Iterate over all files, automatically handling pagination.
|
|
930
|
+
*
|
|
931
|
+
* @example
|
|
932
|
+
* for await (const file of mappa.files.listAll()) {
|
|
933
|
+
* console.log(file.mediaId);
|
|
934
|
+
* }
|
|
935
|
+
*
|
|
936
|
+
* // Or collect all
|
|
937
|
+
* const allFiles = [];
|
|
938
|
+
* for await (const file of mappa.files.listAll({ limit: 50 })) {
|
|
939
|
+
* allFiles.push(file);
|
|
940
|
+
* }
|
|
941
|
+
*/
|
|
942
|
+
listAll(opts?: Omit<ListFilesOptions, "cursor">): AsyncIterable<MediaFile>;
|
|
943
|
+
/**
|
|
944
|
+
* Lock or unlock a file's retention to prevent/allow automatic deletion.
|
|
945
|
+
*
|
|
946
|
+
* @example
|
|
947
|
+
* // Prevent automatic deletion
|
|
948
|
+
* await mappa.files.setRetentionLock("media_abc", true);
|
|
949
|
+
*
|
|
950
|
+
* // Allow automatic deletion
|
|
951
|
+
* await mappa.files.setRetentionLock("media_abc", false);
|
|
952
|
+
*/
|
|
953
|
+
setRetentionLock(mediaId: string, locked: boolean, opts?: {
|
|
954
|
+
requestId?: string;
|
|
955
|
+
signal?: AbortSignal;
|
|
956
|
+
}): Promise<RetentionLockResult>;
|
|
957
|
+
delete(mediaId: string, opts?: {
|
|
958
|
+
idempotencyKey?: string;
|
|
959
|
+
requestId?: string;
|
|
960
|
+
signal?: AbortSignal;
|
|
961
|
+
}): Promise<FileDeleteReceipt>;
|
|
962
|
+
}
|
|
963
|
+
//#endregion
|
|
964
|
+
//#region src/resources/health.d.ts
|
|
965
|
+
declare class HealthResource {
|
|
966
|
+
private readonly transport;
|
|
967
|
+
constructor(transport: Transport);
|
|
968
|
+
ping(): Promise<{
|
|
969
|
+
ok: true;
|
|
970
|
+
time: string;
|
|
971
|
+
}>;
|
|
972
|
+
}
|
|
973
|
+
//#endregion
|
|
974
|
+
//#region src/resources/jobs.d.ts
|
|
975
|
+
declare class JobsResource {
|
|
976
|
+
private readonly transport;
|
|
977
|
+
constructor(transport: Transport);
|
|
978
|
+
get(jobId: string, opts?: {
|
|
979
|
+
requestId?: string;
|
|
980
|
+
signal?: AbortSignal;
|
|
981
|
+
}): Promise<Job>;
|
|
982
|
+
cancel(jobId: string, opts?: {
|
|
983
|
+
idempotencyKey?: string;
|
|
984
|
+
requestId?: string;
|
|
985
|
+
signal?: AbortSignal;
|
|
986
|
+
}): Promise<Job>;
|
|
987
|
+
wait(jobId: string, opts?: WaitOptions): Promise<Job>;
|
|
988
|
+
/**
|
|
989
|
+
* Public stream API.
|
|
990
|
+
* If you add SSE later, keep this signature and switch implementation internally.
|
|
991
|
+
* For now, it yields events based on polling. Use `AbortSignal` to cancel streaming.
|
|
992
|
+
*/
|
|
993
|
+
stream(jobId: string, opts?: {
|
|
994
|
+
signal?: AbortSignal;
|
|
995
|
+
onEvent?: (e: JobEvent) => void;
|
|
996
|
+
}): AsyncIterable<JobEvent>;
|
|
997
|
+
}
|
|
998
|
+
//#endregion
|
|
999
|
+
//#region src/resources/reports.d.ts
|
|
1000
|
+
/**
|
|
1001
|
+
* Request shape for {@link ReportsResource.createJobFromFile}.
|
|
1002
|
+
*
|
|
1003
|
+
* This helper performs two API calls as one logical operation:
|
|
1004
|
+
* 1) Upload bytes via `files.upload()` (multipart)
|
|
1005
|
+
* 2) Create a report job via {@link ReportsResource.createJob} using the returned `{ mediaId }`
|
|
1006
|
+
*
|
|
1007
|
+
* Differences vs {@link ReportCreateJobRequest}:
|
|
1008
|
+
* - `media` is derived from the upload result and therefore omitted.
|
|
1009
|
+
* - `idempotencyKey` applies to the *whole* upload + create-job sequence.
|
|
1010
|
+
* - `requestId` is forwarded to both requests for end-to-end correlation.
|
|
1011
|
+
*
|
|
1012
|
+
* Abort behavior:
|
|
1013
|
+
* - `signal` (from {@link UploadRequest}) is applied to the upload request.
|
|
1014
|
+
* Job creation only runs after a successful upload.
|
|
1015
|
+
*/
|
|
1016
|
+
type ReportCreateJobFromFileRequest = Omit<ReportCreateJobRequest, "media" | "idempotencyKey" | "requestId"> & Omit<UploadRequest, "filename"> & {
|
|
1017
|
+
/**
|
|
1018
|
+
* Optional filename to attach to the upload.
|
|
1019
|
+
*
|
|
1020
|
+
* When omitted, the upload layer may infer it (e.g. from a `File` object).
|
|
1021
|
+
*/
|
|
1022
|
+
filename?: string;
|
|
1023
|
+
/**
|
|
1024
|
+
* Idempotency for the upload + job creation sequence.
|
|
1025
|
+
*/
|
|
1026
|
+
idempotencyKey?: string;
|
|
1027
|
+
/**
|
|
1028
|
+
* Optional request correlation ID forwarded to both the upload and the job creation call.
|
|
1029
|
+
*/
|
|
1030
|
+
requestId?: string;
|
|
1031
|
+
};
|
|
1032
|
+
/**
|
|
1033
|
+
* Request shape for {@link ReportsResource.createJobFromUrl}.
|
|
1034
|
+
*
|
|
1035
|
+
* This helper performs two API calls as one logical operation:
|
|
1036
|
+
* 1) Download bytes from a remote URL using `fetch()`
|
|
1037
|
+
* 2) Upload bytes via `files.upload()` and then create a report job via {@link ReportsResource.createJob}
|
|
1038
|
+
*
|
|
1039
|
+
* Differences vs {@link ReportCreateJobRequest}:
|
|
1040
|
+
* - `media` is derived from the upload result and therefore omitted.
|
|
1041
|
+
* - `idempotencyKey` applies to the *whole* download + upload + create-job sequence.
|
|
1042
|
+
* - `requestId` is forwarded to both upload and job creation calls.
|
|
1043
|
+
*/
|
|
1044
|
+
type ReportCreateJobFromUrlRequest = Omit<ReportCreateJobRequest, "media" | "idempotencyKey" | "requestId"> & {
|
|
1045
|
+
url: string;
|
|
1046
|
+
contentType?: string;
|
|
1047
|
+
filename?: string;
|
|
1048
|
+
idempotencyKey?: string;
|
|
1049
|
+
requestId?: string;
|
|
1050
|
+
signal?: AbortSignal;
|
|
1051
|
+
};
|
|
1052
|
+
/**
|
|
1053
|
+
* Reports API resource.
|
|
1054
|
+
*
|
|
1055
|
+
* Responsibilities:
|
|
1056
|
+
* - Create report jobs (`POST /v1/reports/jobs`).
|
|
1057
|
+
* - Fetch reports by report ID (`GET /v1/reports/:reportId`).
|
|
1058
|
+
* - Fetch reports by job ID (`GET /v1/reports/by-job/:jobId`).
|
|
1059
|
+
*
|
|
1060
|
+
* Convenience helpers:
|
|
1061
|
+
* - {@link ReportsResource.createJobFromFile} orchestrates `files.upload()` + {@link ReportsResource.createJob}.
|
|
1062
|
+
* - {@link ReportsResource.createJobFromUrl} downloads a remote URL, uploads it, then calls {@link ReportsResource.createJob}.
|
|
1063
|
+
* - {@link ReportsResource.generate} / {@link ReportsResource.generateFromFile} are script-friendly wrappers that
|
|
1064
|
+
* create a job, wait for completion, and then fetch the final report.
|
|
1065
|
+
*
|
|
1066
|
+
* For production systems, prefer `createJob*()` plus webhooks or streaming job events rather than blocking waits.
|
|
1067
|
+
*/
|
|
1068
|
+
declare class ReportsResource {
|
|
1069
|
+
private readonly transport;
|
|
1070
|
+
private readonly jobs;
|
|
1071
|
+
private readonly files;
|
|
1072
|
+
private readonly fetchImpl;
|
|
1073
|
+
constructor(transport: Transport, jobs: JobsResource, files: {
|
|
1074
|
+
upload: (req: UploadRequest) => Promise<MediaObject>;
|
|
1075
|
+
}, fetchImpl: typeof fetch);
|
|
1076
|
+
/**
|
|
1077
|
+
* Create a new report job.
|
|
1078
|
+
*
|
|
1079
|
+
* Behavior:
|
|
1080
|
+
* - Validates {@link MediaIdRef} at runtime (must provide `{ mediaId }`).
|
|
1081
|
+
* - Applies an idempotency key: uses `req.idempotencyKey` when provided; otherwise generates a best-effort default.
|
|
1082
|
+
* - Forwards `req.requestId` to the transport for end-to-end correlation.
|
|
1083
|
+
*
|
|
1084
|
+
* The returned receipt includes a {@link ReportRunHandle} (`receipt.handle`) which can be used to:
|
|
1085
|
+
* - stream job events
|
|
1086
|
+
* - wait for completion and fetch the final report
|
|
1087
|
+
* - cancel the job, or fetch job/report metadata
|
|
1088
|
+
*/
|
|
1089
|
+
createJob(req: ReportCreateJobRequest): Promise<ReportJobReceipt>;
|
|
1090
|
+
/**
|
|
1091
|
+
* Upload a file and create a report job in one call.
|
|
1092
|
+
*
|
|
1093
|
+
* Keeps `createJob()` strict about `media: { mediaId }` while offering a
|
|
1094
|
+
* convenient helper when you start from raw bytes.
|
|
1095
|
+
*/
|
|
1096
|
+
createJobFromFile(req: ReportCreateJobFromFileRequest): Promise<ReportJobReceipt>;
|
|
1097
|
+
/**
|
|
1098
|
+
* Download a file from a URL, upload it, and create a report job.
|
|
1099
|
+
*
|
|
1100
|
+
* Recommended when starting from a remote URL because report job creation
|
|
1101
|
+
* only accepts `media: { mediaId }`.
|
|
1102
|
+
*
|
|
1103
|
+
* Workflow:
|
|
1104
|
+
* 1) `fetch(url)`
|
|
1105
|
+
* 2) Validate the response (2xx) and derive `contentType`
|
|
1106
|
+
* 3) `files.upload({ file: Blob, ... })`
|
|
1107
|
+
* 4) `createJob({ media: { mediaId }, ... })`
|
|
1108
|
+
*
|
|
1109
|
+
* Verification / safety:
|
|
1110
|
+
* - Only allows `http:` and `https:` URLs.
|
|
1111
|
+
* - Requires a resolvable `contentType` (from `req.contentType` or response header).
|
|
1112
|
+
*/
|
|
1113
|
+
createJobFromUrl(req: ReportCreateJobFromUrlRequest): Promise<ReportJobReceipt>;
|
|
1114
|
+
get(reportId: string, opts?: {
|
|
1115
|
+
requestId?: string;
|
|
1116
|
+
signal?: AbortSignal;
|
|
1117
|
+
}): Promise<Report>;
|
|
1118
|
+
getByJob(jobId: string, opts?: {
|
|
1119
|
+
requestId?: string;
|
|
1120
|
+
signal?: AbortSignal;
|
|
1121
|
+
}): Promise<Report | null>;
|
|
1122
|
+
/**
|
|
1123
|
+
* Convenience wrapper: createJob + wait + get
|
|
1124
|
+
* Use for scripts; for production prefer createJob + webhooks/stream.
|
|
1125
|
+
*/
|
|
1126
|
+
generate(req: ReportCreateJobRequest, opts?: {
|
|
1127
|
+
wait?: WaitOptions;
|
|
1128
|
+
}): Promise<Report>;
|
|
1129
|
+
/**
|
|
1130
|
+
* Convenience wrapper: createJobFromFile + wait + get.
|
|
1131
|
+
* Use for scripts; for production prefer createJobFromFile + webhooks/stream.
|
|
1132
|
+
*/
|
|
1133
|
+
generateFromFile(req: ReportCreateJobFromFileRequest, opts?: {
|
|
1134
|
+
wait?: WaitOptions;
|
|
1135
|
+
}): Promise<Report>;
|
|
1136
|
+
/**
|
|
1137
|
+
* Convenience wrapper: createJobFromUrl + wait + get.
|
|
1138
|
+
* Use for scripts; for production prefer createJobFromUrl + webhooks/stream.
|
|
1139
|
+
*/
|
|
1140
|
+
generateFromUrl(req: ReportCreateJobFromUrlRequest, opts?: {
|
|
1141
|
+
wait?: WaitOptions;
|
|
1142
|
+
}): Promise<Report>;
|
|
1143
|
+
makeHandle(jobId: string): ReportRunHandle;
|
|
1144
|
+
private defaultIdempotencyKey;
|
|
1145
|
+
private normalizeJobRequest;
|
|
1146
|
+
}
|
|
1147
|
+
//#endregion
|
|
1148
|
+
//#region src/resources/webhooks.d.ts
|
|
1149
|
+
/**
|
|
1150
|
+
* Async signature verification using WebCrypto (works in modern Node and browsers).
|
|
1151
|
+
* Signature scheme placeholder:
|
|
1152
|
+
* headers["mappa-signature"] = "t=1700000000,v1=<hex_hmac_sha256>"
|
|
1153
|
+
* Signed payload: `${t}.${rawBody}`
|
|
1154
|
+
*/
|
|
1155
|
+
declare class WebhooksResource {
|
|
1156
|
+
verifySignature(params: {
|
|
1157
|
+
payload: string;
|
|
1158
|
+
headers: Record<string, string | string[] | undefined>;
|
|
1159
|
+
secret: string;
|
|
1160
|
+
toleranceSec?: number;
|
|
1161
|
+
}): Promise<{
|
|
1162
|
+
ok: true;
|
|
64
1163
|
}>;
|
|
1164
|
+
parseEvent<T = unknown>(payload: string): {
|
|
1165
|
+
id: string;
|
|
1166
|
+
type: string;
|
|
1167
|
+
createdAt: string;
|
|
1168
|
+
data: T;
|
|
1169
|
+
};
|
|
1170
|
+
}
|
|
1171
|
+
//#endregion
|
|
1172
|
+
//#region src/Mappa.d.ts
|
|
1173
|
+
/**
|
|
1174
|
+
* Options for constructing a {@link Mappa} client.
|
|
1175
|
+
*/
|
|
1176
|
+
type MappaClientOptions = {
|
|
1177
|
+
/**
|
|
1178
|
+
* API key used for authenticating requests.
|
|
1179
|
+
*/
|
|
1180
|
+
apiKey: string;
|
|
1181
|
+
/**
|
|
1182
|
+
* Base URL for the Mappa API.
|
|
1183
|
+
*
|
|
1184
|
+
* @defaultValue "https://api.mappa.ai"
|
|
1185
|
+
*/
|
|
1186
|
+
baseUrl?: string;
|
|
1187
|
+
/**
|
|
1188
|
+
* Per-request timeout, in milliseconds.
|
|
1189
|
+
*
|
|
1190
|
+
* Note: this timeout applies to individual HTTP attempts (including retries).
|
|
1191
|
+
* Long-running workflows should use {@link JobsResource.wait} through
|
|
1192
|
+
* {@link ReportsResource.makeHandle} instead.
|
|
1193
|
+
*
|
|
1194
|
+
* @defaultValue 30000
|
|
1195
|
+
*/
|
|
1196
|
+
timeoutMs?: number;
|
|
1197
|
+
/**
|
|
1198
|
+
* Maximum number of retries performed by the transport for retryable requests.
|
|
1199
|
+
*
|
|
1200
|
+
* @defaultValue 2
|
|
1201
|
+
*/
|
|
1202
|
+
maxRetries?: number;
|
|
1203
|
+
/**
|
|
1204
|
+
* Headers that will be sent with every request.
|
|
1205
|
+
*/
|
|
1206
|
+
defaultHeaders?: Record<string, string>;
|
|
1207
|
+
/**
|
|
1208
|
+
* Custom fetch implementation (useful for polyfills, instrumentation, or tests).
|
|
1209
|
+
*/
|
|
1210
|
+
fetch?: typeof fetch;
|
|
1211
|
+
/**
|
|
1212
|
+
* Overrides the User-Agent header.
|
|
1213
|
+
*/
|
|
1214
|
+
userAgent?: string;
|
|
1215
|
+
/**
|
|
1216
|
+
* Telemetry hooks called on request/response/error.
|
|
1217
|
+
*/
|
|
1218
|
+
telemetry?: Telemetry;
|
|
1219
|
+
};
|
|
1220
|
+
/**
|
|
1221
|
+
* Main SDK client.
|
|
1222
|
+
*
|
|
1223
|
+
* Exposes resource namespaces ({@link Mappa.files}, {@link Mappa.reports}, etc.)
|
|
1224
|
+
* and configures a shared HTTP transport.
|
|
1225
|
+
*/
|
|
1226
|
+
declare class Mappa {
|
|
1227
|
+
readonly files: FilesResource;
|
|
1228
|
+
readonly jobs: JobsResource;
|
|
1229
|
+
readonly reports: ReportsResource;
|
|
1230
|
+
readonly feedback: FeedbackResource;
|
|
1231
|
+
readonly credits: CreditsResource;
|
|
1232
|
+
readonly entities: EntitiesResource;
|
|
1233
|
+
readonly webhooks: WebhooksResource;
|
|
1234
|
+
readonly health: HealthResource;
|
|
1235
|
+
private readonly transport;
|
|
1236
|
+
private readonly opts;
|
|
1237
|
+
constructor(options: MappaClientOptions);
|
|
1238
|
+
withOptions(overrides: Partial<MappaClientOptions>): Mappa;
|
|
1239
|
+
close(): void;
|
|
65
1240
|
}
|
|
66
1241
|
//#endregion
|
|
67
|
-
|
|
1242
|
+
//#region src/index.d.ts
|
|
1243
|
+
/**
|
|
1244
|
+
* Type guard for catching SDK errors.
|
|
1245
|
+
*/
|
|
1246
|
+
declare function isMappaError(err: unknown): err is MappaError;
|
|
1247
|
+
//#endregion
|
|
1248
|
+
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 };
|