@cstar.help/js 0.13.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/index.cjs +73 -11
- package/dist/auth/index.d.cts +121 -1
- package/dist/auth/index.d.ts +121 -1
- package/dist/auth/index.js +59 -10
- package/dist/chat/index.cjs +64 -7
- package/dist/chat/index.d.cts +48 -4
- package/dist/chat/index.d.ts +48 -4
- package/dist/chat/index.js +64 -7
- package/dist/community/index.cjs +73 -11
- package/dist/community/index.d.cts +121 -1
- package/dist/community/index.d.ts +121 -1
- package/dist/community/index.js +59 -10
- package/dist/index.cjs +75 -11
- package/dist/index.d.cts +86 -26
- package/dist/index.d.ts +86 -26
- package/dist/index.js +75 -11
- package/dist/library/index.cjs +73 -11
- package/dist/library/index.d.cts +121 -1
- package/dist/library/index.d.ts +121 -1
- package/dist/library/index.js +59 -10
- package/dist/quickhelp/index.cjs +179 -17
- package/dist/quickhelp/index.d.cts +147 -5
- package/dist/quickhelp/index.d.ts +147 -5
- package/dist/quickhelp/index.js +165 -16
- package/dist/webhook/index.cjs +64 -8
- package/dist/webhook/index.d.cts +27 -3
- package/dist/webhook/index.d.ts +27 -3
- package/dist/webhook/index.js +62 -8
- package/dist/webhook/node.cjs +53 -5
- package/dist/webhook/node.d.cts +27 -4
- package/dist/webhook/node.d.ts +27 -4
- package/dist/webhook/node.js +51 -5
- package/package.json +1 -1
package/dist/auth/index.cjs
CHANGED
|
@@ -20,7 +20,20 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/auth/index.ts
|
|
21
21
|
var auth_exports = {};
|
|
22
22
|
__export(auth_exports, {
|
|
23
|
-
AuthClient: () => AuthClient
|
|
23
|
+
AuthClient: () => AuthClient,
|
|
24
|
+
CStarAuthenticationError: () => CStarAuthenticationError,
|
|
25
|
+
CStarConflictError: () => CStarConflictError,
|
|
26
|
+
CStarError: () => CStarError,
|
|
27
|
+
CStarFeatureDisabledError: () => CStarFeatureDisabledError,
|
|
28
|
+
CStarNotFoundError: () => CStarNotFoundError,
|
|
29
|
+
CStarPermissionError: () => CStarPermissionError,
|
|
30
|
+
CStarRateLimitError: () => CStarRateLimitError,
|
|
31
|
+
CStarRealtimeUnavailableError: () => CStarRealtimeUnavailableError,
|
|
32
|
+
CStarServerError: () => CStarServerError,
|
|
33
|
+
CStarValidationError: () => CStarValidationError,
|
|
34
|
+
ErrorType: () => ErrorType,
|
|
35
|
+
parseError: () => parseError,
|
|
36
|
+
parsePublicError: () => parsePublicError
|
|
24
37
|
});
|
|
25
38
|
module.exports = __toCommonJS(auth_exports);
|
|
26
39
|
|
|
@@ -61,7 +74,7 @@ function normalizeArgs(messageOrStatus, maybeBody, defaults) {
|
|
|
61
74
|
}
|
|
62
75
|
};
|
|
63
76
|
}
|
|
64
|
-
var
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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;
|
|
@@ -337,5 +386,18 @@ var AuthClient = class {
|
|
|
337
386
|
};
|
|
338
387
|
// Annotate the CommonJS export names for ESM import in node:
|
|
339
388
|
0 && (module.exports = {
|
|
340
|
-
AuthClient
|
|
389
|
+
AuthClient,
|
|
390
|
+
CStarAuthenticationError,
|
|
391
|
+
CStarConflictError,
|
|
392
|
+
CStarError,
|
|
393
|
+
CStarFeatureDisabledError,
|
|
394
|
+
CStarNotFoundError,
|
|
395
|
+
CStarPermissionError,
|
|
396
|
+
CStarRateLimitError,
|
|
397
|
+
CStarRealtimeUnavailableError,
|
|
398
|
+
CStarServerError,
|
|
399
|
+
CStarValidationError,
|
|
400
|
+
ErrorType,
|
|
401
|
+
parseError,
|
|
402
|
+
parsePublicError
|
|
341
403
|
});
|
package/dist/auth/index.d.cts
CHANGED
|
@@ -56,6 +56,126 @@ interface AuthSession {
|
|
|
56
56
|
refreshToken: string;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Error classes for the cStar SDK.
|
|
61
|
+
*
|
|
62
|
+
* NEW-v3-01 — Cross-subpath instanceof identity.
|
|
63
|
+
*
|
|
64
|
+
* Each public subpath (`/library`, `/auth`, `/community`, `/quickhelp`, ...)
|
|
65
|
+
* is bundled as a separate tsup entry with `splitting: false`, so each one
|
|
66
|
+
* carries its own copy of this module. Without deduplication, errors thrown
|
|
67
|
+
* by `LibraryClient` carry the LibraryClient-bundled `CStarError` class —
|
|
68
|
+
* not the one a consumer imports from `@cstar.help/js`. That makes
|
|
69
|
+
* `instanceof CStarError` checks fail silently, invalidating every "did the
|
|
70
|
+
* SDK throw a typed cStar error?" branch in user code.
|
|
71
|
+
*
|
|
72
|
+
* Fix: register each class on a `Symbol.for(...)` slot of `globalThis`. The
|
|
73
|
+
* symbol is realm-shared, so every bundled copy of this module resolves to
|
|
74
|
+
* the SAME class identity at runtime — the first copy to load wins, and all
|
|
75
|
+
* subsequent copies surface the canonical class via the same slot. The
|
|
76
|
+
* inline `Impl` definitions are only used as the seed for the very first
|
|
77
|
+
* copy to register. Internal `parseError` / `parsePublicError` reference the
|
|
78
|
+
* EXPORTED canonical names so instances they construct also land on the
|
|
79
|
+
* canonical class.
|
|
80
|
+
*/
|
|
81
|
+
/** Error type constants matching the cStar API. */
|
|
82
|
+
declare const ErrorType: {
|
|
83
|
+
readonly AUTHENTICATION_ERROR: "authentication_error";
|
|
84
|
+
readonly PERMISSION_ERROR: "permission_error";
|
|
85
|
+
readonly INVALID_REQUEST_ERROR: "invalid_request_error";
|
|
86
|
+
readonly NOT_FOUND_ERROR: "not_found_error";
|
|
87
|
+
readonly CONFLICT_ERROR: "conflict_error";
|
|
88
|
+
readonly RATE_LIMIT_ERROR: "rate_limit_error";
|
|
89
|
+
readonly FEATURE_NOT_CONFIGURED: "feature_not_configured";
|
|
90
|
+
readonly API_ERROR: "api_error";
|
|
91
|
+
readonly SERVER_ERROR: "server_error";
|
|
92
|
+
};
|
|
93
|
+
/** Shape of the error object returned by the cStar API. */
|
|
94
|
+
interface ApiErrorBody {
|
|
95
|
+
type: string;
|
|
96
|
+
code: string;
|
|
97
|
+
message: string;
|
|
98
|
+
param?: string;
|
|
99
|
+
doc_url: string;
|
|
100
|
+
request_id?: string;
|
|
101
|
+
feature?: string;
|
|
102
|
+
enable_url?: string;
|
|
103
|
+
}
|
|
104
|
+
/** Base error class for all cStar API errors. */
|
|
105
|
+
declare class CStarErrorImpl extends Error {
|
|
106
|
+
readonly type: string;
|
|
107
|
+
readonly code: string;
|
|
108
|
+
readonly param?: string;
|
|
109
|
+
readonly docUrl: string;
|
|
110
|
+
readonly requestId?: string;
|
|
111
|
+
readonly statusCode: number;
|
|
112
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
113
|
+
}
|
|
114
|
+
declare class CStarAuthenticationErrorImpl extends CStarErrorImpl {
|
|
115
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
116
|
+
}
|
|
117
|
+
declare class CStarRateLimitErrorImpl extends CStarErrorImpl {
|
|
118
|
+
readonly retryAfter: number;
|
|
119
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody, retryAfter?: number);
|
|
120
|
+
}
|
|
121
|
+
declare class CStarNotFoundErrorImpl extends CStarErrorImpl {
|
|
122
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
123
|
+
}
|
|
124
|
+
declare class CStarValidationErrorImpl extends CStarErrorImpl {
|
|
125
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
126
|
+
}
|
|
127
|
+
declare class CStarPermissionErrorImpl extends CStarErrorImpl {
|
|
128
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
129
|
+
}
|
|
130
|
+
declare class CStarConflictErrorImpl extends CStarErrorImpl {
|
|
131
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
132
|
+
}
|
|
133
|
+
declare class CStarServerErrorImpl extends CStarErrorImpl {
|
|
134
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
135
|
+
}
|
|
136
|
+
declare class CStarFeatureDisabledErrorImpl extends CStarErrorImpl {
|
|
137
|
+
readonly feature: string;
|
|
138
|
+
readonly enableUrl: string;
|
|
139
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
140
|
+
}
|
|
141
|
+
declare class CStarRealtimeUnavailableErrorImpl extends CStarErrorImpl {
|
|
142
|
+
constructor(message?: string);
|
|
143
|
+
}
|
|
144
|
+
declare const CStarError: typeof CStarErrorImpl;
|
|
145
|
+
type CStarError = InstanceType<typeof CStarErrorImpl>;
|
|
146
|
+
declare const CStarAuthenticationError: typeof CStarAuthenticationErrorImpl;
|
|
147
|
+
type CStarAuthenticationError = InstanceType<typeof CStarAuthenticationErrorImpl>;
|
|
148
|
+
declare const CStarRateLimitError: typeof CStarRateLimitErrorImpl;
|
|
149
|
+
type CStarRateLimitError = InstanceType<typeof CStarRateLimitErrorImpl>;
|
|
150
|
+
declare const CStarNotFoundError: typeof CStarNotFoundErrorImpl;
|
|
151
|
+
type CStarNotFoundError = InstanceType<typeof CStarNotFoundErrorImpl>;
|
|
152
|
+
declare const CStarValidationError: typeof CStarValidationErrorImpl;
|
|
153
|
+
type CStarValidationError = InstanceType<typeof CStarValidationErrorImpl>;
|
|
154
|
+
declare const CStarPermissionError: typeof CStarPermissionErrorImpl;
|
|
155
|
+
type CStarPermissionError = InstanceType<typeof CStarPermissionErrorImpl>;
|
|
156
|
+
declare const CStarConflictError: typeof CStarConflictErrorImpl;
|
|
157
|
+
type CStarConflictError = InstanceType<typeof CStarConflictErrorImpl>;
|
|
158
|
+
declare const CStarServerError: typeof CStarServerErrorImpl;
|
|
159
|
+
type CStarServerError = InstanceType<typeof CStarServerErrorImpl>;
|
|
160
|
+
declare const CStarFeatureDisabledError: typeof CStarFeatureDisabledErrorImpl;
|
|
161
|
+
type CStarFeatureDisabledError = InstanceType<typeof CStarFeatureDisabledErrorImpl>;
|
|
162
|
+
declare const CStarRealtimeUnavailableError: typeof CStarRealtimeUnavailableErrorImpl;
|
|
163
|
+
type CStarRealtimeUnavailableError = InstanceType<typeof CStarRealtimeUnavailableErrorImpl>;
|
|
164
|
+
/**
|
|
165
|
+
* Parse a public-route response (anonymous LibraryClient, CommunityClient,
|
|
166
|
+
* QuickHelpClient, AuthClient) into a typed `CStarError`.
|
|
167
|
+
*
|
|
168
|
+
* Public routes don't always emit the structured `{error: {type, code,
|
|
169
|
+
* doc_url, ...}}` envelope — many emit `{error: 'message string'}` or
|
|
170
|
+
* `{message: '...'}`. This helper normalizes both shapes and dispatches
|
|
171
|
+
* on HTTP status (closes F-026 and F-034 — Library/Auth used to throw
|
|
172
|
+
* plain `Error`).
|
|
173
|
+
*/
|
|
174
|
+
declare function parsePublicError(status: number, body: unknown, fallbackMessage: string): CStarError;
|
|
175
|
+
declare function parseError(statusCode: number, body: {
|
|
176
|
+
error?: ApiErrorBody;
|
|
177
|
+
} | null, retryAfter?: number): CStarError;
|
|
178
|
+
|
|
59
179
|
/**
|
|
60
180
|
* Customer authentication client for the cStar widget API.
|
|
61
181
|
*
|
|
@@ -120,4 +240,4 @@ declare class AuthClient {
|
|
|
120
240
|
private fetch;
|
|
121
241
|
}
|
|
122
242
|
|
|
123
|
-
export { AuthClient, type AuthConfig, type AuthCustomer, type AuthSession, type LoginParams, type LoginResult, type SignupConfirmationResult, type SignupParams, type SignupResult };
|
|
243
|
+
export { type ApiErrorBody, AuthClient, type AuthConfig, type AuthCustomer, type AuthSession, CStarAuthenticationError, CStarConflictError, CStarError, CStarFeatureDisabledError, CStarNotFoundError, CStarPermissionError, CStarRateLimitError, CStarRealtimeUnavailableError, CStarServerError, CStarValidationError, ErrorType, type LoginParams, type LoginResult, type SignupConfirmationResult, type SignupParams, type SignupResult, parseError, parsePublicError };
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -56,6 +56,126 @@ interface AuthSession {
|
|
|
56
56
|
refreshToken: string;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Error classes for the cStar SDK.
|
|
61
|
+
*
|
|
62
|
+
* NEW-v3-01 — Cross-subpath instanceof identity.
|
|
63
|
+
*
|
|
64
|
+
* Each public subpath (`/library`, `/auth`, `/community`, `/quickhelp`, ...)
|
|
65
|
+
* is bundled as a separate tsup entry with `splitting: false`, so each one
|
|
66
|
+
* carries its own copy of this module. Without deduplication, errors thrown
|
|
67
|
+
* by `LibraryClient` carry the LibraryClient-bundled `CStarError` class —
|
|
68
|
+
* not the one a consumer imports from `@cstar.help/js`. That makes
|
|
69
|
+
* `instanceof CStarError` checks fail silently, invalidating every "did the
|
|
70
|
+
* SDK throw a typed cStar error?" branch in user code.
|
|
71
|
+
*
|
|
72
|
+
* Fix: register each class on a `Symbol.for(...)` slot of `globalThis`. The
|
|
73
|
+
* symbol is realm-shared, so every bundled copy of this module resolves to
|
|
74
|
+
* the SAME class identity at runtime — the first copy to load wins, and all
|
|
75
|
+
* subsequent copies surface the canonical class via the same slot. The
|
|
76
|
+
* inline `Impl` definitions are only used as the seed for the very first
|
|
77
|
+
* copy to register. Internal `parseError` / `parsePublicError` reference the
|
|
78
|
+
* EXPORTED canonical names so instances they construct also land on the
|
|
79
|
+
* canonical class.
|
|
80
|
+
*/
|
|
81
|
+
/** Error type constants matching the cStar API. */
|
|
82
|
+
declare const ErrorType: {
|
|
83
|
+
readonly AUTHENTICATION_ERROR: "authentication_error";
|
|
84
|
+
readonly PERMISSION_ERROR: "permission_error";
|
|
85
|
+
readonly INVALID_REQUEST_ERROR: "invalid_request_error";
|
|
86
|
+
readonly NOT_FOUND_ERROR: "not_found_error";
|
|
87
|
+
readonly CONFLICT_ERROR: "conflict_error";
|
|
88
|
+
readonly RATE_LIMIT_ERROR: "rate_limit_error";
|
|
89
|
+
readonly FEATURE_NOT_CONFIGURED: "feature_not_configured";
|
|
90
|
+
readonly API_ERROR: "api_error";
|
|
91
|
+
readonly SERVER_ERROR: "server_error";
|
|
92
|
+
};
|
|
93
|
+
/** Shape of the error object returned by the cStar API. */
|
|
94
|
+
interface ApiErrorBody {
|
|
95
|
+
type: string;
|
|
96
|
+
code: string;
|
|
97
|
+
message: string;
|
|
98
|
+
param?: string;
|
|
99
|
+
doc_url: string;
|
|
100
|
+
request_id?: string;
|
|
101
|
+
feature?: string;
|
|
102
|
+
enable_url?: string;
|
|
103
|
+
}
|
|
104
|
+
/** Base error class for all cStar API errors. */
|
|
105
|
+
declare class CStarErrorImpl extends Error {
|
|
106
|
+
readonly type: string;
|
|
107
|
+
readonly code: string;
|
|
108
|
+
readonly param?: string;
|
|
109
|
+
readonly docUrl: string;
|
|
110
|
+
readonly requestId?: string;
|
|
111
|
+
readonly statusCode: number;
|
|
112
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
113
|
+
}
|
|
114
|
+
declare class CStarAuthenticationErrorImpl extends CStarErrorImpl {
|
|
115
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
116
|
+
}
|
|
117
|
+
declare class CStarRateLimitErrorImpl extends CStarErrorImpl {
|
|
118
|
+
readonly retryAfter: number;
|
|
119
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody, retryAfter?: number);
|
|
120
|
+
}
|
|
121
|
+
declare class CStarNotFoundErrorImpl extends CStarErrorImpl {
|
|
122
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
123
|
+
}
|
|
124
|
+
declare class CStarValidationErrorImpl extends CStarErrorImpl {
|
|
125
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
126
|
+
}
|
|
127
|
+
declare class CStarPermissionErrorImpl extends CStarErrorImpl {
|
|
128
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
129
|
+
}
|
|
130
|
+
declare class CStarConflictErrorImpl extends CStarErrorImpl {
|
|
131
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
132
|
+
}
|
|
133
|
+
declare class CStarServerErrorImpl extends CStarErrorImpl {
|
|
134
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
135
|
+
}
|
|
136
|
+
declare class CStarFeatureDisabledErrorImpl extends CStarErrorImpl {
|
|
137
|
+
readonly feature: string;
|
|
138
|
+
readonly enableUrl: string;
|
|
139
|
+
constructor(messageOrStatus: string | number, body?: ApiErrorBody);
|
|
140
|
+
}
|
|
141
|
+
declare class CStarRealtimeUnavailableErrorImpl extends CStarErrorImpl {
|
|
142
|
+
constructor(message?: string);
|
|
143
|
+
}
|
|
144
|
+
declare const CStarError: typeof CStarErrorImpl;
|
|
145
|
+
type CStarError = InstanceType<typeof CStarErrorImpl>;
|
|
146
|
+
declare const CStarAuthenticationError: typeof CStarAuthenticationErrorImpl;
|
|
147
|
+
type CStarAuthenticationError = InstanceType<typeof CStarAuthenticationErrorImpl>;
|
|
148
|
+
declare const CStarRateLimitError: typeof CStarRateLimitErrorImpl;
|
|
149
|
+
type CStarRateLimitError = InstanceType<typeof CStarRateLimitErrorImpl>;
|
|
150
|
+
declare const CStarNotFoundError: typeof CStarNotFoundErrorImpl;
|
|
151
|
+
type CStarNotFoundError = InstanceType<typeof CStarNotFoundErrorImpl>;
|
|
152
|
+
declare const CStarValidationError: typeof CStarValidationErrorImpl;
|
|
153
|
+
type CStarValidationError = InstanceType<typeof CStarValidationErrorImpl>;
|
|
154
|
+
declare const CStarPermissionError: typeof CStarPermissionErrorImpl;
|
|
155
|
+
type CStarPermissionError = InstanceType<typeof CStarPermissionErrorImpl>;
|
|
156
|
+
declare const CStarConflictError: typeof CStarConflictErrorImpl;
|
|
157
|
+
type CStarConflictError = InstanceType<typeof CStarConflictErrorImpl>;
|
|
158
|
+
declare const CStarServerError: typeof CStarServerErrorImpl;
|
|
159
|
+
type CStarServerError = InstanceType<typeof CStarServerErrorImpl>;
|
|
160
|
+
declare const CStarFeatureDisabledError: typeof CStarFeatureDisabledErrorImpl;
|
|
161
|
+
type CStarFeatureDisabledError = InstanceType<typeof CStarFeatureDisabledErrorImpl>;
|
|
162
|
+
declare const CStarRealtimeUnavailableError: typeof CStarRealtimeUnavailableErrorImpl;
|
|
163
|
+
type CStarRealtimeUnavailableError = InstanceType<typeof CStarRealtimeUnavailableErrorImpl>;
|
|
164
|
+
/**
|
|
165
|
+
* Parse a public-route response (anonymous LibraryClient, CommunityClient,
|
|
166
|
+
* QuickHelpClient, AuthClient) into a typed `CStarError`.
|
|
167
|
+
*
|
|
168
|
+
* Public routes don't always emit the structured `{error: {type, code,
|
|
169
|
+
* doc_url, ...}}` envelope — many emit `{error: 'message string'}` or
|
|
170
|
+
* `{message: '...'}`. This helper normalizes both shapes and dispatches
|
|
171
|
+
* on HTTP status (closes F-026 and F-034 — Library/Auth used to throw
|
|
172
|
+
* plain `Error`).
|
|
173
|
+
*/
|
|
174
|
+
declare function parsePublicError(status: number, body: unknown, fallbackMessage: string): CStarError;
|
|
175
|
+
declare function parseError(statusCode: number, body: {
|
|
176
|
+
error?: ApiErrorBody;
|
|
177
|
+
} | null, retryAfter?: number): CStarError;
|
|
178
|
+
|
|
59
179
|
/**
|
|
60
180
|
* Customer authentication client for the cStar widget API.
|
|
61
181
|
*
|
|
@@ -120,4 +240,4 @@ declare class AuthClient {
|
|
|
120
240
|
private fetch;
|
|
121
241
|
}
|
|
122
242
|
|
|
123
|
-
export { AuthClient, type AuthConfig, type AuthCustomer, type AuthSession, type LoginParams, type LoginResult, type SignupConfirmationResult, type SignupParams, type SignupResult };
|
|
243
|
+
export { type ApiErrorBody, AuthClient, type AuthConfig, type AuthCustomer, type AuthSession, CStarAuthenticationError, CStarConflictError, CStarError, CStarFeatureDisabledError, CStarNotFoundError, CStarPermissionError, CStarRateLimitError, CStarRealtimeUnavailableError, CStarServerError, CStarValidationError, ErrorType, type LoginParams, type LoginResult, type SignupConfirmationResult, type SignupParams, type SignupResult, parseError, parsePublicError };
|
package/dist/auth/index.js
CHANGED
|
@@ -35,7 +35,7 @@ function normalizeArgs(messageOrStatus, maybeBody, defaults) {
|
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
-
var
|
|
38
|
+
var CStarErrorImpl = class extends Error {
|
|
39
39
|
constructor(messageOrStatus, body) {
|
|
40
40
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body);
|
|
41
41
|
super(resolved.message);
|
|
@@ -48,7 +48,7 @@ var CStarError = class extends Error {
|
|
|
48
48
|
this.statusCode = statusCode;
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
var
|
|
51
|
+
var CStarAuthenticationErrorImpl = class extends CStarErrorImpl {
|
|
52
52
|
constructor(messageOrStatus, body) {
|
|
53
53
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
54
54
|
type: ErrorType.AUTHENTICATION_ERROR,
|
|
@@ -59,7 +59,7 @@ var CStarAuthenticationError = class extends CStarError {
|
|
|
59
59
|
this.name = "CStarAuthenticationError";
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
|
-
var
|
|
62
|
+
var CStarRateLimitErrorImpl = class extends CStarErrorImpl {
|
|
63
63
|
constructor(messageOrStatus, body, retryAfter) {
|
|
64
64
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
65
65
|
type: ErrorType.RATE_LIMIT_ERROR,
|
|
@@ -71,7 +71,7 @@ var CStarRateLimitError = class extends CStarError {
|
|
|
71
71
|
this.retryAfter = retryAfter ?? 60;
|
|
72
72
|
}
|
|
73
73
|
};
|
|
74
|
-
var
|
|
74
|
+
var CStarNotFoundErrorImpl = class extends CStarErrorImpl {
|
|
75
75
|
constructor(messageOrStatus, body) {
|
|
76
76
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
77
77
|
type: ErrorType.NOT_FOUND_ERROR,
|
|
@@ -82,7 +82,7 @@ var CStarNotFoundError = class extends CStarError {
|
|
|
82
82
|
this.name = "CStarNotFoundError";
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
|
-
var
|
|
85
|
+
var CStarValidationErrorImpl = class extends CStarErrorImpl {
|
|
86
86
|
constructor(messageOrStatus, body) {
|
|
87
87
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
88
88
|
type: ErrorType.INVALID_REQUEST_ERROR,
|
|
@@ -93,7 +93,7 @@ var CStarValidationError = class extends CStarError {
|
|
|
93
93
|
this.name = "CStarValidationError";
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
|
-
var
|
|
96
|
+
var CStarPermissionErrorImpl = class extends CStarErrorImpl {
|
|
97
97
|
constructor(messageOrStatus, body) {
|
|
98
98
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
99
99
|
type: ErrorType.PERMISSION_ERROR,
|
|
@@ -104,7 +104,7 @@ var CStarPermissionError = class extends CStarError {
|
|
|
104
104
|
this.name = "CStarPermissionError";
|
|
105
105
|
}
|
|
106
106
|
};
|
|
107
|
-
var
|
|
107
|
+
var CStarConflictErrorImpl = class extends CStarErrorImpl {
|
|
108
108
|
constructor(messageOrStatus, body) {
|
|
109
109
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
110
110
|
type: ErrorType.CONFLICT_ERROR,
|
|
@@ -115,7 +115,7 @@ var CStarConflictError = class extends CStarError {
|
|
|
115
115
|
this.name = "CStarConflictError";
|
|
116
116
|
}
|
|
117
117
|
};
|
|
118
|
-
var
|
|
118
|
+
var CStarServerErrorImpl = class extends CStarErrorImpl {
|
|
119
119
|
constructor(messageOrStatus, body) {
|
|
120
120
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
121
121
|
type: ErrorType.SERVER_ERROR,
|
|
@@ -126,7 +126,7 @@ var CStarServerError = class extends CStarError {
|
|
|
126
126
|
this.name = "CStarServerError";
|
|
127
127
|
}
|
|
128
128
|
};
|
|
129
|
-
var
|
|
129
|
+
var CStarFeatureDisabledErrorImpl = class extends CStarErrorImpl {
|
|
130
130
|
constructor(messageOrStatus, body) {
|
|
131
131
|
const { statusCode, body: resolved } = normalizeArgs(messageOrStatus, body, {
|
|
132
132
|
type: ErrorType.FEATURE_NOT_CONFIGURED,
|
|
@@ -139,6 +139,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;
|
|
@@ -310,5 +346,18 @@ var AuthClient = class {
|
|
|
310
346
|
}
|
|
311
347
|
};
|
|
312
348
|
export {
|
|
313
|
-
AuthClient
|
|
349
|
+
AuthClient,
|
|
350
|
+
CStarAuthenticationError,
|
|
351
|
+
CStarConflictError,
|
|
352
|
+
CStarError,
|
|
353
|
+
CStarFeatureDisabledError,
|
|
354
|
+
CStarNotFoundError,
|
|
355
|
+
CStarPermissionError,
|
|
356
|
+
CStarRateLimitError,
|
|
357
|
+
CStarRealtimeUnavailableError,
|
|
358
|
+
CStarServerError,
|
|
359
|
+
CStarValidationError,
|
|
360
|
+
ErrorType,
|
|
361
|
+
parseError,
|
|
362
|
+
parsePublicError
|
|
314
363
|
};
|