@cstar.help/js 0.17.4 → 0.18.0
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 +45 -26
- package/dist/auth/index.cjs +220 -21
- package/dist/auth/index.d.cts +84 -32
- package/dist/auth/index.d.ts +84 -32
- package/dist/auth/index.js +210 -21
- package/dist/chat/index.cjs +131 -20
- package/dist/chat/index.d.cts +32 -4
- package/dist/chat/index.d.ts +32 -4
- package/dist/chat/index.js +131 -20
- package/dist/community/index.d.cts +1 -1
- package/dist/community/index.d.ts +1 -1
- package/dist/errors-bW8CwTn4.d.cts +121 -0
- package/dist/errors-bW8CwTn4.d.ts +121 -0
- package/dist/index.cjs +94 -41
- package/dist/index.d.cts +454 -153
- package/dist/index.d.ts +454 -153
- package/dist/index.js +94 -41
- package/dist/library/index.d.cts +1 -1
- package/dist/library/index.d.ts +1 -1
- package/dist/proactive/index.cjs +46 -33
- package/dist/proactive/index.js +45 -34
- package/dist/quickhelp/index.d.cts +1 -1
- package/dist/quickhelp/index.d.ts +1 -1
- package/dist/webhook/index.d.cts +1 -1
- package/dist/webhook/index.d.ts +1 -1
- package/dist/webhook/node.d.cts +1 -1
- package/dist/webhook/node.d.ts +1 -1
- package/dist/{webhookEvents-1N2i2GcQ.d.cts → webhookEvents-Lqpsj935.d.cts} +0 -1
- package/dist/{webhookEvents-1N2i2GcQ.d.ts → webhookEvents-Lqpsj935.d.ts} +0 -1
- package/package.json +1 -1
- package/dist/errors-b5A4wfAg.d.cts +0 -398
- package/dist/errors-b5A4wfAg.d.ts +0 -398
package/dist/index.cjs
CHANGED
|
@@ -278,7 +278,7 @@ function parseError(statusCode, body, retryAfter) {
|
|
|
278
278
|
}
|
|
279
279
|
|
|
280
280
|
// src/client.ts
|
|
281
|
-
var SDK_VERSION = "0.
|
|
281
|
+
var SDK_VERSION = "0.18.0";
|
|
282
282
|
var DEFAULT_BASE_URL = "https://www.cstar.help";
|
|
283
283
|
var DEFAULT_API_VERSION = "2026-03-01";
|
|
284
284
|
var DEFAULT_MAX_RETRIES = 3;
|
|
@@ -298,7 +298,7 @@ var HttpClient = class {
|
|
|
298
298
|
this.lastMeta = { requestId: null, timestamp: null, pagination: null };
|
|
299
299
|
if (!config || typeof config.apiKey !== "string" || config.apiKey.length === 0) {
|
|
300
300
|
throw new Error(
|
|
301
|
-
"[cStar] CStarClient: apiKey is required. Pass a secret key (sk_live_... / sk_test_...)
|
|
301
|
+
"[cStar] CStarClient: apiKey is required. Pass a secret key (sk_live_... / sk_test_...). Publishable keys (pk_...) cannot read team endpoints; use them with LibraryClient or CommunityClient. See https://cstar.help/developers/quickstart"
|
|
302
302
|
);
|
|
303
303
|
}
|
|
304
304
|
if (typeof config.teamId !== "string" || config.teamId.length === 0) {
|
|
@@ -530,6 +530,8 @@ var CStarRealtime = class {
|
|
|
530
530
|
this.retryTimer = null;
|
|
531
531
|
this._connected = false;
|
|
532
532
|
this.destroyed = false;
|
|
533
|
+
/** The server closed the stream because the API key was revoked or expired. */
|
|
534
|
+
this.revoked = false;
|
|
533
535
|
this.connecting = false;
|
|
534
536
|
/** Short-lived SSE token (exchanged from secret key). */
|
|
535
537
|
this.sseToken = null;
|
|
@@ -605,7 +607,7 @@ var CStarRealtime = class {
|
|
|
605
607
|
}
|
|
606
608
|
/** Start the SSE connection. Called automatically on first handler registration. */
|
|
607
609
|
connect() {
|
|
608
|
-
if (this.eventSource || this.destroyed || this.connecting) return;
|
|
610
|
+
if (this.eventSource || this.destroyed || this.revoked || this.connecting) return;
|
|
609
611
|
if (!this.resolveEventSource()) {
|
|
610
612
|
throw new CStarRealtimeUnavailableError();
|
|
611
613
|
}
|
|
@@ -665,6 +667,7 @@ var CStarRealtime = class {
|
|
|
665
667
|
this.eventSource.close();
|
|
666
668
|
this.eventSource = null;
|
|
667
669
|
}
|
|
670
|
+
if (this.revoked) return;
|
|
668
671
|
if (this.autoReconnect && !this.destroyed && this.retryCount < this.maxRetries) {
|
|
669
672
|
this.scheduleReconnect();
|
|
670
673
|
} else if (this.retryCount >= this.maxRetries) {
|
|
@@ -674,6 +677,9 @@ var CStarRealtime = class {
|
|
|
674
677
|
this.eventSource.onmessage = (event) => {
|
|
675
678
|
this.handleMessage(event);
|
|
676
679
|
};
|
|
680
|
+
this.eventSource.addEventListener("revoked", (event) => {
|
|
681
|
+
this.handleRevoked(event);
|
|
682
|
+
});
|
|
677
683
|
const knownTypes = [
|
|
678
684
|
"ticket.created",
|
|
679
685
|
"ticket.updated",
|
|
@@ -802,6 +808,40 @@ var CStarRealtime = class {
|
|
|
802
808
|
for (const handler of this.connectionHandlers) handler(value);
|
|
803
809
|
}
|
|
804
810
|
}
|
|
811
|
+
handleRevoked(event) {
|
|
812
|
+
if (this.revoked || this.destroyed) return;
|
|
813
|
+
this.revoked = true;
|
|
814
|
+
let body = {};
|
|
815
|
+
try {
|
|
816
|
+
body = JSON.parse(event.data).error ?? {};
|
|
817
|
+
} catch {
|
|
818
|
+
}
|
|
819
|
+
if (this.retryTimer) {
|
|
820
|
+
clearTimeout(this.retryTimer);
|
|
821
|
+
this.retryTimer = null;
|
|
822
|
+
}
|
|
823
|
+
if (this.tokenRefreshTimer) {
|
|
824
|
+
clearTimeout(this.tokenRefreshTimer);
|
|
825
|
+
this.tokenRefreshTimer = null;
|
|
826
|
+
}
|
|
827
|
+
if (this.eventSource) {
|
|
828
|
+
this.eventSource.close();
|
|
829
|
+
this.eventSource = null;
|
|
830
|
+
}
|
|
831
|
+
this.sseToken = null;
|
|
832
|
+
this.sseTokenExpiresAt = 0;
|
|
833
|
+
this.connecting = false;
|
|
834
|
+
this.setConnected(false);
|
|
835
|
+
this.emitError(
|
|
836
|
+
new CStarAuthenticationError(401, {
|
|
837
|
+
type: body.type ?? "authentication_error",
|
|
838
|
+
code: body.code ?? "invalid_api_key",
|
|
839
|
+
message: body.message ?? "This API key was revoked or has expired, so the stream is closed.",
|
|
840
|
+
doc_url: body.doc_url ?? "https://www.cstar.help/developers/errors#invalid_api_key",
|
|
841
|
+
...body.request_id ? { request_id: body.request_id } : {}
|
|
842
|
+
})
|
|
843
|
+
);
|
|
844
|
+
}
|
|
805
845
|
emitError(error) {
|
|
806
846
|
for (const handler of this.errorHandlers) handler(error);
|
|
807
847
|
}
|
|
@@ -1162,9 +1202,11 @@ var TicketMessagesResource = class {
|
|
|
1162
1202
|
constructor(client) {
|
|
1163
1203
|
this.client = client;
|
|
1164
1204
|
}
|
|
1165
|
-
/** List
|
|
1166
|
-
async list(ticketId) {
|
|
1167
|
-
return this.client.request("GET", `/tickets/${ticketId}/messages
|
|
1205
|
+
/** List one page of a ticket history. Use pagination.hasMore to request the next page. */
|
|
1206
|
+
async list(ticketId, params) {
|
|
1207
|
+
return this.client.request("GET", `/tickets/${ticketId}/messages`, {
|
|
1208
|
+
query: params ? { ...params } : void 0
|
|
1209
|
+
});
|
|
1168
1210
|
}
|
|
1169
1211
|
/** Add a message to a ticket. */
|
|
1170
1212
|
async create(ticketId, params, options) {
|
|
@@ -1519,11 +1561,17 @@ var SettingsResource = class {
|
|
|
1519
1561
|
async update(params) {
|
|
1520
1562
|
return this.client.request("PATCH", "/settings", { body: params });
|
|
1521
1563
|
}
|
|
1522
|
-
/**
|
|
1564
|
+
/**
|
|
1565
|
+
* Get the chat widget's online hours (outside them the widget shows its
|
|
1566
|
+
* offline message). Not the SLA working hours that SLA deadlines use.
|
|
1567
|
+
*/
|
|
1523
1568
|
async getBusinessHours() {
|
|
1524
1569
|
return this.client.request("GET", "/settings/business-hours");
|
|
1525
1570
|
}
|
|
1526
|
-
/**
|
|
1571
|
+
/**
|
|
1572
|
+
* Update the chat widget's online hours. SLA deadlines don't change:
|
|
1573
|
+
* they follow the SLA working hours in Settings > Business Hours.
|
|
1574
|
+
*/
|
|
1527
1575
|
async updateBusinessHours(params) {
|
|
1528
1576
|
return this.client.request("PATCH", "/settings/business-hours", {
|
|
1529
1577
|
body: params
|
|
@@ -1548,8 +1596,10 @@ var NotificationsResource = class {
|
|
|
1548
1596
|
}
|
|
1549
1597
|
/** List notifications for a user. */
|
|
1550
1598
|
async list(params) {
|
|
1599
|
+
const { unreadOnly, ...query } = params;
|
|
1600
|
+
if (unreadOnly && query.isRead === void 0) query.isRead = false;
|
|
1551
1601
|
return this.client.request("GET", "/notifications", {
|
|
1552
|
-
query
|
|
1602
|
+
query
|
|
1553
1603
|
});
|
|
1554
1604
|
}
|
|
1555
1605
|
/** Get unread notification count for a user. */
|
|
@@ -1623,15 +1673,22 @@ var AttachmentsResource = class {
|
|
|
1623
1673
|
constructor(client) {
|
|
1624
1674
|
this.client = client;
|
|
1625
1675
|
}
|
|
1626
|
-
/** List
|
|
1676
|
+
/** List message files, each with a short-lived signed `url`. */
|
|
1627
1677
|
async list(params) {
|
|
1628
1678
|
return this.client.request("GET", "/attachments", {
|
|
1629
1679
|
query: params
|
|
1630
1680
|
});
|
|
1631
1681
|
}
|
|
1632
|
-
/**
|
|
1633
|
-
|
|
1634
|
-
|
|
1682
|
+
/**
|
|
1683
|
+
* Get a signed download URL, valid for `expiresIn` seconds, for a stored
|
|
1684
|
+
* file. Pass `storagePath` and `bucket` from `list()`.
|
|
1685
|
+
*/
|
|
1686
|
+
async get(storagePath, params) {
|
|
1687
|
+
return this.client.request(
|
|
1688
|
+
"GET",
|
|
1689
|
+
`/attachments/${storagePath}`,
|
|
1690
|
+
params?.bucket ? { query: { bucket: params.bucket } } : void 0
|
|
1691
|
+
);
|
|
1635
1692
|
}
|
|
1636
1693
|
/** Delete an attachment. */
|
|
1637
1694
|
async del(attachmentId) {
|
|
@@ -1647,16 +1704,12 @@ var CustomFieldsResource = class {
|
|
|
1647
1704
|
constructor(client) {
|
|
1648
1705
|
this.client = client;
|
|
1649
1706
|
}
|
|
1650
|
-
/** List custom
|
|
1707
|
+
/** List custom field definitions, optionally for one record type. There is no single-field GET. */
|
|
1651
1708
|
async list(params) {
|
|
1652
1709
|
return this.client.request("GET", "/custom-fields", {
|
|
1653
1710
|
query: params
|
|
1654
1711
|
});
|
|
1655
1712
|
}
|
|
1656
|
-
/** Get a single custom field. */
|
|
1657
|
-
async get(fieldId) {
|
|
1658
|
-
return this.client.request("GET", `/custom-fields/${fieldId}`);
|
|
1659
|
-
}
|
|
1660
1713
|
/** Create a custom field. */
|
|
1661
1714
|
async create(params, options) {
|
|
1662
1715
|
return this.client.request("POST", "/custom-fields", {
|
|
@@ -1691,11 +1744,9 @@ var SlaResource = class {
|
|
|
1691
1744
|
constructor(client) {
|
|
1692
1745
|
this.client = client;
|
|
1693
1746
|
}
|
|
1694
|
-
/** List SLA rules. */
|
|
1695
|
-
async list(
|
|
1696
|
-
return this.client.request("GET", "/sla/rules"
|
|
1697
|
-
query: params
|
|
1698
|
-
});
|
|
1747
|
+
/** List SLA rules in evaluation order. */
|
|
1748
|
+
async list() {
|
|
1749
|
+
return this.client.request("GET", "/sla/rules");
|
|
1699
1750
|
}
|
|
1700
1751
|
/** Create an SLA rule. */
|
|
1701
1752
|
async create(params, options) {
|
|
@@ -1884,25 +1935,28 @@ var TagsResource = class {
|
|
|
1884
1935
|
constructor(client) {
|
|
1885
1936
|
this.client = client;
|
|
1886
1937
|
}
|
|
1887
|
-
/** List
|
|
1938
|
+
/** List tags with usage counts, one row per tag and entity type. */
|
|
1888
1939
|
async list(params) {
|
|
1889
1940
|
return this.client.request("GET", "/tags", {
|
|
1890
1941
|
query: params
|
|
1891
1942
|
});
|
|
1892
1943
|
}
|
|
1893
|
-
/**
|
|
1894
|
-
async
|
|
1944
|
+
/** Replace `fromTag` with `toTag` on every record that carries it. */
|
|
1945
|
+
async merge(params, options) {
|
|
1895
1946
|
return this.client.request("POST", "/tags", {
|
|
1896
|
-
body: {
|
|
1947
|
+
body: { action: "merge", ...params },
|
|
1897
1948
|
idempotencyKey: options?.idempotencyKey
|
|
1898
1949
|
});
|
|
1899
1950
|
}
|
|
1900
|
-
/**
|
|
1901
|
-
async
|
|
1902
|
-
return this.client.request(
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1951
|
+
/** Remove a tag from every record that carries it. */
|
|
1952
|
+
async remove(tag, params) {
|
|
1953
|
+
return this.client.request("DELETE", "/tags", {
|
|
1954
|
+
body: { tag, ...params }
|
|
1955
|
+
});
|
|
1956
|
+
}
|
|
1957
|
+
/** @deprecated Use `remove()`. */
|
|
1958
|
+
async del(tag, params) {
|
|
1959
|
+
return this.remove(tag, params);
|
|
1906
1960
|
}
|
|
1907
1961
|
};
|
|
1908
1962
|
|
|
@@ -2348,7 +2402,7 @@ var ViewsResource = class extends BaseResource {
|
|
|
2348
2402
|
constructor(client) {
|
|
2349
2403
|
super(client, "/views");
|
|
2350
2404
|
}
|
|
2351
|
-
/** Execute a view
|
|
2405
|
+
/** Execute a view and return the filtered results. The server uses the view's entity_type to determine which table to query. */
|
|
2352
2406
|
async execute(viewId, params) {
|
|
2353
2407
|
return this.client.request("GET", `/views/${viewId}/execute`, {
|
|
2354
2408
|
query: params
|
|
@@ -2584,7 +2638,7 @@ var WEBHOOK_EVENT_SAMPLES = {
|
|
|
2584
2638
|
"comment": {
|
|
2585
2639
|
"id": "cmt_01H8X9YZ7E0J3K4M5N6X",
|
|
2586
2640
|
"post_id": "post_01H8X9YZ7E0J3K4M5N6W",
|
|
2587
|
-
"content": "I would love this
|
|
2641
|
+
"content": "I would love this. Bumping for visibility.",
|
|
2588
2642
|
"author_id": "cus_01H8X9YZ7E0J3K4M5N6Q",
|
|
2589
2643
|
"created_at": "2026-04-27T18:55:02.000Z"
|
|
2590
2644
|
}
|
|
@@ -2804,15 +2858,14 @@ var WEBHOOK_EVENT_SAMPLES = {
|
|
|
2804
2858
|
"id": "tkt_01H8X9YZ7E0J3K4M5N6P",
|
|
2805
2859
|
"prefixed_id": "CST-1024",
|
|
2806
2860
|
"title": "Cannot reset password",
|
|
2807
|
-
"status": "
|
|
2861
|
+
"status": "closed",
|
|
2808
2862
|
"priority": "normal",
|
|
2809
|
-
"channel": "widget"
|
|
2810
|
-
"resolved_at": "2026-04-27T19:08:43.000Z"
|
|
2863
|
+
"channel": "widget"
|
|
2811
2864
|
},
|
|
2812
2865
|
"changes": {
|
|
2813
2866
|
"status": {
|
|
2814
2867
|
"from": "open",
|
|
2815
|
-
"to": "
|
|
2868
|
+
"to": "closed"
|
|
2816
2869
|
}
|
|
2817
2870
|
}
|
|
2818
2871
|
},
|
|
@@ -2845,7 +2898,7 @@ var WEBHOOK_EVENT_SAMPLES = {
|
|
|
2845
2898
|
"id": "msg_01H8X9YZ7E0J3K4M5N6R",
|
|
2846
2899
|
"sender": "agent",
|
|
2847
2900
|
"sender_name": "Riley",
|
|
2848
|
-
"content": "I just sent a reset link to your inbox
|
|
2901
|
+
"content": "I just sent a reset link to your inbox. Let me know if it lands.",
|
|
2849
2902
|
"created_at": "2026-04-27T18:55:02.000Z"
|
|
2850
2903
|
},
|
|
2851
2904
|
"customer": {
|
|
@@ -2911,7 +2964,7 @@ var WEBHOOK_EVENT_CATALOG = {
|
|
|
2911
2964
|
"survey.submitted": { label: "Customer Feedback Received", description: "Fired when a customer submits a CSAT survey response", category: "csat" },
|
|
2912
2965
|
"team.preferences_updated": { label: "Team Preferences Updated", description: "Fired when team-wide UX preferences change (e.g., bossBattlesEnabled toggled)", category: "team" },
|
|
2913
2966
|
"ticket.assigned": { label: "Ticket Assigned", description: "Fired when a ticket is assigned to an agent", category: "tickets" },
|
|
2914
|
-
"ticket.closed": { label: "Ticket Closed
|
|
2967
|
+
"ticket.closed": { label: "Ticket Closed", description: "Fired when a ticket's status changes to Closed. Moving a ticket to Resolved sends ticket.updated instead.", category: "tickets" },
|
|
2915
2968
|
"ticket.created": { label: "New Ticket Created", description: "Fired when a new ticket is created via app, widget, API, or email", category: "tickets" },
|
|
2916
2969
|
"ticket.deleted": { label: "Ticket Deleted", description: "Fired when a ticket is deleted via app or API", category: "tickets" },
|
|
2917
2970
|
"ticket.message_added": { label: "New Message on Ticket", description: "Fired when a new message is added to a ticket", category: "tickets" },
|