@cstar.help/js 0.14.0 → 0.15.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 +73 -11
- package/dist/auth/index.d.cts +121 -1
- package/dist/auth/index.d.ts +121 -1
- package/dist/auth/index.js +59 -10
- package/dist/chat/index.cjs +30 -8
- package/dist/chat/index.d.cts +18 -15
- package/dist/chat/index.d.ts +18 -15
- package/dist/chat/index.js +30 -8
- package/dist/community/index.cjs +73 -11
- package/dist/community/index.d.cts +121 -1
- package/dist/community/index.d.ts +121 -1
- package/dist/community/index.js +59 -10
- package/dist/index.cjs +35 -11
- package/dist/index.d.cts +58 -26
- package/dist/index.d.ts +58 -26
- package/dist/index.js +35 -11
- package/dist/library/index.cjs +73 -11
- package/dist/library/index.d.cts +121 -1
- package/dist/library/index.d.ts +121 -1
- package/dist/library/index.js +59 -10
- package/dist/quickhelp/index.cjs +134 -11
- package/dist/quickhelp/index.d.cts +121 -1
- package/dist/quickhelp/index.d.ts +121 -1
- package/dist/quickhelp/index.js +120 -10
- package/dist/webhook/index.cjs +64 -8
- package/dist/webhook/index.d.cts +27 -3
- package/dist/webhook/index.d.ts +27 -3
- package/dist/webhook/index.js +62 -8
- package/dist/webhook/node.cjs +53 -5
- package/dist/webhook/node.d.cts +27 -4
- package/dist/webhook/node.d.ts +27 -4
- package/dist/webhook/node.js +51 -5
- package/package.json +1 -1
package/dist/chat/index.d.cts
CHANGED
|
@@ -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 }`).
|
|
115
|
-
*
|
|
116
|
-
*
|
|
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
|
|
120
|
+
/** Tickets on this page. */
|
|
120
121
|
data: Ticket[];
|
|
121
|
-
/** Pagination cursor + a flag for whether more pages exist
|
|
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). */
|
package/dist/chat/index.d.ts
CHANGED
|
@@ -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 }`).
|
|
115
|
-
*
|
|
116
|
-
*
|
|
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
|
|
120
|
+
/** Tickets on this page. */
|
|
120
121
|
data: Ticket[];
|
|
121
|
-
/** Pagination cursor + a flag for whether more pages exist
|
|
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). */
|
package/dist/chat/index.js
CHANGED
|
@@ -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
|
-
|
|
710
|
-
|
|
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
|
-
|
|
734
|
-
|
|
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: {
|
package/dist/community/index.cjs
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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,42 @@ 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 CStarError = registry.CStarError;
|
|
208
|
+
var CStarAuthenticationError = registry.CStarAuthenticationError;
|
|
209
|
+
var CStarRateLimitError = registry.CStarRateLimitError;
|
|
210
|
+
var CStarNotFoundError = registry.CStarNotFoundError;
|
|
211
|
+
var CStarValidationError = registry.CStarValidationError;
|
|
212
|
+
var CStarPermissionError = registry.CStarPermissionError;
|
|
213
|
+
var CStarConflictError = registry.CStarConflictError;
|
|
214
|
+
var CStarServerError = registry.CStarServerError;
|
|
215
|
+
var CStarFeatureDisabledError = registry.CStarFeatureDisabledError;
|
|
216
|
+
var CStarRealtimeUnavailableError = registry.CStarRealtimeUnavailableError;
|
|
168
217
|
function parsePublicError(status, body, fallbackMessage) {
|
|
169
218
|
const obj = body && typeof body === "object" ? body : null;
|
|
170
219
|
const errVal = obj?.error;
|
|
@@ -529,5 +578,18 @@ var CommunityClient = class {
|
|
|
529
578
|
};
|
|
530
579
|
// Annotate the CommonJS export names for ESM import in node:
|
|
531
580
|
0 && (module.exports = {
|
|
532
|
-
|
|
581
|
+
CStarAuthenticationError,
|
|
582
|
+
CStarConflictError,
|
|
583
|
+
CStarError,
|
|
584
|
+
CStarFeatureDisabledError,
|
|
585
|
+
CStarNotFoundError,
|
|
586
|
+
CStarPermissionError,
|
|
587
|
+
CStarRateLimitError,
|
|
588
|
+
CStarRealtimeUnavailableError,
|
|
589
|
+
CStarServerError,
|
|
590
|
+
CStarValidationError,
|
|
591
|
+
CommunityClient,
|
|
592
|
+
ErrorType,
|
|
593
|
+
parseError,
|
|
594
|
+
parsePublicError
|
|
533
595
|
});
|
|
@@ -187,6 +187,126 @@ interface CommunityPostDetail {
|
|
|
187
187
|
comments: CommunityComment[];
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
+
/**
|
|
191
|
+
* Error classes for the cStar SDK.
|
|
192
|
+
*
|
|
193
|
+
* NEW-v3-01 — Cross-subpath instanceof identity.
|
|
194
|
+
*
|
|
195
|
+
* Each public subpath (`/library`, `/auth`, `/community`, `/quickhelp`, ...)
|
|
196
|
+
* is bundled as a separate tsup entry with `splitting: false`, so each one
|
|
197
|
+
* carries its own copy of this module. Without deduplication, errors thrown
|
|
198
|
+
* by `LibraryClient` carry the LibraryClient-bundled `CStarError` class —
|
|
199
|
+
* not the one a consumer imports from `@cstar.help/js`. That makes
|
|
200
|
+
* `instanceof CStarError` checks fail silently, invalidating every "did the
|
|
201
|
+
* SDK throw a typed cStar error?" branch in user code.
|
|
202
|
+
*
|
|
203
|
+
* Fix: register each class on a `Symbol.for(...)` slot of `globalThis`. The
|
|
204
|
+
* symbol is realm-shared, so every bundled copy of this module resolves to
|
|
205
|
+
* the SAME class identity at runtime — the first copy to load wins, and all
|
|
206
|
+
* subsequent copies surface the canonical class via the same slot. The
|
|
207
|
+
* inline `Impl` definitions are only used as the seed for the very first
|
|
208
|
+
* copy to register. Internal `parseError` / `parsePublicError` reference the
|
|
209
|
+
* EXPORTED canonical names so instances they construct also land on the
|
|
210
|
+
* canonical class.
|
|
211
|
+
*/
|
|
212
|
+
/** Error type constants matching the cStar API. */
|
|
213
|
+
declare const ErrorType: {
|
|
214
|
+
readonly AUTHENTICATION_ERROR: "authentication_error";
|
|
215
|
+
readonly PERMISSION_ERROR: "permission_error";
|
|
216
|
+
readonly INVALID_REQUEST_ERROR: "invalid_request_error";
|
|
217
|
+
readonly NOT_FOUND_ERROR: "not_found_error";
|
|
218
|
+
readonly CONFLICT_ERROR: "conflict_error";
|
|
219
|
+
readonly RATE_LIMIT_ERROR: "rate_limit_error";
|
|
220
|
+
readonly FEATURE_NOT_CONFIGURED: "feature_not_configured";
|
|
221
|
+
readonly API_ERROR: "api_error";
|
|
222
|
+
readonly SERVER_ERROR: "server_error";
|
|
223
|
+
};
|
|
224
|
+
/** Shape of the error object returned by the cStar API. */
|
|
225
|
+
interface ApiErrorBody {
|
|
226
|
+
type: string;
|
|
227
|
+
code: string;
|
|
228
|
+
message: string;
|
|
229
|
+
param?: string;
|
|
230
|
+
doc_url: string;
|
|
231
|
+
request_id?: string;
|
|
232
|
+
feature?: string;
|
|
233
|
+
enable_url?: string;
|
|
234
|
+
}
|
|
235
|
+
/** Base error class for all cStar API errors. */
|
|
236
|
+
declare class CStarErrorImpl extends Error {
|
|
237
|
+
readonly type: string;
|
|
238
|
+
readonly code: string;
|
|
239
|
+
readonly param?: string;
|
|
240
|
+
readonly docUrl: string;
|
|
241
|
+
readonly requestId?: string;
|
|
242
|
+
readonly statusCode: number;
|
|
243
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
244
|
+
}
|
|
245
|
+
declare class CStarAuthenticationErrorImpl extends CStarErrorImpl {
|
|
246
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
247
|
+
}
|
|
248
|
+
declare class CStarRateLimitErrorImpl extends CStarErrorImpl {
|
|
249
|
+
readonly retryAfter: number;
|
|
250
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody, retryAfter?: number);
|
|
251
|
+
}
|
|
252
|
+
declare class CStarNotFoundErrorImpl extends CStarErrorImpl {
|
|
253
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
254
|
+
}
|
|
255
|
+
declare class CStarValidationErrorImpl extends CStarErrorImpl {
|
|
256
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
257
|
+
}
|
|
258
|
+
declare class CStarPermissionErrorImpl extends CStarErrorImpl {
|
|
259
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
260
|
+
}
|
|
261
|
+
declare class CStarConflictErrorImpl extends CStarErrorImpl {
|
|
262
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
263
|
+
}
|
|
264
|
+
declare class CStarServerErrorImpl extends CStarErrorImpl {
|
|
265
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
266
|
+
}
|
|
267
|
+
declare class CStarFeatureDisabledErrorImpl extends CStarErrorImpl {
|
|
268
|
+
readonly feature: string;
|
|
269
|
+
readonly enableUrl: string;
|
|
270
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
271
|
+
}
|
|
272
|
+
declare class CStarRealtimeUnavailableErrorImpl extends CStarErrorImpl {
|
|
273
|
+
constructor(message?: string);
|
|
274
|
+
}
|
|
275
|
+
declare const CStarError: typeof CStarErrorImpl;
|
|
276
|
+
type CStarError = InstanceType<typeof CStarErrorImpl>;
|
|
277
|
+
declare const CStarAuthenticationError: typeof CStarAuthenticationErrorImpl;
|
|
278
|
+
type CStarAuthenticationError = InstanceType<typeof CStarAuthenticationErrorImpl>;
|
|
279
|
+
declare const CStarRateLimitError: typeof CStarRateLimitErrorImpl;
|
|
280
|
+
type CStarRateLimitError = InstanceType<typeof CStarRateLimitErrorImpl>;
|
|
281
|
+
declare const CStarNotFoundError: typeof CStarNotFoundErrorImpl;
|
|
282
|
+
type CStarNotFoundError = InstanceType<typeof CStarNotFoundErrorImpl>;
|
|
283
|
+
declare const CStarValidationError: typeof CStarValidationErrorImpl;
|
|
284
|
+
type CStarValidationError = InstanceType<typeof CStarValidationErrorImpl>;
|
|
285
|
+
declare const CStarPermissionError: typeof CStarPermissionErrorImpl;
|
|
286
|
+
type CStarPermissionError = InstanceType<typeof CStarPermissionErrorImpl>;
|
|
287
|
+
declare const CStarConflictError: typeof CStarConflictErrorImpl;
|
|
288
|
+
type CStarConflictError = InstanceType<typeof CStarConflictErrorImpl>;
|
|
289
|
+
declare const CStarServerError: typeof CStarServerErrorImpl;
|
|
290
|
+
type CStarServerError = InstanceType<typeof CStarServerErrorImpl>;
|
|
291
|
+
declare const CStarFeatureDisabledError: typeof CStarFeatureDisabledErrorImpl;
|
|
292
|
+
type CStarFeatureDisabledError = InstanceType<typeof CStarFeatureDisabledErrorImpl>;
|
|
293
|
+
declare const CStarRealtimeUnavailableError: typeof CStarRealtimeUnavailableErrorImpl;
|
|
294
|
+
type CStarRealtimeUnavailableError = InstanceType<typeof CStarRealtimeUnavailableErrorImpl>;
|
|
295
|
+
/**
|
|
296
|
+
* Parse a public-route response (anonymous LibraryClient, CommunityClient,
|
|
297
|
+
* QuickHelpClient, AuthClient) into a typed `CStarError`.
|
|
298
|
+
*
|
|
299
|
+
* Public routes don't always emit the structured `{error: {type, code,
|
|
300
|
+
* doc_url, ...}}` envelope — many emit `{error: 'message string'}` or
|
|
301
|
+
* `{message: '...'}`. This helper normalizes both shapes and dispatches
|
|
302
|
+
* on HTTP status (closes F-026 and F-034 — Library/Auth used to throw
|
|
303
|
+
* plain `Error`).
|
|
304
|
+
*/
|
|
305
|
+
declare function parsePublicError(status: number, body: unknown, fallbackMessage: string): CStarError;
|
|
306
|
+
declare function parseError(statusCode: number, body: {
|
|
307
|
+
error?: ApiErrorBody;
|
|
308
|
+
} | null, retryAfter?: number): CStarError;
|
|
309
|
+
|
|
190
310
|
/**
|
|
191
311
|
* Public community client. No authentication required.
|
|
192
312
|
*
|
|
@@ -291,4 +411,4 @@ declare class CommunityClient {
|
|
|
291
411
|
private fetch;
|
|
292
412
|
}
|
|
293
413
|
|
|
294
|
-
export { CommunityClient, type CommunityComment, type CommunityConfig, type CommunityCreateCommentParams, type CommunityCreatePostParams, type CommunityCreatedComment, type CommunityCreatedPost, type CommunityFollowResult, type CommunityPost, type CommunityPostDetail, type CommunityPostListParams, type CommunitySearchResult, type CommunityTopic, type CommunityUpdateCommentParams, type CommunityUpdatePostParams, type CommunityVoteResult };
|
|
414
|
+
export { type ApiErrorBody, CStarAuthenticationError, CStarConflictError, CStarError, CStarFeatureDisabledError, CStarNotFoundError, CStarPermissionError, CStarRateLimitError, CStarRealtimeUnavailableError, CStarServerError, CStarValidationError, CommunityClient, type CommunityComment, type CommunityConfig, type CommunityCreateCommentParams, type CommunityCreatePostParams, type CommunityCreatedComment, type CommunityCreatedPost, type CommunityFollowResult, type CommunityPost, type CommunityPostDetail, type CommunityPostListParams, type CommunitySearchResult, type CommunityTopic, type CommunityUpdateCommentParams, type CommunityUpdatePostParams, type CommunityVoteResult, ErrorType, parseError, parsePublicError };
|
|
@@ -187,6 +187,126 @@ interface CommunityPostDetail {
|
|
|
187
187
|
comments: CommunityComment[];
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
+
/**
|
|
191
|
+
* Error classes for the cStar SDK.
|
|
192
|
+
*
|
|
193
|
+
* NEW-v3-01 — Cross-subpath instanceof identity.
|
|
194
|
+
*
|
|
195
|
+
* Each public subpath (`/library`, `/auth`, `/community`, `/quickhelp`, ...)
|
|
196
|
+
* is bundled as a separate tsup entry with `splitting: false`, so each one
|
|
197
|
+
* carries its own copy of this module. Without deduplication, errors thrown
|
|
198
|
+
* by `LibraryClient` carry the LibraryClient-bundled `CStarError` class —
|
|
199
|
+
* not the one a consumer imports from `@cstar.help/js`. That makes
|
|
200
|
+
* `instanceof CStarError` checks fail silently, invalidating every "did the
|
|
201
|
+
* SDK throw a typed cStar error?" branch in user code.
|
|
202
|
+
*
|
|
203
|
+
* Fix: register each class on a `Symbol.for(...)` slot of `globalThis`. The
|
|
204
|
+
* symbol is realm-shared, so every bundled copy of this module resolves to
|
|
205
|
+
* the SAME class identity at runtime — the first copy to load wins, and all
|
|
206
|
+
* subsequent copies surface the canonical class via the same slot. The
|
|
207
|
+
* inline `Impl` definitions are only used as the seed for the very first
|
|
208
|
+
* copy to register. Internal `parseError` / `parsePublicError` reference the
|
|
209
|
+
* EXPORTED canonical names so instances they construct also land on the
|
|
210
|
+
* canonical class.
|
|
211
|
+
*/
|
|
212
|
+
/** Error type constants matching the cStar API. */
|
|
213
|
+
declare const ErrorType: {
|
|
214
|
+
readonly AUTHENTICATION_ERROR: "authentication_error";
|
|
215
|
+
readonly PERMISSION_ERROR: "permission_error";
|
|
216
|
+
readonly INVALID_REQUEST_ERROR: "invalid_request_error";
|
|
217
|
+
readonly NOT_FOUND_ERROR: "not_found_error";
|
|
218
|
+
readonly CONFLICT_ERROR: "conflict_error";
|
|
219
|
+
readonly RATE_LIMIT_ERROR: "rate_limit_error";
|
|
220
|
+
readonly FEATURE_NOT_CONFIGURED: "feature_not_configured";
|
|
221
|
+
readonly API_ERROR: "api_error";
|
|
222
|
+
readonly SERVER_ERROR: "server_error";
|
|
223
|
+
};
|
|
224
|
+
/** Shape of the error object returned by the cStar API. */
|
|
225
|
+
interface ApiErrorBody {
|
|
226
|
+
type: string;
|
|
227
|
+
code: string;
|
|
228
|
+
message: string;
|
|
229
|
+
param?: string;
|
|
230
|
+
doc_url: string;
|
|
231
|
+
request_id?: string;
|
|
232
|
+
feature?: string;
|
|
233
|
+
enable_url?: string;
|
|
234
|
+
}
|
|
235
|
+
/** Base error class for all cStar API errors. */
|
|
236
|
+
declare class CStarErrorImpl extends Error {
|
|
237
|
+
readonly type: string;
|
|
238
|
+
readonly code: string;
|
|
239
|
+
readonly param?: string;
|
|
240
|
+
readonly docUrl: string;
|
|
241
|
+
readonly requestId?: string;
|
|
242
|
+
readonly statusCode: number;
|
|
243
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
244
|
+
}
|
|
245
|
+
declare class CStarAuthenticationErrorImpl extends CStarErrorImpl {
|
|
246
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
247
|
+
}
|
|
248
|
+
declare class CStarRateLimitErrorImpl extends CStarErrorImpl {
|
|
249
|
+
readonly retryAfter: number;
|
|
250
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody, retryAfter?: number);
|
|
251
|
+
}
|
|
252
|
+
declare class CStarNotFoundErrorImpl extends CStarErrorImpl {
|
|
253
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
254
|
+
}
|
|
255
|
+
declare class CStarValidationErrorImpl extends CStarErrorImpl {
|
|
256
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
257
|
+
}
|
|
258
|
+
declare class CStarPermissionErrorImpl extends CStarErrorImpl {
|
|
259
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
260
|
+
}
|
|
261
|
+
declare class CStarConflictErrorImpl extends CStarErrorImpl {
|
|
262
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
263
|
+
}
|
|
264
|
+
declare class CStarServerErrorImpl extends CStarErrorImpl {
|
|
265
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
266
|
+
}
|
|
267
|
+
declare class CStarFeatureDisabledErrorImpl extends CStarErrorImpl {
|
|
268
|
+
readonly feature: string;
|
|
269
|
+
readonly enableUrl: string;
|
|
270
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
271
|
+
}
|
|
272
|
+
declare class CStarRealtimeUnavailableErrorImpl extends CStarErrorImpl {
|
|
273
|
+
constructor(message?: string);
|
|
274
|
+
}
|
|
275
|
+
declare const CStarError: typeof CStarErrorImpl;
|
|
276
|
+
type CStarError = InstanceType<typeof CStarErrorImpl>;
|
|
277
|
+
declare const CStarAuthenticationError: typeof CStarAuthenticationErrorImpl;
|
|
278
|
+
type CStarAuthenticationError = InstanceType<typeof CStarAuthenticationErrorImpl>;
|
|
279
|
+
declare const CStarRateLimitError: typeof CStarRateLimitErrorImpl;
|
|
280
|
+
type CStarRateLimitError = InstanceType<typeof CStarRateLimitErrorImpl>;
|
|
281
|
+
declare const CStarNotFoundError: typeof CStarNotFoundErrorImpl;
|
|
282
|
+
type CStarNotFoundError = InstanceType<typeof CStarNotFoundErrorImpl>;
|
|
283
|
+
declare const CStarValidationError: typeof CStarValidationErrorImpl;
|
|
284
|
+
type CStarValidationError = InstanceType<typeof CStarValidationErrorImpl>;
|
|
285
|
+
declare const CStarPermissionError: typeof CStarPermissionErrorImpl;
|
|
286
|
+
type CStarPermissionError = InstanceType<typeof CStarPermissionErrorImpl>;
|
|
287
|
+
declare const CStarConflictError: typeof CStarConflictErrorImpl;
|
|
288
|
+
type CStarConflictError = InstanceType<typeof CStarConflictErrorImpl>;
|
|
289
|
+
declare const CStarServerError: typeof CStarServerErrorImpl;
|
|
290
|
+
type CStarServerError = InstanceType<typeof CStarServerErrorImpl>;
|
|
291
|
+
declare const CStarFeatureDisabledError: typeof CStarFeatureDisabledErrorImpl;
|
|
292
|
+
type CStarFeatureDisabledError = InstanceType<typeof CStarFeatureDisabledErrorImpl>;
|
|
293
|
+
declare const CStarRealtimeUnavailableError: typeof CStarRealtimeUnavailableErrorImpl;
|
|
294
|
+
type CStarRealtimeUnavailableError = InstanceType<typeof CStarRealtimeUnavailableErrorImpl>;
|
|
295
|
+
/**
|
|
296
|
+
* Parse a public-route response (anonymous LibraryClient, CommunityClient,
|
|
297
|
+
* QuickHelpClient, AuthClient) into a typed `CStarError`.
|
|
298
|
+
*
|
|
299
|
+
* Public routes don't always emit the structured `{error: {type, code,
|
|
300
|
+
* doc_url, ...}}` envelope — many emit `{error: 'message string'}` or
|
|
301
|
+
* `{message: '...'}`. This helper normalizes both shapes and dispatches
|
|
302
|
+
* on HTTP status (closes F-026 and F-034 — Library/Auth used to throw
|
|
303
|
+
* plain `Error`).
|
|
304
|
+
*/
|
|
305
|
+
declare function parsePublicError(status: number, body: unknown, fallbackMessage: string): CStarError;
|
|
306
|
+
declare function parseError(statusCode: number, body: {
|
|
307
|
+
error?: ApiErrorBody;
|
|
308
|
+
} | null, retryAfter?: number): CStarError;
|
|
309
|
+
|
|
190
310
|
/**
|
|
191
311
|
* Public community client. No authentication required.
|
|
192
312
|
*
|
|
@@ -291,4 +411,4 @@ declare class CommunityClient {
|
|
|
291
411
|
private fetch;
|
|
292
412
|
}
|
|
293
413
|
|
|
294
|
-
export { CommunityClient, type CommunityComment, type CommunityConfig, type CommunityCreateCommentParams, type CommunityCreatePostParams, type CommunityCreatedComment, type CommunityCreatedPost, type CommunityFollowResult, type CommunityPost, type CommunityPostDetail, type CommunityPostListParams, type CommunitySearchResult, type CommunityTopic, type CommunityUpdateCommentParams, type CommunityUpdatePostParams, type CommunityVoteResult };
|
|
414
|
+
export { type ApiErrorBody, CStarAuthenticationError, CStarConflictError, CStarError, CStarFeatureDisabledError, CStarNotFoundError, CStarPermissionError, CStarRateLimitError, CStarRealtimeUnavailableError, CStarServerError, CStarValidationError, CommunityClient, type CommunityComment, type CommunityConfig, type CommunityCreateCommentParams, type CommunityCreatePostParams, type CommunityCreatedComment, type CommunityCreatedPost, type CommunityFollowResult, type CommunityPost, type CommunityPostDetail, type CommunityPostListParams, type CommunitySearchResult, type CommunityTopic, type CommunityUpdateCommentParams, type CommunityUpdatePostParams, type CommunityVoteResult, ErrorType, parseError, parsePublicError };
|