@cstar.help/js 0.13.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 +64 -7
- package/dist/chat/index.d.cts +48 -4
- package/dist/chat/index.d.ts +48 -4
- package/dist/chat/index.js +64 -7
- 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 +75 -11
- package/dist/index.d.cts +86 -26
- package/dist/index.d.ts +86 -26
- package/dist/index.js +75 -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 +179 -17
- package/dist/quickhelp/index.d.cts +147 -5
- package/dist/quickhelp/index.d.ts +147 -5
- package/dist/quickhelp/index.js +165 -16
- 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/quickhelp/index.cjs
CHANGED
|
@@ -20,8 +20,21 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/quickhelp/index.ts
|
|
21
21
|
var quickhelp_exports = {};
|
|
22
22
|
__export(quickhelp_exports, {
|
|
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
|
+
ErrorType: () => ErrorType,
|
|
23
34
|
QuickHelpClient: () => QuickHelpClient,
|
|
24
|
-
QuickHelpError: () => QuickHelpError
|
|
35
|
+
QuickHelpError: () => QuickHelpError,
|
|
36
|
+
parseError: () => parseError,
|
|
37
|
+
parsePublicError: () => parsePublicError
|
|
25
38
|
});
|
|
26
39
|
module.exports = __toCommonJS(quickhelp_exports);
|
|
27
40
|
|
|
@@ -62,7 +75,7 @@ function normalizeArgs(messageOrStatus, maybeBody, defaults) {
|
|
|
62
75
|
}
|
|
63
76
|
};
|
|
64
77
|
}
|
|
65
|
-
var
|
|
78
|
+
var CStarErrorImpl = class extends Error {
|
|
66
79
|
constructor(messageOrStatus, body) {
|
|
67
80
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body);
|
|
68
81
|
super(resolved.message);
|
|
@@ -75,7 +88,7 @@ var CStarError = class extends Error {
|
|
|
75
88
|
this.statusCode = statusCode;
|
|
76
89
|
}
|
|
77
90
|
};
|
|
78
|
-
var
|
|
91
|
+
var CStarAuthenticationErrorImpl = class extends CStarErrorImpl {
|
|
79
92
|
constructor(messageOrStatus, body) {
|
|
80
93
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
81
94
|
type: ErrorType.AUTHENTICATION_ERROR,
|
|
@@ -86,7 +99,7 @@ var CStarAuthenticationError = class extends CStarError {
|
|
|
86
99
|
this.name = "CStarAuthenticationError";
|
|
87
100
|
}
|
|
88
101
|
};
|
|
89
|
-
var
|
|
102
|
+
var CStarRateLimitErrorImpl = class extends CStarErrorImpl {
|
|
90
103
|
constructor(messageOrStatus, body, retryAfter) {
|
|
91
104
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
92
105
|
type: ErrorType.RATE_LIMIT_ERROR,
|
|
@@ -98,7 +111,7 @@ var CStarRateLimitError = class extends CStarError {
|
|
|
98
111
|
this.retryAfter = retryAfter ?? 60;
|
|
99
112
|
}
|
|
100
113
|
};
|
|
101
|
-
var
|
|
114
|
+
var CStarNotFoundErrorImpl = class extends CStarErrorImpl {
|
|
102
115
|
constructor(messageOrStatus, body) {
|
|
103
116
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
104
117
|
type: ErrorType.NOT_FOUND_ERROR,
|
|
@@ -109,7 +122,7 @@ var CStarNotFoundError = class extends CStarError {
|
|
|
109
122
|
this.name = "CStarNotFoundError";
|
|
110
123
|
}
|
|
111
124
|
};
|
|
112
|
-
var
|
|
125
|
+
var CStarValidationErrorImpl = class extends CStarErrorImpl {
|
|
113
126
|
constructor(messageOrStatus, body) {
|
|
114
127
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
115
128
|
type: ErrorType.INVALID_REQUEST_ERROR,
|
|
@@ -120,7 +133,7 @@ var CStarValidationError = class extends CStarError {
|
|
|
120
133
|
this.name = "CStarValidationError";
|
|
121
134
|
}
|
|
122
135
|
};
|
|
123
|
-
var
|
|
136
|
+
var CStarPermissionErrorImpl = class extends CStarErrorImpl {
|
|
124
137
|
constructor(messageOrStatus, body) {
|
|
125
138
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
126
139
|
type: ErrorType.PERMISSION_ERROR,
|
|
@@ -131,7 +144,7 @@ var CStarPermissionError = class extends CStarError {
|
|
|
131
144
|
this.name = "CStarPermissionError";
|
|
132
145
|
}
|
|
133
146
|
};
|
|
134
|
-
var
|
|
147
|
+
var CStarConflictErrorImpl = class extends CStarErrorImpl {
|
|
135
148
|
constructor(messageOrStatus, body) {
|
|
136
149
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
137
150
|
type: ErrorType.CONFLICT_ERROR,
|
|
@@ -142,7 +155,7 @@ var CStarConflictError = class extends CStarError {
|
|
|
142
155
|
this.name = "CStarConflictError";
|
|
143
156
|
}
|
|
144
157
|
};
|
|
145
|
-
var
|
|
158
|
+
var CStarServerErrorImpl = class extends CStarErrorImpl {
|
|
146
159
|
constructor(messageOrStatus, body) {
|
|
147
160
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
148
161
|
type: ErrorType.SERVER_ERROR,
|
|
@@ -153,7 +166,7 @@ var CStarServerError = class extends CStarError {
|
|
|
153
166
|
this.name = "CStarServerError";
|
|
154
167
|
}
|
|
155
168
|
};
|
|
156
|
-
var
|
|
169
|
+
var CStarFeatureDisabledErrorImpl = class extends CStarErrorImpl {
|
|
157
170
|
constructor(messageOrStatus, body) {
|
|
158
171
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
159
172
|
type: ErrorType.FEATURE_NOT_CONFIGURED,
|
|
@@ -166,6 +179,82 @@ var CStarFeatureDisabledError = class extends CStarError {
|
|
|
166
179
|
this.enableUrl = resolved.enable_url ?? "";
|
|
167
180
|
}
|
|
168
181
|
};
|
|
182
|
+
var CStarRealtimeUnavailableErrorImpl = class extends CStarErrorImpl {
|
|
183
|
+
constructor(message) {
|
|
184
|
+
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";
|
|
185
|
+
super(0, {
|
|
186
|
+
type: ErrorType.API_ERROR,
|
|
187
|
+
code: "realtime_unavailable",
|
|
188
|
+
message: resolved,
|
|
189
|
+
doc_url: "https://cstar.help/developers/sdk/realtime#ssr"
|
|
190
|
+
});
|
|
191
|
+
this.name = "CStarRealtimeUnavailableError";
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
var REGISTRY_KEY = /* @__PURE__ */ Symbol.for("@cstar.help/js/errors/v1");
|
|
195
|
+
var globalSlot = globalThis;
|
|
196
|
+
var registry = globalSlot[REGISTRY_KEY] ?? (globalSlot[REGISTRY_KEY] = {
|
|
197
|
+
CStarError: CStarErrorImpl,
|
|
198
|
+
CStarAuthenticationError: CStarAuthenticationErrorImpl,
|
|
199
|
+
CStarRateLimitError: CStarRateLimitErrorImpl,
|
|
200
|
+
CStarNotFoundError: CStarNotFoundErrorImpl,
|
|
201
|
+
CStarValidationError: CStarValidationErrorImpl,
|
|
202
|
+
CStarPermissionError: CStarPermissionErrorImpl,
|
|
203
|
+
CStarConflictError: CStarConflictErrorImpl,
|
|
204
|
+
CStarServerError: CStarServerErrorImpl,
|
|
205
|
+
CStarFeatureDisabledError: CStarFeatureDisabledErrorImpl,
|
|
206
|
+
CStarRealtimeUnavailableError: CStarRealtimeUnavailableErrorImpl
|
|
207
|
+
});
|
|
208
|
+
var CStarError = registry.CStarError;
|
|
209
|
+
var CStarAuthenticationError = registry.CStarAuthenticationError;
|
|
210
|
+
var CStarRateLimitError = registry.CStarRateLimitError;
|
|
211
|
+
var CStarNotFoundError = registry.CStarNotFoundError;
|
|
212
|
+
var CStarValidationError = registry.CStarValidationError;
|
|
213
|
+
var CStarPermissionError = registry.CStarPermissionError;
|
|
214
|
+
var CStarConflictError = registry.CStarConflictError;
|
|
215
|
+
var CStarServerError = registry.CStarServerError;
|
|
216
|
+
var CStarFeatureDisabledError = registry.CStarFeatureDisabledError;
|
|
217
|
+
var CStarRealtimeUnavailableError = registry.CStarRealtimeUnavailableError;
|
|
218
|
+
function parsePublicError(status, body, fallbackMessage) {
|
|
219
|
+
const obj = body && typeof body === "object" ? body : null;
|
|
220
|
+
const errVal = obj?.error;
|
|
221
|
+
let message = fallbackMessage;
|
|
222
|
+
let structured = null;
|
|
223
|
+
if (typeof errVal === "string") {
|
|
224
|
+
message = errVal;
|
|
225
|
+
} else if (errVal && typeof errVal === "object") {
|
|
226
|
+
const e = errVal;
|
|
227
|
+
if (typeof e.message === "string") message = e.message;
|
|
228
|
+
structured = {
|
|
229
|
+
type: typeof e.type === "string" ? e.type : ErrorType.API_ERROR,
|
|
230
|
+
code: typeof e.code === "string" ? e.code : "api_error",
|
|
231
|
+
message,
|
|
232
|
+
param: typeof e.param === "string" ? e.param : void 0,
|
|
233
|
+
doc_url: typeof e.doc_url === "string" ? e.doc_url : DEFAULT_DOC_URL,
|
|
234
|
+
request_id: typeof e.request_id === "string" ? e.request_id : void 0,
|
|
235
|
+
feature: typeof e.feature === "string" ? e.feature : void 0,
|
|
236
|
+
enable_url: typeof e.enable_url === "string" ? e.enable_url : void 0
|
|
237
|
+
};
|
|
238
|
+
} else if (typeof obj?.message === "string") {
|
|
239
|
+
message = obj.message;
|
|
240
|
+
}
|
|
241
|
+
const errorBody = structured ?? {
|
|
242
|
+
type: ErrorType.API_ERROR,
|
|
243
|
+
code: status >= 500 ? "server_error" : "request_failed",
|
|
244
|
+
message,
|
|
245
|
+
doc_url: DEFAULT_DOC_URL
|
|
246
|
+
};
|
|
247
|
+
return parseError(status, { error: errorBody });
|
|
248
|
+
}
|
|
249
|
+
var STATUS_TO_CLASS = {
|
|
250
|
+
400: CStarValidationError,
|
|
251
|
+
401: CStarAuthenticationError,
|
|
252
|
+
403: CStarPermissionError,
|
|
253
|
+
404: CStarNotFoundError,
|
|
254
|
+
409: CStarConflictError,
|
|
255
|
+
422: CStarValidationError,
|
|
256
|
+
429: CStarRateLimitError
|
|
257
|
+
};
|
|
169
258
|
var TYPE_TO_CLASS = {
|
|
170
259
|
[ErrorType.AUTHENTICATION_ERROR]: CStarAuthenticationError,
|
|
171
260
|
[ErrorType.PERMISSION_ERROR]: CStarPermissionError,
|
|
@@ -176,16 +265,41 @@ var TYPE_TO_CLASS = {
|
|
|
176
265
|
[ErrorType.SERVER_ERROR]: CStarServerError,
|
|
177
266
|
[ErrorType.FEATURE_NOT_CONFIGURED]: CStarFeatureDisabledError
|
|
178
267
|
};
|
|
268
|
+
function parseError(statusCode, body, retryAfter) {
|
|
269
|
+
const errorBody = body?.error ?? {
|
|
270
|
+
type: ErrorType.API_ERROR,
|
|
271
|
+
code: "unknown_error",
|
|
272
|
+
message: `Request failed with status ${statusCode}`,
|
|
273
|
+
doc_url: DEFAULT_DOC_URL
|
|
274
|
+
};
|
|
275
|
+
if (statusCode === 429) {
|
|
276
|
+
return new CStarRateLimitError(statusCode, errorBody, retryAfter ?? 60);
|
|
277
|
+
}
|
|
278
|
+
const StatusCls = STATUS_TO_CLASS[statusCode];
|
|
279
|
+
if (StatusCls) {
|
|
280
|
+
return new StatusCls(statusCode, errorBody);
|
|
281
|
+
}
|
|
282
|
+
const TypeCls = TYPE_TO_CLASS[errorBody.type];
|
|
283
|
+
if (TypeCls) {
|
|
284
|
+
return new TypeCls(statusCode, errorBody);
|
|
285
|
+
}
|
|
286
|
+
if (statusCode >= 500) return new CStarServerError(statusCode, errorBody);
|
|
287
|
+
return new CStarError(statusCode, errorBody);
|
|
288
|
+
}
|
|
179
289
|
|
|
180
290
|
// src/quickhelp/index.ts
|
|
181
291
|
var DEFAULT_BASE_URL = "https://www.cstar.help";
|
|
182
292
|
var QuickHelpClient = class {
|
|
183
293
|
constructor(config) {
|
|
184
|
-
|
|
185
|
-
|
|
294
|
+
this.resolveTeamIdPromise = null;
|
|
295
|
+
if (!config?.teamId && !config?.teamSlug) {
|
|
296
|
+
throw new Error(
|
|
297
|
+
'QuickHelpClient: either `teamId` or `teamSlug` is required. Pass `teamSlug` (e.g. "acme") for the easiest setup.'
|
|
298
|
+
);
|
|
186
299
|
}
|
|
187
300
|
this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
188
|
-
this.teamId = config.teamId;
|
|
301
|
+
this.teamId = config.teamId ?? null;
|
|
302
|
+
this.teamSlug = config.teamSlug ?? null;
|
|
189
303
|
this.publishableKey = config.publishableKey ?? null;
|
|
190
304
|
this.mode = this.publishableKey?.startsWith("pk_test_") ? "test" : "live";
|
|
191
305
|
if (this.publishableKey && !/^pk_(test|live)_/.test(this.publishableKey)) {
|
|
@@ -197,6 +311,39 @@ var QuickHelpClient = class {
|
|
|
197
311
|
authHeaders() {
|
|
198
312
|
return this.publishableKey ? { Authorization: `Bearer ${this.publishableKey}` } : {};
|
|
199
313
|
}
|
|
314
|
+
/**
|
|
315
|
+
* Resolve `teamSlug` → `teamId` lazily on the first call that needs it.
|
|
316
|
+
* Cached for the life of the client. NEW-v2-05.
|
|
317
|
+
*/
|
|
318
|
+
async resolveTeamId() {
|
|
319
|
+
if (this.teamId) return this.teamId;
|
|
320
|
+
if (!this.teamSlug) throw new Error("QuickHelpClient: no teamId or teamSlug set");
|
|
321
|
+
if (this.resolveTeamIdPromise) return this.resolveTeamIdPromise;
|
|
322
|
+
this.resolveTeamIdPromise = (async () => {
|
|
323
|
+
const url = `${this.baseUrl}/api/widget/team-by-slug?teamSlug=${encodeURIComponent(this.teamSlug)}`;
|
|
324
|
+
const res = await globalThis.fetch(url, { method: "GET", headers: this.authHeaders() });
|
|
325
|
+
if (!res.ok) {
|
|
326
|
+
throw new Error(
|
|
327
|
+
`QuickHelpClient: could not resolve teamSlug "${this.teamSlug}" (HTTP ${res.status}).`
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
const body = await res.json();
|
|
331
|
+
const id = body?.data?.teamId;
|
|
332
|
+
if (!id) {
|
|
333
|
+
throw new Error(
|
|
334
|
+
`QuickHelpClient: lookup for teamSlug "${this.teamSlug}" returned no teamId.`
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
this.teamId = id;
|
|
338
|
+
return id;
|
|
339
|
+
})();
|
|
340
|
+
try {
|
|
341
|
+
return await this.resolveTeamIdPromise;
|
|
342
|
+
} catch (err) {
|
|
343
|
+
this.resolveTeamIdPromise = null;
|
|
344
|
+
throw err;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
200
347
|
/**
|
|
201
348
|
* Fetch the sanitized public config (title, subtitle, placeholder,
|
|
202
349
|
* theme overrides). Never includes agent id or escalation contact
|
|
@@ -205,7 +352,8 @@ var QuickHelpClient = class {
|
|
|
205
352
|
* Returns `null` if Quick Help is disabled on the team (404).
|
|
206
353
|
*/
|
|
207
354
|
async config() {
|
|
208
|
-
const
|
|
355
|
+
const teamId = await this.resolveTeamId();
|
|
356
|
+
const url = `${this.baseUrl}/api/quickhelp/config/${encodeURIComponent(teamId)}`;
|
|
209
357
|
const res = await globalThis.fetch(url, { method: "GET", headers: this.authHeaders() });
|
|
210
358
|
if (res.status === 404) return null;
|
|
211
359
|
if (!res.ok) {
|
|
@@ -222,12 +370,13 @@ var QuickHelpClient = class {
|
|
|
222
370
|
* property set from the response body.
|
|
223
371
|
*/
|
|
224
372
|
async ask(params) {
|
|
373
|
+
const teamId = await this.resolveTeamId();
|
|
225
374
|
const url = `${this.baseUrl}/api/quickhelp/ask`;
|
|
226
375
|
const res = await globalThis.fetch(url, {
|
|
227
376
|
method: "POST",
|
|
228
377
|
headers: { "Content-Type": "application/json", ...this.authHeaders() },
|
|
229
378
|
body: JSON.stringify({
|
|
230
|
-
team_id:
|
|
379
|
+
team_id: teamId,
|
|
231
380
|
session_id: params.sessionId ?? null,
|
|
232
381
|
question: params.question
|
|
233
382
|
})
|
|
@@ -241,7 +390,7 @@ var QuickHelpClient = class {
|
|
|
241
390
|
message: body?.error?.message ?? "Quick Help is not available on this team. Enable an AI Agent (Settings \u2192 AI Agents) and configure Quick Help (Settings \u2192 Quick Help) before calling .ask().",
|
|
242
391
|
doc_url: "https://cstar.help/developers/api/errors#feature-not-configured",
|
|
243
392
|
feature: "quickHelp",
|
|
244
|
-
enable_url: `${this.baseUrl}/team/${encodeURIComponent(
|
|
393
|
+
enable_url: `${this.baseUrl}/team/${encodeURIComponent(teamId)}/settings?section=quickHelp`
|
|
245
394
|
});
|
|
246
395
|
}
|
|
247
396
|
const message = body?.error?.message ?? `Quick Help ask failed: ${res.status}`;
|
|
@@ -271,6 +420,19 @@ function parseRetryAfter(header) {
|
|
|
271
420
|
}
|
|
272
421
|
// Annotate the CommonJS export names for ESM import in node:
|
|
273
422
|
0 && (module.exports = {
|
|
423
|
+
CStarAuthenticationError,
|
|
424
|
+
CStarConflictError,
|
|
425
|
+
CStarError,
|
|
426
|
+
CStarFeatureDisabledError,
|
|
427
|
+
CStarNotFoundError,
|
|
428
|
+
CStarPermissionError,
|
|
429
|
+
CStarRateLimitError,
|
|
430
|
+
CStarRealtimeUnavailableError,
|
|
431
|
+
CStarServerError,
|
|
432
|
+
CStarValidationError,
|
|
433
|
+
ErrorType,
|
|
274
434
|
QuickHelpClient,
|
|
275
|
-
QuickHelpError
|
|
435
|
+
QuickHelpError,
|
|
436
|
+
parseError,
|
|
437
|
+
parsePublicError
|
|
276
438
|
});
|
|
@@ -1,7 +1,21 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Options for the QuickHelpClient. No auth — Quick Help is anonymous by
|
|
3
|
+
* design.
|
|
4
|
+
*
|
|
5
|
+
* NEW-v2-05: pass either `teamId` (UUID, fastest — no roundtrip) or the
|
|
6
|
+
* easier-to-discover `teamSlug`. The slug is resolved to a UUID on the
|
|
7
|
+
* first network call and cached for the life of the client. At least one
|
|
8
|
+
* is required.
|
|
9
|
+
*/
|
|
2
10
|
interface QuickHelpConfig {
|
|
3
|
-
/** Your team's UUID.
|
|
4
|
-
teamId
|
|
11
|
+
/** Your team's UUID. Either this or `teamSlug` is required. */
|
|
12
|
+
teamId?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Your team's slug (e.g. `acme`). Resolved to `teamId` lazily via the
|
|
15
|
+
* public `/api/widget/team-by-slug` endpoint on the first call. Cached
|
|
16
|
+
* thereafter. Either this or `teamId` is required.
|
|
17
|
+
*/
|
|
18
|
+
teamSlug?: string;
|
|
5
19
|
/**
|
|
6
20
|
* Optional publishable key (`pk_test_*` or `pk_live_*`). Sent as
|
|
7
21
|
* `Authorization: Bearer` so test-mode dev sessions can be scoped
|
|
@@ -41,6 +55,126 @@ interface QuickHelpAskResult {
|
|
|
41
55
|
turnNumber: number;
|
|
42
56
|
}
|
|
43
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Error classes for the cStar SDK.
|
|
60
|
+
*
|
|
61
|
+
* NEW-v3-01 — Cross-subpath instanceof identity.
|
|
62
|
+
*
|
|
63
|
+
* Each public subpath (`/library`, `/auth`, `/community`, `/quickhelp`, ...)
|
|
64
|
+
* is bundled as a separate tsup entry with `splitting: false`, so each one
|
|
65
|
+
* carries its own copy of this module. Without deduplication, errors thrown
|
|
66
|
+
* by `LibraryClient` carry the LibraryClient-bundled `CStarError` class —
|
|
67
|
+
* not the one a consumer imports from `@cstar.help/js`. That makes
|
|
68
|
+
* `instanceof CStarError` checks fail silently, invalidating every "did the
|
|
69
|
+
* SDK throw a typed cStar error?" branch in user code.
|
|
70
|
+
*
|
|
71
|
+
* Fix: register each class on a `Symbol.for(...)` slot of `globalThis`. The
|
|
72
|
+
* symbol is realm-shared, so every bundled copy of this module resolves to
|
|
73
|
+
* the SAME class identity at runtime — the first copy to load wins, and all
|
|
74
|
+
* subsequent copies surface the canonical class via the same slot. The
|
|
75
|
+
* inline `Impl` definitions are only used as the seed for the very first
|
|
76
|
+
* copy to register. Internal `parseError` / `parsePublicError` reference the
|
|
77
|
+
* EXPORTED canonical names so instances they construct also land on the
|
|
78
|
+
* canonical class.
|
|
79
|
+
*/
|
|
80
|
+
/** Error type constants matching the cStar API. */
|
|
81
|
+
declare const ErrorType: {
|
|
82
|
+
readonly AUTHENTICATION_ERROR: "authentication_error";
|
|
83
|
+
readonly PERMISSION_ERROR: "permission_error";
|
|
84
|
+
readonly INVALID_REQUEST_ERROR: "invalid_request_error";
|
|
85
|
+
readonly NOT_FOUND_ERROR: "not_found_error";
|
|
86
|
+
readonly CONFLICT_ERROR: "conflict_error";
|
|
87
|
+
readonly RATE_LIMIT_ERROR: "rate_limit_error";
|
|
88
|
+
readonly FEATURE_NOT_CONFIGURED: "feature_not_configured";
|
|
89
|
+
readonly API_ERROR: "api_error";
|
|
90
|
+
readonly SERVER_ERROR: "server_error";
|
|
91
|
+
};
|
|
92
|
+
/** Shape of the error object returned by the cStar API. */
|
|
93
|
+
interface ApiErrorBody {
|
|
94
|
+
type: string;
|
|
95
|
+
code: string;
|
|
96
|
+
message: string;
|
|
97
|
+
param?: string;
|
|
98
|
+
doc_url: string;
|
|
99
|
+
request_id?: string;
|
|
100
|
+
feature?: string;
|
|
101
|
+
enable_url?: string;
|
|
102
|
+
}
|
|
103
|
+
/** Base error class for all cStar API errors. */
|
|
104
|
+
declare class CStarErrorImpl extends Error {
|
|
105
|
+
readonly type: string;
|
|
106
|
+
readonly code: string;
|
|
107
|
+
readonly param?: string;
|
|
108
|
+
readonly docUrl: string;
|
|
109
|
+
readonly requestId?: string;
|
|
110
|
+
readonly statusCode: number;
|
|
111
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
112
|
+
}
|
|
113
|
+
declare class CStarAuthenticationErrorImpl extends CStarErrorImpl {
|
|
114
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
115
|
+
}
|
|
116
|
+
declare class CStarRateLimitErrorImpl extends CStarErrorImpl {
|
|
117
|
+
readonly retryAfter: number;
|
|
118
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody, retryAfter?: number);
|
|
119
|
+
}
|
|
120
|
+
declare class CStarNotFoundErrorImpl extends CStarErrorImpl {
|
|
121
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
122
|
+
}
|
|
123
|
+
declare class CStarValidationErrorImpl extends CStarErrorImpl {
|
|
124
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
125
|
+
}
|
|
126
|
+
declare class CStarPermissionErrorImpl extends CStarErrorImpl {
|
|
127
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
128
|
+
}
|
|
129
|
+
declare class CStarConflictErrorImpl extends CStarErrorImpl {
|
|
130
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
131
|
+
}
|
|
132
|
+
declare class CStarServerErrorImpl extends CStarErrorImpl {
|
|
133
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
134
|
+
}
|
|
135
|
+
declare class CStarFeatureDisabledErrorImpl extends CStarErrorImpl {
|
|
136
|
+
readonly feature: string;
|
|
137
|
+
readonly enableUrl: string;
|
|
138
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
139
|
+
}
|
|
140
|
+
declare class CStarRealtimeUnavailableErrorImpl extends CStarErrorImpl {
|
|
141
|
+
constructor(message?: string);
|
|
142
|
+
}
|
|
143
|
+
declare const CStarError: typeof CStarErrorImpl;
|
|
144
|
+
type CStarError = InstanceType<typeof CStarErrorImpl>;
|
|
145
|
+
declare const CStarAuthenticationError: typeof CStarAuthenticationErrorImpl;
|
|
146
|
+
type CStarAuthenticationError = InstanceType<typeof CStarAuthenticationErrorImpl>;
|
|
147
|
+
declare const CStarRateLimitError: typeof CStarRateLimitErrorImpl;
|
|
148
|
+
type CStarRateLimitError = InstanceType<typeof CStarRateLimitErrorImpl>;
|
|
149
|
+
declare const CStarNotFoundError: typeof CStarNotFoundErrorImpl;
|
|
150
|
+
type CStarNotFoundError = InstanceType<typeof CStarNotFoundErrorImpl>;
|
|
151
|
+
declare const CStarValidationError: typeof CStarValidationErrorImpl;
|
|
152
|
+
type CStarValidationError = InstanceType<typeof CStarValidationErrorImpl>;
|
|
153
|
+
declare const CStarPermissionError: typeof CStarPermissionErrorImpl;
|
|
154
|
+
type CStarPermissionError = InstanceType<typeof CStarPermissionErrorImpl>;
|
|
155
|
+
declare const CStarConflictError: typeof CStarConflictErrorImpl;
|
|
156
|
+
type CStarConflictError = InstanceType<typeof CStarConflictErrorImpl>;
|
|
157
|
+
declare const CStarServerError: typeof CStarServerErrorImpl;
|
|
158
|
+
type CStarServerError = InstanceType<typeof CStarServerErrorImpl>;
|
|
159
|
+
declare const CStarFeatureDisabledError: typeof CStarFeatureDisabledErrorImpl;
|
|
160
|
+
type CStarFeatureDisabledError = InstanceType<typeof CStarFeatureDisabledErrorImpl>;
|
|
161
|
+
declare const CStarRealtimeUnavailableError: typeof CStarRealtimeUnavailableErrorImpl;
|
|
162
|
+
type CStarRealtimeUnavailableError = InstanceType<typeof CStarRealtimeUnavailableErrorImpl>;
|
|
163
|
+
/**
|
|
164
|
+
* Parse a public-route response (anonymous LibraryClient, CommunityClient,
|
|
165
|
+
* QuickHelpClient, AuthClient) into a typed `CStarError`.
|
|
166
|
+
*
|
|
167
|
+
* Public routes don't always emit the structured `{error: {type, code,
|
|
168
|
+
* doc_url, ...}}` envelope — many emit `{error: 'message string'}` or
|
|
169
|
+
* `{message: '...'}`. This helper normalizes both shapes and dispatches
|
|
170
|
+
* on HTTP status (closes F-026 and F-034 — Library/Auth used to throw
|
|
171
|
+
* plain `Error`).
|
|
172
|
+
*/
|
|
173
|
+
declare function parsePublicError(status: number, body: unknown, fallbackMessage: string): CStarError;
|
|
174
|
+
declare function parseError(statusCode: number, body: {
|
|
175
|
+
error?: ApiErrorBody;
|
|
176
|
+
} | null, retryAfter?: number): CStarError;
|
|
177
|
+
|
|
44
178
|
/**
|
|
45
179
|
* Quick Help — anonymous AI Q&A client.
|
|
46
180
|
*
|
|
@@ -67,12 +201,20 @@ interface QuickHelpAskResult {
|
|
|
67
201
|
*/
|
|
68
202
|
declare class QuickHelpClient {
|
|
69
203
|
private readonly baseUrl;
|
|
70
|
-
|
|
204
|
+
/** Cached resolved teamId. `null` until the first lookup completes. */
|
|
205
|
+
private teamId;
|
|
206
|
+
private readonly teamSlug;
|
|
207
|
+
private resolveTeamIdPromise;
|
|
71
208
|
private readonly publishableKey;
|
|
72
209
|
/** Resolved mode based on the publishable-key prefix. */
|
|
73
210
|
readonly mode: 'live' | 'test';
|
|
74
211
|
constructor(config: QuickHelpConfig);
|
|
75
212
|
private authHeaders;
|
|
213
|
+
/**
|
|
214
|
+
* Resolve `teamSlug` → `teamId` lazily on the first call that needs it.
|
|
215
|
+
* Cached for the life of the client. NEW-v2-05.
|
|
216
|
+
*/
|
|
217
|
+
private resolveTeamId;
|
|
76
218
|
/**
|
|
77
219
|
* Fetch the sanitized public config (title, subtitle, placeholder,
|
|
78
220
|
* theme overrides). Never includes agent id or escalation contact
|
|
@@ -105,4 +247,4 @@ declare class QuickHelpError extends Error {
|
|
|
105
247
|
});
|
|
106
248
|
}
|
|
107
249
|
|
|
108
|
-
export { type QuickHelpAskParams, type QuickHelpAskResult, QuickHelpClient, type QuickHelpConfig, QuickHelpError, type QuickHelpPublicConfig, type QuickHelpTurnOutcome };
|
|
250
|
+
export { type ApiErrorBody, CStarAuthenticationError, CStarConflictError, CStarError, CStarFeatureDisabledError, CStarNotFoundError, CStarPermissionError, CStarRateLimitError, CStarRealtimeUnavailableError, CStarServerError, CStarValidationError, ErrorType, type QuickHelpAskParams, type QuickHelpAskResult, QuickHelpClient, type QuickHelpConfig, QuickHelpError, type QuickHelpPublicConfig, type QuickHelpTurnOutcome, parseError, parsePublicError };
|
|
@@ -1,7 +1,21 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Options for the QuickHelpClient. No auth — Quick Help is anonymous by
|
|
3
|
+
* design.
|
|
4
|
+
*
|
|
5
|
+
* NEW-v2-05: pass either `teamId` (UUID, fastest — no roundtrip) or the
|
|
6
|
+
* easier-to-discover `teamSlug`. The slug is resolved to a UUID on the
|
|
7
|
+
* first network call and cached for the life of the client. At least one
|
|
8
|
+
* is required.
|
|
9
|
+
*/
|
|
2
10
|
interface QuickHelpConfig {
|
|
3
|
-
/** Your team's UUID.
|
|
4
|
-
teamId
|
|
11
|
+
/** Your team's UUID. Either this or `teamSlug` is required. */
|
|
12
|
+
teamId?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Your team's slug (e.g. `acme`). Resolved to `teamId` lazily via the
|
|
15
|
+
* public `/api/widget/team-by-slug` endpoint on the first call. Cached
|
|
16
|
+
* thereafter. Either this or `teamId` is required.
|
|
17
|
+
*/
|
|
18
|
+
teamSlug?: string;
|
|
5
19
|
/**
|
|
6
20
|
* Optional publishable key (`pk_test_*` or `pk_live_*`). Sent as
|
|
7
21
|
* `Authorization: Bearer` so test-mode dev sessions can be scoped
|
|
@@ -41,6 +55,126 @@ interface QuickHelpAskResult {
|
|
|
41
55
|
turnNumber: number;
|
|
42
56
|
}
|
|
43
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Error classes for the cStar SDK.
|
|
60
|
+
*
|
|
61
|
+
* NEW-v3-01 — Cross-subpath instanceof identity.
|
|
62
|
+
*
|
|
63
|
+
* Each public subpath (`/library`, `/auth`, `/community`, `/quickhelp`, ...)
|
|
64
|
+
* is bundled as a separate tsup entry with `splitting: false`, so each one
|
|
65
|
+
* carries its own copy of this module. Without deduplication, errors thrown
|
|
66
|
+
* by `LibraryClient` carry the LibraryClient-bundled `CStarError` class —
|
|
67
|
+
* not the one a consumer imports from `@cstar.help/js`. That makes
|
|
68
|
+
* `instanceof CStarError` checks fail silently, invalidating every "did the
|
|
69
|
+
* SDK throw a typed cStar error?" branch in user code.
|
|
70
|
+
*
|
|
71
|
+
* Fix: register each class on a `Symbol.for(...)` slot of `globalThis`. The
|
|
72
|
+
* symbol is realm-shared, so every bundled copy of this module resolves to
|
|
73
|
+
* the SAME class identity at runtime — the first copy to load wins, and all
|
|
74
|
+
* subsequent copies surface the canonical class via the same slot. The
|
|
75
|
+
* inline `Impl` definitions are only used as the seed for the very first
|
|
76
|
+
* copy to register. Internal `parseError` / `parsePublicError` reference the
|
|
77
|
+
* EXPORTED canonical names so instances they construct also land on the
|
|
78
|
+
* canonical class.
|
|
79
|
+
*/
|
|
80
|
+
/** Error type constants matching the cStar API. */
|
|
81
|
+
declare const ErrorType: {
|
|
82
|
+
readonly AUTHENTICATION_ERROR: "authentication_error";
|
|
83
|
+
readonly PERMISSION_ERROR: "permission_error";
|
|
84
|
+
readonly INVALID_REQUEST_ERROR: "invalid_request_error";
|
|
85
|
+
readonly NOT_FOUND_ERROR: "not_found_error";
|
|
86
|
+
readonly CONFLICT_ERROR: "conflict_error";
|
|
87
|
+
readonly RATE_LIMIT_ERROR: "rate_limit_error";
|
|
88
|
+
readonly FEATURE_NOT_CONFIGURED: "feature_not_configured";
|
|
89
|
+
readonly API_ERROR: "api_error";
|
|
90
|
+
readonly SERVER_ERROR: "server_error";
|
|
91
|
+
};
|
|
92
|
+
/** Shape of the error object returned by the cStar API. */
|
|
93
|
+
interface ApiErrorBody {
|
|
94
|
+
type: string;
|
|
95
|
+
code: string;
|
|
96
|
+
message: string;
|
|
97
|
+
param?: string;
|
|
98
|
+
doc_url: string;
|
|
99
|
+
request_id?: string;
|
|
100
|
+
feature?: string;
|
|
101
|
+
enable_url?: string;
|
|
102
|
+
}
|
|
103
|
+
/** Base error class for all cStar API errors. */
|
|
104
|
+
declare class CStarErrorImpl extends Error {
|
|
105
|
+
readonly type: string;
|
|
106
|
+
readonly code: string;
|
|
107
|
+
readonly param?: string;
|
|
108
|
+
readonly docUrl: string;
|
|
109
|
+
readonly requestId?: string;
|
|
110
|
+
readonly statusCode: number;
|
|
111
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
112
|
+
}
|
|
113
|
+
declare class CStarAuthenticationErrorImpl extends CStarErrorImpl {
|
|
114
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
115
|
+
}
|
|
116
|
+
declare class CStarRateLimitErrorImpl extends CStarErrorImpl {
|
|
117
|
+
readonly retryAfter: number;
|
|
118
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody, retryAfter?: number);
|
|
119
|
+
}
|
|
120
|
+
declare class CStarNotFoundErrorImpl extends CStarErrorImpl {
|
|
121
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
122
|
+
}
|
|
123
|
+
declare class CStarValidationErrorImpl extends CStarErrorImpl {
|
|
124
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
125
|
+
}
|
|
126
|
+
declare class CStarPermissionErrorImpl extends CStarErrorImpl {
|
|
127
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
128
|
+
}
|
|
129
|
+
declare class CStarConflictErrorImpl extends CStarErrorImpl {
|
|
130
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
131
|
+
}
|
|
132
|
+
declare class CStarServerErrorImpl extends CStarErrorImpl {
|
|
133
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
134
|
+
}
|
|
135
|
+
declare class CStarFeatureDisabledErrorImpl extends CStarErrorImpl {
|
|
136
|
+
readonly feature: string;
|
|
137
|
+
readonly enableUrl: string;
|
|
138
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
139
|
+
}
|
|
140
|
+
declare class CStarRealtimeUnavailableErrorImpl extends CStarErrorImpl {
|
|
141
|
+
constructor(message?: string);
|
|
142
|
+
}
|
|
143
|
+
declare const CStarError: typeof CStarErrorImpl;
|
|
144
|
+
type CStarError = InstanceType<typeof CStarErrorImpl>;
|
|
145
|
+
declare const CStarAuthenticationError: typeof CStarAuthenticationErrorImpl;
|
|
146
|
+
type CStarAuthenticationError = InstanceType<typeof CStarAuthenticationErrorImpl>;
|
|
147
|
+
declare const CStarRateLimitError: typeof CStarRateLimitErrorImpl;
|
|
148
|
+
type CStarRateLimitError = InstanceType<typeof CStarRateLimitErrorImpl>;
|
|
149
|
+
declare const CStarNotFoundError: typeof CStarNotFoundErrorImpl;
|
|
150
|
+
type CStarNotFoundError = InstanceType<typeof CStarNotFoundErrorImpl>;
|
|
151
|
+
declare const CStarValidationError: typeof CStarValidationErrorImpl;
|
|
152
|
+
type CStarValidationError = InstanceType<typeof CStarValidationErrorImpl>;
|
|
153
|
+
declare const CStarPermissionError: typeof CStarPermissionErrorImpl;
|
|
154
|
+
type CStarPermissionError = InstanceType<typeof CStarPermissionErrorImpl>;
|
|
155
|
+
declare const CStarConflictError: typeof CStarConflictErrorImpl;
|
|
156
|
+
type CStarConflictError = InstanceType<typeof CStarConflictErrorImpl>;
|
|
157
|
+
declare const CStarServerError: typeof CStarServerErrorImpl;
|
|
158
|
+
type CStarServerError = InstanceType<typeof CStarServerErrorImpl>;
|
|
159
|
+
declare const CStarFeatureDisabledError: typeof CStarFeatureDisabledErrorImpl;
|
|
160
|
+
type CStarFeatureDisabledError = InstanceType<typeof CStarFeatureDisabledErrorImpl>;
|
|
161
|
+
declare const CStarRealtimeUnavailableError: typeof CStarRealtimeUnavailableErrorImpl;
|
|
162
|
+
type CStarRealtimeUnavailableError = InstanceType<typeof CStarRealtimeUnavailableErrorImpl>;
|
|
163
|
+
/**
|
|
164
|
+
* Parse a public-route response (anonymous LibraryClient, CommunityClient,
|
|
165
|
+
* QuickHelpClient, AuthClient) into a typed `CStarError`.
|
|
166
|
+
*
|
|
167
|
+
* Public routes don't always emit the structured `{error: {type, code,
|
|
168
|
+
* doc_url, ...}}` envelope — many emit `{error: 'message string'}` or
|
|
169
|
+
* `{message: '...'}`. This helper normalizes both shapes and dispatches
|
|
170
|
+
* on HTTP status (closes F-026 and F-034 — Library/Auth used to throw
|
|
171
|
+
* plain `Error`).
|
|
172
|
+
*/
|
|
173
|
+
declare function parsePublicError(status: number, body: unknown, fallbackMessage: string): CStarError;
|
|
174
|
+
declare function parseError(statusCode: number, body: {
|
|
175
|
+
error?: ApiErrorBody;
|
|
176
|
+
} | null, retryAfter?: number): CStarError;
|
|
177
|
+
|
|
44
178
|
/**
|
|
45
179
|
* Quick Help — anonymous AI Q&A client.
|
|
46
180
|
*
|
|
@@ -67,12 +201,20 @@ interface QuickHelpAskResult {
|
|
|
67
201
|
*/
|
|
68
202
|
declare class QuickHelpClient {
|
|
69
203
|
private readonly baseUrl;
|
|
70
|
-
|
|
204
|
+
/** Cached resolved teamId. `null` until the first lookup completes. */
|
|
205
|
+
private teamId;
|
|
206
|
+
private readonly teamSlug;
|
|
207
|
+
private resolveTeamIdPromise;
|
|
71
208
|
private readonly publishableKey;
|
|
72
209
|
/** Resolved mode based on the publishable-key prefix. */
|
|
73
210
|
readonly mode: 'live' | 'test';
|
|
74
211
|
constructor(config: QuickHelpConfig);
|
|
75
212
|
private authHeaders;
|
|
213
|
+
/**
|
|
214
|
+
* Resolve `teamSlug` → `teamId` lazily on the first call that needs it.
|
|
215
|
+
* Cached for the life of the client. NEW-v2-05.
|
|
216
|
+
*/
|
|
217
|
+
private resolveTeamId;
|
|
76
218
|
/**
|
|
77
219
|
* Fetch the sanitized public config (title, subtitle, placeholder,
|
|
78
220
|
* theme overrides). Never includes agent id or escalation contact
|
|
@@ -105,4 +247,4 @@ declare class QuickHelpError extends Error {
|
|
|
105
247
|
});
|
|
106
248
|
}
|
|
107
249
|
|
|
108
|
-
export { type QuickHelpAskParams, type QuickHelpAskResult, QuickHelpClient, type QuickHelpConfig, QuickHelpError, type QuickHelpPublicConfig, type QuickHelpTurnOutcome };
|
|
250
|
+
export { type ApiErrorBody, CStarAuthenticationError, CStarConflictError, CStarError, CStarFeatureDisabledError, CStarNotFoundError, CStarPermissionError, CStarRateLimitError, CStarRealtimeUnavailableError, CStarServerError, CStarValidationError, ErrorType, type QuickHelpAskParams, type QuickHelpAskResult, QuickHelpClient, type QuickHelpConfig, QuickHelpError, type QuickHelpPublicConfig, type QuickHelpTurnOutcome, parseError, parsePublicError };
|