@dispatchtickets/sdk 0.8.0 → 0.8.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.cjs CHANGED
@@ -239,7 +239,9 @@ var HttpClient = class {
239
239
  return delay + jitter;
240
240
  }
241
241
  buildUrl(path, query) {
242
- const url = new URL(path, this.config.baseUrl);
242
+ const base = this.config.baseUrl.endsWith("/") ? this.config.baseUrl : `${this.config.baseUrl}/`;
243
+ const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
244
+ const url = new URL(normalizedPath, base);
243
245
  if (query) {
244
246
  for (const [key, value] of Object.entries(query)) {
245
247
  if (value !== void 0) {
@@ -1470,6 +1472,146 @@ var PortalTicketsResource = class extends BaseResource {
1470
1472
  signal: options?.signal
1471
1473
  });
1472
1474
  }
1475
+ // ==========================================================================
1476
+ // Attachment Methods
1477
+ // ==========================================================================
1478
+ /**
1479
+ * Initiate a pending attachment upload (before ticket creation)
1480
+ *
1481
+ * Use this to upload files before creating a ticket. After uploading to the
1482
+ * presigned URL, confirm the upload, then pass the attachment IDs when
1483
+ * creating the ticket.
1484
+ *
1485
+ * @param data - Attachment metadata
1486
+ * @param options - Request options
1487
+ * @returns Upload URL and attachment ID
1488
+ *
1489
+ * @example
1490
+ * ```typescript
1491
+ * // 1. Initiate upload
1492
+ * const upload = await portal.tickets.initiatePendingUpload({
1493
+ * filename: 'screenshot.png',
1494
+ * contentType: 'image/png',
1495
+ * size: 12345,
1496
+ * });
1497
+ *
1498
+ * // 2. Upload file to presigned URL
1499
+ * await fetch(upload.uploadUrl, {
1500
+ * method: 'PUT',
1501
+ * body: fileBuffer,
1502
+ * headers: { 'Content-Type': 'image/png' },
1503
+ * });
1504
+ *
1505
+ * // 3. Confirm upload
1506
+ * await portal.tickets.confirmPendingUpload(upload.id);
1507
+ *
1508
+ * // 4. Create ticket with attachment
1509
+ * const ticket = await portal.tickets.create({
1510
+ * title: 'Bug report',
1511
+ * body: 'See attached screenshot',
1512
+ * attachmentIds: [upload.id],
1513
+ * });
1514
+ * ```
1515
+ */
1516
+ async initiatePendingUpload(data, options) {
1517
+ return this._post(
1518
+ "/portal/tickets/attachments/pending",
1519
+ data,
1520
+ options
1521
+ );
1522
+ }
1523
+ /**
1524
+ * Confirm a pending attachment upload
1525
+ *
1526
+ * Call this after successfully uploading the file to the presigned URL.
1527
+ *
1528
+ * @param attachmentId - Attachment ID from initiatePendingUpload
1529
+ * @param options - Request options
1530
+ * @returns Confirmed attachment
1531
+ */
1532
+ async confirmPendingUpload(attachmentId, options) {
1533
+ return this._post(
1534
+ `/portal/tickets/attachments/pending/${attachmentId}/confirm`,
1535
+ {},
1536
+ options
1537
+ );
1538
+ }
1539
+ /**
1540
+ * Initiate attachment upload for an existing ticket
1541
+ *
1542
+ * @param ticketId - Ticket ID
1543
+ * @param data - Attachment metadata
1544
+ * @param options - Request options
1545
+ * @returns Upload URL and attachment ID
1546
+ *
1547
+ * @example
1548
+ * ```typescript
1549
+ * const upload = await portal.tickets.initiateUpload('tkt_abc123', {
1550
+ * filename: 'document.pdf',
1551
+ * contentType: 'application/pdf',
1552
+ * size: 54321,
1553
+ * });
1554
+ *
1555
+ * await fetch(upload.uploadUrl, {
1556
+ * method: 'PUT',
1557
+ * body: fileBuffer,
1558
+ * headers: { 'Content-Type': 'application/pdf' },
1559
+ * });
1560
+ *
1561
+ * await portal.tickets.confirmUpload('tkt_abc123', upload.id);
1562
+ * ```
1563
+ */
1564
+ async initiateUpload(ticketId, data, options) {
1565
+ return this._post(
1566
+ `/portal/tickets/${ticketId}/attachments`,
1567
+ data,
1568
+ options
1569
+ );
1570
+ }
1571
+ /**
1572
+ * Confirm attachment upload for a ticket
1573
+ *
1574
+ * @param ticketId - Ticket ID
1575
+ * @param attachmentId - Attachment ID from initiateUpload
1576
+ * @param options - Request options
1577
+ * @returns Confirmed attachment
1578
+ */
1579
+ async confirmUpload(ticketId, attachmentId, options) {
1580
+ return this._post(
1581
+ `/portal/tickets/${ticketId}/attachments/${attachmentId}/confirm`,
1582
+ {},
1583
+ options
1584
+ );
1585
+ }
1586
+ /**
1587
+ * List attachments on a ticket
1588
+ *
1589
+ * @param ticketId - Ticket ID
1590
+ * @param options - Request options
1591
+ * @returns Array of attachments
1592
+ */
1593
+ async listAttachments(ticketId, options) {
1594
+ return this._get(
1595
+ `/portal/tickets/${ticketId}/attachments`,
1596
+ void 0,
1597
+ options
1598
+ );
1599
+ }
1600
+ /**
1601
+ * Get attachment with download URL
1602
+ *
1603
+ * @param ticketId - Ticket ID
1604
+ * @param attachmentId - Attachment ID
1605
+ * @param options - Request options
1606
+ * @returns Attachment with presigned download URL
1607
+ */
1608
+ async getAttachment(ticketId, attachmentId, options) {
1609
+ return this._get(
1610
+ `/portal/tickets/${ticketId}/attachments/${attachmentId}`,
1611
+ void 0,
1612
+ options
1613
+ );
1614
+ }
1473
1615
  /**
1474
1616
  * Build query parameters from filters
1475
1617
  */