@vigneshreddy/cms-sdk 1.0.6 → 1.0.7
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/src/client.d.ts +5 -3
- package/dist/src/client.js +12 -4
- package/dist/src/errors/base.js +13 -0
- package/dist/src/errors.js +10 -2
- package/dist/src/funcs/trackLead.d.ts +1 -2
- package/dist/src/funcs/trackLead.js +1 -5
- package/dist/src/funcs/trackSale.d.ts +1 -2
- package/dist/src/funcs/trackSale.js +1 -5
- package/dist/src/generated/api.js +2 -4
- package/package.json +1 -1
package/dist/src/client.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { EventsApi
|
|
1
|
+
import { EventsApi } from "./generated";
|
|
2
|
+
export type LeadPayload = Record<string, unknown>;
|
|
3
|
+
export type SalePayload = Record<string, unknown>;
|
|
2
4
|
export interface CMSConfig {
|
|
3
5
|
apiKey: string;
|
|
4
6
|
/**
|
|
@@ -41,6 +43,6 @@ export declare class CMS {
|
|
|
41
43
|
private sleep;
|
|
42
44
|
private withRetry;
|
|
43
45
|
private isRetryableErrorWithOptions;
|
|
44
|
-
trackLead(
|
|
45
|
-
trackSale(
|
|
46
|
+
trackLead(leadData: LeadPayload, options?: RequestOptions): Promise<import("./generated").TrackResponse>;
|
|
47
|
+
trackSale(saleData: SalePayload, options?: RequestOptions): Promise<import("./generated").TrackResponse>;
|
|
46
48
|
}
|
package/dist/src/client.js
CHANGED
|
@@ -96,14 +96,22 @@ class CMS {
|
|
|
96
96
|
}
|
|
97
97
|
return false;
|
|
98
98
|
}
|
|
99
|
-
async trackLead(
|
|
99
|
+
async trackLead(leadData, options) {
|
|
100
|
+
const payload = {
|
|
101
|
+
type: "lead",
|
|
102
|
+
lead: leadData,
|
|
103
|
+
};
|
|
100
104
|
return this.withRetry(async () => {
|
|
101
|
-
return this.events.trackLead(
|
|
105
|
+
return this.events.trackLead(payload);
|
|
102
106
|
}, options);
|
|
103
107
|
}
|
|
104
|
-
async trackSale(
|
|
108
|
+
async trackSale(saleData, options) {
|
|
109
|
+
const payload = {
|
|
110
|
+
type: "sale",
|
|
111
|
+
sale: saleData,
|
|
112
|
+
};
|
|
105
113
|
return this.withRetry(async () => {
|
|
106
|
-
return this.events.trackSale(
|
|
114
|
+
return this.events.trackSale(payload);
|
|
107
115
|
}, options);
|
|
108
116
|
}
|
|
109
117
|
}
|
package/dist/src/errors/base.js
CHANGED
|
@@ -14,6 +14,19 @@ class CMSAPIError extends Error {
|
|
|
14
14
|
this.rawError = rawError;
|
|
15
15
|
this.request = request;
|
|
16
16
|
this.response = response;
|
|
17
|
+
// Make heavy properties non-enumerable so console.log / inspection
|
|
18
|
+
// stays focused on the high-level error information.
|
|
19
|
+
try {
|
|
20
|
+
Object.defineProperties(this, {
|
|
21
|
+
rawError: { enumerable: false },
|
|
22
|
+
request: { enumerable: false },
|
|
23
|
+
response: { enumerable: false },
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
// If defineProperties fails for any reason, we still keep the data;
|
|
28
|
+
// it will just remain enumerable.
|
|
29
|
+
}
|
|
17
30
|
}
|
|
18
31
|
}
|
|
19
32
|
exports.CMSAPIError = CMSAPIError;
|
package/dist/src/errors.js
CHANGED
|
@@ -25,6 +25,14 @@ Object.defineProperty(exports, "createSpecificError", { enumerable: true, get: f
|
|
|
25
25
|
*/
|
|
26
26
|
function handleApiError(error, request, response) {
|
|
27
27
|
var _a, _b, _c;
|
|
28
|
+
const sanitizeRequest = (req) => {
|
|
29
|
+
if (!req || typeof req !== "object")
|
|
30
|
+
return undefined;
|
|
31
|
+
return {
|
|
32
|
+
url: req.url,
|
|
33
|
+
method: req.method,
|
|
34
|
+
};
|
|
35
|
+
};
|
|
28
36
|
// Error with response from server
|
|
29
37
|
if ((error === null || error === void 0 ? void 0 : error.response) || response) {
|
|
30
38
|
const res = (error === null || error === void 0 ? void 0 : error.response) || response;
|
|
@@ -33,7 +41,7 @@ function handleApiError(error, request, response) {
|
|
|
33
41
|
res.statusText ||
|
|
34
42
|
"Unknown API Error";
|
|
35
43
|
// Create error with request/response metadata
|
|
36
|
-
const apiError = new base_1.CMSAPIError(`CMS API Error: ${statusCode} - ${message}`, statusCode, ((_b = res.data) === null || _b === void 0 ? void 0 : _b.type) || "api_error", (_c = res.data) !== null && _c !== void 0 ? _c : error, request || (error === null || error === void 0 ? void 0 : error.request), {
|
|
44
|
+
const apiError = new base_1.CMSAPIError(`CMS API Error: ${statusCode} - ${message}`, statusCode, ((_b = res.data) === null || _b === void 0 ? void 0 : _b.type) || "api_error", (_c = res.data) !== null && _c !== void 0 ? _c : error, sanitizeRequest(request || (error === null || error === void 0 ? void 0 : error.request)), {
|
|
37
45
|
status: statusCode,
|
|
38
46
|
statusText: res.statusText || "",
|
|
39
47
|
data: res.data,
|
|
@@ -43,7 +51,7 @@ function handleApiError(error, request, response) {
|
|
|
43
51
|
}
|
|
44
52
|
// Error where request was made but no response received
|
|
45
53
|
if ((error === null || error === void 0 ? void 0 : error.request) || request) {
|
|
46
|
-
const req = (error === null || error === void 0 ? void 0 : error.request) || request;
|
|
54
|
+
const req = sanitizeRequest((error === null || error === void 0 ? void 0 : error.request) || request);
|
|
47
55
|
const isTimeout = error.code === "ECONNABORTED" ||
|
|
48
56
|
typeof error.message === "string" &&
|
|
49
57
|
error.message.toLowerCase().includes("timeout");
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { CMS } from "../client";
|
|
1
|
+
import { CMS, type LeadPayload } from "../client";
|
|
2
2
|
import type { TrackResponse } from "../generated/api";
|
|
3
3
|
import { Result } from "../types/result";
|
|
4
4
|
import { CMSAPIError, BadRequestError, UnauthorizedError, ForbiddenError, NotFoundError, ConflictError, UnprocessableEntityError, RateLimitError, InternalServerError, BadGatewayError, ServiceUnavailableError, GatewayTimeoutError } from "../errors";
|
|
5
5
|
export type TrackLeadError = BadRequestError | UnauthorizedError | ForbiddenError | NotFoundError | ConflictError | UnprocessableEntityError | RateLimitError | InternalServerError | BadGatewayError | ServiceUnavailableError | GatewayTimeoutError | CMSAPIError;
|
|
6
|
-
export type LeadPayload = Record<string, unknown>;
|
|
7
6
|
/**
|
|
8
7
|
* Track a lead for a short link.
|
|
9
8
|
*
|
|
@@ -43,11 +43,7 @@ const errors_1 = require("../errors");
|
|
|
43
43
|
*/
|
|
44
44
|
async function trackLead(client, leadData) {
|
|
45
45
|
try {
|
|
46
|
-
const
|
|
47
|
-
type: "lead",
|
|
48
|
-
lead: leadData,
|
|
49
|
-
};
|
|
50
|
-
const value = await client.trackLead(payload);
|
|
46
|
+
const value = await client.trackLead(leadData);
|
|
51
47
|
return (0, result_1.ok)(value);
|
|
52
48
|
}
|
|
53
49
|
catch (error) {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { CMS } from "../client";
|
|
1
|
+
import { CMS, type SalePayload } from "../client";
|
|
2
2
|
import type { TrackResponse } from "../generated/api";
|
|
3
3
|
import { Result } from "../types/result";
|
|
4
4
|
import { CMSAPIError, BadRequestError, UnauthorizedError, ForbiddenError, NotFoundError, ConflictError, UnprocessableEntityError, RateLimitError, InternalServerError, BadGatewayError, ServiceUnavailableError, GatewayTimeoutError } from "../errors";
|
|
5
5
|
export type TrackSaleError = BadRequestError | UnauthorizedError | ForbiddenError | NotFoundError | ConflictError | UnprocessableEntityError | RateLimitError | InternalServerError | BadGatewayError | ServiceUnavailableError | GatewayTimeoutError | CMSAPIError;
|
|
6
|
-
export type SalePayload = Record<string, unknown>;
|
|
7
6
|
/**
|
|
8
7
|
* Track a sale for a short link.
|
|
9
8
|
*
|
|
@@ -45,11 +45,7 @@ const errors_1 = require("../errors");
|
|
|
45
45
|
*/
|
|
46
46
|
async function trackSale(client, saleData) {
|
|
47
47
|
try {
|
|
48
|
-
const
|
|
49
|
-
type: "sale",
|
|
50
|
-
sale: saleData,
|
|
51
|
-
};
|
|
52
|
-
const value = await client.trackSale(payload);
|
|
48
|
+
const value = await client.trackSale(saleData);
|
|
53
49
|
return (0, result_1.ok)(value);
|
|
54
50
|
}
|
|
55
51
|
catch (error) {
|
|
@@ -249,10 +249,8 @@ async function performFetchRequest(requestArgs, basePath) {
|
|
|
249
249
|
err.code = "ECONNABORTED";
|
|
250
250
|
}
|
|
251
251
|
if (!err.response) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
options: requestArgs.options,
|
|
255
|
-
};
|
|
252
|
+
// Attach only minimal request info to avoid leaking sensitive data
|
|
253
|
+
err.request = { url };
|
|
256
254
|
}
|
|
257
255
|
throw err;
|
|
258
256
|
}
|