@vigneshreddy/cms-sdk 1.0.7 → 1.0.9

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/README.md CHANGED
@@ -1,11 +1,10 @@
1
- # CMS TypeScript SDK (cms)
1
+ # @vigneshreddy/cms-sdk
2
2
 
3
- TypeScript/JavaScript SDK for the CutMeShort CMS API.
3
+ Official TypeScript/JavaScript SDK for the CutMeShort CMS API.
4
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).
5
+ Use this package to send:
6
+ - lead tracking events (`trackLead`)
7
+ - sale tracking events (`trackSale`)
9
8
 
10
9
  ## Install
11
10
 
@@ -13,104 +12,117 @@ This SDK is:
13
12
  npm install @vigneshreddy/cms-sdk
14
13
  ```
15
14
 
16
- ## Runtime requirements
15
+ ## Requirements
17
16
 
18
- - Browser: any modern browser with `fetch`.
19
- - Node.js: Node 18+ recommended (built-in `fetch`).
20
- - Node < 18: add a fetch polyfill and set it globally before using the SDK.
17
+ - Node.js 18+ (recommended) or any runtime with global `fetch`
18
+ - TypeScript 5+ (optional, for type safety)
19
+
20
+ If your runtime does not provide `fetch`, add a polyfill before creating the client.
21
21
 
22
22
  ```ts
23
23
  import fetch, { Headers, Request, Response } from "cross-fetch";
24
24
 
25
- // @ts-ignore
26
- global.fetch = fetch as any;
27
- // @ts-ignore
28
- global.Headers = Headers as any;
29
- // @ts-ignore
30
- global.Request = Request as any;
31
- // @ts-ignore
32
- global.Response = Response as any;
25
+ (globalThis as any).fetch = fetch;
26
+ (globalThis as any).Headers = Headers;
27
+ (globalThis as any).Request = Request;
28
+ (globalThis as any).Response = Response;
33
29
  ```
34
30
 
35
- ## Quick start
36
-
37
- Create the client once and reuse it across calls.
31
+ ## Quick Start
38
32
 
39
33
  ```ts
40
34
  import { CMS } from "@vigneshreddy/cms-sdk";
41
35
 
42
- const sdk = new CMS({
36
+ const cms = new CMS({
43
37
  apiKey: process.env.CMS_API_KEY!,
44
38
  timeout: 10_000,
45
39
  });
46
- ```
47
-
48
- ## Track a lead
49
-
50
- ### Class-based usage (throws on error)
51
40
 
52
- ```ts
53
- import { CMS } from "@vigneshreddy/cms-sdk";
54
-
55
- const sdk = new CMS({ apiKey: "sk_live_123" });
56
-
57
- const leadResponse = await sdk.trackLead({
41
+ const response = await cms.trackLead({
58
42
  clickId: "id_123",
59
43
  eventName: "signup_started",
60
44
  customerId: "user_42",
61
45
  });
62
46
 
63
- console.log("Lead response:", leadResponse);
47
+ console.log(response);
64
48
  ```
65
49
 
66
- ### Functional helper (Result pattern)
50
+ ## API Methods
51
+
52
+ ### `trackLead(leadData, options?)`
67
53
 
68
54
  ```ts
69
- import { CMS, trackLead } from "@vigneshreddy/cms-sdk";
55
+ import { CMS } from "@vigneshreddy/cms-sdk";
70
56
 
71
- const sdk = new CMS({ apiKey: "sk_live_123" });
57
+ const cms = new CMS({ apiKey: "sk_live_xxx" });
72
58
 
73
- const res = await trackLead(sdk, {
59
+ await cms.trackLead({
74
60
  clickId: "id_123",
75
61
  eventName: "signup_started",
76
62
  customerId: "user_42",
77
63
  });
78
-
79
- if (res.ok) {
80
- console.log("Lead response:", res.value);
81
- } else {
82
- console.error("Lead error:", res.error);
83
- }
84
64
  ```
85
65
 
86
- ## Track a sale
66
+ Lead payload fields:
67
+ - `clickId: string`
68
+ - `eventName: string`
69
+ - `customerId: string`
87
70
 
88
- ### Class-based usage (throws on error)
71
+ ### `trackSale(saleData, options?)`
89
72
 
90
73
  ```ts
91
74
  import { CMS } from "@vigneshreddy/cms-sdk";
92
75
 
93
- const sdk = new CMS({ apiKey: "sk_live_123" });
76
+ const cms = new CMS({ apiKey: "sk_live_xxx" });
94
77
 
95
- const saleResponse = await sdk.trackSale({
78
+ await cms.trackSale({
96
79
  clickId: "id_123",
97
80
  eventName: "purchase_completed",
98
81
  invoiceId: "inv_987",
99
82
  amount: 4999,
100
83
  currency: "USD",
101
84
  });
85
+ ```
86
+
87
+ Sale payload fields:
88
+ - `clickId: string`
89
+ - `eventName: string`
90
+ - `invoiceId: string`
91
+ - `amount: number` (in cents)
92
+ - `currency: string` (3-letter code, e.g. `USD`)
93
+
94
+ ## Functional Style (Result Pattern)
95
+
96
+ If you prefer not to use `try/catch`, use helper functions that return `Result`.
97
+
98
+ ### Lead Example
99
+
100
+ ```ts
101
+ import { CMS, trackLead } from "@vigneshreddy/cms-sdk";
102
+
103
+ const cms = new CMS({ apiKey: "sk_live_xxx" });
104
+
105
+ const result = await trackLead(cms, {
106
+ clickId: "id_123",
107
+ eventName: "signup_started",
108
+ customerId: "user_42",
109
+ });
102
110
 
103
- console.log("Sale response:", saleResponse);
111
+ if (result.ok) {
112
+ console.log("Tracked lead:", result.value);
113
+ } else {
114
+ console.error("Lead error:", result.error);
115
+ }
104
116
  ```
105
117
 
106
- ### Functional helper (Result pattern)
118
+ ### Sale Example
107
119
 
108
120
  ```ts
109
- import { CMS, trackSale } from "cms";
121
+ import { CMS, trackSale } from "@vigneshreddy/cms-sdk";
110
122
 
111
- const sdk = new CMS({ apiKey: "sk_live_123" });
123
+ const cms = new CMS({ apiKey: "sk_live_xxx" });
112
124
 
113
- const res = await trackSale(sdk, {
125
+ const result = await trackSale(cms, {
114
126
  clickId: "id_123",
115
127
  eventName: "purchase_completed",
116
128
  invoiceId: "inv_987",
@@ -118,43 +130,45 @@ const res = await trackSale(sdk, {
118
130
  currency: "USD",
119
131
  });
120
132
 
121
- if (res.ok) {
122
- console.log("Sale response:", res.value);
133
+ if (result.ok) {
134
+ console.log("Tracked sale:", result.value);
123
135
  } else {
124
- console.error("Sale error:", res.error);
136
+ console.error("Sale error:", result.error);
125
137
  }
126
138
  ```
127
139
 
128
140
  ## Configuration
129
141
 
142
+ `new CMS(config)` accepts:
143
+
130
144
  ```ts
131
- export interface CMSConfig {
145
+ type CMSConfig = {
132
146
  apiKey: string;
133
147
  timeout?: number;
134
148
  maxRetries?: number;
135
149
  retryDelayMs?: number;
136
150
  retryOnStatuses?: number[];
137
151
  retryOnNetworkError?: boolean;
138
- }
152
+ };
139
153
  ```
140
154
 
141
- - `apiKey` (required): CMS secret API key.
142
- - `timeout`: request timeout in ms (default: 10000).
143
- - `maxRetries`: retry attempts for transient failures (default: 2).
144
- - `retryDelayMs`: base delay for linear backoff (default: 500).
145
- - `retryOnStatuses`: HTTP codes that are retryable (default: 429, 500, 502, 503, 504).
146
- - `retryOnNetworkError`: retry on network/timeout errors (default: true).
155
+ Defaults:
156
+ - `timeout`: `10000`
157
+ - `maxRetries`: `2`
158
+ - `retryDelayMs`: `500`
159
+ - `retryOnStatuses`: `[429, 500, 502, 503, 504]`
160
+ - `retryOnNetworkError`: `true`
147
161
 
148
- ## Per-request overrides
162
+ ## Per-request Overrides
149
163
 
150
- You can override retries and timeout on a single request.
164
+ You can override retry/timeout settings for a specific call:
151
165
 
152
166
  ```ts
153
167
  import { CMS } from "@vigneshreddy/cms-sdk";
154
168
 
155
- const sdk = new CMS({ apiKey: "sk_live_123" });
169
+ const cms = new CMS({ apiKey: "sk_live_xxx" });
156
170
 
157
- await sdk.trackLead(
171
+ await cms.trackLead(
158
172
  {
159
173
  clickId: "id_123",
160
174
  eventName: "signup_started",
@@ -163,47 +177,62 @@ await sdk.trackLead(
163
177
  {
164
178
  timeout: 5000,
165
179
  maxRetries: 1,
180
+ retryDelayMs: 300,
166
181
  }
167
182
  );
168
183
  ```
169
184
 
170
- ## Error handling
185
+ ## Error Handling
171
186
 
172
- All thrown errors from class-based methods are normalized as `CMSAPIError` or its specific subclasses.
187
+ Class-based methods (`cms.trackLead`, `cms.trackSale`) throw `CMSAPIError` on failure.
173
188
 
174
189
  ```ts
175
190
  import { CMS, CMSAPIError } from "@vigneshreddy/cms-sdk";
176
191
 
177
- const sdk = new CMS({ apiKey: "sk_live_123" });
192
+ const cms = new CMS({ apiKey: "sk_live_xxx" });
178
193
 
179
194
  try {
180
- await sdk.trackLead({
195
+ await cms.trackSale({
181
196
  clickId: "id_123",
182
- eventName: "signup_started",
183
- customerId: "user_42",
197
+ eventName: "purchase_completed",
198
+ invoiceId: "inv_987",
199
+ amount: 4999,
200
+ currency: "USD",
184
201
  });
185
- } catch (err) {
186
- if (err instanceof CMSAPIError) {
187
- console.error("CMS API Error:", {
188
- statusCode: err.statusCode,
189
- type: err.type,
190
- message: err.message,
202
+ } catch (error) {
203
+ if (error instanceof CMSAPIError) {
204
+ console.error("CMS API error", {
205
+ statusCode: error.statusCode,
206
+ type: error.type,
207
+ message: error.message,
191
208
  });
192
209
  } else {
193
- console.error("Unexpected error:", err);
210
+ console.error("Unexpected error", error);
194
211
  }
195
212
  }
196
213
  ```
197
214
 
198
- ## Exports
215
+ ## TypeScript Types
199
216
 
200
217
  ```ts
201
- import { CMS } from "@vigneshreddy/cms-sdk";
202
- import { trackLead, trackSale } from "@vigneshreddy/cms-sdk";
203
- import { CMSAPIError } from "@vigneshreddy/cms-sdk";
204
- import type { TrackLeadRequest, TrackSaleRequest, TrackResponse } from "@vigneshreddy/cms-sdk";
218
+ import type {
219
+ TrackLeadRequest,
220
+ TrackSaleRequest,
221
+ TrackResponse,
222
+ RequestOptions,
223
+ CMSConfig,
224
+ } from "@vigneshreddy/cms-sdk";
205
225
  ```
206
226
 
207
- ## Security
227
+ ## Exports
228
+
229
+ Main package exports:
230
+ - `CMS`
231
+ - `trackLead`, `trackSale`
232
+ - `CMSAPIError` and specific error classes
233
+ - `ok`, `err`, `Result`
234
+ - generated request/response types
235
+
236
+ ## Security Best Practice
208
237
 
209
- Do not expose secret API keys in frontend code. Use a backend or secure proxy if the key is private.
238
+ Do not expose private API keys in public frontend code. Use this SDK from a trusted backend/server environment when using secret keys.
@@ -1,14 +1,3 @@
1
- /**
2
- * CMS API
3
- * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
4
- *
5
- * The version of the OpenAPI document: 1.0.0
6
- *
7
- *
8
- * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9
- * https://openapi-generator.tech
10
- * Do not edit the class manually.
11
- */
12
1
  import type { Configuration } from './configuration';
13
2
  export type RequestOptions = RequestInit & {
14
3
  /**
@@ -1,20 +1,7 @@
1
1
  "use strict";
2
- /* tslint:disable */
3
- /* eslint-disable */
4
- /**
5
- * CMS API
6
- * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
7
- *
8
- * The version of the OpenAPI document: 1.0.0
9
- *
10
- *
11
- * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
12
- * https://openapi-generator.tech
13
- * Do not edit the class manually.
14
- */
15
2
  Object.defineProperty(exports, "__esModule", { value: true });
16
3
  exports.operationServerMap = exports.RequiredError = exports.BaseAPI = exports.COLLECTION_FORMATS = exports.BASE_PATH = void 0;
17
- exports.BASE_PATH = "https://www.cutmeshort.com/api".replace(/\/+$/, "");
4
+ exports.BASE_PATH = "https://www.cutmeshort.com/sdk".replace(/\/+$/, "");
18
5
  exports.COLLECTION_FORMATS = {
19
6
  csv: ",",
20
7
  ssv: " ",
@@ -1,14 +1,3 @@
1
- /**
2
- * CMS API
3
- * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
4
- *
5
- * The version of the OpenAPI document: 1.0.0
6
- *
7
- *
8
- * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9
- * https://openapi-generator.tech
10
- * Do not edit the class manually.
11
- */
12
1
  import type { Configuration } from "./configuration";
13
2
  export declare const DUMMY_BASE_URL = "https://example.com";
14
3
  /**
@@ -1,17 +1,4 @@
1
1
  "use strict";
2
- /* tslint:disable */
3
- /* eslint-disable */
4
- /**
5
- * CMS API
6
- * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
7
- *
8
- * The version of the OpenAPI document: 1.0.0
9
- *
10
- *
11
- * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
12
- * https://openapi-generator.tech
13
- * Do not edit the class manually.
14
- */
15
2
  Object.defineProperty(exports, "__esModule", { value: true });
16
3
  exports.toPathString = exports.serializeDataIfNeeded = exports.replaceWithSerializableTypeIfNeeded = exports.setSearchParams = exports.setOAuthToObject = exports.setBearerAuthToObject = exports.setBasicAuthToObject = exports.setApiKeyToObject = exports.assertParamExists = exports.DUMMY_BASE_URL = void 0;
17
4
  const base_1 = require("./base");
@@ -1,14 +1,3 @@
1
- /**
2
- * CMS API
3
- * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
4
- *
5
- * The version of the OpenAPI document: 1.0.0
6
- *
7
- *
8
- * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9
- * https://openapi-generator.tech
10
- * Do not edit the class manually.
11
- */
12
1
  interface AWSv4Configuration {
13
2
  options?: {
14
3
  region?: string;
@@ -1,16 +1,4 @@
1
1
  "use strict";
2
- /* tslint:disable */
3
- /**
4
- * CMS API
5
- * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
6
- *
7
- * The version of the OpenAPI document: 1.0.0
8
- *
9
- *
10
- * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
- * https://openapi-generator.tech
12
- * Do not edit the class manually.
13
- */
14
2
  Object.defineProperty(exports, "__esModule", { value: true });
15
3
  exports.Configuration = void 0;
16
4
  class Configuration {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vigneshreddy/cms-sdk",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Official TypeScript SDK for CutMeShort CMS API",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",