@vigneshreddy/cms-sdk 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CutMeShort
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,217 @@
1
+ # CMS TypeScript SDK (cms)
2
+
3
+ TypeScript/JavaScript SDK for the CutMeShort CMS API.
4
+
5
+ This SDK is:
6
+ - Fetch-based (uses native `fetch`).
7
+ - Typed (TypeScript types for requests/responses).
8
+ - Resilient (built-in retries for transient errors).
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install cms
14
+ ```
15
+
16
+ ## Publish to npm
17
+
18
+ ```bash
19
+ npm login
20
+ npm run build
21
+ npm publish --access public
22
+ ```
23
+
24
+ ## Runtime requirements
25
+
26
+ - Browser: any modern browser with `fetch`.
27
+ - Node.js: Node 18+ recommended (built-in `fetch`).
28
+ - Node < 18: add a fetch polyfill and set it globally before using the SDK.
29
+
30
+ ```ts
31
+ import fetch, { Headers, Request, Response } from "cross-fetch";
32
+
33
+ // @ts-ignore
34
+ global.fetch = fetch as any;
35
+ // @ts-ignore
36
+ global.Headers = Headers as any;
37
+ // @ts-ignore
38
+ global.Request = Request as any;
39
+ // @ts-ignore
40
+ global.Response = Response as any;
41
+ ```
42
+
43
+ ## Quick start
44
+
45
+ Create the client once and reuse it across calls.
46
+
47
+ ```ts
48
+ import { CMS } from "cms";
49
+
50
+ const sdk = new CMS({
51
+ apiKey: process.env.CMS_API_KEY!,
52
+ timeout: 10_000,
53
+ });
54
+ ```
55
+
56
+ ## Track a lead
57
+
58
+ ### Class-based usage (throws on error)
59
+
60
+ ```ts
61
+ import { CMS } from "cms";
62
+
63
+ const sdk = new CMS({ apiKey: "sk_live_123" });
64
+
65
+ const leadResponse = await sdk.trackLead({
66
+ clickId: "dub_123",
67
+ eventName: "signup_started",
68
+ customerId: "user_42",
69
+ });
70
+
71
+ console.log("Lead response:", leadResponse);
72
+ ```
73
+
74
+ ### Functional helper (Result pattern)
75
+
76
+ ```ts
77
+ import { CMS, trackLead } from "cms";
78
+
79
+ const sdk = new CMS({ apiKey: "sk_live_123" });
80
+
81
+ const res = await trackLead(sdk, {
82
+ clickId: "dub_123",
83
+ eventName: "signup_started",
84
+ customerId: "user_42",
85
+ });
86
+
87
+ if (res.ok) {
88
+ console.log("Lead response:", res.value);
89
+ } else {
90
+ console.error("Lead error:", res.error);
91
+ }
92
+ ```
93
+
94
+ ## Track a sale
95
+
96
+ ### Class-based usage (throws on error)
97
+
98
+ ```ts
99
+ import { CMS } from "cms";
100
+
101
+ const sdk = new CMS({ apiKey: "sk_live_123" });
102
+
103
+ const saleResponse = await sdk.trackSale({
104
+ clickId: "dub_123",
105
+ eventName: "purchase_completed",
106
+ invoiceId: "inv_987",
107
+ amount: 4999,
108
+ currency: "USD",
109
+ });
110
+
111
+ console.log("Sale response:", saleResponse);
112
+ ```
113
+
114
+ ### Functional helper (Result pattern)
115
+
116
+ ```ts
117
+ import { CMS, trackSale } from "cms";
118
+
119
+ const sdk = new CMS({ apiKey: "sk_live_123" });
120
+
121
+ const res = await trackSale(sdk, {
122
+ clickId: "dub_123",
123
+ eventName: "purchase_completed",
124
+ invoiceId: "inv_987",
125
+ amount: 4999,
126
+ currency: "USD",
127
+ });
128
+
129
+ if (res.ok) {
130
+ console.log("Sale response:", res.value);
131
+ } else {
132
+ console.error("Sale error:", res.error);
133
+ }
134
+ ```
135
+
136
+ ## Configuration
137
+
138
+ ```ts
139
+ export interface CMSConfig {
140
+ apiKey: string;
141
+ timeout?: number;
142
+ maxRetries?: number;
143
+ retryDelayMs?: number;
144
+ retryOnStatuses?: number[];
145
+ retryOnNetworkError?: boolean;
146
+ }
147
+ ```
148
+
149
+ - `apiKey` (required): CMS secret API key.
150
+ - `timeout`: request timeout in ms (default: 10000).
151
+ - `maxRetries`: retry attempts for transient failures (default: 2).
152
+ - `retryDelayMs`: base delay for linear backoff (default: 500).
153
+ - `retryOnStatuses`: HTTP codes that are retryable (default: 429, 500, 502, 503, 504).
154
+ - `retryOnNetworkError`: retry on network/timeout errors (default: true).
155
+
156
+ ## Per-request overrides
157
+
158
+ You can override retries and timeout on a single request.
159
+
160
+ ```ts
161
+ import { CMS } from "cms";
162
+
163
+ const sdk = new CMS({ apiKey: "sk_live_123" });
164
+
165
+ await sdk.trackLead(
166
+ {
167
+ clickId: "dub_123",
168
+ eventName: "signup_started",
169
+ customerId: "user_42",
170
+ },
171
+ {
172
+ timeout: 5000,
173
+ maxRetries: 1,
174
+ }
175
+ );
176
+ ```
177
+
178
+ ## Error handling
179
+
180
+ All thrown errors from class-based methods are normalized as `CMSAPIError` or its specific subclasses.
181
+
182
+ ```ts
183
+ import { CMS, CMSAPIError } from "cms";
184
+
185
+ const sdk = new CMS({ apiKey: "sk_live_123" });
186
+
187
+ try {
188
+ await sdk.trackLead({
189
+ clickId: "dub_123",
190
+ eventName: "signup_started",
191
+ customerId: "user_42",
192
+ });
193
+ } catch (err) {
194
+ if (err instanceof CMSAPIError) {
195
+ console.error("CMS API Error:", {
196
+ statusCode: err.statusCode,
197
+ type: err.type,
198
+ message: err.message,
199
+ });
200
+ } else {
201
+ console.error("Unexpected error:", err);
202
+ }
203
+ }
204
+ ```
205
+
206
+ ## Exports
207
+
208
+ ```ts
209
+ import { CMS } from "cms";
210
+ import { trackLead, trackSale } from "cms";
211
+ import { CMSAPIError } from "cms";
212
+ import type { TrackLeadRequest, TrackSaleRequest, TrackResponse } from "cms";
213
+ ```
214
+
215
+ ## Security
216
+
217
+ Do not expose secret API keys in frontend code. Use a backend or secure proxy if the key is private.
@@ -0,0 +1,46 @@
1
+ import { EventsApi, TrackLeadRequest, TrackSaleRequest } from "./generated";
2
+ export interface CMSConfig {
3
+ apiKey: string;
4
+ /**
5
+ * Optional timeout in milliseconds for HTTP requests.
6
+ * This is implemented using AbortController around the native fetch API.
7
+ */
8
+ timeout?: number;
9
+ /** Maximum number of retry attempts for transient failures */
10
+ maxRetries?: number;
11
+ /** Base delay (in ms) between retries for transient failures */
12
+ retryDelayMs?: number;
13
+ /** HTTP status codes that should be retried */
14
+ retryOnStatuses?: number[];
15
+ /** Whether to retry on network errors (no response / timeout) */
16
+ retryOnNetworkError?: boolean;
17
+ }
18
+ /**
19
+ * Per-request options that can override default SDK configuration
20
+ */
21
+ export interface RequestOptions {
22
+ /** Override timeout for this specific request */
23
+ timeout?: number;
24
+ /** Override max retries for this specific request */
25
+ maxRetries?: number;
26
+ /** Override retry delay for this specific request */
27
+ retryDelayMs?: number;
28
+ /** Override retry status codes for this specific request */
29
+ retryOnStatuses?: number[];
30
+ /** Override retry on network error setting for this specific request */
31
+ retryOnNetworkError?: boolean;
32
+ }
33
+ export declare class CMS {
34
+ readonly events: EventsApi;
35
+ private readonly maxRetries;
36
+ private readonly retryDelayMs;
37
+ private readonly retryOnStatuses;
38
+ private readonly retryOnNetworkError;
39
+ constructor(config: CMSConfig);
40
+ private isRetryableError;
41
+ private sleep;
42
+ private withRetry;
43
+ private isRetryableErrorWithOptions;
44
+ trackLead(request: TrackLeadRequest, options?: RequestOptions): Promise<import("./generated").TrackResponse>;
45
+ trackSale(request: TrackSaleRequest, options?: RequestOptions): Promise<import("./generated").TrackResponse>;
46
+ }
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CMS = void 0;
4
+ // src/client.ts
5
+ const generated_1 = require("./generated");
6
+ const errors_1 = require("./errors");
7
+ class CMS {
8
+ constructor(config) {
9
+ var _a, _b, _c, _d, _e;
10
+ if (!config.apiKey) {
11
+ throw new Error("CMS SDK: apiKey is required.");
12
+ }
13
+ const basePath = "https://www.cutmeshort.com/api";
14
+ // Retry configuration with sensible defaults
15
+ this.maxRetries = (_a = config.maxRetries) !== null && _a !== void 0 ? _a : 2;
16
+ this.retryDelayMs = (_b = config.retryDelayMs) !== null && _b !== void 0 ? _b : 500;
17
+ this.retryOnStatuses = new Set((_c = config.retryOnStatuses) !== null && _c !== void 0 ? _c : [429, 500, 502, 503, 504]);
18
+ this.retryOnNetworkError = (_d = config.retryOnNetworkError) !== null && _d !== void 0 ? _d : true;
19
+ // Create the Configuration object
20
+ const apiConfig = new generated_1.Configuration({
21
+ basePath,
22
+ accessToken: config.apiKey,
23
+ baseOptions: {
24
+ // Ensure generated client uses the same timeout & headers
25
+ timeout: (_e = config.timeout) !== null && _e !== void 0 ? _e : 10000,
26
+ headers: {
27
+ 'User-Agent': 'CMS-Node-SDK/1.0.0',
28
+ 'Content-Type': 'application/json'
29
+ },
30
+ },
31
+ });
32
+ // Instantiate the EventsApi using configuration and basePath.
33
+ // The underlying implementation uses the global `fetch` API.
34
+ this.events = new generated_1.EventsApi(apiConfig, basePath);
35
+ }
36
+ isRetryableError(error) {
37
+ var _a;
38
+ const axiosError = error;
39
+ // Network / timeout errors
40
+ if (this.retryOnNetworkError && (!axiosError.response || axiosError.code === "ECONNABORTED")) {
41
+ return true;
42
+ }
43
+ // HTTP status based retries
44
+ const status = (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status;
45
+ if (status && this.retryOnStatuses.has(status)) {
46
+ return true;
47
+ }
48
+ return false;
49
+ }
50
+ async sleep(ms) {
51
+ return new Promise((resolve) => setTimeout(resolve, ms));
52
+ }
53
+ async withRetry(fn, options) {
54
+ var _a, _b, _c;
55
+ let attempt = 0;
56
+ // Use per-request options if provided, otherwise use instance defaults
57
+ const maxRetries = (_a = options === null || options === void 0 ? void 0 : options.maxRetries) !== null && _a !== void 0 ? _a : this.maxRetries;
58
+ const retryDelayMs = (_b = options === null || options === void 0 ? void 0 : options.retryDelayMs) !== null && _b !== void 0 ? _b : this.retryDelayMs;
59
+ const retryOnStatuses = (options === null || options === void 0 ? void 0 : options.retryOnStatuses)
60
+ ? new Set(options.retryOnStatuses)
61
+ : this.retryOnStatuses;
62
+ const retryOnNetworkError = (_c = options === null || options === void 0 ? void 0 : options.retryOnNetworkError) !== null && _c !== void 0 ? _c : this.retryOnNetworkError;
63
+ // attempt 0 + maxRetries additional retries
64
+ // e.g. maxRetries=2 -> attempts: 0,1,2
65
+ const maxAttempts = maxRetries + 1;
66
+ // eslint-disable-next-line no-constant-condition
67
+ while (true) {
68
+ try {
69
+ return await fn();
70
+ }
71
+ catch (error) {
72
+ attempt += 1;
73
+ // Check if error is retryable with current settings
74
+ const isRetryable = this.isRetryableErrorWithOptions(error, retryOnStatuses, retryOnNetworkError);
75
+ if (attempt >= maxAttempts || !isRetryable) {
76
+ // Final failure, let our error handler wrap it
77
+ return (0, errors_1.handleApiError)(error);
78
+ }
79
+ const delay = retryDelayMs * attempt; // simple linear backoff
80
+ await this.sleep(delay);
81
+ }
82
+ }
83
+ }
84
+ isRetryableErrorWithOptions(error, retryOnStatuses, retryOnNetworkError) {
85
+ var _a;
86
+ const axiosError = error;
87
+ // Network / timeout errors
88
+ if (retryOnNetworkError && (!axiosError.response || axiosError.code === "ECONNABORTED")) {
89
+ return true;
90
+ }
91
+ // HTTP status based retries
92
+ const status = (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status;
93
+ if (status && retryOnStatuses.has(status)) {
94
+ return true;
95
+ }
96
+ return false;
97
+ }
98
+ async trackLead(request, options) {
99
+ return this.withRetry(async () => {
100
+ return this.events.trackLead(request);
101
+ }, options);
102
+ }
103
+ async trackSale(request, options) {
104
+ return this.withRetry(async () => {
105
+ return this.events.trackSale(request);
106
+ }, options);
107
+ }
108
+ }
109
+ exports.CMS = CMS;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Base error class for CMS API errors.
3
+ * Separated into its own file to avoid circular dependencies.
4
+ */
5
+ export declare class CMSAPIError extends Error {
6
+ readonly statusCode: number;
7
+ readonly type: string;
8
+ readonly rawError: any;
9
+ readonly request?: {
10
+ url?: string;
11
+ method?: string;
12
+ headers?: Record<string, any>;
13
+ };
14
+ readonly response?: {
15
+ status: number;
16
+ statusText: string;
17
+ data?: any;
18
+ headers?: Record<string, any>;
19
+ };
20
+ constructor(message: string, statusCode: number, type: string, rawError: any, request?: CMSAPIError["request"], response?: CMSAPIError["response"]);
21
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CMSAPIError = void 0;
4
+ /**
5
+ * Base error class for CMS API errors.
6
+ * Separated into its own file to avoid circular dependencies.
7
+ */
8
+ class CMSAPIError extends Error {
9
+ constructor(message, statusCode, type, rawError, request, response) {
10
+ super(message);
11
+ this.name = "CMSAPIError";
12
+ this.statusCode = statusCode;
13
+ this.type = type;
14
+ this.rawError = rawError;
15
+ this.request = request;
16
+ this.response = response;
17
+ }
18
+ }
19
+ exports.CMSAPIError = CMSAPIError;
@@ -0,0 +1,3 @@
1
+ export { CMSAPIError } from "./base";
2
+ export { handleApiError } from "../errors";
3
+ export { BadRequestError, UnauthorizedError, ForbiddenError, NotFoundError, ConflictError, UnprocessableEntityError, RateLimitError, InternalServerError, BadGatewayError, ServiceUnavailableError, GatewayTimeoutError, createSpecificError, } from "./specific";
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSpecificError = exports.GatewayTimeoutError = exports.ServiceUnavailableError = exports.BadGatewayError = exports.InternalServerError = exports.RateLimitError = exports.UnprocessableEntityError = exports.ConflictError = exports.NotFoundError = exports.ForbiddenError = exports.UnauthorizedError = exports.BadRequestError = exports.handleApiError = exports.CMSAPIError = void 0;
4
+ // Re-export base error
5
+ var base_1 = require("./base");
6
+ Object.defineProperty(exports, "CMSAPIError", { enumerable: true, get: function () { return base_1.CMSAPIError; } });
7
+ var errors_1 = require("../errors");
8
+ Object.defineProperty(exports, "handleApiError", { enumerable: true, get: function () { return errors_1.handleApiError; } });
9
+ // Specific error types
10
+ var specific_1 = require("./specific");
11
+ Object.defineProperty(exports, "BadRequestError", { enumerable: true, get: function () { return specific_1.BadRequestError; } });
12
+ Object.defineProperty(exports, "UnauthorizedError", { enumerable: true, get: function () { return specific_1.UnauthorizedError; } });
13
+ Object.defineProperty(exports, "ForbiddenError", { enumerable: true, get: function () { return specific_1.ForbiddenError; } });
14
+ Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return specific_1.NotFoundError; } });
15
+ Object.defineProperty(exports, "ConflictError", { enumerable: true, get: function () { return specific_1.ConflictError; } });
16
+ Object.defineProperty(exports, "UnprocessableEntityError", { enumerable: true, get: function () { return specific_1.UnprocessableEntityError; } });
17
+ Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return specific_1.RateLimitError; } });
18
+ Object.defineProperty(exports, "InternalServerError", { enumerable: true, get: function () { return specific_1.InternalServerError; } });
19
+ Object.defineProperty(exports, "BadGatewayError", { enumerable: true, get: function () { return specific_1.BadGatewayError; } });
20
+ Object.defineProperty(exports, "ServiceUnavailableError", { enumerable: true, get: function () { return specific_1.ServiceUnavailableError; } });
21
+ Object.defineProperty(exports, "GatewayTimeoutError", { enumerable: true, get: function () { return specific_1.GatewayTimeoutError; } });
22
+ Object.defineProperty(exports, "createSpecificError", { enumerable: true, get: function () { return specific_1.createSpecificError; } });
@@ -0,0 +1,43 @@
1
+ import { CMSAPIError } from "./base";
2
+ export { CMSAPIError };
3
+ /**
4
+ * Specific error types for different HTTP status codes.
5
+ * These provide better type safety and allow users to handle specific errors.
6
+ */
7
+ export declare class BadRequestError extends CMSAPIError {
8
+ constructor(message: string, rawError?: any);
9
+ }
10
+ export declare class UnauthorizedError extends CMSAPIError {
11
+ constructor(message: string, rawError?: any);
12
+ }
13
+ export declare class ForbiddenError extends CMSAPIError {
14
+ constructor(message: string, rawError?: any);
15
+ }
16
+ export declare class NotFoundError extends CMSAPIError {
17
+ constructor(message: string, rawError?: any);
18
+ }
19
+ export declare class ConflictError extends CMSAPIError {
20
+ constructor(message: string, rawError?: any);
21
+ }
22
+ export declare class UnprocessableEntityError extends CMSAPIError {
23
+ constructor(message: string, rawError?: any);
24
+ }
25
+ export declare class RateLimitError extends CMSAPIError {
26
+ constructor(message: string, rawError?: any);
27
+ }
28
+ export declare class InternalServerError extends CMSAPIError {
29
+ constructor(message: string, rawError?: any);
30
+ }
31
+ export declare class BadGatewayError extends CMSAPIError {
32
+ constructor(message: string, rawError?: any);
33
+ }
34
+ export declare class ServiceUnavailableError extends CMSAPIError {
35
+ constructor(message: string, rawError?: any);
36
+ }
37
+ export declare class GatewayTimeoutError extends CMSAPIError {
38
+ constructor(message: string, rawError?: any);
39
+ }
40
+ /**
41
+ * Maps HTTP status codes to specific error classes
42
+ */
43
+ export declare function createSpecificError(statusCode: number, message: string, rawError?: any): CMSAPIError;
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GatewayTimeoutError = exports.ServiceUnavailableError = exports.BadGatewayError = exports.InternalServerError = exports.RateLimitError = exports.UnprocessableEntityError = exports.ConflictError = exports.NotFoundError = exports.ForbiddenError = exports.UnauthorizedError = exports.BadRequestError = exports.CMSAPIError = void 0;
4
+ exports.createSpecificError = createSpecificError;
5
+ const base_1 = require("./base");
6
+ Object.defineProperty(exports, "CMSAPIError", { enumerable: true, get: function () { return base_1.CMSAPIError; } });
7
+ /**
8
+ * Specific error types for different HTTP status codes.
9
+ * These provide better type safety and allow users to handle specific errors.
10
+ */
11
+ class BadRequestError extends base_1.CMSAPIError {
12
+ constructor(message, rawError) {
13
+ super(message, 400, "bad_request", rawError);
14
+ this.name = "BadRequestError";
15
+ }
16
+ }
17
+ exports.BadRequestError = BadRequestError;
18
+ class UnauthorizedError extends base_1.CMSAPIError {
19
+ constructor(message, rawError) {
20
+ super(message, 401, "unauthorized", rawError);
21
+ this.name = "UnauthorizedError";
22
+ }
23
+ }
24
+ exports.UnauthorizedError = UnauthorizedError;
25
+ class ForbiddenError extends base_1.CMSAPIError {
26
+ constructor(message, rawError) {
27
+ super(message, 403, "forbidden", rawError);
28
+ this.name = "ForbiddenError";
29
+ }
30
+ }
31
+ exports.ForbiddenError = ForbiddenError;
32
+ class NotFoundError extends base_1.CMSAPIError {
33
+ constructor(message, rawError) {
34
+ super(message, 404, "not_found", rawError);
35
+ this.name = "NotFoundError";
36
+ }
37
+ }
38
+ exports.NotFoundError = NotFoundError;
39
+ class ConflictError extends base_1.CMSAPIError {
40
+ constructor(message, rawError) {
41
+ super(message, 409, "conflict", rawError);
42
+ this.name = "ConflictError";
43
+ }
44
+ }
45
+ exports.ConflictError = ConflictError;
46
+ class UnprocessableEntityError extends base_1.CMSAPIError {
47
+ constructor(message, rawError) {
48
+ super(message, 422, "unprocessable_entity", rawError);
49
+ this.name = "UnprocessableEntityError";
50
+ }
51
+ }
52
+ exports.UnprocessableEntityError = UnprocessableEntityError;
53
+ class RateLimitError extends base_1.CMSAPIError {
54
+ constructor(message, rawError) {
55
+ super(message, 429, "rate_limit_exceeded", rawError);
56
+ this.name = "RateLimitError";
57
+ }
58
+ }
59
+ exports.RateLimitError = RateLimitError;
60
+ class InternalServerError extends base_1.CMSAPIError {
61
+ constructor(message, rawError) {
62
+ super(message, 500, "internal_server_error", rawError);
63
+ this.name = "InternalServerError";
64
+ }
65
+ }
66
+ exports.InternalServerError = InternalServerError;
67
+ class BadGatewayError extends base_1.CMSAPIError {
68
+ constructor(message, rawError) {
69
+ super(message, 502, "bad_gateway", rawError);
70
+ this.name = "BadGatewayError";
71
+ }
72
+ }
73
+ exports.BadGatewayError = BadGatewayError;
74
+ class ServiceUnavailableError extends base_1.CMSAPIError {
75
+ constructor(message, rawError) {
76
+ super(message, 503, "service_unavailable", rawError);
77
+ this.name = "ServiceUnavailableError";
78
+ }
79
+ }
80
+ exports.ServiceUnavailableError = ServiceUnavailableError;
81
+ class GatewayTimeoutError extends base_1.CMSAPIError {
82
+ constructor(message, rawError) {
83
+ super(message, 504, "gateway_timeout", rawError);
84
+ this.name = "GatewayTimeoutError";
85
+ }
86
+ }
87
+ exports.GatewayTimeoutError = GatewayTimeoutError;
88
+ /**
89
+ * Maps HTTP status codes to specific error classes
90
+ */
91
+ function createSpecificError(statusCode, message, rawError) {
92
+ switch (statusCode) {
93
+ case 400:
94
+ return new BadRequestError(message, rawError);
95
+ case 401:
96
+ return new UnauthorizedError(message, rawError);
97
+ case 403:
98
+ return new ForbiddenError(message, rawError);
99
+ case 404:
100
+ return new NotFoundError(message, rawError);
101
+ case 409:
102
+ return new ConflictError(message, rawError);
103
+ case 422:
104
+ return new UnprocessableEntityError(message, rawError);
105
+ case 429:
106
+ return new RateLimitError(message, rawError);
107
+ case 500:
108
+ return new InternalServerError(message, rawError);
109
+ case 502:
110
+ return new BadGatewayError(message, rawError);
111
+ case 503:
112
+ return new ServiceUnavailableError(message, rawError);
113
+ case 504:
114
+ return new GatewayTimeoutError(message, rawError);
115
+ default:
116
+ return new base_1.CMSAPIError(message, statusCode, "api_error", rawError);
117
+ }
118
+ }
@@ -0,0 +1,8 @@
1
+ import { CMSAPIError } from "./errors/base";
2
+ export { CMSAPIError };
3
+ export { BadRequestError, UnauthorizedError, ForbiddenError, NotFoundError, ConflictError, UnprocessableEntityError, RateLimitError, InternalServerError, BadGatewayError, ServiceUnavailableError, GatewayTimeoutError, createSpecificError, } from "./errors/index";
4
+ /**
5
+ * Parses fetch/network errors into a clean CMSAPIError
6
+ * Uses specific error types when possible for better type safety
7
+ */
8
+ export declare function handleApiError(error: any, request?: any, response?: any): never;