@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
|
@@ -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 };
|
package/dist/community/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,42 @@ 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 CStarError = registry.CStarError;
|
|
169
|
+
var CStarAuthenticationError = registry.CStarAuthenticationError;
|
|
170
|
+
var CStarRateLimitError = registry.CStarRateLimitError;
|
|
171
|
+
var CStarNotFoundError = registry.CStarNotFoundError;
|
|
172
|
+
var CStarValidationError = registry.CStarValidationError;
|
|
173
|
+
var CStarPermissionError = registry.CStarPermissionError;
|
|
174
|
+
var CStarConflictError = registry.CStarConflictError;
|
|
175
|
+
var CStarServerError = registry.CStarServerError;
|
|
176
|
+
var CStarFeatureDisabledError = registry.CStarFeatureDisabledError;
|
|
177
|
+
var CStarRealtimeUnavailableError = registry.CStarRealtimeUnavailableError;
|
|
142
178
|
function parsePublicError(status, body, fallbackMessage) {
|
|
143
179
|
const obj = body && typeof body === "object" ? body : null;
|
|
144
180
|
const errVal = obj?.error;
|
|
@@ -502,5 +538,18 @@ var CommunityClient = class {
|
|
|
502
538
|
}
|
|
503
539
|
};
|
|
504
540
|
export {
|
|
505
|
-
|
|
541
|
+
CStarAuthenticationError,
|
|
542
|
+
CStarConflictError,
|
|
543
|
+
CStarError,
|
|
544
|
+
CStarFeatureDisabledError,
|
|
545
|
+
CStarNotFoundError,
|
|
546
|
+
CStarPermissionError,
|
|
547
|
+
CStarRateLimitError,
|
|
548
|
+
CStarRealtimeUnavailableError,
|
|
549
|
+
CStarServerError,
|
|
550
|
+
CStarValidationError,
|
|
551
|
+
CommunityClient,
|
|
552
|
+
ErrorType,
|
|
553
|
+
parseError,
|
|
554
|
+
parsePublicError
|
|
506
555
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -74,7 +74,7 @@ function normalizeArgs(messageOrStatus, maybeBody, defaults) {
|
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
|
-
var
|
|
77
|
+
var CStarErrorImpl = class extends Error {
|
|
78
78
|
constructor(messageOrStatus, body) {
|
|
79
79
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body);
|
|
80
80
|
super(resolved.message);
|
|
@@ -87,7 +87,7 @@ var CStarError = class extends Error {
|
|
|
87
87
|
this.statusCode = statusCode;
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
|
-
var
|
|
90
|
+
var CStarAuthenticationErrorImpl = class extends CStarErrorImpl {
|
|
91
91
|
constructor(messageOrStatus, body) {
|
|
92
92
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
93
93
|
type: ErrorType.AUTHENTICATION_ERROR,
|
|
@@ -98,7 +98,7 @@ var CStarAuthenticationError = class extends CStarError {
|
|
|
98
98
|
this.name = "CStarAuthenticationError";
|
|
99
99
|
}
|
|
100
100
|
};
|
|
101
|
-
var
|
|
101
|
+
var CStarRateLimitErrorImpl = class extends CStarErrorImpl {
|
|
102
102
|
constructor(messageOrStatus, body, retryAfter) {
|
|
103
103
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
104
104
|
type: ErrorType.RATE_LIMIT_ERROR,
|
|
@@ -110,7 +110,7 @@ var CStarRateLimitError = class extends CStarError {
|
|
|
110
110
|
this.retryAfter = retryAfter ?? 60;
|
|
111
111
|
}
|
|
112
112
|
};
|
|
113
|
-
var
|
|
113
|
+
var CStarNotFoundErrorImpl = class extends CStarErrorImpl {
|
|
114
114
|
constructor(messageOrStatus, body) {
|
|
115
115
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
116
116
|
type: ErrorType.NOT_FOUND_ERROR,
|
|
@@ -121,7 +121,7 @@ var CStarNotFoundError = class extends CStarError {
|
|
|
121
121
|
this.name = "CStarNotFoundError";
|
|
122
122
|
}
|
|
123
123
|
};
|
|
124
|
-
var
|
|
124
|
+
var CStarValidationErrorImpl = class extends CStarErrorImpl {
|
|
125
125
|
constructor(messageOrStatus, body) {
|
|
126
126
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
127
127
|
type: ErrorType.INVALID_REQUEST_ERROR,
|
|
@@ -132,7 +132,7 @@ var CStarValidationError = class extends CStarError {
|
|
|
132
132
|
this.name = "CStarValidationError";
|
|
133
133
|
}
|
|
134
134
|
};
|
|
135
|
-
var
|
|
135
|
+
var CStarPermissionErrorImpl = class extends CStarErrorImpl {
|
|
136
136
|
constructor(messageOrStatus, body) {
|
|
137
137
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
138
138
|
type: ErrorType.PERMISSION_ERROR,
|
|
@@ -143,7 +143,7 @@ var CStarPermissionError = class extends CStarError {
|
|
|
143
143
|
this.name = "CStarPermissionError";
|
|
144
144
|
}
|
|
145
145
|
};
|
|
146
|
-
var
|
|
146
|
+
var CStarConflictErrorImpl = class extends CStarErrorImpl {
|
|
147
147
|
constructor(messageOrStatus, body) {
|
|
148
148
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
149
149
|
type: ErrorType.CONFLICT_ERROR,
|
|
@@ -154,7 +154,7 @@ var CStarConflictError = class extends CStarError {
|
|
|
154
154
|
this.name = "CStarConflictError";
|
|
155
155
|
}
|
|
156
156
|
};
|
|
157
|
-
var
|
|
157
|
+
var CStarServerErrorImpl = class extends CStarErrorImpl {
|
|
158
158
|
constructor(messageOrStatus, body) {
|
|
159
159
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
160
160
|
type: ErrorType.SERVER_ERROR,
|
|
@@ -165,7 +165,7 @@ var CStarServerError = class extends CStarError {
|
|
|
165
165
|
this.name = "CStarServerError";
|
|
166
166
|
}
|
|
167
167
|
};
|
|
168
|
-
var
|
|
168
|
+
var CStarFeatureDisabledErrorImpl = class extends CStarErrorImpl {
|
|
169
169
|
constructor(messageOrStatus, body) {
|
|
170
170
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
171
171
|
type: ErrorType.FEATURE_NOT_CONFIGURED,
|
|
@@ -178,6 +178,42 @@ var CStarFeatureDisabledError = class extends CStarError {
|
|
|
178
178
|
this.enableUrl = resolved.enable_url ?? "";
|
|
179
179
|
}
|
|
180
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;
|
|
181
217
|
var STATUS_TO_CLASS = {
|
|
182
218
|
400: CStarValidationError,
|
|
183
219
|
401: CStarAuthenticationError,
|
|
@@ -220,7 +256,7 @@ function parseError(statusCode, body, retryAfter) {
|
|
|
220
256
|
}
|
|
221
257
|
|
|
222
258
|
// src/client.ts
|
|
223
|
-
var SDK_VERSION = "0.
|
|
259
|
+
var SDK_VERSION = "0.15.0";
|
|
224
260
|
var DEFAULT_BASE_URL = "https://www.cstar.help";
|
|
225
261
|
var DEFAULT_API_VERSION = "2026-03-01";
|
|
226
262
|
var DEFAULT_MAX_RETRIES = 3;
|
|
@@ -465,6 +501,18 @@ var CStarRealtime = class {
|
|
|
465
501
|
this.autoReconnect = options?.autoReconnect ?? true;
|
|
466
502
|
this.maxRetries = options?.maxRetries ?? 10;
|
|
467
503
|
this.types = options?.types;
|
|
504
|
+
this.eventSourceCtor = options?.eventSource;
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Resolve the EventSource constructor to use for this connection.
|
|
508
|
+
* Returns the explicit polyfill when one was injected, otherwise the
|
|
509
|
+
* global. Returns `undefined` when neither is available — callers must
|
|
510
|
+
* convert to `CStarRealtimeUnavailableError` before touching it.
|
|
511
|
+
*/
|
|
512
|
+
resolveEventSource() {
|
|
513
|
+
if (this.eventSourceCtor) return this.eventSourceCtor;
|
|
514
|
+
const fromGlobal = globalThis.EventSource;
|
|
515
|
+
return typeof fromGlobal === "function" ? fromGlobal : void 0;
|
|
468
516
|
}
|
|
469
517
|
/** Subscribe to a specific event type. Supports wildcards (e.g., 'ticket.*'). Returns an unsubscribe function. */
|
|
470
518
|
on(eventType, handler) {
|
|
@@ -519,6 +567,9 @@ var CStarRealtime = class {
|
|
|
519
567
|
/** Start the SSE connection. Called automatically on first handler registration. */
|
|
520
568
|
connect() {
|
|
521
569
|
if (this.eventSource || this.destroyed || this.connecting) return;
|
|
570
|
+
if (!this.resolveEventSource()) {
|
|
571
|
+
throw new CStarRealtimeUnavailableError();
|
|
572
|
+
}
|
|
522
573
|
this.connecting = true;
|
|
523
574
|
const headers = this.httpClient.getAuthHeaders();
|
|
524
575
|
const rawKey = headers.Authorization?.replace("Bearer ", "") ?? "";
|
|
@@ -557,7 +608,12 @@ var CStarRealtime = class {
|
|
|
557
608
|
}
|
|
558
609
|
const separator = qs ? "&" : "?";
|
|
559
610
|
const authenticatedUrl = authToken ? `${url}${separator}token=${authToken}` : url;
|
|
560
|
-
|
|
611
|
+
const Ctor = this.resolveEventSource();
|
|
612
|
+
if (!Ctor) {
|
|
613
|
+
this.connecting = false;
|
|
614
|
+
throw new CStarRealtimeUnavailableError();
|
|
615
|
+
}
|
|
616
|
+
this.eventSource = new Ctor(authenticatedUrl);
|
|
561
617
|
this.eventSource.onopen = () => {
|
|
562
618
|
this.connecting = false;
|
|
563
619
|
this.retryCount = 0;
|
|
@@ -976,6 +1032,14 @@ var BaseResource = class {
|
|
|
976
1032
|
async del(id) {
|
|
977
1033
|
return this.client.request("DELETE", `${this.basePath}/${id}`);
|
|
978
1034
|
}
|
|
1035
|
+
/**
|
|
1036
|
+
* Delete a resource by ID. Alias for `del()` — kept because IDE
|
|
1037
|
+
* auto-complete and documentation both surface `delete` first. Closes
|
|
1038
|
+
* NEW-v2-06.
|
|
1039
|
+
*/
|
|
1040
|
+
async delete(id) {
|
|
1041
|
+
return this.del(id);
|
|
1042
|
+
}
|
|
979
1043
|
/**
|
|
980
1044
|
* Auto-paginating async iterator that yields every item across all pages.
|
|
981
1045
|
*
|