@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.
- package/dist/auth/index.cjs +93 -11
- package/dist/auth/index.d.cts +398 -1
- package/dist/auth/index.d.ts +398 -1
- package/dist/auth/index.js +79 -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 +93 -11
- package/dist/community/index.d.cts +398 -1
- package/dist/community/index.d.ts +398 -1
- package/dist/community/index.js +79 -10
- package/dist/index.cjs +55 -11
- package/dist/index.d.cts +334 -53
- package/dist/index.d.ts +334 -53
- package/dist/index.js +55 -11
- package/dist/library/index.cjs +93 -11
- package/dist/library/index.d.cts +398 -1
- package/dist/library/index.d.ts +398 -1
- package/dist/library/index.js +79 -10
- package/dist/quickhelp/index.cjs +154 -11
- package/dist/quickhelp/index.d.cts +398 -1
- package/dist/quickhelp/index.d.ts +398 -1
- package/dist/quickhelp/index.js +140 -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/auth/index.d.ts
CHANGED
|
@@ -56,6 +56,403 @@ interface AuthSession {
|
|
|
56
56
|
refreshToken: string;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Error classes for the cStar SDK.
|
|
61
|
+
*
|
|
62
|
+
* NEW-v3-01 — Cross-subpath instanceof identity.
|
|
63
|
+
*
|
|
64
|
+
* Each public subpath (`/library`, `/auth`, `/community`, `/quickhelp`, ...)
|
|
65
|
+
* is bundled as a separate tsup entry with `splitting: false`, so each one
|
|
66
|
+
* carries its own copy of this module. Without deduplication, errors thrown
|
|
67
|
+
* by `LibraryClient` carry the LibraryClient-bundled `CStarError` class —
|
|
68
|
+
* not the one a consumer imports from `@cstar.help/js`. That makes
|
|
69
|
+
* `instanceof CStarError` checks fail silently, invalidating every "did the
|
|
70
|
+
* SDK throw a typed cStar error?" branch in user code.
|
|
71
|
+
*
|
|
72
|
+
* Fix: register each class on a `Symbol.for(...)` slot of `globalThis`. The
|
|
73
|
+
* symbol is realm-shared, so every bundled copy of this module resolves to
|
|
74
|
+
* the SAME class identity at runtime — the first copy to load wins, and all
|
|
75
|
+
* subsequent copies surface the canonical class via the same slot. The
|
|
76
|
+
* inline `Impl` definitions are only used as the seed for the very first
|
|
77
|
+
* copy to register. Internal `parseError` / `parsePublicError` reference the
|
|
78
|
+
* EXPORTED canonical names so instances they construct also land on the
|
|
79
|
+
* canonical class.
|
|
80
|
+
*/
|
|
81
|
+
/** Error type constants matching the cStar API. */
|
|
82
|
+
declare const ErrorType: {
|
|
83
|
+
readonly AUTHENTICATION_ERROR: "authentication_error";
|
|
84
|
+
readonly PERMISSION_ERROR: "permission_error";
|
|
85
|
+
readonly INVALID_REQUEST_ERROR: "invalid_request_error";
|
|
86
|
+
readonly NOT_FOUND_ERROR: "not_found_error";
|
|
87
|
+
readonly CONFLICT_ERROR: "conflict_error";
|
|
88
|
+
readonly RATE_LIMIT_ERROR: "rate_limit_error";
|
|
89
|
+
readonly FEATURE_NOT_CONFIGURED: "feature_not_configured";
|
|
90
|
+
readonly API_ERROR: "api_error";
|
|
91
|
+
readonly SERVER_ERROR: "server_error";
|
|
92
|
+
};
|
|
93
|
+
/** Shape of the error object returned by the cStar API. */
|
|
94
|
+
interface ApiErrorBody {
|
|
95
|
+
type: string;
|
|
96
|
+
code: string;
|
|
97
|
+
message: string;
|
|
98
|
+
param?: string;
|
|
99
|
+
doc_url: string;
|
|
100
|
+
request_id?: string;
|
|
101
|
+
feature?: string;
|
|
102
|
+
enable_url?: string;
|
|
103
|
+
}
|
|
104
|
+
/** Base error class for all cStar API errors. */
|
|
105
|
+
declare const CStarErrorImpl: {
|
|
106
|
+
new (messageOrStatus: string | number, body?: ApiErrorBody): {
|
|
107
|
+
readonly type: string;
|
|
108
|
+
readonly code: string;
|
|
109
|
+
readonly param?: string;
|
|
110
|
+
readonly docUrl: string;
|
|
111
|
+
readonly requestId?: string;
|
|
112
|
+
readonly statusCode: number;
|
|
113
|
+
name: string;
|
|
114
|
+
message: string;
|
|
115
|
+
stack?: string;
|
|
116
|
+
};
|
|
117
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
118
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
119
|
+
stackTraceLimit: number;
|
|
120
|
+
};
|
|
121
|
+
declare const CStarAuthenticationErrorImpl: {
|
|
122
|
+
new (messageOrStatus: string | number, body?: ApiErrorBody): {
|
|
123
|
+
readonly type: string;
|
|
124
|
+
readonly code: string;
|
|
125
|
+
readonly param?: string;
|
|
126
|
+
readonly docUrl: string;
|
|
127
|
+
readonly requestId?: string;
|
|
128
|
+
readonly statusCode: number;
|
|
129
|
+
name: string;
|
|
130
|
+
message: string;
|
|
131
|
+
stack?: string;
|
|
132
|
+
};
|
|
133
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
134
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
135
|
+
stackTraceLimit: number;
|
|
136
|
+
};
|
|
137
|
+
declare const CStarRateLimitErrorImpl: {
|
|
138
|
+
new (messageOrStatus: string | number, body?: ApiErrorBody, retryAfter?: number): {
|
|
139
|
+
readonly retryAfter: number;
|
|
140
|
+
readonly type: string;
|
|
141
|
+
readonly code: string;
|
|
142
|
+
readonly param?: string;
|
|
143
|
+
readonly docUrl: string;
|
|
144
|
+
readonly requestId?: string;
|
|
145
|
+
readonly statusCode: number;
|
|
146
|
+
name: string;
|
|
147
|
+
message: string;
|
|
148
|
+
stack?: string;
|
|
149
|
+
};
|
|
150
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
151
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
152
|
+
stackTraceLimit: number;
|
|
153
|
+
};
|
|
154
|
+
declare const CStarNotFoundErrorImpl: {
|
|
155
|
+
new (messageOrStatus: string | number, body?: ApiErrorBody): {
|
|
156
|
+
readonly type: string;
|
|
157
|
+
readonly code: string;
|
|
158
|
+
readonly param?: string;
|
|
159
|
+
readonly docUrl: string;
|
|
160
|
+
readonly requestId?: string;
|
|
161
|
+
readonly statusCode: number;
|
|
162
|
+
name: string;
|
|
163
|
+
message: string;
|
|
164
|
+
stack?: string;
|
|
165
|
+
};
|
|
166
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
167
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
168
|
+
stackTraceLimit: number;
|
|
169
|
+
};
|
|
170
|
+
declare const CStarValidationErrorImpl: {
|
|
171
|
+
new (messageOrStatus: string | number, body?: ApiErrorBody): {
|
|
172
|
+
readonly type: string;
|
|
173
|
+
readonly code: string;
|
|
174
|
+
readonly param?: string;
|
|
175
|
+
readonly docUrl: string;
|
|
176
|
+
readonly requestId?: string;
|
|
177
|
+
readonly statusCode: number;
|
|
178
|
+
name: string;
|
|
179
|
+
message: string;
|
|
180
|
+
stack?: string;
|
|
181
|
+
};
|
|
182
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
183
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
184
|
+
stackTraceLimit: number;
|
|
185
|
+
};
|
|
186
|
+
declare const CStarPermissionErrorImpl: {
|
|
187
|
+
new (messageOrStatus: string | number, body?: ApiErrorBody): {
|
|
188
|
+
readonly type: string;
|
|
189
|
+
readonly code: string;
|
|
190
|
+
readonly param?: string;
|
|
191
|
+
readonly docUrl: string;
|
|
192
|
+
readonly requestId?: string;
|
|
193
|
+
readonly statusCode: number;
|
|
194
|
+
name: string;
|
|
195
|
+
message: string;
|
|
196
|
+
stack?: string;
|
|
197
|
+
};
|
|
198
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
199
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
200
|
+
stackTraceLimit: number;
|
|
201
|
+
};
|
|
202
|
+
declare const CStarConflictErrorImpl: {
|
|
203
|
+
new (messageOrStatus: string | number, body?: ApiErrorBody): {
|
|
204
|
+
readonly type: string;
|
|
205
|
+
readonly code: string;
|
|
206
|
+
readonly param?: string;
|
|
207
|
+
readonly docUrl: string;
|
|
208
|
+
readonly requestId?: string;
|
|
209
|
+
readonly statusCode: number;
|
|
210
|
+
name: string;
|
|
211
|
+
message: string;
|
|
212
|
+
stack?: string;
|
|
213
|
+
};
|
|
214
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
215
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
216
|
+
stackTraceLimit: number;
|
|
217
|
+
};
|
|
218
|
+
declare const CStarServerErrorImpl: {
|
|
219
|
+
new (messageOrStatus: string | number, body?: ApiErrorBody): {
|
|
220
|
+
readonly type: string;
|
|
221
|
+
readonly code: string;
|
|
222
|
+
readonly param?: string;
|
|
223
|
+
readonly docUrl: string;
|
|
224
|
+
readonly requestId?: string;
|
|
225
|
+
readonly statusCode: number;
|
|
226
|
+
name: string;
|
|
227
|
+
message: string;
|
|
228
|
+
stack?: string;
|
|
229
|
+
};
|
|
230
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
231
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
232
|
+
stackTraceLimit: number;
|
|
233
|
+
};
|
|
234
|
+
declare const CStarFeatureDisabledErrorImpl: {
|
|
235
|
+
new (messageOrStatus: string | number, body?: ApiErrorBody): {
|
|
236
|
+
readonly feature: string;
|
|
237
|
+
readonly enableUrl: string;
|
|
238
|
+
readonly type: string;
|
|
239
|
+
readonly code: string;
|
|
240
|
+
readonly param?: string;
|
|
241
|
+
readonly docUrl: string;
|
|
242
|
+
readonly requestId?: string;
|
|
243
|
+
readonly statusCode: number;
|
|
244
|
+
name: string;
|
|
245
|
+
message: string;
|
|
246
|
+
stack?: string;
|
|
247
|
+
};
|
|
248
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
249
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
250
|
+
stackTraceLimit: number;
|
|
251
|
+
};
|
|
252
|
+
declare const CStarRealtimeUnavailableErrorImpl: {
|
|
253
|
+
new (message?: string): {
|
|
254
|
+
readonly type: string;
|
|
255
|
+
readonly code: string;
|
|
256
|
+
readonly param?: string;
|
|
257
|
+
readonly docUrl: string;
|
|
258
|
+
readonly requestId?: string;
|
|
259
|
+
readonly statusCode: number;
|
|
260
|
+
name: string;
|
|
261
|
+
message: string;
|
|
262
|
+
stack?: string;
|
|
263
|
+
};
|
|
264
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
265
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
266
|
+
stackTraceLimit: number;
|
|
267
|
+
};
|
|
268
|
+
declare const CStarError: {
|
|
269
|
+
new (messageOrStatus: string | number, body?: ApiErrorBody): {
|
|
270
|
+
readonly type: string;
|
|
271
|
+
readonly code: string;
|
|
272
|
+
readonly param?: string;
|
|
273
|
+
readonly docUrl: string;
|
|
274
|
+
readonly requestId?: string;
|
|
275
|
+
readonly statusCode: number;
|
|
276
|
+
name: string;
|
|
277
|
+
message: string;
|
|
278
|
+
stack?: string;
|
|
279
|
+
};
|
|
280
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
281
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
282
|
+
stackTraceLimit: number;
|
|
283
|
+
};
|
|
284
|
+
type CStarError = InstanceType<typeof CStarErrorImpl>;
|
|
285
|
+
declare const CStarAuthenticationError: {
|
|
286
|
+
new (messageOrStatus: string | number, body?: ApiErrorBody): {
|
|
287
|
+
readonly type: string;
|
|
288
|
+
readonly code: string;
|
|
289
|
+
readonly param?: string;
|
|
290
|
+
readonly docUrl: string;
|
|
291
|
+
readonly requestId?: string;
|
|
292
|
+
readonly statusCode: number;
|
|
293
|
+
name: string;
|
|
294
|
+
message: string;
|
|
295
|
+
stack?: string;
|
|
296
|
+
};
|
|
297
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
298
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
299
|
+
stackTraceLimit: number;
|
|
300
|
+
};
|
|
301
|
+
type CStarAuthenticationError = InstanceType<typeof CStarAuthenticationErrorImpl>;
|
|
302
|
+
declare const CStarRateLimitError: {
|
|
303
|
+
new (messageOrStatus: string | number, body?: ApiErrorBody, retryAfter?: number): {
|
|
304
|
+
readonly retryAfter: number;
|
|
305
|
+
readonly type: string;
|
|
306
|
+
readonly code: string;
|
|
307
|
+
readonly param?: string;
|
|
308
|
+
readonly docUrl: string;
|
|
309
|
+
readonly requestId?: string;
|
|
310
|
+
readonly statusCode: number;
|
|
311
|
+
name: string;
|
|
312
|
+
message: string;
|
|
313
|
+
stack?: string;
|
|
314
|
+
};
|
|
315
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
316
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
317
|
+
stackTraceLimit: number;
|
|
318
|
+
};
|
|
319
|
+
type CStarRateLimitError = InstanceType<typeof CStarRateLimitErrorImpl>;
|
|
320
|
+
declare const CStarNotFoundError: {
|
|
321
|
+
new (messageOrStatus: string | number, body?: ApiErrorBody): {
|
|
322
|
+
readonly type: string;
|
|
323
|
+
readonly code: string;
|
|
324
|
+
readonly param?: string;
|
|
325
|
+
readonly docUrl: string;
|
|
326
|
+
readonly requestId?: string;
|
|
327
|
+
readonly statusCode: number;
|
|
328
|
+
name: string;
|
|
329
|
+
message: string;
|
|
330
|
+
stack?: string;
|
|
331
|
+
};
|
|
332
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
333
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
334
|
+
stackTraceLimit: number;
|
|
335
|
+
};
|
|
336
|
+
type CStarNotFoundError = InstanceType<typeof CStarNotFoundErrorImpl>;
|
|
337
|
+
declare const CStarValidationError: {
|
|
338
|
+
new (messageOrStatus: string | number, body?: ApiErrorBody): {
|
|
339
|
+
readonly type: string;
|
|
340
|
+
readonly code: string;
|
|
341
|
+
readonly param?: string;
|
|
342
|
+
readonly docUrl: string;
|
|
343
|
+
readonly requestId?: string;
|
|
344
|
+
readonly statusCode: number;
|
|
345
|
+
name: string;
|
|
346
|
+
message: string;
|
|
347
|
+
stack?: string;
|
|
348
|
+
};
|
|
349
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
350
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
351
|
+
stackTraceLimit: number;
|
|
352
|
+
};
|
|
353
|
+
type CStarValidationError = InstanceType<typeof CStarValidationErrorImpl>;
|
|
354
|
+
declare const CStarPermissionError: {
|
|
355
|
+
new (messageOrStatus: string | number, body?: ApiErrorBody): {
|
|
356
|
+
readonly type: string;
|
|
357
|
+
readonly code: string;
|
|
358
|
+
readonly param?: string;
|
|
359
|
+
readonly docUrl: string;
|
|
360
|
+
readonly requestId?: string;
|
|
361
|
+
readonly statusCode: number;
|
|
362
|
+
name: string;
|
|
363
|
+
message: string;
|
|
364
|
+
stack?: string;
|
|
365
|
+
};
|
|
366
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
367
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
368
|
+
stackTraceLimit: number;
|
|
369
|
+
};
|
|
370
|
+
type CStarPermissionError = InstanceType<typeof CStarPermissionErrorImpl>;
|
|
371
|
+
declare const CStarConflictError: {
|
|
372
|
+
new (messageOrStatus: string | number, body?: ApiErrorBody): {
|
|
373
|
+
readonly type: string;
|
|
374
|
+
readonly code: string;
|
|
375
|
+
readonly param?: string;
|
|
376
|
+
readonly docUrl: string;
|
|
377
|
+
readonly requestId?: string;
|
|
378
|
+
readonly statusCode: number;
|
|
379
|
+
name: string;
|
|
380
|
+
message: string;
|
|
381
|
+
stack?: string;
|
|
382
|
+
};
|
|
383
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
384
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
385
|
+
stackTraceLimit: number;
|
|
386
|
+
};
|
|
387
|
+
type CStarConflictError = InstanceType<typeof CStarConflictErrorImpl>;
|
|
388
|
+
declare const CStarServerError: {
|
|
389
|
+
new (messageOrStatus: string | number, body?: ApiErrorBody): {
|
|
390
|
+
readonly type: string;
|
|
391
|
+
readonly code: string;
|
|
392
|
+
readonly param?: string;
|
|
393
|
+
readonly docUrl: string;
|
|
394
|
+
readonly requestId?: string;
|
|
395
|
+
readonly statusCode: number;
|
|
396
|
+
name: string;
|
|
397
|
+
message: string;
|
|
398
|
+
stack?: string;
|
|
399
|
+
};
|
|
400
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
401
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
402
|
+
stackTraceLimit: number;
|
|
403
|
+
};
|
|
404
|
+
type CStarServerError = InstanceType<typeof CStarServerErrorImpl>;
|
|
405
|
+
declare const CStarFeatureDisabledError: {
|
|
406
|
+
new (messageOrStatus: string | number, body?: ApiErrorBody): {
|
|
407
|
+
readonly feature: string;
|
|
408
|
+
readonly enableUrl: string;
|
|
409
|
+
readonly type: string;
|
|
410
|
+
readonly code: string;
|
|
411
|
+
readonly param?: string;
|
|
412
|
+
readonly docUrl: string;
|
|
413
|
+
readonly requestId?: string;
|
|
414
|
+
readonly statusCode: number;
|
|
415
|
+
name: string;
|
|
416
|
+
message: string;
|
|
417
|
+
stack?: string;
|
|
418
|
+
};
|
|
419
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
420
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
421
|
+
stackTraceLimit: number;
|
|
422
|
+
};
|
|
423
|
+
type CStarFeatureDisabledError = InstanceType<typeof CStarFeatureDisabledErrorImpl>;
|
|
424
|
+
declare const CStarRealtimeUnavailableError: {
|
|
425
|
+
new (message?: string): {
|
|
426
|
+
readonly type: string;
|
|
427
|
+
readonly code: string;
|
|
428
|
+
readonly param?: string;
|
|
429
|
+
readonly docUrl: string;
|
|
430
|
+
readonly requestId?: string;
|
|
431
|
+
readonly statusCode: number;
|
|
432
|
+
name: string;
|
|
433
|
+
message: string;
|
|
434
|
+
stack?: string;
|
|
435
|
+
};
|
|
436
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
437
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
438
|
+
stackTraceLimit: number;
|
|
439
|
+
};
|
|
440
|
+
type CStarRealtimeUnavailableError = InstanceType<typeof CStarRealtimeUnavailableErrorImpl>;
|
|
441
|
+
/**
|
|
442
|
+
* Parse a public-route response (anonymous LibraryClient, CommunityClient,
|
|
443
|
+
* QuickHelpClient, AuthClient) into a typed `CStarError`.
|
|
444
|
+
*
|
|
445
|
+
* Public routes don't always emit the structured `{error: {type, code,
|
|
446
|
+
* doc_url, ...}}` envelope — many emit `{error: 'message string'}` or
|
|
447
|
+
* `{message: '...'}`. This helper normalizes both shapes and dispatches
|
|
448
|
+
* on HTTP status (closes F-026 and F-034 — Library/Auth used to throw
|
|
449
|
+
* plain `Error`).
|
|
450
|
+
*/
|
|
451
|
+
declare function parsePublicError(status: number, body: unknown, fallbackMessage: string): CStarError;
|
|
452
|
+
declare function parseError(statusCode: number, body: {
|
|
453
|
+
error?: ApiErrorBody;
|
|
454
|
+
} | null, retryAfter?: number): CStarError;
|
|
455
|
+
|
|
59
456
|
/**
|
|
60
457
|
* Customer authentication client for the cStar widget API.
|
|
61
458
|
*
|
|
@@ -120,4 +517,4 @@ declare class AuthClient {
|
|
|
120
517
|
private fetch;
|
|
121
518
|
}
|
|
122
519
|
|
|
123
|
-
export { AuthClient, type AuthConfig, type AuthCustomer, type AuthSession, type LoginParams, type LoginResult, type SignupConfirmationResult, type SignupParams, type SignupResult };
|
|
520
|
+
export { type ApiErrorBody, AuthClient, type AuthConfig, type AuthCustomer, type AuthSession, CStarAuthenticationError, CStarConflictError, CStarError, CStarFeatureDisabledError, CStarNotFoundError, CStarPermissionError, CStarRateLimitError, CStarRealtimeUnavailableError, CStarServerError, CStarValidationError, ErrorType, type LoginParams, type LoginResult, type SignupConfirmationResult, type SignupParams, type SignupResult, parseError, parsePublicError };
|
package/dist/auth/index.js
CHANGED
|
@@ -35,7 +35,7 @@ function normalizeArgs(messageOrStatus, maybeBody, defaults) {
|
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
-
var
|
|
38
|
+
var CStarErrorImpl = class extends Error {
|
|
39
39
|
constructor(messageOrStatus, body) {
|
|
40
40
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body);
|
|
41
41
|
super(resolved.message);
|
|
@@ -48,7 +48,7 @@ var CStarError = class extends Error {
|
|
|
48
48
|
this.statusCode = statusCode;
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
var
|
|
51
|
+
var CStarAuthenticationErrorImpl = class extends CStarErrorImpl {
|
|
52
52
|
constructor(messageOrStatus, body) {
|
|
53
53
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
54
54
|
type: ErrorType.AUTHENTICATION_ERROR,
|
|
@@ -59,7 +59,7 @@ var CStarAuthenticationError = class extends CStarError {
|
|
|
59
59
|
this.name = "CStarAuthenticationError";
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
|
-
var
|
|
62
|
+
var CStarRateLimitErrorImpl = class extends CStarErrorImpl {
|
|
63
63
|
constructor(messageOrStatus, body, retryAfter) {
|
|
64
64
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
65
65
|
type: ErrorType.RATE_LIMIT_ERROR,
|
|
@@ -71,7 +71,7 @@ var CStarRateLimitError = class extends CStarError {
|
|
|
71
71
|
this.retryAfter = retryAfter ?? 60;
|
|
72
72
|
}
|
|
73
73
|
};
|
|
74
|
-
var
|
|
74
|
+
var CStarNotFoundErrorImpl = class extends CStarErrorImpl {
|
|
75
75
|
constructor(messageOrStatus, body) {
|
|
76
76
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
77
77
|
type: ErrorType.NOT_FOUND_ERROR,
|
|
@@ -82,7 +82,7 @@ var CStarNotFoundError = class extends CStarError {
|
|
|
82
82
|
this.name = "CStarNotFoundError";
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
|
-
var
|
|
85
|
+
var CStarValidationErrorImpl = class extends CStarErrorImpl {
|
|
86
86
|
constructor(messageOrStatus, body) {
|
|
87
87
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
88
88
|
type: ErrorType.INVALID_REQUEST_ERROR,
|
|
@@ -93,7 +93,7 @@ var CStarValidationError = class extends CStarError {
|
|
|
93
93
|
this.name = "CStarValidationError";
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
|
-
var
|
|
96
|
+
var CStarPermissionErrorImpl = class extends CStarErrorImpl {
|
|
97
97
|
constructor(messageOrStatus, body) {
|
|
98
98
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
99
99
|
type: ErrorType.PERMISSION_ERROR,
|
|
@@ -104,7 +104,7 @@ var CStarPermissionError = class extends CStarError {
|
|
|
104
104
|
this.name = "CStarPermissionError";
|
|
105
105
|
}
|
|
106
106
|
};
|
|
107
|
-
var
|
|
107
|
+
var CStarConflictErrorImpl = class extends CStarErrorImpl {
|
|
108
108
|
constructor(messageOrStatus, body) {
|
|
109
109
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
110
110
|
type: ErrorType.CONFLICT_ERROR,
|
|
@@ -115,7 +115,7 @@ var CStarConflictError = class extends CStarError {
|
|
|
115
115
|
this.name = "CStarConflictError";
|
|
116
116
|
}
|
|
117
117
|
};
|
|
118
|
-
var
|
|
118
|
+
var CStarServerErrorImpl = class extends CStarErrorImpl {
|
|
119
119
|
constructor(messageOrStatus, body) {
|
|
120
120
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
121
121
|
type: ErrorType.SERVER_ERROR,
|
|
@@ -126,7 +126,7 @@ var CStarServerError = class extends CStarError {
|
|
|
126
126
|
this.name = "CStarServerError";
|
|
127
127
|
}
|
|
128
128
|
};
|
|
129
|
-
var
|
|
129
|
+
var CStarFeatureDisabledErrorImpl = class extends CStarErrorImpl {
|
|
130
130
|
constructor(messageOrStatus, body) {
|
|
131
131
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
132
132
|
type: ErrorType.FEATURE_NOT_CONFIGURED,
|
|
@@ -139,6 +139,62 @@ var CStarFeatureDisabledError = class extends CStarError {
|
|
|
139
139
|
this.enableUrl = resolved.enable_url ?? "";
|
|
140
140
|
}
|
|
141
141
|
};
|
|
142
|
+
var CStarRealtimeUnavailableErrorImpl = class extends CStarErrorImpl {
|
|
143
|
+
constructor(message) {
|
|
144
|
+
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";
|
|
145
|
+
super(0, {
|
|
146
|
+
type: ErrorType.API_ERROR,
|
|
147
|
+
code: "realtime_unavailable",
|
|
148
|
+
message: resolved,
|
|
149
|
+
doc_url: "https://cstar.help/developers/sdk/realtime#ssr"
|
|
150
|
+
});
|
|
151
|
+
this.name = "CStarRealtimeUnavailableError";
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
var REGISTRY_KEY = /* @__PURE__ */ Symbol.for("@cstar.help/js/errors/v1");
|
|
155
|
+
var globalSlot = globalThis;
|
|
156
|
+
var registry = globalSlot[REGISTRY_KEY] ?? (globalSlot[REGISTRY_KEY] = {
|
|
157
|
+
CStarError: CStarErrorImpl,
|
|
158
|
+
CStarAuthenticationError: CStarAuthenticationErrorImpl,
|
|
159
|
+
CStarRateLimitError: CStarRateLimitErrorImpl,
|
|
160
|
+
CStarNotFoundError: CStarNotFoundErrorImpl,
|
|
161
|
+
CStarValidationError: CStarValidationErrorImpl,
|
|
162
|
+
CStarPermissionError: CStarPermissionErrorImpl,
|
|
163
|
+
CStarConflictError: CStarConflictErrorImpl,
|
|
164
|
+
CStarServerError: CStarServerErrorImpl,
|
|
165
|
+
CStarFeatureDisabledError: CStarFeatureDisabledErrorImpl,
|
|
166
|
+
CStarRealtimeUnavailableError: CStarRealtimeUnavailableErrorImpl
|
|
167
|
+
});
|
|
168
|
+
var NAME_FIXES = [
|
|
169
|
+
"CStarError",
|
|
170
|
+
"CStarAuthenticationError",
|
|
171
|
+
"CStarRateLimitError",
|
|
172
|
+
"CStarNotFoundError",
|
|
173
|
+
"CStarValidationError",
|
|
174
|
+
"CStarPermissionError",
|
|
175
|
+
"CStarConflictError",
|
|
176
|
+
"CStarServerError",
|
|
177
|
+
"CStarFeatureDisabledError",
|
|
178
|
+
"CStarRealtimeUnavailableError"
|
|
179
|
+
];
|
|
180
|
+
for (const key of NAME_FIXES) {
|
|
181
|
+
if (registry[key].name !== key) {
|
|
182
|
+
Object.defineProperty(registry[key], "name", {
|
|
183
|
+
value: key,
|
|
184
|
+
configurable: true
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
var CStarError = registry.CStarError;
|
|
189
|
+
var CStarAuthenticationError = registry.CStarAuthenticationError;
|
|
190
|
+
var CStarRateLimitError = registry.CStarRateLimitError;
|
|
191
|
+
var CStarNotFoundError = registry.CStarNotFoundError;
|
|
192
|
+
var CStarValidationError = registry.CStarValidationError;
|
|
193
|
+
var CStarPermissionError = registry.CStarPermissionError;
|
|
194
|
+
var CStarConflictError = registry.CStarConflictError;
|
|
195
|
+
var CStarServerError = registry.CStarServerError;
|
|
196
|
+
var CStarFeatureDisabledError = registry.CStarFeatureDisabledError;
|
|
197
|
+
var CStarRealtimeUnavailableError = registry.CStarRealtimeUnavailableError;
|
|
142
198
|
function parsePublicError(status, body, fallbackMessage) {
|
|
143
199
|
const obj = body && typeof body === "object" ? body : null;
|
|
144
200
|
const errVal = obj?.error;
|
|
@@ -310,5 +366,18 @@ var AuthClient = class {
|
|
|
310
366
|
}
|
|
311
367
|
};
|
|
312
368
|
export {
|
|
313
|
-
AuthClient
|
|
369
|
+
AuthClient,
|
|
370
|
+
CStarAuthenticationError,
|
|
371
|
+
CStarConflictError,
|
|
372
|
+
CStarError,
|
|
373
|
+
CStarFeatureDisabledError,
|
|
374
|
+
CStarNotFoundError,
|
|
375
|
+
CStarPermissionError,
|
|
376
|
+
CStarRateLimitError,
|
|
377
|
+
CStarRealtimeUnavailableError,
|
|
378
|
+
CStarServerError,
|
|
379
|
+
CStarValidationError,
|
|
380
|
+
ErrorType,
|
|
381
|
+
parseError,
|
|
382
|
+
parsePublicError
|
|
314
383
|
};
|
package/dist/chat/index.cjs
CHANGED
|
@@ -662,6 +662,27 @@ var ChatClient = class {
|
|
|
662
662
|
getTeamId() {
|
|
663
663
|
return this.teamId;
|
|
664
664
|
}
|
|
665
|
+
/**
|
|
666
|
+
* Resolve a team ID, lazily looking it up from `teamSlug` if no team ID
|
|
667
|
+
* has been cached yet. Used by `tickets.list` and friends so that a
|
|
668
|
+
* caller who constructed `new ChatClient({ teamSlug, publishableKey })`
|
|
669
|
+
* doesn't have to manually call `loginWithCredentials` before reading
|
|
670
|
+
* public data.
|
|
671
|
+
*
|
|
672
|
+
* Closes NEW-v3-05 — `TicketsState(chatClient)` previously errored
|
|
673
|
+
* `"Missing teamId"` when the chat client was teamSlug-only because the
|
|
674
|
+
* tickets sub-resource read `getTeamId()` synchronously and bailed.
|
|
675
|
+
*/
|
|
676
|
+
async ensureTeamId() {
|
|
677
|
+
if (this.teamId) return this.teamId;
|
|
678
|
+
if (!this.teamSlug) {
|
|
679
|
+
throw new ChatClientAuthError(
|
|
680
|
+
"Missing teamId. Construct ChatClient with `teamSlug` or call `setTeamId()` / `identify()` / `loginWithCredentials()` first."
|
|
681
|
+
);
|
|
682
|
+
}
|
|
683
|
+
this.teamId = await this.resolveTeamIdFromSlug();
|
|
684
|
+
return this.teamId;
|
|
685
|
+
}
|
|
665
686
|
/** @internal Set team ID from identify response or other source. */
|
|
666
687
|
setTeamId(teamId) {
|
|
667
688
|
this.teamId = teamId;
|
|
@@ -747,8 +768,10 @@ var TicketsApi = class {
|
|
|
747
768
|
}
|
|
748
769
|
/** List tickets for the identified customer. */
|
|
749
770
|
async list(params) {
|
|
750
|
-
|
|
751
|
-
|
|
771
|
+
if (this.chat.getAuthMode() === null) {
|
|
772
|
+
throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
|
|
773
|
+
}
|
|
774
|
+
const teamId = await this.chat.ensureTeamId();
|
|
752
775
|
const response = await this.chat.fetch("/api/widget/conversations", {
|
|
753
776
|
method: "GET",
|
|
754
777
|
query: {
|
|
@@ -763,16 +786,15 @@ var TicketsApi = class {
|
|
|
763
786
|
return {
|
|
764
787
|
data,
|
|
765
788
|
pagination: { cursor, hasMore },
|
|
766
|
-
hasMore
|
|
767
|
-
// Deprecated aliases — same references, no extra allocation.
|
|
768
|
-
tickets: data,
|
|
769
|
-
cursor
|
|
789
|
+
hasMore
|
|
770
790
|
};
|
|
771
791
|
}
|
|
772
792
|
/** Create a new ticket. */
|
|
773
793
|
async create(params) {
|
|
774
|
-
|
|
775
|
-
|
|
794
|
+
if (this.chat.getAuthMode() === null) {
|
|
795
|
+
throw new ChatClientAuthError("Not identified. Call chat.identify() first.");
|
|
796
|
+
}
|
|
797
|
+
const teamId = await this.chat.ensureTeamId();
|
|
776
798
|
const response = await this.chat.fetch("/api/widget/tickets", {
|
|
777
799
|
method: "POST",
|
|
778
800
|
body: {
|
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). */
|