@mappa-ai/mappa-node 1.2.3 → 1.2.4

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
@@ -1303,9 +1303,52 @@ declare class ReportsResource {
1303
1303
  }
1304
1304
  //#endregion
1305
1305
  //#region src/resources/webhooks.d.ts
1306
+ /**
1307
+ * Webhook event types supported by the API.
1308
+ */
1309
+ type WebhookEventType = "report.completed" | "report.failed";
1310
+ /**
1311
+ * Base webhook event structure.
1312
+ */
1313
+ interface WebhookEvent<T = unknown> {
1314
+ type: string;
1315
+ timestamp: string;
1316
+ data: T;
1317
+ }
1318
+ /**
1319
+ * Payload for successful report completion.
1320
+ */
1321
+ interface ReportCompletedData {
1322
+ jobId: string;
1323
+ reportId: string;
1324
+ status: "succeeded";
1325
+ }
1326
+ /**
1327
+ * Payload for failed report processing.
1328
+ */
1329
+ interface ReportFailedData {
1330
+ jobId: string;
1331
+ status: "failed";
1332
+ error: {
1333
+ code: string;
1334
+ message: string;
1335
+ };
1336
+ }
1337
+ /**
1338
+ * Event emitted when a report completes successfully.
1339
+ */
1340
+ type ReportCompletedEvent = WebhookEvent<ReportCompletedData> & {
1341
+ type: "report.completed";
1342
+ };
1343
+ /**
1344
+ * Event emitted when a report fails.
1345
+ */
1346
+ type ReportFailedEvent = WebhookEvent<ReportFailedData> & {
1347
+ type: "report.failed";
1348
+ };
1306
1349
  /**
1307
1350
  * Async signature verification using WebCrypto (works in modern Node and browsers).
1308
- * Signature scheme placeholder:
1351
+ * Signature scheme:
1309
1352
  * headers["mappa-signature"] = "t=1700000000,v1=<hex_hmac_sha256>"
1310
1353
  * Signed payload: `${t}.${rawBody}`
1311
1354
  */
@@ -1318,12 +1361,14 @@ declare class WebhooksResource {
1318
1361
  }): Promise<{
1319
1362
  ok: true;
1320
1363
  }>;
1321
- parseEvent<T = unknown>(payload: string): {
1322
- id: string;
1323
- type: string;
1324
- createdAt: string;
1325
- data: T;
1326
- };
1364
+ /**
1365
+ * Parse and validate a webhook event payload.
1366
+ *
1367
+ * @param payload - Raw JSON string from the webhook request body
1368
+ * @returns Parsed and validated webhook event
1369
+ * @throws Error if payload is invalid or missing required fields
1370
+ */
1371
+ parseEvent<T = unknown>(payload: string): WebhookEvent<T>;
1327
1372
  }
1328
1373
  //#endregion
1329
1374
  //#region src/Mappa.d.ts
@@ -1437,5 +1482,5 @@ declare function isInsufficientCreditsError(err: unknown): err is InsufficientCr
1437
1482
  */
1438
1483
  declare function isStreamError(err: unknown): err is StreamError;
1439
1484
  //#endregion
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 };
1485
+ 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, type ReportCompletedData, type ReportCompletedEvent, ReportCreateJobRequest, type ReportFailedData, type ReportFailedEvent, 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, type WebhookEvent, type WebhookEventType, hasEntity, isInsufficientCreditsError, isJsonReport, isMappaError, isMarkdownReport, isPdfReport, isStreamError, isUrlReport };
1441
1486
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.mts CHANGED
@@ -1303,9 +1303,52 @@ declare class ReportsResource {
1303
1303
  }
1304
1304
  //#endregion
1305
1305
  //#region src/resources/webhooks.d.ts
1306
+ /**
1307
+ * Webhook event types supported by the API.
1308
+ */
1309
+ type WebhookEventType = "report.completed" | "report.failed";
1310
+ /**
1311
+ * Base webhook event structure.
1312
+ */
1313
+ interface WebhookEvent<T = unknown> {
1314
+ type: string;
1315
+ timestamp: string;
1316
+ data: T;
1317
+ }
1318
+ /**
1319
+ * Payload for successful report completion.
1320
+ */
1321
+ interface ReportCompletedData {
1322
+ jobId: string;
1323
+ reportId: string;
1324
+ status: "succeeded";
1325
+ }
1326
+ /**
1327
+ * Payload for failed report processing.
1328
+ */
1329
+ interface ReportFailedData {
1330
+ jobId: string;
1331
+ status: "failed";
1332
+ error: {
1333
+ code: string;
1334
+ message: string;
1335
+ };
1336
+ }
1337
+ /**
1338
+ * Event emitted when a report completes successfully.
1339
+ */
1340
+ type ReportCompletedEvent = WebhookEvent<ReportCompletedData> & {
1341
+ type: "report.completed";
1342
+ };
1343
+ /**
1344
+ * Event emitted when a report fails.
1345
+ */
1346
+ type ReportFailedEvent = WebhookEvent<ReportFailedData> & {
1347
+ type: "report.failed";
1348
+ };
1306
1349
  /**
1307
1350
  * Async signature verification using WebCrypto (works in modern Node and browsers).
1308
- * Signature scheme placeholder:
1351
+ * Signature scheme:
1309
1352
  * headers["mappa-signature"] = "t=1700000000,v1=<hex_hmac_sha256>"
1310
1353
  * Signed payload: `${t}.${rawBody}`
1311
1354
  */
@@ -1318,12 +1361,14 @@ declare class WebhooksResource {
1318
1361
  }): Promise<{
1319
1362
  ok: true;
1320
1363
  }>;
1321
- parseEvent<T = unknown>(payload: string): {
1322
- id: string;
1323
- type: string;
1324
- createdAt: string;
1325
- data: T;
1326
- };
1364
+ /**
1365
+ * Parse and validate a webhook event payload.
1366
+ *
1367
+ * @param payload - Raw JSON string from the webhook request body
1368
+ * @returns Parsed and validated webhook event
1369
+ * @throws Error if payload is invalid or missing required fields
1370
+ */
1371
+ parseEvent<T = unknown>(payload: string): WebhookEvent<T>;
1327
1372
  }
1328
1373
  //#endregion
1329
1374
  //#region src/Mappa.d.ts
@@ -1437,5 +1482,5 @@ declare function isInsufficientCreditsError(err: unknown): err is InsufficientCr
1437
1482
  */
1438
1483
  declare function isStreamError(err: unknown): err is StreamError;
1439
1484
  //#endregion
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 };
1485
+ 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, type ReportCompletedData, type ReportCompletedEvent, ReportCreateJobRequest, type ReportFailedData, type ReportFailedEvent, 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, type WebhookEvent, type WebhookEventType, hasEntity, isInsufficientCreditsError, isJsonReport, isMappaError, isMarkdownReport, isPdfReport, isStreamError, isUrlReport };
1441
1486
  //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -1614,7 +1614,7 @@ function isObject(v) {
1614
1614
  }
1615
1615
  /**
1616
1616
  * Async signature verification using WebCrypto (works in modern Node and browsers).
1617
- * Signature scheme placeholder:
1617
+ * Signature scheme:
1618
1618
  * headers["mappa-signature"] = "t=1700000000,v1=<hex_hmac_sha256>"
1619
1619
  * Signed payload: `${t}.${rawBody}`
1620
1620
  */
@@ -1632,20 +1632,24 @@ var WebhooksResource = class {
1632
1632
  if (!timingSafeEqualHex(await hmacHex(params.secret, signed), parts.v1)) throw new Error("Invalid signature");
1633
1633
  return { ok: true };
1634
1634
  }
1635
+ /**
1636
+ * Parse and validate a webhook event payload.
1637
+ *
1638
+ * @param payload - Raw JSON string from the webhook request body
1639
+ * @returns Parsed and validated webhook event
1640
+ * @throws Error if payload is invalid or missing required fields
1641
+ */
1635
1642
  parseEvent(payload) {
1636
1643
  const raw = JSON.parse(payload);
1637
1644
  if (!isObject(raw)) throw new Error("Invalid webhook payload: not an object");
1638
1645
  const obj = raw;
1639
- const id = obj.id;
1640
1646
  const type = obj.type;
1641
- const createdAt = obj.createdAt;
1642
- if (typeof id !== "string") throw new Error("Invalid webhook payload: id must be a string");
1647
+ const timestamp = obj.timestamp;
1643
1648
  if (typeof type !== "string") throw new Error("Invalid webhook payload: type must be a string");
1644
- if (typeof createdAt !== "string") throw new Error("Invalid webhook payload: createdAt must be a string");
1649
+ if (typeof timestamp !== "string") throw new Error("Invalid webhook payload: timestamp must be a string");
1645
1650
  return {
1646
- id,
1647
1651
  type,
1648
- createdAt,
1652
+ timestamp,
1649
1653
  data: "data" in obj ? obj.data : void 0
1650
1654
  };
1651
1655
  }