@cstar.help/js 0.12.0 → 0.13.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/dist/auth/index.cjs +227 -13
- package/dist/auth/index.d.cts +4 -4
- package/dist/auth/index.d.ts +4 -4
- package/dist/auth/index.js +225 -13
- package/dist/chat/index.cjs +46 -26
- package/dist/chat/index.d.cts +28 -24
- package/dist/chat/index.d.ts +28 -24
- package/dist/chat/index.js +46 -26
- package/dist/community/index.cjs +233 -9
- package/dist/community/index.d.cts +11 -0
- package/dist/community/index.d.ts +11 -0
- package/dist/community/index.js +231 -9
- package/dist/index.cjs +268 -73
- package/dist/index.d.cts +216 -73
- package/dist/index.d.ts +216 -73
- package/dist/index.js +267 -73
- package/dist/library/index.cjs +254 -9
- package/dist/library/index.d.cts +26 -3
- package/dist/library/index.d.ts +26 -3
- package/dist/library/index.js +252 -9
- package/dist/quickhelp/index.cjs +176 -2
- package/dist/quickhelp/index.d.cts +11 -0
- package/dist/quickhelp/index.d.ts +11 -0
- package/dist/quickhelp/index.js +174 -2
- package/dist/webhook/index.cjs +0 -18
- package/dist/webhook/index.d.cts +18 -29
- package/dist/webhook/index.d.ts +18 -29
- package/dist/webhook/index.js +0 -23
- package/dist/webhook/node.cjs +57 -0
- package/dist/webhook/node.d.cts +440 -0
- package/dist/webhook/node.d.ts +440 -0
- package/dist/webhook/node.js +30 -0
- package/package.json +14 -2
package/dist/chat/index.cjs
CHANGED
|
@@ -289,37 +289,45 @@ var PresenceManager = class {
|
|
|
289
289
|
};
|
|
290
290
|
|
|
291
291
|
// src/chat/errors.ts
|
|
292
|
+
function normalizeChatArgs(arg, fallbackCode) {
|
|
293
|
+
if (typeof arg === "string") {
|
|
294
|
+
return { message: arg, code: fallbackCode, statusCode: 0, requestId: null };
|
|
295
|
+
}
|
|
296
|
+
return { ...arg, code: arg.code ?? fallbackCode };
|
|
297
|
+
}
|
|
292
298
|
var ChatClientError = class extends Error {
|
|
293
|
-
constructor(
|
|
294
|
-
|
|
299
|
+
constructor(arg) {
|
|
300
|
+
const opts = normalizeChatArgs(arg, "UNKNOWN");
|
|
301
|
+
super(opts.message);
|
|
295
302
|
this.name = "ChatClientError";
|
|
296
303
|
this.code = opts.code ?? "UNKNOWN";
|
|
297
|
-
this.statusCode = opts.statusCode;
|
|
304
|
+
this.statusCode = opts.statusCode ?? 0;
|
|
298
305
|
this.requestId = opts.requestId ?? null;
|
|
299
306
|
}
|
|
300
307
|
};
|
|
301
308
|
var ChatClientAuthError = class extends ChatClientError {
|
|
302
|
-
constructor(
|
|
303
|
-
super(
|
|
309
|
+
constructor(arg) {
|
|
310
|
+
super(normalizeChatArgs(arg, "AUTH_ERROR"));
|
|
304
311
|
this.name = "ChatClientAuthError";
|
|
305
312
|
}
|
|
306
313
|
};
|
|
307
314
|
var ChatClientRateLimitError = class extends ChatClientError {
|
|
308
|
-
constructor(
|
|
309
|
-
|
|
315
|
+
constructor(arg) {
|
|
316
|
+
const opts = typeof arg === "string" ? { message: arg, code: "RATE_LIMIT", statusCode: 429, requestId: null, retryAfter: null } : { ...arg, code: arg.code ?? "RATE_LIMIT" };
|
|
317
|
+
super(opts);
|
|
310
318
|
this.name = "ChatClientRateLimitError";
|
|
311
319
|
this.retryAfter = opts.retryAfter ?? null;
|
|
312
320
|
}
|
|
313
321
|
};
|
|
314
322
|
var ChatClientServerError = class extends ChatClientError {
|
|
315
|
-
constructor(
|
|
316
|
-
super(
|
|
323
|
+
constructor(arg) {
|
|
324
|
+
super(normalizeChatArgs(arg, "SERVER_ERROR"));
|
|
317
325
|
this.name = "ChatClientServerError";
|
|
318
326
|
}
|
|
319
327
|
};
|
|
320
328
|
var ChatClientNetworkError = class extends ChatClientError {
|
|
321
329
|
constructor(opts) {
|
|
322
|
-
super(opts.message,
|
|
330
|
+
super({ message: opts.message, code: "NETWORK_ERROR", statusCode: 0, requestId: null });
|
|
323
331
|
this.name = "ChatClientNetworkError";
|
|
324
332
|
this.originalError = opts.originalError;
|
|
325
333
|
}
|
|
@@ -374,6 +382,7 @@ var ChatClient = class {
|
|
|
374
382
|
this.sessionToken = response.data.sessionToken;
|
|
375
383
|
this.teamId = response.data.teamId;
|
|
376
384
|
this.customerId = response.data.customer.id;
|
|
385
|
+
this.authMode = "hmac";
|
|
377
386
|
if (this.realtimeEnabled) {
|
|
378
387
|
this.realtimeInitPromise = this.initRealtime(
|
|
379
388
|
response.data.customer.id,
|
|
@@ -571,7 +580,8 @@ var ChatClient = class {
|
|
|
571
580
|
requestId
|
|
572
581
|
});
|
|
573
582
|
}
|
|
574
|
-
throw new ChatClientError(
|
|
583
|
+
throw new ChatClientError({
|
|
584
|
+
message,
|
|
575
585
|
code,
|
|
576
586
|
statusCode: response.status,
|
|
577
587
|
requestId
|
|
@@ -709,7 +719,7 @@ var TicketsApi = class {
|
|
|
709
719
|
/** List tickets for the identified customer. */
|
|
710
720
|
async list(params) {
|
|
711
721
|
const teamId = this.chat.getTeamId();
|
|
712
|
-
if (!teamId) throw new
|
|
722
|
+
if (!teamId) throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
|
|
713
723
|
const response = await this.chat.fetch("/api/widget/conversations", {
|
|
714
724
|
method: "GET",
|
|
715
725
|
query: {
|
|
@@ -727,7 +737,7 @@ var TicketsApi = class {
|
|
|
727
737
|
/** Create a new ticket. */
|
|
728
738
|
async create(params) {
|
|
729
739
|
const teamId = this.chat.getTeamId();
|
|
730
|
-
if (!teamId) throw new
|
|
740
|
+
if (!teamId) throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
|
|
731
741
|
const response = await this.chat.fetch("/api/widget/tickets", {
|
|
732
742
|
method: "POST",
|
|
733
743
|
body: {
|
|
@@ -736,15 +746,25 @@ var TicketsApi = class {
|
|
|
736
746
|
message: params.message
|
|
737
747
|
}
|
|
738
748
|
});
|
|
749
|
+
const messages = (response.data.messages ?? []).map((m) => ({
|
|
750
|
+
id: m.id,
|
|
751
|
+
content: m.content,
|
|
752
|
+
sender: m.sender,
|
|
753
|
+
sender_name: m.sender_name,
|
|
754
|
+
created_at: m.created_at,
|
|
755
|
+
read_at: m.read_at,
|
|
756
|
+
attachments: m.attachments ?? []
|
|
757
|
+
}));
|
|
739
758
|
return {
|
|
740
759
|
id: response.data.id,
|
|
741
|
-
ticketNumber:
|
|
760
|
+
ticketNumber: null,
|
|
742
761
|
subject: response.data.subject,
|
|
743
762
|
status: response.data.status,
|
|
744
|
-
messageCount:
|
|
763
|
+
messageCount: messages.length,
|
|
745
764
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
746
765
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
747
|
-
closedAt: null
|
|
766
|
+
closedAt: null,
|
|
767
|
+
messages
|
|
748
768
|
};
|
|
749
769
|
}
|
|
750
770
|
};
|
|
@@ -755,7 +775,7 @@ var ChatCommunityApi = class {
|
|
|
755
775
|
/** Create a new community post as the identified customer. */
|
|
756
776
|
async createPost(params) {
|
|
757
777
|
const teamId = this.chat.getTeamId();
|
|
758
|
-
if (!teamId) throw new
|
|
778
|
+
if (!teamId) throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
|
|
759
779
|
const response = await this.chat.fetch("/api/widget/community", {
|
|
760
780
|
method: "POST",
|
|
761
781
|
body: {
|
|
@@ -772,7 +792,7 @@ var ChatCommunityApi = class {
|
|
|
772
792
|
/** Update a post. Only the original author can edit. */
|
|
773
793
|
async updatePost(postId, params) {
|
|
774
794
|
const teamId = this.chat.getTeamId();
|
|
775
|
-
if (!teamId) throw new
|
|
795
|
+
if (!teamId) throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
|
|
776
796
|
const response = await this.chat.fetch("/api/widget/community", {
|
|
777
797
|
method: "POST",
|
|
778
798
|
body: {
|
|
@@ -789,7 +809,7 @@ var ChatCommunityApi = class {
|
|
|
789
809
|
/** Delete a post (soft delete). Only the original author can delete. */
|
|
790
810
|
async deletePost(postId) {
|
|
791
811
|
const teamId = this.chat.getTeamId();
|
|
792
|
-
if (!teamId) throw new
|
|
812
|
+
if (!teamId) throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
|
|
793
813
|
await this.chat.fetch("/api/widget/community", {
|
|
794
814
|
method: "POST",
|
|
795
815
|
body: { teamId, action: "deletePost", postId }
|
|
@@ -798,7 +818,7 @@ var ChatCommunityApi = class {
|
|
|
798
818
|
/** Update a comment. Only the original author can edit. */
|
|
799
819
|
async updateComment(postId, commentId, params) {
|
|
800
820
|
const teamId = this.chat.getTeamId();
|
|
801
|
-
if (!teamId) throw new
|
|
821
|
+
if (!teamId) throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
|
|
802
822
|
const response = await this.chat.fetch("/api/widget/community", {
|
|
803
823
|
method: "POST",
|
|
804
824
|
body: {
|
|
@@ -814,7 +834,7 @@ var ChatCommunityApi = class {
|
|
|
814
834
|
/** Delete a comment (soft delete). Only the original author can delete. */
|
|
815
835
|
async deleteComment(postId, commentId) {
|
|
816
836
|
const teamId = this.chat.getTeamId();
|
|
817
|
-
if (!teamId) throw new
|
|
837
|
+
if (!teamId) throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
|
|
818
838
|
await this.chat.fetch("/api/widget/community", {
|
|
819
839
|
method: "POST",
|
|
820
840
|
body: { teamId, action: "deleteComment", postId, commentId }
|
|
@@ -823,7 +843,7 @@ var ChatCommunityApi = class {
|
|
|
823
843
|
/** Toggle vote on a post. Returns new vote state and count. */
|
|
824
844
|
async vote(postId) {
|
|
825
845
|
const teamId = this.chat.getTeamId();
|
|
826
|
-
if (!teamId) throw new
|
|
846
|
+
if (!teamId) throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
|
|
827
847
|
const response = await this.chat.fetch("/api/widget/community", {
|
|
828
848
|
method: "POST",
|
|
829
849
|
body: { teamId, action: "vote", postId }
|
|
@@ -833,7 +853,7 @@ var ChatCommunityApi = class {
|
|
|
833
853
|
/** Add a comment to a post. Supports 1-level nesting via parentCommentId. */
|
|
834
854
|
async comment(postId, params) {
|
|
835
855
|
const teamId = this.chat.getTeamId();
|
|
836
|
-
if (!teamId) throw new
|
|
856
|
+
if (!teamId) throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
|
|
837
857
|
const response = await this.chat.fetch("/api/widget/community", {
|
|
838
858
|
method: "POST",
|
|
839
859
|
body: {
|
|
@@ -849,7 +869,7 @@ var ChatCommunityApi = class {
|
|
|
849
869
|
/** Toggle follow on a post. */
|
|
850
870
|
async follow(postId) {
|
|
851
871
|
const teamId = this.chat.getTeamId();
|
|
852
|
-
if (!teamId) throw new
|
|
872
|
+
if (!teamId) throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
|
|
853
873
|
const response = await this.chat.fetch("/api/widget/community", {
|
|
854
874
|
method: "POST",
|
|
855
875
|
body: { teamId, action: "follow", postId }
|
|
@@ -859,7 +879,7 @@ var ChatCommunityApi = class {
|
|
|
859
879
|
/** Check if the current user has voted on a post. */
|
|
860
880
|
async getVoteStatus(postId) {
|
|
861
881
|
const teamId = this.chat.getTeamId();
|
|
862
|
-
if (!teamId) throw new
|
|
882
|
+
if (!teamId) throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
|
|
863
883
|
const response = await this.chat.fetch("/api/widget/community", {
|
|
864
884
|
method: "GET",
|
|
865
885
|
query: { teamId, postId }
|
|
@@ -870,7 +890,7 @@ var ChatCommunityApi = class {
|
|
|
870
890
|
async bulkVoteStatus(postIds) {
|
|
871
891
|
if (postIds.length === 0) return {};
|
|
872
892
|
const teamId = this.chat.getTeamId();
|
|
873
|
-
if (!teamId) throw new
|
|
893
|
+
if (!teamId) throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
|
|
874
894
|
const response = await this.chat.fetch("/api/widget/community", {
|
|
875
895
|
method: "GET",
|
|
876
896
|
query: { teamId, postIds: postIds.join(",") }
|
package/dist/chat/index.d.cts
CHANGED
|
@@ -88,13 +88,24 @@ interface RealtimeTokenResponse {
|
|
|
88
88
|
/** A ticket — a customer's support thread. */
|
|
89
89
|
interface Ticket {
|
|
90
90
|
id: string;
|
|
91
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Server-issued display ID (e.g. `CST-1024`). `null` immediately after
|
|
93
|
+
* `tickets.create` (the prefix is assigned asynchronously); populated on
|
|
94
|
+
* subsequent `tickets.list` / single fetches.
|
|
95
|
+
*/
|
|
96
|
+
ticketNumber: string | null;
|
|
92
97
|
subject: string;
|
|
93
98
|
status: string;
|
|
94
99
|
messageCount: number;
|
|
95
100
|
createdAt: string;
|
|
96
101
|
updatedAt: string;
|
|
97
102
|
closedAt: string | null;
|
|
103
|
+
/**
|
|
104
|
+
* Set on `tickets.create` responses — contains the first message the
|
|
105
|
+
* widget sent, so callers don't need a round-trip `messages.list(...)`
|
|
106
|
+
* to echo it back. `undefined` on list/get responses.
|
|
107
|
+
*/
|
|
108
|
+
messages?: Message[];
|
|
98
109
|
}
|
|
99
110
|
/** Paginated ticket list response. */
|
|
100
111
|
interface TicketListResponse {
|
|
@@ -244,46 +255,39 @@ interface CommunityFollowResult {
|
|
|
244
255
|
* }
|
|
245
256
|
* }
|
|
246
257
|
* ```
|
|
258
|
+
*
|
|
259
|
+
* Constructors accept either a full opts object (used by the SDK's HTTP
|
|
260
|
+
* paths) or a bare message string — handy for SDK precondition checks
|
|
261
|
+
* (`throw new ChatClientAuthError('Not identified...')`) and tests.
|
|
262
|
+
* Closes F-032's spirit for the chat-client classes.
|
|
247
263
|
*/
|
|
264
|
+
interface ChatErrorOpts {
|
|
265
|
+
message: string;
|
|
266
|
+
code?: string;
|
|
267
|
+
statusCode?: number;
|
|
268
|
+
requestId?: string | null;
|
|
269
|
+
}
|
|
248
270
|
/** Base class. Thrown by `ChatClient.fetch()` for any non-2xx response. */
|
|
249
271
|
declare class ChatClientError extends Error {
|
|
250
272
|
readonly code: string;
|
|
251
273
|
readonly statusCode: number;
|
|
252
274
|
readonly requestId: string | null;
|
|
253
|
-
constructor(
|
|
254
|
-
code?: string;
|
|
255
|
-
statusCode: number;
|
|
256
|
-
requestId?: string | null;
|
|
257
|
-
});
|
|
275
|
+
constructor(arg: ChatErrorOpts | string);
|
|
258
276
|
}
|
|
259
277
|
/** 401 / 403 — auth failed (bad/expired token, wrong team, etc.). */
|
|
260
278
|
declare class ChatClientAuthError extends ChatClientError {
|
|
261
|
-
constructor(
|
|
262
|
-
message: string;
|
|
263
|
-
code?: string;
|
|
264
|
-
statusCode: number;
|
|
265
|
-
requestId?: string | null;
|
|
266
|
-
});
|
|
279
|
+
constructor(arg: ChatErrorOpts | string);
|
|
267
280
|
}
|
|
268
281
|
/** 429 — too many requests. Inspect `retryAfter` (seconds) before retrying. */
|
|
269
282
|
declare class ChatClientRateLimitError extends ChatClientError {
|
|
270
283
|
readonly retryAfter: number | null;
|
|
271
|
-
constructor(
|
|
272
|
-
message: string;
|
|
273
|
-
code?: string;
|
|
274
|
-
statusCode: number;
|
|
275
|
-
requestId?: string | null;
|
|
284
|
+
constructor(arg: (ChatErrorOpts & {
|
|
276
285
|
retryAfter?: number | null;
|
|
277
|
-
});
|
|
286
|
+
}) | string);
|
|
278
287
|
}
|
|
279
288
|
/** 5xx — the cStar server hit an internal error. Usually transient. */
|
|
280
289
|
declare class ChatClientServerError extends ChatClientError {
|
|
281
|
-
constructor(
|
|
282
|
-
message: string;
|
|
283
|
-
code?: string;
|
|
284
|
-
statusCode: number;
|
|
285
|
-
requestId?: string | null;
|
|
286
|
-
});
|
|
290
|
+
constructor(arg: ChatErrorOpts | string);
|
|
287
291
|
}
|
|
288
292
|
/**
|
|
289
293
|
* `fetch()` itself failed before a response was received — DNS, TLS,
|
package/dist/chat/index.d.ts
CHANGED
|
@@ -88,13 +88,24 @@ interface RealtimeTokenResponse {
|
|
|
88
88
|
/** A ticket — a customer's support thread. */
|
|
89
89
|
interface Ticket {
|
|
90
90
|
id: string;
|
|
91
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Server-issued display ID (e.g. `CST-1024`). `null` immediately after
|
|
93
|
+
* `tickets.create` (the prefix is assigned asynchronously); populated on
|
|
94
|
+
* subsequent `tickets.list` / single fetches.
|
|
95
|
+
*/
|
|
96
|
+
ticketNumber: string | null;
|
|
92
97
|
subject: string;
|
|
93
98
|
status: string;
|
|
94
99
|
messageCount: number;
|
|
95
100
|
createdAt: string;
|
|
96
101
|
updatedAt: string;
|
|
97
102
|
closedAt: string | null;
|
|
103
|
+
/**
|
|
104
|
+
* Set on `tickets.create` responses — contains the first message the
|
|
105
|
+
* widget sent, so callers don't need a round-trip `messages.list(...)`
|
|
106
|
+
* to echo it back. `undefined` on list/get responses.
|
|
107
|
+
*/
|
|
108
|
+
messages?: Message[];
|
|
98
109
|
}
|
|
99
110
|
/** Paginated ticket list response. */
|
|
100
111
|
interface TicketListResponse {
|
|
@@ -244,46 +255,39 @@ interface CommunityFollowResult {
|
|
|
244
255
|
* }
|
|
245
256
|
* }
|
|
246
257
|
* ```
|
|
258
|
+
*
|
|
259
|
+
* Constructors accept either a full opts object (used by the SDK's HTTP
|
|
260
|
+
* paths) or a bare message string — handy for SDK precondition checks
|
|
261
|
+
* (`throw new ChatClientAuthError('Not identified...')`) and tests.
|
|
262
|
+
* Closes F-032's spirit for the chat-client classes.
|
|
247
263
|
*/
|
|
264
|
+
interface ChatErrorOpts {
|
|
265
|
+
message: string;
|
|
266
|
+
code?: string;
|
|
267
|
+
statusCode?: number;
|
|
268
|
+
requestId?: string | null;
|
|
269
|
+
}
|
|
248
270
|
/** Base class. Thrown by `ChatClient.fetch()` for any non-2xx response. */
|
|
249
271
|
declare class ChatClientError extends Error {
|
|
250
272
|
readonly code: string;
|
|
251
273
|
readonly statusCode: number;
|
|
252
274
|
readonly requestId: string | null;
|
|
253
|
-
constructor(
|
|
254
|
-
code?: string;
|
|
255
|
-
statusCode: number;
|
|
256
|
-
requestId?: string | null;
|
|
257
|
-
});
|
|
275
|
+
constructor(arg: ChatErrorOpts | string);
|
|
258
276
|
}
|
|
259
277
|
/** 401 / 403 — auth failed (bad/expired token, wrong team, etc.). */
|
|
260
278
|
declare class ChatClientAuthError extends ChatClientError {
|
|
261
|
-
constructor(
|
|
262
|
-
message: string;
|
|
263
|
-
code?: string;
|
|
264
|
-
statusCode: number;
|
|
265
|
-
requestId?: string | null;
|
|
266
|
-
});
|
|
279
|
+
constructor(arg: ChatErrorOpts | string);
|
|
267
280
|
}
|
|
268
281
|
/** 429 — too many requests. Inspect `retryAfter` (seconds) before retrying. */
|
|
269
282
|
declare class ChatClientRateLimitError extends ChatClientError {
|
|
270
283
|
readonly retryAfter: number | null;
|
|
271
|
-
constructor(
|
|
272
|
-
message: string;
|
|
273
|
-
code?: string;
|
|
274
|
-
statusCode: number;
|
|
275
|
-
requestId?: string | null;
|
|
284
|
+
constructor(arg: (ChatErrorOpts & {
|
|
276
285
|
retryAfter?: number | null;
|
|
277
|
-
});
|
|
286
|
+
}) | string);
|
|
278
287
|
}
|
|
279
288
|
/** 5xx — the cStar server hit an internal error. Usually transient. */
|
|
280
289
|
declare class ChatClientServerError extends ChatClientError {
|
|
281
|
-
constructor(
|
|
282
|
-
message: string;
|
|
283
|
-
code?: string;
|
|
284
|
-
statusCode: number;
|
|
285
|
-
requestId?: string | null;
|
|
286
|
-
});
|
|
290
|
+
constructor(arg: ChatErrorOpts | string);
|
|
287
291
|
}
|
|
288
292
|
/**
|
|
289
293
|
* `fetch()` itself failed before a response was received — DNS, TLS,
|
package/dist/chat/index.js
CHANGED
|
@@ -248,37 +248,45 @@ var PresenceManager = class {
|
|
|
248
248
|
};
|
|
249
249
|
|
|
250
250
|
// src/chat/errors.ts
|
|
251
|
+
function normalizeChatArgs(arg, fallbackCode) {
|
|
252
|
+
if (typeof arg === "string") {
|
|
253
|
+
return { message: arg, code: fallbackCode, statusCode: 0, requestId: null };
|
|
254
|
+
}
|
|
255
|
+
return { ...arg, code: arg.code ?? fallbackCode };
|
|
256
|
+
}
|
|
251
257
|
var ChatClientError = class extends Error {
|
|
252
|
-
constructor(
|
|
253
|
-
|
|
258
|
+
constructor(arg) {
|
|
259
|
+
const opts = normalizeChatArgs(arg, "UNKNOWN");
|
|
260
|
+
super(opts.message);
|
|
254
261
|
this.name = "ChatClientError";
|
|
255
262
|
this.code = opts.code ?? "UNKNOWN";
|
|
256
|
-
this.statusCode = opts.statusCode;
|
|
263
|
+
this.statusCode = opts.statusCode ?? 0;
|
|
257
264
|
this.requestId = opts.requestId ?? null;
|
|
258
265
|
}
|
|
259
266
|
};
|
|
260
267
|
var ChatClientAuthError = class extends ChatClientError {
|
|
261
|
-
constructor(
|
|
262
|
-
super(
|
|
268
|
+
constructor(arg) {
|
|
269
|
+
super(normalizeChatArgs(arg, "AUTH_ERROR"));
|
|
263
270
|
this.name = "ChatClientAuthError";
|
|
264
271
|
}
|
|
265
272
|
};
|
|
266
273
|
var ChatClientRateLimitError = class extends ChatClientError {
|
|
267
|
-
constructor(
|
|
268
|
-
|
|
274
|
+
constructor(arg) {
|
|
275
|
+
const opts = typeof arg === "string" ? { message: arg, code: "RATE_LIMIT", statusCode: 429, requestId: null, retryAfter: null } : { ...arg, code: arg.code ?? "RATE_LIMIT" };
|
|
276
|
+
super(opts);
|
|
269
277
|
this.name = "ChatClientRateLimitError";
|
|
270
278
|
this.retryAfter = opts.retryAfter ?? null;
|
|
271
279
|
}
|
|
272
280
|
};
|
|
273
281
|
var ChatClientServerError = class extends ChatClientError {
|
|
274
|
-
constructor(
|
|
275
|
-
super(
|
|
282
|
+
constructor(arg) {
|
|
283
|
+
super(normalizeChatArgs(arg, "SERVER_ERROR"));
|
|
276
284
|
this.name = "ChatClientServerError";
|
|
277
285
|
}
|
|
278
286
|
};
|
|
279
287
|
var ChatClientNetworkError = class extends ChatClientError {
|
|
280
288
|
constructor(opts) {
|
|
281
|
-
super(opts.message,
|
|
289
|
+
super({ message: opts.message, code: "NETWORK_ERROR", statusCode: 0, requestId: null });
|
|
282
290
|
this.name = "ChatClientNetworkError";
|
|
283
291
|
this.originalError = opts.originalError;
|
|
284
292
|
}
|
|
@@ -333,6 +341,7 @@ var ChatClient = class {
|
|
|
333
341
|
this.sessionToken = response.data.sessionToken;
|
|
334
342
|
this.teamId = response.data.teamId;
|
|
335
343
|
this.customerId = response.data.customer.id;
|
|
344
|
+
this.authMode = "hmac";
|
|
336
345
|
if (this.realtimeEnabled) {
|
|
337
346
|
this.realtimeInitPromise = this.initRealtime(
|
|
338
347
|
response.data.customer.id,
|
|
@@ -530,7 +539,8 @@ var ChatClient = class {
|
|
|
530
539
|
requestId
|
|
531
540
|
});
|
|
532
541
|
}
|
|
533
|
-
throw new ChatClientError(
|
|
542
|
+
throw new ChatClientError({
|
|
543
|
+
message,
|
|
534
544
|
code,
|
|
535
545
|
statusCode: response.status,
|
|
536
546
|
requestId
|
|
@@ -668,7 +678,7 @@ var TicketsApi = class {
|
|
|
668
678
|
/** List tickets for the identified customer. */
|
|
669
679
|
async list(params) {
|
|
670
680
|
const teamId = this.chat.getTeamId();
|
|
671
|
-
if (!teamId) throw new
|
|
681
|
+
if (!teamId) throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
|
|
672
682
|
const response = await this.chat.fetch("/api/widget/conversations", {
|
|
673
683
|
method: "GET",
|
|
674
684
|
query: {
|
|
@@ -686,7 +696,7 @@ var TicketsApi = class {
|
|
|
686
696
|
/** Create a new ticket. */
|
|
687
697
|
async create(params) {
|
|
688
698
|
const teamId = this.chat.getTeamId();
|
|
689
|
-
if (!teamId) throw new
|
|
699
|
+
if (!teamId) throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
|
|
690
700
|
const response = await this.chat.fetch("/api/widget/tickets", {
|
|
691
701
|
method: "POST",
|
|
692
702
|
body: {
|
|
@@ -695,15 +705,25 @@ var TicketsApi = class {
|
|
|
695
705
|
message: params.message
|
|
696
706
|
}
|
|
697
707
|
});
|
|
708
|
+
const messages = (response.data.messages ?? []).map((m) => ({
|
|
709
|
+
id: m.id,
|
|
710
|
+
content: m.content,
|
|
711
|
+
sender: m.sender,
|
|
712
|
+
sender_name: m.sender_name,
|
|
713
|
+
created_at: m.created_at,
|
|
714
|
+
read_at: m.read_at,
|
|
715
|
+
attachments: m.attachments ?? []
|
|
716
|
+
}));
|
|
698
717
|
return {
|
|
699
718
|
id: response.data.id,
|
|
700
|
-
ticketNumber:
|
|
719
|
+
ticketNumber: null,
|
|
701
720
|
subject: response.data.subject,
|
|
702
721
|
status: response.data.status,
|
|
703
|
-
messageCount:
|
|
722
|
+
messageCount: messages.length,
|
|
704
723
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
705
724
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
706
|
-
closedAt: null
|
|
725
|
+
closedAt: null,
|
|
726
|
+
messages
|
|
707
727
|
};
|
|
708
728
|
}
|
|
709
729
|
};
|
|
@@ -714,7 +734,7 @@ var ChatCommunityApi = class {
|
|
|
714
734
|
/** Create a new community post as the identified customer. */
|
|
715
735
|
async createPost(params) {
|
|
716
736
|
const teamId = this.chat.getTeamId();
|
|
717
|
-
if (!teamId) throw new
|
|
737
|
+
if (!teamId) throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
|
|
718
738
|
const response = await this.chat.fetch("/api/widget/community", {
|
|
719
739
|
method: "POST",
|
|
720
740
|
body: {
|
|
@@ -731,7 +751,7 @@ var ChatCommunityApi = class {
|
|
|
731
751
|
/** Update a post. Only the original author can edit. */
|
|
732
752
|
async updatePost(postId, params) {
|
|
733
753
|
const teamId = this.chat.getTeamId();
|
|
734
|
-
if (!teamId) throw new
|
|
754
|
+
if (!teamId) throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
|
|
735
755
|
const response = await this.chat.fetch("/api/widget/community", {
|
|
736
756
|
method: "POST",
|
|
737
757
|
body: {
|
|
@@ -748,7 +768,7 @@ var ChatCommunityApi = class {
|
|
|
748
768
|
/** Delete a post (soft delete). Only the original author can delete. */
|
|
749
769
|
async deletePost(postId) {
|
|
750
770
|
const teamId = this.chat.getTeamId();
|
|
751
|
-
if (!teamId) throw new
|
|
771
|
+
if (!teamId) throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
|
|
752
772
|
await this.chat.fetch("/api/widget/community", {
|
|
753
773
|
method: "POST",
|
|
754
774
|
body: { teamId, action: "deletePost", postId }
|
|
@@ -757,7 +777,7 @@ var ChatCommunityApi = class {
|
|
|
757
777
|
/** Update a comment. Only the original author can edit. */
|
|
758
778
|
async updateComment(postId, commentId, params) {
|
|
759
779
|
const teamId = this.chat.getTeamId();
|
|
760
|
-
if (!teamId) throw new
|
|
780
|
+
if (!teamId) throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
|
|
761
781
|
const response = await this.chat.fetch("/api/widget/community", {
|
|
762
782
|
method: "POST",
|
|
763
783
|
body: {
|
|
@@ -773,7 +793,7 @@ var ChatCommunityApi = class {
|
|
|
773
793
|
/** Delete a comment (soft delete). Only the original author can delete. */
|
|
774
794
|
async deleteComment(postId, commentId) {
|
|
775
795
|
const teamId = this.chat.getTeamId();
|
|
776
|
-
if (!teamId) throw new
|
|
796
|
+
if (!teamId) throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
|
|
777
797
|
await this.chat.fetch("/api/widget/community", {
|
|
778
798
|
method: "POST",
|
|
779
799
|
body: { teamId, action: "deleteComment", postId, commentId }
|
|
@@ -782,7 +802,7 @@ var ChatCommunityApi = class {
|
|
|
782
802
|
/** Toggle vote on a post. Returns new vote state and count. */
|
|
783
803
|
async vote(postId) {
|
|
784
804
|
const teamId = this.chat.getTeamId();
|
|
785
|
-
if (!teamId) throw new
|
|
805
|
+
if (!teamId) throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
|
|
786
806
|
const response = await this.chat.fetch("/api/widget/community", {
|
|
787
807
|
method: "POST",
|
|
788
808
|
body: { teamId, action: "vote", postId }
|
|
@@ -792,7 +812,7 @@ var ChatCommunityApi = class {
|
|
|
792
812
|
/** Add a comment to a post. Supports 1-level nesting via parentCommentId. */
|
|
793
813
|
async comment(postId, params) {
|
|
794
814
|
const teamId = this.chat.getTeamId();
|
|
795
|
-
if (!teamId) throw new
|
|
815
|
+
if (!teamId) throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
|
|
796
816
|
const response = await this.chat.fetch("/api/widget/community", {
|
|
797
817
|
method: "POST",
|
|
798
818
|
body: {
|
|
@@ -808,7 +828,7 @@ var ChatCommunityApi = class {
|
|
|
808
828
|
/** Toggle follow on a post. */
|
|
809
829
|
async follow(postId) {
|
|
810
830
|
const teamId = this.chat.getTeamId();
|
|
811
|
-
if (!teamId) throw new
|
|
831
|
+
if (!teamId) throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
|
|
812
832
|
const response = await this.chat.fetch("/api/widget/community", {
|
|
813
833
|
method: "POST",
|
|
814
834
|
body: { teamId, action: "follow", postId }
|
|
@@ -818,7 +838,7 @@ var ChatCommunityApi = class {
|
|
|
818
838
|
/** Check if the current user has voted on a post. */
|
|
819
839
|
async getVoteStatus(postId) {
|
|
820
840
|
const teamId = this.chat.getTeamId();
|
|
821
|
-
if (!teamId) throw new
|
|
841
|
+
if (!teamId) throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
|
|
822
842
|
const response = await this.chat.fetch("/api/widget/community", {
|
|
823
843
|
method: "GET",
|
|
824
844
|
query: { teamId, postId }
|
|
@@ -829,7 +849,7 @@ var ChatCommunityApi = class {
|
|
|
829
849
|
async bulkVoteStatus(postIds) {
|
|
830
850
|
if (postIds.length === 0) return {};
|
|
831
851
|
const teamId = this.chat.getTeamId();
|
|
832
|
-
if (!teamId) throw new
|
|
852
|
+
if (!teamId) throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
|
|
833
853
|
const response = await this.chat.fetch("/api/widget/community", {
|
|
834
854
|
method: "GET",
|
|
835
855
|
query: { teamId, postIds: postIds.join(",") }
|