@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/index.d.cts CHANGED
@@ -134,6 +134,13 @@ declare class HttpClient {
134
134
  private sleep;
135
135
  }
136
136
 
137
+ /**
138
+ * The subset of the global `EventSource` constructor surface that the
139
+ * realtime client uses. Allows polyfill injection (e.g. the `eventsource`
140
+ * npm package on Node) without forcing the polyfill to satisfy the full
141
+ * lib.dom.d.ts shape.
142
+ */
143
+ type EventSourceConstructor = new (url: string) => EventSource;
137
144
  /** Options for configuring the realtime connection. */
138
145
  interface RealtimeOptions {
139
146
  /** Event types to subscribe to (e.g., ['ticket.*', 'boss.*']). Omit for all. */
@@ -142,6 +149,13 @@ interface RealtimeOptions {
142
149
  autoReconnect?: boolean;
143
150
  /** Max reconnection attempts before giving up (default: 10). */
144
151
  maxRetries?: number;
152
+ /**
153
+ * EventSource constructor to use. Defaults to `globalThis.EventSource`
154
+ * (browsers and Node 22+). Pass an explicit polyfill (e.g. the
155
+ * `eventsource` npm package) to subscribe from a Node environment that
156
+ * lacks the global. Closes NEW-v2-02.
157
+ */
158
+ eventSource?: EventSourceConstructor;
145
159
  }
146
160
  /** A parsed realtime event from the SSE stream. */
147
161
  interface RealtimeEvent<T = unknown> {
@@ -189,7 +203,15 @@ declare class CStarRealtime {
189
203
  private readonly autoReconnect;
190
204
  private readonly maxRetries;
191
205
  private readonly types;
206
+ private readonly eventSourceCtor;
192
207
  constructor(httpClient: HttpClient, options?: RealtimeOptions);
208
+ /**
209
+ * Resolve the EventSource constructor to use for this connection.
210
+ * Returns the explicit polyfill when one was injected, otherwise the
211
+ * global. Returns `undefined` when neither is available — callers must
212
+ * convert to `CStarRealtimeUnavailableError` before touching it.
213
+ */
214
+ private resolveEventSource;
193
215
  /** Subscribe to a specific event type. Supports wildcards (e.g., 'ticket.*'). Returns an unsubscribe function. */
194
216
  on<T = unknown>(eventType: string, handler: EventHandler<T>): () => void;
195
217
  /** Subscribe to all events. Returns an unsubscribe function. */
@@ -393,6 +415,12 @@ declare abstract class BaseResource<TEntity, TListParams extends PaginationParam
393
415
  update(id: string, params: TUpdateParams, options?: RequestOptions): Promise<TEntity>;
394
416
  /** Delete a resource by ID. */
395
417
  del(id: string): Promise<DeleteResponse>;
418
+ /**
419
+ * Delete a resource by ID. Alias for `del()` — kept because IDE
420
+ * auto-complete and documentation both surface `delete` first. Closes
421
+ * NEW-v2-06.
422
+ */
423
+ delete(id: string): Promise<DeleteResponse>;
396
424
  /**
397
425
  * Auto-paginating async iterator that yields every item across all pages.
398
426
  *
@@ -989,7 +1017,15 @@ interface Webhook {
989
1017
  metadata: Metadata;
990
1018
  createdAt: string;
991
1019
  updatedAt: string;
992
- /** Only returned on creation (POST). */
1020
+ /**
1021
+ * Signing secret for HMAC verification (`whsec_*`). Only returned on
1022
+ * creation (POST `/webhooks`). Save it immediately — subsequent reads
1023
+ * will not include it. Use it as the `secret` argument to
1024
+ * `constructEvent` / `verifySignature` from `@cstar.help/js/webhook`.
1025
+ */
1026
+ signingSecret?: string;
1027
+ /** @deprecated since 0.15.0 — use {@link signingSecret} instead. Kept
1028
+ * during the deprecation window so 0.14.x consumers keep working. */
993
1029
  secret?: string;
994
1030
  }
995
1031
  /** Parameters for listing webhooks. */
@@ -3028,6 +3064,28 @@ declare class OfflineQueue {
3028
3064
  private loadFromStorage;
3029
3065
  }
3030
3066
 
3067
+ /**
3068
+ * Error classes for the cStar SDK.
3069
+ *
3070
+ * NEW-v3-01 — Cross-subpath instanceof identity.
3071
+ *
3072
+ * Each public subpath (`/library`, `/auth`, `/community`, `/quickhelp`, ...)
3073
+ * is bundled as a separate tsup entry with `splitting: false`, so each one
3074
+ * carries its own copy of this module. Without deduplication, errors thrown
3075
+ * by `LibraryClient` carry the LibraryClient-bundled `CStarError` class —
3076
+ * not the one a consumer imports from `@cstar.help/js`. That makes
3077
+ * `instanceof CStarError` checks fail silently, invalidating every "did the
3078
+ * SDK throw a typed cStar error?" branch in user code.
3079
+ *
3080
+ * Fix: register each class on a `Symbol.for(...)` slot of `globalThis`. The
3081
+ * symbol is realm-shared, so every bundled copy of this module resolves to
3082
+ * the SAME class identity at runtime — the first copy to load wins, and all
3083
+ * subsequent copies surface the canonical class via the same slot. The
3084
+ * inline `Impl` definitions are only used as the seed for the very first
3085
+ * copy to register. Internal `parseError` / `parsePublicError` reference the
3086
+ * EXPORTED canonical names so instances they construct also land on the
3087
+ * canonical class.
3088
+ */
3031
3089
  /** Error type constants matching the cStar API. */
3032
3090
  declare const ErrorType: {
3033
3091
  readonly AUTHENTICATION_ERROR: "authentication_error";
@@ -3052,7 +3110,7 @@ interface ApiErrorBody {
3052
3110
  enable_url?: string;
3053
3111
  }
3054
3112
  /** Base error class for all cStar API errors. */
3055
- declare class CStarError extends Error {
3113
+ declare class CStarErrorImpl extends Error {
3056
3114
  readonly type: string;
3057
3115
  readonly code: string;
3058
3116
  readonly param?: string;
@@ -3061,49 +3119,51 @@ declare class CStarError extends Error {
3061
3119
  readonly statusCode: number;
3062
3120
  constructor(messageOrStatus: string | number, body?: ApiErrorBody);
3063
3121
  }
3064
- /** Thrown when authentication fails (401). */
3065
- declare class CStarAuthenticationError extends CStarError {
3122
+ declare class CStarAuthenticationErrorImpl extends CStarErrorImpl {
3066
3123
  constructor(messageOrStatus: string | number, body?: ApiErrorBody);
3067
3124
  }
3068
- /** Thrown when rate limited (429). Includes retry timing. */
3069
- declare class CStarRateLimitError extends CStarError {
3125
+ declare class CStarRateLimitErrorImpl extends CStarErrorImpl {
3070
3126
  readonly retryAfter: number;
3071
3127
  constructor(messageOrStatus: string | number, body?: ApiErrorBody, retryAfter?: number);
3072
3128
  }
3073
- /** Thrown when a resource is not found (404). */
3074
- declare class CStarNotFoundError extends CStarError {
3129
+ declare class CStarNotFoundErrorImpl extends CStarErrorImpl {
3075
3130
  constructor(messageOrStatus: string | number, body?: ApiErrorBody);
3076
3131
  }
3077
- /** Thrown on invalid request parameters (400/422). */
3078
- declare class CStarValidationError extends CStarError {
3132
+ declare class CStarValidationErrorImpl extends CStarErrorImpl {
3079
3133
  constructor(messageOrStatus: string | number, body?: ApiErrorBody);
3080
3134
  }
3081
- /** Thrown when authenticated but lacking permission (403). */
3082
- declare class CStarPermissionError extends CStarError {
3135
+ declare class CStarPermissionErrorImpl extends CStarErrorImpl {
3083
3136
  constructor(messageOrStatus: string | number, body?: ApiErrorBody);
3084
3137
  }
3085
- /** Thrown on resource conflicts (409). */
3086
- declare class CStarConflictError extends CStarError {
3138
+ declare class CStarConflictErrorImpl extends CStarErrorImpl {
3087
3139
  constructor(messageOrStatus: string | number, body?: ApiErrorBody);
3088
3140
  }
3089
- /** Thrown on internal server errors (500+). */
3090
- declare class CStarServerError extends CStarError {
3141
+ declare class CStarServerErrorImpl extends CStarErrorImpl {
3091
3142
  constructor(messageOrStatus: string | number, body?: ApiErrorBody);
3092
3143
  }
3093
- /**
3094
- * Thrown when the call landed on a feature that the team has not enabled
3095
- * or configured (e.g. Quick Help on a team without an AI agent). Carries
3096
- * `feature` and `enableUrl` so the caller can route the user to the
3097
- * dashboard setting that fixes it.
3098
- *
3099
- * Closes F-031 — anonymous QuickHelp `.ask()` previously surfaced as an
3100
- * unactionable 503.
3101
- */
3102
- declare class CStarFeatureDisabledError extends CStarError {
3144
+ declare class CStarFeatureDisabledErrorImpl extends CStarErrorImpl {
3103
3145
  readonly feature: string;
3104
3146
  readonly enableUrl: string;
3105
3147
  constructor(messageOrStatus: string | number, body?: ApiErrorBody);
3106
3148
  }
3149
+ declare const CStarError: typeof CStarErrorImpl;
3150
+ type CStarError = InstanceType<typeof CStarErrorImpl>;
3151
+ declare const CStarAuthenticationError: typeof CStarAuthenticationErrorImpl;
3152
+ type CStarAuthenticationError = InstanceType<typeof CStarAuthenticationErrorImpl>;
3153
+ declare const CStarRateLimitError: typeof CStarRateLimitErrorImpl;
3154
+ type CStarRateLimitError = InstanceType<typeof CStarRateLimitErrorImpl>;
3155
+ declare const CStarNotFoundError: typeof CStarNotFoundErrorImpl;
3156
+ type CStarNotFoundError = InstanceType<typeof CStarNotFoundErrorImpl>;
3157
+ declare const CStarValidationError: typeof CStarValidationErrorImpl;
3158
+ type CStarValidationError = InstanceType<typeof CStarValidationErrorImpl>;
3159
+ declare const CStarPermissionError: typeof CStarPermissionErrorImpl;
3160
+ type CStarPermissionError = InstanceType<typeof CStarPermissionErrorImpl>;
3161
+ declare const CStarConflictError: typeof CStarConflictErrorImpl;
3162
+ type CStarConflictError = InstanceType<typeof CStarConflictErrorImpl>;
3163
+ declare const CStarServerError: typeof CStarServerErrorImpl;
3164
+ type CStarServerError = InstanceType<typeof CStarServerErrorImpl>;
3165
+ declare const CStarFeatureDisabledError: typeof CStarFeatureDisabledErrorImpl;
3166
+ type CStarFeatureDisabledError = InstanceType<typeof CStarFeatureDisabledErrorImpl>;
3107
3167
 
3108
3168
  /** Configuration for the CStarClient. */
3109
3169
  interface CStarClientConfig {
package/dist/index.d.ts CHANGED
@@ -134,6 +134,13 @@ declare class HttpClient {
134
134
  private sleep;
135
135
  }
136
136
 
137
+ /**
138
+ * The subset of the global `EventSource` constructor surface that the
139
+ * realtime client uses. Allows polyfill injection (e.g. the `eventsource`
140
+ * npm package on Node) without forcing the polyfill to satisfy the full
141
+ * lib.dom.d.ts shape.
142
+ */
143
+ type EventSourceConstructor = new (url: string) => EventSource;
137
144
  /** Options for configuring the realtime connection. */
138
145
  interface RealtimeOptions {
139
146
  /** Event types to subscribe to (e.g., ['ticket.*', 'boss.*']). Omit for all. */
@@ -142,6 +149,13 @@ interface RealtimeOptions {
142
149
  autoReconnect?: boolean;
143
150
  /** Max reconnection attempts before giving up (default: 10). */
144
151
  maxRetries?: number;
152
+ /**
153
+ * EventSource constructor to use. Defaults to `globalThis.EventSource`
154
+ * (browsers and Node 22+). Pass an explicit polyfill (e.g. the
155
+ * `eventsource` npm package) to subscribe from a Node environment that
156
+ * lacks the global. Closes NEW-v2-02.
157
+ */
158
+ eventSource?: EventSourceConstructor;
145
159
  }
146
160
  /** A parsed realtime event from the SSE stream. */
147
161
  interface RealtimeEvent<T = unknown> {
@@ -189,7 +203,15 @@ declare class CStarRealtime {
189
203
  private readonly autoReconnect;
190
204
  private readonly maxRetries;
191
205
  private readonly types;
206
+ private readonly eventSourceCtor;
192
207
  constructor(httpClient: HttpClient, options?: RealtimeOptions);
208
+ /**
209
+ * Resolve the EventSource constructor to use for this connection.
210
+ * Returns the explicit polyfill when one was injected, otherwise the
211
+ * global. Returns `undefined` when neither is available — callers must
212
+ * convert to `CStarRealtimeUnavailableError` before touching it.
213
+ */
214
+ private resolveEventSource;
193
215
  /** Subscribe to a specific event type. Supports wildcards (e.g., 'ticket.*'). Returns an unsubscribe function. */
194
216
  on<T = unknown>(eventType: string, handler: EventHandler<T>): () => void;
195
217
  /** Subscribe to all events. Returns an unsubscribe function. */
@@ -393,6 +415,12 @@ declare abstract class BaseResource<TEntity, TListParams extends PaginationParam
393
415
  update(id: string, params: TUpdateParams, options?: RequestOptions): Promise<TEntity>;
394
416
  /** Delete a resource by ID. */
395
417
  del(id: string): Promise<DeleteResponse>;
418
+ /**
419
+ * Delete a resource by ID. Alias for `del()` — kept because IDE
420
+ * auto-complete and documentation both surface `delete` first. Closes
421
+ * NEW-v2-06.
422
+ */
423
+ delete(id: string): Promise<DeleteResponse>;
396
424
  /**
397
425
  * Auto-paginating async iterator that yields every item across all pages.
398
426
  *
@@ -989,7 +1017,15 @@ interface Webhook {
989
1017
  metadata: Metadata;
990
1018
  createdAt: string;
991
1019
  updatedAt: string;
992
- /** Only returned on creation (POST). */
1020
+ /**
1021
+ * Signing secret for HMAC verification (`whsec_*`). Only returned on
1022
+ * creation (POST `/webhooks`). Save it immediately — subsequent reads
1023
+ * will not include it. Use it as the `secret` argument to
1024
+ * `constructEvent` / `verifySignature` from `@cstar.help/js/webhook`.
1025
+ */
1026
+ signingSecret?: string;
1027
+ /** @deprecated since 0.15.0 — use {@link signingSecret} instead. Kept
1028
+ * during the deprecation window so 0.14.x consumers keep working. */
993
1029
  secret?: string;
994
1030
  }
995
1031
  /** Parameters for listing webhooks. */
@@ -3028,6 +3064,28 @@ declare class OfflineQueue {
3028
3064
  private loadFromStorage;
3029
3065
  }
3030
3066
 
3067
+ /**
3068
+ * Error classes for the cStar SDK.
3069
+ *
3070
+ * NEW-v3-01 — Cross-subpath instanceof identity.
3071
+ *
3072
+ * Each public subpath (`/library`, `/auth`, `/community`, `/quickhelp`, ...)
3073
+ * is bundled as a separate tsup entry with `splitting: false`, so each one
3074
+ * carries its own copy of this module. Without deduplication, errors thrown
3075
+ * by `LibraryClient` carry the LibraryClient-bundled `CStarError` class —
3076
+ * not the one a consumer imports from `@cstar.help/js`. That makes
3077
+ * `instanceof CStarError` checks fail silently, invalidating every "did the
3078
+ * SDK throw a typed cStar error?" branch in user code.
3079
+ *
3080
+ * Fix: register each class on a `Symbol.for(...)` slot of `globalThis`. The
3081
+ * symbol is realm-shared, so every bundled copy of this module resolves to
3082
+ * the SAME class identity at runtime — the first copy to load wins, and all
3083
+ * subsequent copies surface the canonical class via the same slot. The
3084
+ * inline `Impl` definitions are only used as the seed for the very first
3085
+ * copy to register. Internal `parseError` / `parsePublicError` reference the
3086
+ * EXPORTED canonical names so instances they construct also land on the
3087
+ * canonical class.
3088
+ */
3031
3089
  /** Error type constants matching the cStar API. */
3032
3090
  declare const ErrorType: {
3033
3091
  readonly AUTHENTICATION_ERROR: "authentication_error";
@@ -3052,7 +3110,7 @@ interface ApiErrorBody {
3052
3110
  enable_url?: string;
3053
3111
  }
3054
3112
  /** Base error class for all cStar API errors. */
3055
- declare class CStarError extends Error {
3113
+ declare class CStarErrorImpl extends Error {
3056
3114
  readonly type: string;
3057
3115
  readonly code: string;
3058
3116
  readonly param?: string;
@@ -3061,49 +3119,51 @@ declare class CStarError extends Error {
3061
3119
  readonly statusCode: number;
3062
3120
  constructor(messageOrStatus: string | number, body?: ApiErrorBody);
3063
3121
  }
3064
- /** Thrown when authentication fails (401). */
3065
- declare class CStarAuthenticationError extends CStarError {
3122
+ declare class CStarAuthenticationErrorImpl extends CStarErrorImpl {
3066
3123
  constructor(messageOrStatus: string | number, body?: ApiErrorBody);
3067
3124
  }
3068
- /** Thrown when rate limited (429). Includes retry timing. */
3069
- declare class CStarRateLimitError extends CStarError {
3125
+ declare class CStarRateLimitErrorImpl extends CStarErrorImpl {
3070
3126
  readonly retryAfter: number;
3071
3127
  constructor(messageOrStatus: string | number, body?: ApiErrorBody, retryAfter?: number);
3072
3128
  }
3073
- /** Thrown when a resource is not found (404). */
3074
- declare class CStarNotFoundError extends CStarError {
3129
+ declare class CStarNotFoundErrorImpl extends CStarErrorImpl {
3075
3130
  constructor(messageOrStatus: string | number, body?: ApiErrorBody);
3076
3131
  }
3077
- /** Thrown on invalid request parameters (400/422). */
3078
- declare class CStarValidationError extends CStarError {
3132
+ declare class CStarValidationErrorImpl extends CStarErrorImpl {
3079
3133
  constructor(messageOrStatus: string | number, body?: ApiErrorBody);
3080
3134
  }
3081
- /** Thrown when authenticated but lacking permission (403). */
3082
- declare class CStarPermissionError extends CStarError {
3135
+ declare class CStarPermissionErrorImpl extends CStarErrorImpl {
3083
3136
  constructor(messageOrStatus: string | number, body?: ApiErrorBody);
3084
3137
  }
3085
- /** Thrown on resource conflicts (409). */
3086
- declare class CStarConflictError extends CStarError {
3138
+ declare class CStarConflictErrorImpl extends CStarErrorImpl {
3087
3139
  constructor(messageOrStatus: string | number, body?: ApiErrorBody);
3088
3140
  }
3089
- /** Thrown on internal server errors (500+). */
3090
- declare class CStarServerError extends CStarError {
3141
+ declare class CStarServerErrorImpl extends CStarErrorImpl {
3091
3142
  constructor(messageOrStatus: string | number, body?: ApiErrorBody);
3092
3143
  }
3093
- /**
3094
- * Thrown when the call landed on a feature that the team has not enabled
3095
- * or configured (e.g. Quick Help on a team without an AI agent). Carries
3096
- * `feature` and `enableUrl` so the caller can route the user to the
3097
- * dashboard setting that fixes it.
3098
- *
3099
- * Closes F-031 — anonymous QuickHelp `.ask()` previously surfaced as an
3100
- * unactionable 503.
3101
- */
3102
- declare class CStarFeatureDisabledError extends CStarError {
3144
+ declare class CStarFeatureDisabledErrorImpl extends CStarErrorImpl {
3103
3145
  readonly feature: string;
3104
3146
  readonly enableUrl: string;
3105
3147
  constructor(messageOrStatus: string | number, body?: ApiErrorBody);
3106
3148
  }
3149
+ declare const CStarError: typeof CStarErrorImpl;
3150
+ type CStarError = InstanceType<typeof CStarErrorImpl>;
3151
+ declare const CStarAuthenticationError: typeof CStarAuthenticationErrorImpl;
3152
+ type CStarAuthenticationError = InstanceType<typeof CStarAuthenticationErrorImpl>;
3153
+ declare const CStarRateLimitError: typeof CStarRateLimitErrorImpl;
3154
+ type CStarRateLimitError = InstanceType<typeof CStarRateLimitErrorImpl>;
3155
+ declare const CStarNotFoundError: typeof CStarNotFoundErrorImpl;
3156
+ type CStarNotFoundError = InstanceType<typeof CStarNotFoundErrorImpl>;
3157
+ declare const CStarValidationError: typeof CStarValidationErrorImpl;
3158
+ type CStarValidationError = InstanceType<typeof CStarValidationErrorImpl>;
3159
+ declare const CStarPermissionError: typeof CStarPermissionErrorImpl;
3160
+ type CStarPermissionError = InstanceType<typeof CStarPermissionErrorImpl>;
3161
+ declare const CStarConflictError: typeof CStarConflictErrorImpl;
3162
+ type CStarConflictError = InstanceType<typeof CStarConflictErrorImpl>;
3163
+ declare const CStarServerError: typeof CStarServerErrorImpl;
3164
+ type CStarServerError = InstanceType<typeof CStarServerErrorImpl>;
3165
+ declare const CStarFeatureDisabledError: typeof CStarFeatureDisabledErrorImpl;
3166
+ type CStarFeatureDisabledError = InstanceType<typeof CStarFeatureDisabledErrorImpl>;
3107
3167
 
3108
3168
  /** Configuration for the CStarClient. */
3109
3169
  interface CStarClientConfig {
package/dist/index.js CHANGED
@@ -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
  var STATUS_TO_CLASS = {
143
179
  400: CStarValidationError,
144
180
  401: CStarAuthenticationError,
@@ -181,7 +217,7 @@ function parseError(statusCode, body, retryAfter) {
181
217
  }
182
218
 
183
219
  // src/client.ts
184
- var SDK_VERSION = "0.13.0";
220
+ var SDK_VERSION = "0.15.0";
185
221
  var DEFAULT_BASE_URL = "https://www.cstar.help";
186
222
  var DEFAULT_API_VERSION = "2026-03-01";
187
223
  var DEFAULT_MAX_RETRIES = 3;
@@ -426,6 +462,18 @@ var CStarRealtime = class {
426
462
  this.autoReconnect = options?.autoReconnect ?? true;
427
463
  this.maxRetries = options?.maxRetries ?? 10;
428
464
  this.types = options?.types;
465
+ this.eventSourceCtor = options?.eventSource;
466
+ }
467
+ /**
468
+ * Resolve the EventSource constructor to use for this connection.
469
+ * Returns the explicit polyfill when one was injected, otherwise the
470
+ * global. Returns `undefined` when neither is available — callers must
471
+ * convert to `CStarRealtimeUnavailableError` before touching it.
472
+ */
473
+ resolveEventSource() {
474
+ if (this.eventSourceCtor) return this.eventSourceCtor;
475
+ const fromGlobal = globalThis.EventSource;
476
+ return typeof fromGlobal === "function" ? fromGlobal : void 0;
429
477
  }
430
478
  /** Subscribe to a specific event type. Supports wildcards (e.g., 'ticket.*'). Returns an unsubscribe function. */
431
479
  on(eventType, handler) {
@@ -480,6 +528,9 @@ var CStarRealtime = class {
480
528
  /** Start the SSE connection. Called automatically on first handler registration. */
481
529
  connect() {
482
530
  if (this.eventSource || this.destroyed || this.connecting) return;
531
+ if (!this.resolveEventSource()) {
532
+ throw new CStarRealtimeUnavailableError();
533
+ }
483
534
  this.connecting = true;
484
535
  const headers = this.httpClient.getAuthHeaders();
485
536
  const rawKey = headers.Authorization?.replace("Bearer ", "") ?? "";
@@ -518,7 +569,12 @@ var CStarRealtime = class {
518
569
  }
519
570
  const separator = qs ? "&" : "?";
520
571
  const authenticatedUrl = authToken ? `${url}${separator}token=${authToken}` : url;
521
- this.eventSource = new EventSource(authenticatedUrl);
572
+ const Ctor = this.resolveEventSource();
573
+ if (!Ctor) {
574
+ this.connecting = false;
575
+ throw new CStarRealtimeUnavailableError();
576
+ }
577
+ this.eventSource = new Ctor(authenticatedUrl);
522
578
  this.eventSource.onopen = () => {
523
579
  this.connecting = false;
524
580
  this.retryCount = 0;
@@ -937,6 +993,14 @@ var BaseResource = class {
937
993
  async del(id) {
938
994
  return this.client.request("DELETE", `${this.basePath}/${id}`);
939
995
  }
996
+ /**
997
+ * Delete a resource by ID. Alias for `del()` — kept because IDE
998
+ * auto-complete and documentation both surface `delete` first. Closes
999
+ * NEW-v2-06.
1000
+ */
1001
+ async delete(id) {
1002
+ return this.del(id);
1003
+ }
940
1004
  /**
941
1005
  * Auto-paginating async iterator that yields every item across all pages.
942
1006
  *