@cstar.help/js 0.14.0 → 0.15.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.
@@ -111,30 +111,21 @@ interface Ticket {
111
111
  * Paginated ticket list response.
112
112
  *
113
113
  * As of `@cstar.help/js@0.14.0` the canonical fields match the admin SDK and
114
- * library SDK envelopes (`{ data, pagination, hasMore }`). The legacy
115
- * `tickets` and `cursor` fields are kept as aliases — they reference the
116
- * same data — and will be removed in the next major. Closes F-037.
114
+ * library SDK envelopes (`{ data, pagination, hasMore }`). Closes F-037.
115
+ *
116
+ * Breaking change in 0.15.0 (B-11): the deprecated `tickets` and `cursor`
117
+ * top-level aliases are removed. Read `data` and `pagination.cursor`.
117
118
  */
118
119
  interface TicketListResponse {
119
- /** Tickets on this page (canonical). */
120
+ /** Tickets on this page. */
120
121
  data: Ticket[];
121
- /** Pagination cursor + a flag for whether more pages exist (canonical). */
122
+ /** Pagination cursor + a flag for whether more pages exist. */
122
123
  pagination: {
123
124
  cursor: string | null;
124
125
  hasMore: boolean;
125
126
  };
126
127
  /** Convenience copy of `pagination.hasMore`. */
127
128
  hasMore: boolean;
128
- /**
129
- * @deprecated since 0.14.0 — use `data`. Same array reference for now.
130
- * Will be removed in the next major.
131
- */
132
- tickets: Ticket[];
133
- /**
134
- * @deprecated since 0.14.0 — use `pagination.cursor`. Same value.
135
- * Will be removed in the next major.
136
- */
137
- cursor: string | null;
138
129
  }
139
130
  /** A message on a ticket. */
140
131
  interface Message {
@@ -494,6 +485,18 @@ declare class ChatClient {
494
485
  private initRealtimeFromSession;
495
486
  /** @internal Get the stored team ID for requests that need it. */
496
487
  getTeamId(): string | null;
488
+ /**
489
+ * Resolve a team ID, lazily looking it up from `teamSlug` if no team ID
490
+ * has been cached yet. Used by `tickets.list` and friends so that a
491
+ * caller who constructed `new ChatClient({ teamSlug, publishableKey })`
492
+ * doesn't have to manually call `loginWithCredentials` before reading
493
+ * public data.
494
+ *
495
+ * Closes NEW-v3-05 — `TicketsState(chatClient)` previously errored
496
+ * `"Missing teamId"` when the chat client was teamSlug-only because the
497
+ * tickets sub-resource read `getTeamId()` synchronously and bailed.
498
+ */
499
+ ensureTeamId(): Promise<string>;
497
500
  /** @internal Set team ID from identify response or other source. */
498
501
  setTeamId(teamId: string): void;
499
502
  /** @internal Wait for realtime to be initialized (for testing). */
@@ -621,6 +621,27 @@ var ChatClient = class {
621
621
  getTeamId() {
622
622
  return this.teamId;
623
623
  }
624
+ /**
625
+ * Resolve a team ID, lazily looking it up from `teamSlug` if no team ID
626
+ * has been cached yet. Used by `tickets.list` and friends so that a
627
+ * caller who constructed `new ChatClient({ teamSlug, publishableKey })`
628
+ * doesn't have to manually call `loginWithCredentials` before reading
629
+ * public data.
630
+ *
631
+ * Closes NEW-v3-05 — `TicketsState(chatClient)` previously errored
632
+ * `"Missing teamId"` when the chat client was teamSlug-only because the
633
+ * tickets sub-resource read `getTeamId()` synchronously and bailed.
634
+ */
635
+ async ensureTeamId() {
636
+ if (this.teamId) return this.teamId;
637
+ if (!this.teamSlug) {
638
+ throw new ChatClientAuthError(
639
+ "Missing teamId. Construct ChatClient with `teamSlug` or call `setTeamId()` / `identify()` / `loginWithCredentials()` first."
640
+ );
641
+ }
642
+ this.teamId = await this.resolveTeamIdFromSlug();
643
+ return this.teamId;
644
+ }
624
645
  /** @internal Set team ID from identify response or other source. */
625
646
  setTeamId(teamId) {
626
647
  this.teamId = teamId;
@@ -706,8 +727,10 @@ var TicketsApi = class {
706
727
  }
707
728
  /** List tickets for the identified customer. */
708
729
  async list(params) {
709
- const teamId = this.chat.getTeamId();
710
- if (!teamId) throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
730
+ if (this.chat.getAuthMode() === null) {
731
+ throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
732
+ }
733
+ const teamId = await this.chat.ensureTeamId();
711
734
  const response = await this.chat.fetch("/api/widget/conversations", {
712
735
  method: "GET",
713
736
  query: {
@@ -722,16 +745,15 @@ var TicketsApi = class {
722
745
  return {
723
746
  data,
724
747
  pagination: { cursor, hasMore },
725
- hasMore,
726
- // Deprecated aliases — same references, no extra allocation.
727
- tickets: data,
728
- cursor
748
+ hasMore
729
749
  };
730
750
  }
731
751
  /** Create a new ticket. */
732
752
  async create(params) {
733
- const teamId = this.chat.getTeamId();
734
- if (!teamId) throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
753
+ if (this.chat.getAuthMode() === null) {
754
+ throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
755
+ }
756
+ const teamId = await this.chat.ensureTeamId();
735
757
  const response = await this.chat.fetch("/api/widget/tickets", {
736
758
  method: "POST",
737
759
  body: {
@@ -20,7 +20,20 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/community/index.ts
21
21
  var community_exports = {};
22
22
  __export(community_exports, {
23
- CommunityClient: () => CommunityClient
23
+ CStarAuthenticationError: () => CStarAuthenticationError,
24
+ CStarConflictError: () => CStarConflictError,
25
+ CStarError: () => CStarError,
26
+ CStarFeatureDisabledError: () => CStarFeatureDisabledError,
27
+ CStarNotFoundError: () => CStarNotFoundError,
28
+ CStarPermissionError: () => CStarPermissionError,
29
+ CStarRateLimitError: () => CStarRateLimitError,
30
+ CStarRealtimeUnavailableError: () => CStarRealtimeUnavailableError,
31
+ CStarServerError: () => CStarServerError,
32
+ CStarValidationError: () => CStarValidationError,
33
+ CommunityClient: () => CommunityClient,
34
+ ErrorType: () => ErrorType,
35
+ parseError: () => parseError,
36
+ parsePublicError: () => parsePublicError
24
37
  });
25
38
  module.exports = __toCommonJS(community_exports);
26
39
 
@@ -61,7 +74,7 @@ function normalizeArgs(messageOrStatus, maybeBody, defaults) {
61
74
  }
62
75
  };
63
76
  }
64
- var CStarError = class extends Error {
77
+ var CStarErrorImpl = class extends Error {
65
78
  constructor(messageOrStatus, body) {
66
79
  const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body);
67
80
  super(resolved.message);
@@ -74,7 +87,7 @@ var CStarError = class extends Error {
74
87
  this.statusCode = statusCode;
75
88
  }
76
89
  };
77
- var CStarAuthenticationError = class extends CStarError {
90
+ var CStarAuthenticationErrorImpl = class extends CStarErrorImpl {
78
91
  constructor(messageOrStatus, body) {
79
92
  const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
80
93
  type: ErrorType.AUTHENTICATION_ERROR,
@@ -85,7 +98,7 @@ var CStarAuthenticationError = class extends CStarError {
85
98
  this.name = "CStarAuthenticationError";
86
99
  }
87
100
  };
88
- var CStarRateLimitError = class extends CStarError {
101
+ var CStarRateLimitErrorImpl = class extends CStarErrorImpl {
89
102
  constructor(messageOrStatus, body, retryAfter) {
90
103
  const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
91
104
  type: ErrorType.RATE_LIMIT_ERROR,
@@ -97,7 +110,7 @@ var CStarRateLimitError = class extends CStarError {
97
110
  this.retryAfter = retryAfter ?? 60;
98
111
  }
99
112
  };
100
- var CStarNotFoundError = class extends CStarError {
113
+ var CStarNotFoundErrorImpl = class extends CStarErrorImpl {
101
114
  constructor(messageOrStatus, body) {
102
115
  const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
103
116
  type: ErrorType.NOT_FOUND_ERROR,
@@ -108,7 +121,7 @@ var CStarNotFoundError = class extends CStarError {
108
121
  this.name = "CStarNotFoundError";
109
122
  }
110
123
  };
111
- var CStarValidationError = class extends CStarError {
124
+ var CStarValidationErrorImpl = class extends CStarErrorImpl {
112
125
  constructor(messageOrStatus, body) {
113
126
  const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
114
127
  type: ErrorType.INVALID_REQUEST_ERROR,
@@ -119,7 +132,7 @@ var CStarValidationError = class extends CStarError {
119
132
  this.name = "CStarValidationError";
120
133
  }
121
134
  };
122
- var CStarPermissionError = class extends CStarError {
135
+ var CStarPermissionErrorImpl = class extends CStarErrorImpl {
123
136
  constructor(messageOrStatus, body) {
124
137
  const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
125
138
  type: ErrorType.PERMISSION_ERROR,
@@ -130,7 +143,7 @@ var CStarPermissionError = class extends CStarError {
130
143
  this.name = "CStarPermissionError";
131
144
  }
132
145
  };
133
- var CStarConflictError = class extends CStarError {
146
+ var CStarConflictErrorImpl = class extends CStarErrorImpl {
134
147
  constructor(messageOrStatus, body) {
135
148
  const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
136
149
  type: ErrorType.CONFLICT_ERROR,
@@ -141,7 +154,7 @@ var CStarConflictError = class extends CStarError {
141
154
  this.name = "CStarConflictError";
142
155
  }
143
156
  };
144
- var CStarServerError = class extends CStarError {
157
+ var CStarServerErrorImpl = class extends CStarErrorImpl {
145
158
  constructor(messageOrStatus, body) {
146
159
  const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
147
160
  type: ErrorType.SERVER_ERROR,
@@ -152,7 +165,7 @@ var CStarServerError = class extends CStarError {
152
165
  this.name = "CStarServerError";
153
166
  }
154
167
  };
155
- var CStarFeatureDisabledError = class extends CStarError {
168
+ var CStarFeatureDisabledErrorImpl = class extends CStarErrorImpl {
156
169
  constructor(messageOrStatus, body) {
157
170
  const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
158
171
  type: ErrorType.FEATURE_NOT_CONFIGURED,
@@ -165,6 +178,62 @@ var CStarFeatureDisabledError = class extends CStarError {
165
178
  this.enableUrl = resolved.enable_url ?? "";
166
179
  }
167
180
  };
181
+ var CStarRealtimeUnavailableErrorImpl = class extends CStarErrorImpl {
182
+ constructor(message) {
183
+ const resolved = message ?? "EventSource is not available in this environment. Real-time subscriptions only work in the browser. Move the call to a client-only path (`useEffect` / `onMount`), or pass an `eventSource` polyfill via the realtime options. See https://cstar.help/developers/sdk/realtime#ssr";
184
+ super(0, {
185
+ type: ErrorType.API_ERROR,
186
+ code: "realtime_unavailable",
187
+ message: resolved,
188
+ doc_url: "https://cstar.help/developers/sdk/realtime#ssr"
189
+ });
190
+ this.name = "CStarRealtimeUnavailableError";
191
+ }
192
+ };
193
+ var REGISTRY_KEY = /* @__PURE__ */ Symbol.for("@cstar.help/js/errors/v1");
194
+ var globalSlot = globalThis;
195
+ var registry = globalSlot[REGISTRY_KEY] ?? (globalSlot[REGISTRY_KEY] = {
196
+ CStarError: CStarErrorImpl,
197
+ CStarAuthenticationError: CStarAuthenticationErrorImpl,
198
+ CStarRateLimitError: CStarRateLimitErrorImpl,
199
+ CStarNotFoundError: CStarNotFoundErrorImpl,
200
+ CStarValidationError: CStarValidationErrorImpl,
201
+ CStarPermissionError: CStarPermissionErrorImpl,
202
+ CStarConflictError: CStarConflictErrorImpl,
203
+ CStarServerError: CStarServerErrorImpl,
204
+ CStarFeatureDisabledError: CStarFeatureDisabledErrorImpl,
205
+ CStarRealtimeUnavailableError: CStarRealtimeUnavailableErrorImpl
206
+ });
207
+ var NAME_FIXES = [
208
+ "CStarError",
209
+ "CStarAuthenticationError",
210
+ "CStarRateLimitError",
211
+ "CStarNotFoundError",
212
+ "CStarValidationError",
213
+ "CStarPermissionError",
214
+ "CStarConflictError",
215
+ "CStarServerError",
216
+ "CStarFeatureDisabledError",
217
+ "CStarRealtimeUnavailableError"
218
+ ];
219
+ for (const key of NAME_FIXES) {
220
+ if (registry[key].name !== key) {
221
+ Object.defineProperty(registry[key], "name", {
222
+ value: key,
223
+ configurable: true
224
+ });
225
+ }
226
+ }
227
+ var CStarError = registry.CStarError;
228
+ var CStarAuthenticationError = registry.CStarAuthenticationError;
229
+ var CStarRateLimitError = registry.CStarRateLimitError;
230
+ var CStarNotFoundError = registry.CStarNotFoundError;
231
+ var CStarValidationError = registry.CStarValidationError;
232
+ var CStarPermissionError = registry.CStarPermissionError;
233
+ var CStarConflictError = registry.CStarConflictError;
234
+ var CStarServerError = registry.CStarServerError;
235
+ var CStarFeatureDisabledError = registry.CStarFeatureDisabledError;
236
+ var CStarRealtimeUnavailableError = registry.CStarRealtimeUnavailableError;
168
237
  function parsePublicError(status, body, fallbackMessage) {
169
238
  const obj = body && typeof body === "object" ? body : null;
170
239
  const errVal = obj?.error;
@@ -529,5 +598,18 @@ var CommunityClient = class {
529
598
  };
530
599
  // Annotate the CommonJS export names for ESM import in node:
531
600
  0 && (module.exports = {
532
- CommunityClient
601
+ CStarAuthenticationError,
602
+ CStarConflictError,
603
+ CStarError,
604
+ CStarFeatureDisabledError,
605
+ CStarNotFoundError,
606
+ CStarPermissionError,
607
+ CStarRateLimitError,
608
+ CStarRealtimeUnavailableError,
609
+ CStarServerError,
610
+ CStarValidationError,
611
+ CommunityClient,
612
+ ErrorType,
613
+ parseError,
614
+ parsePublicError
533
615
  });