@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.
@@ -20,7 +20,20 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/library/index.ts
21
21
  var library_exports = {};
22
22
  __export(library_exports, {
23
- LibraryClient: () => LibraryClient
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,
34
+ LibraryClient: () => LibraryClient,
35
+ parseError: () => parseError,
36
+ parsePublicError: () => parsePublicError
24
37
  });
25
38
  module.exports = __toCommonJS(library_exports);
26
39
 
@@ -61,7 +74,7 @@ function normalizeArgs(messageOrStatus, maybeBody, defaults) {
61
74
  }
62
75
  };
63
76
  }
64
- var CStarError = class extends Error {
77
+ var CStarErrorImpl = class extends Error {
65
78
  constructor(messageOrStatus, body) {
66
79
  const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body);
67
80
  super(resolved.message);
@@ -74,7 +87,7 @@ var CStarError = class extends Error {
74
87
  this.statusCode = statusCode;
75
88
  }
76
89
  };
77
- var CStarAuthenticationError = class extends CStarError {
90
+ var CStarAuthenticationErrorImpl = class extends CStarErrorImpl {
78
91
  constructor(messageOrStatus, body) {
79
92
  const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
80
93
  type: ErrorType.AUTHENTICATION_ERROR,
@@ -85,7 +98,7 @@ var CStarAuthenticationError = class extends CStarError {
85
98
  this.name = "CStarAuthenticationError";
86
99
  }
87
100
  };
88
- var CStarRateLimitError = class extends CStarError {
101
+ var CStarRateLimitErrorImpl = class extends CStarErrorImpl {
89
102
  constructor(messageOrStatus, body, retryAfter) {
90
103
  const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
91
104
  type: ErrorType.RATE_LIMIT_ERROR,
@@ -97,7 +110,7 @@ var CStarRateLimitError = class extends CStarError {
97
110
  this.retryAfter = retryAfter ?? 60;
98
111
  }
99
112
  };
100
- var CStarNotFoundError = class extends CStarError {
113
+ var CStarNotFoundErrorImpl = class extends CStarErrorImpl {
101
114
  constructor(messageOrStatus, body) {
102
115
  const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
103
116
  type: ErrorType.NOT_FOUND_ERROR,
@@ -108,7 +121,7 @@ var CStarNotFoundError = class extends CStarError {
108
121
  this.name = "CStarNotFoundError";
109
122
  }
110
123
  };
111
- var CStarValidationError = class extends CStarError {
124
+ var CStarValidationErrorImpl = class extends CStarErrorImpl {
112
125
  constructor(messageOrStatus, body) {
113
126
  const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
114
127
  type: ErrorType.INVALID_REQUEST_ERROR,
@@ -119,7 +132,7 @@ var CStarValidationError = class extends CStarError {
119
132
  this.name = "CStarValidationError";
120
133
  }
121
134
  };
122
- var CStarPermissionError = class extends CStarError {
135
+ var CStarPermissionErrorImpl = class extends CStarErrorImpl {
123
136
  constructor(messageOrStatus, body) {
124
137
  const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
125
138
  type: ErrorType.PERMISSION_ERROR,
@@ -130,7 +143,7 @@ var CStarPermissionError = class extends CStarError {
130
143
  this.name = "CStarPermissionError";
131
144
  }
132
145
  };
133
- var CStarConflictError = class extends CStarError {
146
+ var CStarConflictErrorImpl = class extends CStarErrorImpl {
134
147
  constructor(messageOrStatus, body) {
135
148
  const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
136
149
  type: ErrorType.CONFLICT_ERROR,
@@ -141,7 +154,7 @@ var CStarConflictError = class extends CStarError {
141
154
  this.name = "CStarConflictError";
142
155
  }
143
156
  };
144
- var CStarServerError = class extends CStarError {
157
+ var CStarServerErrorImpl = class extends CStarErrorImpl {
145
158
  constructor(messageOrStatus, body) {
146
159
  const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
147
160
  type: ErrorType.SERVER_ERROR,
@@ -152,7 +165,7 @@ var CStarServerError = class extends CStarError {
152
165
  this.name = "CStarServerError";
153
166
  }
154
167
  };
155
- var CStarFeatureDisabledError = class extends CStarError {
168
+ var CStarFeatureDisabledErrorImpl = class extends CStarErrorImpl {
156
169
  constructor(messageOrStatus, body) {
157
170
  const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
158
171
  type: ErrorType.FEATURE_NOT_CONFIGURED,
@@ -165,6 +178,42 @@ var CStarFeatureDisabledError = class extends CStarError {
165
178
  this.enableUrl = resolved.enable_url ?? "";
166
179
  }
167
180
  };
181
+ var CStarRealtimeUnavailableErrorImpl = class extends CStarErrorImpl {
182
+ constructor(message) {
183
+ const resolved = message ?? "EventSource is not available in this environment. Real-time subscriptions only work in the browser. Move the call to a client-only path (`useEffect` / `onMount`), or pass an `eventSource` polyfill via the realtime options. See https://cstar.help/developers/sdk/realtime#ssr";
184
+ super(0, {
185
+ type: ErrorType.API_ERROR,
186
+ code: "realtime_unavailable",
187
+ message: resolved,
188
+ doc_url: "https://cstar.help/developers/sdk/realtime#ssr"
189
+ });
190
+ this.name = "CStarRealtimeUnavailableError";
191
+ }
192
+ };
193
+ var REGISTRY_KEY = /* @__PURE__ */ Symbol.for("@cstar.help/js/errors/v1");
194
+ var globalSlot = globalThis;
195
+ var registry = globalSlot[REGISTRY_KEY] ?? (globalSlot[REGISTRY_KEY] = {
196
+ CStarError: CStarErrorImpl,
197
+ CStarAuthenticationError: CStarAuthenticationErrorImpl,
198
+ CStarRateLimitError: CStarRateLimitErrorImpl,
199
+ CStarNotFoundError: CStarNotFoundErrorImpl,
200
+ CStarValidationError: CStarValidationErrorImpl,
201
+ CStarPermissionError: CStarPermissionErrorImpl,
202
+ CStarConflictError: CStarConflictErrorImpl,
203
+ CStarServerError: CStarServerErrorImpl,
204
+ CStarFeatureDisabledError: CStarFeatureDisabledErrorImpl,
205
+ CStarRealtimeUnavailableError: CStarRealtimeUnavailableErrorImpl
206
+ });
207
+ var CStarError = registry.CStarError;
208
+ var CStarAuthenticationError = registry.CStarAuthenticationError;
209
+ var CStarRateLimitError = registry.CStarRateLimitError;
210
+ var CStarNotFoundError = registry.CStarNotFoundError;
211
+ var CStarValidationError = registry.CStarValidationError;
212
+ var CStarPermissionError = registry.CStarPermissionError;
213
+ var CStarConflictError = registry.CStarConflictError;
214
+ var CStarServerError = registry.CStarServerError;
215
+ var CStarFeatureDisabledError = registry.CStarFeatureDisabledError;
216
+ var CStarRealtimeUnavailableError = registry.CStarRealtimeUnavailableError;
168
217
  function parsePublicError(status, body, fallbackMessage) {
169
218
  const obj = body && typeof body === "object" ? body : null;
170
219
  const errVal = obj?.error;
@@ -402,5 +451,18 @@ var LibraryClient = class {
402
451
  };
403
452
  // Annotate the CommonJS export names for ESM import in node:
404
453
  0 && (module.exports = {
405
- LibraryClient
454
+ CStarAuthenticationError,
455
+ CStarConflictError,
456
+ CStarError,
457
+ CStarFeatureDisabledError,
458
+ CStarNotFoundError,
459
+ CStarPermissionError,
460
+ CStarRateLimitError,
461
+ CStarRealtimeUnavailableError,
462
+ CStarServerError,
463
+ CStarValidationError,
464
+ ErrorType,
465
+ LibraryClient,
466
+ parseError,
467
+ parsePublicError
406
468
  });
@@ -88,6 +88,126 @@ interface ArticleFeedbackResult {
88
88
  error?: string;
89
89
  }
90
90
 
91
+ /**
92
+ * Error classes for the cStar SDK.
93
+ *
94
+ * NEW-v3-01 — Cross-subpath instanceof identity.
95
+ *
96
+ * Each public subpath (`/library`, `/auth`, `/community`, `/quickhelp`, ...)
97
+ * is bundled as a separate tsup entry with `splitting: false`, so each one
98
+ * carries its own copy of this module. Without deduplication, errors thrown
99
+ * by `LibraryClient` carry the LibraryClient-bundled `CStarError` class —
100
+ * not the one a consumer imports from `@cstar.help/js`. That makes
101
+ * `instanceof CStarError` checks fail silently, invalidating every "did the
102
+ * SDK throw a typed cStar error?" branch in user code.
103
+ *
104
+ * Fix: register each class on a `Symbol.for(...)` slot of `globalThis`. The
105
+ * symbol is realm-shared, so every bundled copy of this module resolves to
106
+ * the SAME class identity at runtime — the first copy to load wins, and all
107
+ * subsequent copies surface the canonical class via the same slot. The
108
+ * inline `Impl` definitions are only used as the seed for the very first
109
+ * copy to register. Internal `parseError` / `parsePublicError` reference the
110
+ * EXPORTED canonical names so instances they construct also land on the
111
+ * canonical class.
112
+ */
113
+ /** Error type constants matching the cStar API. */
114
+ declare const ErrorType: {
115
+ readonly AUTHENTICATION_ERROR: "authentication_error";
116
+ readonly PERMISSION_ERROR: "permission_error";
117
+ readonly INVALID_REQUEST_ERROR: "invalid_request_error";
118
+ readonly NOT_FOUND_ERROR: "not_found_error";
119
+ readonly CONFLICT_ERROR: "conflict_error";
120
+ readonly RATE_LIMIT_ERROR: "rate_limit_error";
121
+ readonly FEATURE_NOT_CONFIGURED: "feature_not_configured";
122
+ readonly API_ERROR: "api_error";
123
+ readonly SERVER_ERROR: "server_error";
124
+ };
125
+ /** Shape of the error object returned by the cStar API. */
126
+ interface ApiErrorBody {
127
+ type: string;
128
+ code: string;
129
+ message: string;
130
+ param?: string;
131
+ doc_url: string;
132
+ request_id?: string;
133
+ feature?: string;
134
+ enable_url?: string;
135
+ }
136
+ /** Base error class for all cStar API errors. */
137
+ declare class CStarErrorImpl extends Error {
138
+ readonly type: string;
139
+ readonly code: string;
140
+ readonly param?: string;
141
+ readonly docUrl: string;
142
+ readonly requestId?: string;
143
+ readonly statusCode: number;
144
+ constructor(messageOrStatus: string | number, body?: ApiErrorBody);
145
+ }
146
+ declare class CStarAuthenticationErrorImpl extends CStarErrorImpl {
147
+ constructor(messageOrStatus: string | number, body?: ApiErrorBody);
148
+ }
149
+ declare class CStarRateLimitErrorImpl extends CStarErrorImpl {
150
+ readonly retryAfter: number;
151
+ constructor(messageOrStatus: string | number, body?: ApiErrorBody, retryAfter?: number);
152
+ }
153
+ declare class CStarNotFoundErrorImpl extends CStarErrorImpl {
154
+ constructor(messageOrStatus: string | number, body?: ApiErrorBody);
155
+ }
156
+ declare class CStarValidationErrorImpl extends CStarErrorImpl {
157
+ constructor(messageOrStatus: string | number, body?: ApiErrorBody);
158
+ }
159
+ declare class CStarPermissionErrorImpl extends CStarErrorImpl {
160
+ constructor(messageOrStatus: string | number, body?: ApiErrorBody);
161
+ }
162
+ declare class CStarConflictErrorImpl extends CStarErrorImpl {
163
+ constructor(messageOrStatus: string | number, body?: ApiErrorBody);
164
+ }
165
+ declare class CStarServerErrorImpl extends CStarErrorImpl {
166
+ constructor(messageOrStatus: string | number, body?: ApiErrorBody);
167
+ }
168
+ declare class CStarFeatureDisabledErrorImpl extends CStarErrorImpl {
169
+ readonly feature: string;
170
+ readonly enableUrl: string;
171
+ constructor(messageOrStatus: string | number, body?: ApiErrorBody);
172
+ }
173
+ declare class CStarRealtimeUnavailableErrorImpl extends CStarErrorImpl {
174
+ constructor(message?: string);
175
+ }
176
+ declare const CStarError: typeof CStarErrorImpl;
177
+ type CStarError = InstanceType<typeof CStarErrorImpl>;
178
+ declare const CStarAuthenticationError: typeof CStarAuthenticationErrorImpl;
179
+ type CStarAuthenticationError = InstanceType<typeof CStarAuthenticationErrorImpl>;
180
+ declare const CStarRateLimitError: typeof CStarRateLimitErrorImpl;
181
+ type CStarRateLimitError = InstanceType<typeof CStarRateLimitErrorImpl>;
182
+ declare const CStarNotFoundError: typeof CStarNotFoundErrorImpl;
183
+ type CStarNotFoundError = InstanceType<typeof CStarNotFoundErrorImpl>;
184
+ declare const CStarValidationError: typeof CStarValidationErrorImpl;
185
+ type CStarValidationError = InstanceType<typeof CStarValidationErrorImpl>;
186
+ declare const CStarPermissionError: typeof CStarPermissionErrorImpl;
187
+ type CStarPermissionError = InstanceType<typeof CStarPermissionErrorImpl>;
188
+ declare const CStarConflictError: typeof CStarConflictErrorImpl;
189
+ type CStarConflictError = InstanceType<typeof CStarConflictErrorImpl>;
190
+ declare const CStarServerError: typeof CStarServerErrorImpl;
191
+ type CStarServerError = InstanceType<typeof CStarServerErrorImpl>;
192
+ declare const CStarFeatureDisabledError: typeof CStarFeatureDisabledErrorImpl;
193
+ type CStarFeatureDisabledError = InstanceType<typeof CStarFeatureDisabledErrorImpl>;
194
+ declare const CStarRealtimeUnavailableError: typeof CStarRealtimeUnavailableErrorImpl;
195
+ type CStarRealtimeUnavailableError = InstanceType<typeof CStarRealtimeUnavailableErrorImpl>;
196
+ /**
197
+ * Parse a public-route response (anonymous LibraryClient, CommunityClient,
198
+ * QuickHelpClient, AuthClient) into a typed `CStarError`.
199
+ *
200
+ * Public routes don't always emit the structured `{error: {type, code,
201
+ * doc_url, ...}}` envelope — many emit `{error: 'message string'}` or
202
+ * `{message: '...'}`. This helper normalizes both shapes and dispatches
203
+ * on HTTP status (closes F-026 and F-034 — Library/Auth used to throw
204
+ * plain `Error`).
205
+ */
206
+ declare function parsePublicError(status: number, body: unknown, fallbackMessage: string): CStarError;
207
+ declare function parseError(statusCode: number, body: {
208
+ error?: ApiErrorBody;
209
+ } | null, retryAfter?: number): CStarError;
210
+
91
211
  /**
92
212
  * Public knowledge base client. Authentication is optional — supply a
93
213
  * publishable key (`pk_test_*` or `pk_live_*`) to switch the data scope
@@ -155,4 +275,4 @@ declare class LibraryClient {
155
275
  private fetch;
156
276
  }
157
277
 
158
- export { type ArticleFeedbackParams, type ArticleFeedbackResult, type Category, type LibraryArticle, type LibraryArticleListParams, LibraryClient, type LibraryConfig, type LibrarySearchParams, type LibrarySearchResult, type LibraryStats };
278
+ export { type ApiErrorBody, type ArticleFeedbackParams, type ArticleFeedbackResult, CStarAuthenticationError, CStarConflictError, CStarError, CStarFeatureDisabledError, CStarNotFoundError, CStarPermissionError, CStarRateLimitError, CStarRealtimeUnavailableError, CStarServerError, CStarValidationError, type Category, ErrorType, type LibraryArticle, type LibraryArticleListParams, LibraryClient, type LibraryConfig, type LibrarySearchParams, type LibrarySearchResult, type LibraryStats, parseError, parsePublicError };
@@ -88,6 +88,126 @@ interface ArticleFeedbackResult {
88
88
  error?: string;
89
89
  }
90
90
 
91
+ /**
92
+ * Error classes for the cStar SDK.
93
+ *
94
+ * NEW-v3-01 — Cross-subpath instanceof identity.
95
+ *
96
+ * Each public subpath (`/library`, `/auth`, `/community`, `/quickhelp`, ...)
97
+ * is bundled as a separate tsup entry with `splitting: false`, so each one
98
+ * carries its own copy of this module. Without deduplication, errors thrown
99
+ * by `LibraryClient` carry the LibraryClient-bundled `CStarError` class —
100
+ * not the one a consumer imports from `@cstar.help/js`. That makes
101
+ * `instanceof CStarError` checks fail silently, invalidating every "did the
102
+ * SDK throw a typed cStar error?" branch in user code.
103
+ *
104
+ * Fix: register each class on a `Symbol.for(...)` slot of `globalThis`. The
105
+ * symbol is realm-shared, so every bundled copy of this module resolves to
106
+ * the SAME class identity at runtime — the first copy to load wins, and all
107
+ * subsequent copies surface the canonical class via the same slot. The
108
+ * inline `Impl` definitions are only used as the seed for the very first
109
+ * copy to register. Internal `parseError` / `parsePublicError` reference the
110
+ * EXPORTED canonical names so instances they construct also land on the
111
+ * canonical class.
112
+ */
113
+ /** Error type constants matching the cStar API. */
114
+ declare const ErrorType: {
115
+ readonly AUTHENTICATION_ERROR: "authentication_error";
116
+ readonly PERMISSION_ERROR: "permission_error";
117
+ readonly INVALID_REQUEST_ERROR: "invalid_request_error";
118
+ readonly NOT_FOUND_ERROR: "not_found_error";
119
+ readonly CONFLICT_ERROR: "conflict_error";
120
+ readonly RATE_LIMIT_ERROR: "rate_limit_error";
121
+ readonly FEATURE_NOT_CONFIGURED: "feature_not_configured";
122
+ readonly API_ERROR: "api_error";
123
+ readonly SERVER_ERROR: "server_error";
124
+ };
125
+ /** Shape of the error object returned by the cStar API. */
126
+ interface ApiErrorBody {
127
+ type: string;
128
+ code: string;
129
+ message: string;
130
+ param?: string;
131
+ doc_url: string;
132
+ request_id?: string;
133
+ feature?: string;
134
+ enable_url?: string;
135
+ }
136
+ /** Base error class for all cStar API errors. */
137
+ declare class CStarErrorImpl extends Error {
138
+ readonly type: string;
139
+ readonly code: string;
140
+ readonly param?: string;
141
+ readonly docUrl: string;
142
+ readonly requestId?: string;
143
+ readonly statusCode: number;
144
+ constructor(messageOrStatus: string | number, body?: ApiErrorBody);
145
+ }
146
+ declare class CStarAuthenticationErrorImpl extends CStarErrorImpl {
147
+ constructor(messageOrStatus: string | number, body?: ApiErrorBody);
148
+ }
149
+ declare class CStarRateLimitErrorImpl extends CStarErrorImpl {
150
+ readonly retryAfter: number;
151
+ constructor(messageOrStatus: string | number, body?: ApiErrorBody, retryAfter?: number);
152
+ }
153
+ declare class CStarNotFoundErrorImpl extends CStarErrorImpl {
154
+ constructor(messageOrStatus: string | number, body?: ApiErrorBody);
155
+ }
156
+ declare class CStarValidationErrorImpl extends CStarErrorImpl {
157
+ constructor(messageOrStatus: string | number, body?: ApiErrorBody);
158
+ }
159
+ declare class CStarPermissionErrorImpl extends CStarErrorImpl {
160
+ constructor(messageOrStatus: string | number, body?: ApiErrorBody);
161
+ }
162
+ declare class CStarConflictErrorImpl extends CStarErrorImpl {
163
+ constructor(messageOrStatus: string | number, body?: ApiErrorBody);
164
+ }
165
+ declare class CStarServerErrorImpl extends CStarErrorImpl {
166
+ constructor(messageOrStatus: string | number, body?: ApiErrorBody);
167
+ }
168
+ declare class CStarFeatureDisabledErrorImpl extends CStarErrorImpl {
169
+ readonly feature: string;
170
+ readonly enableUrl: string;
171
+ constructor(messageOrStatus: string | number, body?: ApiErrorBody);
172
+ }
173
+ declare class CStarRealtimeUnavailableErrorImpl extends CStarErrorImpl {
174
+ constructor(message?: string);
175
+ }
176
+ declare const CStarError: typeof CStarErrorImpl;
177
+ type CStarError = InstanceType<typeof CStarErrorImpl>;
178
+ declare const CStarAuthenticationError: typeof CStarAuthenticationErrorImpl;
179
+ type CStarAuthenticationError = InstanceType<typeof CStarAuthenticationErrorImpl>;
180
+ declare const CStarRateLimitError: typeof CStarRateLimitErrorImpl;
181
+ type CStarRateLimitError = InstanceType<typeof CStarRateLimitErrorImpl>;
182
+ declare const CStarNotFoundError: typeof CStarNotFoundErrorImpl;
183
+ type CStarNotFoundError = InstanceType<typeof CStarNotFoundErrorImpl>;
184
+ declare const CStarValidationError: typeof CStarValidationErrorImpl;
185
+ type CStarValidationError = InstanceType<typeof CStarValidationErrorImpl>;
186
+ declare const CStarPermissionError: typeof CStarPermissionErrorImpl;
187
+ type CStarPermissionError = InstanceType<typeof CStarPermissionErrorImpl>;
188
+ declare const CStarConflictError: typeof CStarConflictErrorImpl;
189
+ type CStarConflictError = InstanceType<typeof CStarConflictErrorImpl>;
190
+ declare const CStarServerError: typeof CStarServerErrorImpl;
191
+ type CStarServerError = InstanceType<typeof CStarServerErrorImpl>;
192
+ declare const CStarFeatureDisabledError: typeof CStarFeatureDisabledErrorImpl;
193
+ type CStarFeatureDisabledError = InstanceType<typeof CStarFeatureDisabledErrorImpl>;
194
+ declare const CStarRealtimeUnavailableError: typeof CStarRealtimeUnavailableErrorImpl;
195
+ type CStarRealtimeUnavailableError = InstanceType<typeof CStarRealtimeUnavailableErrorImpl>;
196
+ /**
197
+ * Parse a public-route response (anonymous LibraryClient, CommunityClient,
198
+ * QuickHelpClient, AuthClient) into a typed `CStarError`.
199
+ *
200
+ * Public routes don't always emit the structured `{error: {type, code,
201
+ * doc_url, ...}}` envelope — many emit `{error: 'message string'}` or
202
+ * `{message: '...'}`. This helper normalizes both shapes and dispatches
203
+ * on HTTP status (closes F-026 and F-034 — Library/Auth used to throw
204
+ * plain `Error`).
205
+ */
206
+ declare function parsePublicError(status: number, body: unknown, fallbackMessage: string): CStarError;
207
+ declare function parseError(statusCode: number, body: {
208
+ error?: ApiErrorBody;
209
+ } | null, retryAfter?: number): CStarError;
210
+
91
211
  /**
92
212
  * Public knowledge base client. Authentication is optional — supply a
93
213
  * publishable key (`pk_test_*` or `pk_live_*`) to switch the data scope
@@ -155,4 +275,4 @@ declare class LibraryClient {
155
275
  private fetch;
156
276
  }
157
277
 
158
- export { type ArticleFeedbackParams, type ArticleFeedbackResult, type Category, type LibraryArticle, type LibraryArticleListParams, LibraryClient, type LibraryConfig, type LibrarySearchParams, type LibrarySearchResult, type LibraryStats };
278
+ export { type ApiErrorBody, type ArticleFeedbackParams, type ArticleFeedbackResult, CStarAuthenticationError, CStarConflictError, CStarError, CStarFeatureDisabledError, CStarNotFoundError, CStarPermissionError, CStarRateLimitError, CStarRealtimeUnavailableError, CStarServerError, CStarValidationError, type Category, ErrorType, type LibraryArticle, type LibraryArticleListParams, LibraryClient, type LibraryConfig, type LibrarySearchParams, type LibrarySearchResult, type LibraryStats, parseError, parsePublicError };
@@ -35,7 +35,7 @@ function normalizeArgs(messageOrStatus, maybeBody, defaults) {
35
35
  }
36
36
  };
37
37
  }
38
- var CStarError = class extends Error {
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 CStarAuthenticationError = class extends CStarError {
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 CStarRateLimitError = class extends CStarError {
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 CStarNotFoundError = class extends CStarError {
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 CStarValidationError = class extends CStarError {
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 CStarPermissionError = class extends CStarError {
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 CStarConflictError = class extends CStarError {
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 CStarServerError = class extends CStarError {
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 CStarFeatureDisabledError = class extends CStarError {
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;
@@ -375,5 +411,18 @@ var LibraryClient = class {
375
411
  }
376
412
  };
377
413
  export {
378
- LibraryClient
414
+ CStarAuthenticationError,
415
+ CStarConflictError,
416
+ CStarError,
417
+ CStarFeatureDisabledError,
418
+ CStarNotFoundError,
419
+ CStarPermissionError,
420
+ CStarRateLimitError,
421
+ CStarRealtimeUnavailableError,
422
+ CStarServerError,
423
+ CStarValidationError,
424
+ ErrorType,
425
+ LibraryClient,
426
+ parseError,
427
+ parsePublicError
379
428
  };