@vigneshreddy/cms-sdk 1.0.15 → 1.0.16
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/package.json +1 -1
- package/dist/src/circuit-breaker.d.ts +0 -97
- package/dist/src/circuit-breaker.js +0 -162
- package/dist/src/constants.d.ts +0 -128
- package/dist/src/constants.js +0 -182
- package/dist/src/generated/api.d.ts +0 -192
- package/dist/src/generated/api.js +0 -276
- package/dist/src/generated/base.d.ts +0 -46
- package/dist/src/generated/base.js +0 -39
- package/dist/src/generated/common.d.ts +0 -20
- package/dist/src/generated/common.js +0 -103
- package/dist/src/generated/configuration.d.ts +0 -87
- package/dist/src/generated/configuration.js +0 -37
- package/dist/src/generated/index.d.ts +0 -4
- package/dist/src/generated/index.js +0 -20
- package/dist/src/rate-limiter.d.ts +0 -74
- package/dist/src/rate-limiter.js +0 -109
- package/dist/src/validation.d.ts +0 -119
- package/dist/src/validation.js +0 -196
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
interface AWSv4Configuration {
|
|
2
|
-
options?: {
|
|
3
|
-
region?: string;
|
|
4
|
-
service?: string;
|
|
5
|
-
};
|
|
6
|
-
credentials?: {
|
|
7
|
-
accessKeyId?: string;
|
|
8
|
-
secretAccessKey?: string;
|
|
9
|
-
sessionToken?: string;
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
export interface ConfigurationParameters {
|
|
13
|
-
apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
|
|
14
|
-
username?: string;
|
|
15
|
-
password?: string;
|
|
16
|
-
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise<string>);
|
|
17
|
-
awsv4?: AWSv4Configuration;
|
|
18
|
-
basePath?: string;
|
|
19
|
-
serverIndex?: number;
|
|
20
|
-
baseOptions?: any;
|
|
21
|
-
formDataCtor?: new () => any;
|
|
22
|
-
}
|
|
23
|
-
export declare class Configuration {
|
|
24
|
-
/**
|
|
25
|
-
* parameter for apiKey security
|
|
26
|
-
* @param name security name
|
|
27
|
-
*/
|
|
28
|
-
apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
|
|
29
|
-
/**
|
|
30
|
-
* parameter for basic security
|
|
31
|
-
*/
|
|
32
|
-
username?: string;
|
|
33
|
-
/**
|
|
34
|
-
* parameter for basic security
|
|
35
|
-
*/
|
|
36
|
-
password?: string;
|
|
37
|
-
/**
|
|
38
|
-
* parameter for oauth2 security
|
|
39
|
-
* @param name security name
|
|
40
|
-
* @param scopes oauth2 scope
|
|
41
|
-
*/
|
|
42
|
-
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise<string>);
|
|
43
|
-
/**
|
|
44
|
-
* parameter for aws4 signature security
|
|
45
|
-
* @param {Object} AWS4Signature - AWS4 Signature security
|
|
46
|
-
* @param {string} options.region - aws region
|
|
47
|
-
* @param {string} options.service - name of the service.
|
|
48
|
-
* @param {string} credentials.accessKeyId - aws access key id
|
|
49
|
-
* @param {string} credentials.secretAccessKey - aws access key
|
|
50
|
-
* @param {string} credentials.sessionToken - aws session token
|
|
51
|
-
* @memberof Configuration
|
|
52
|
-
*/
|
|
53
|
-
awsv4?: AWSv4Configuration;
|
|
54
|
-
/**
|
|
55
|
-
* override base path
|
|
56
|
-
*/
|
|
57
|
-
basePath?: string;
|
|
58
|
-
/**
|
|
59
|
-
* override server index
|
|
60
|
-
*/
|
|
61
|
-
serverIndex?: number;
|
|
62
|
-
/**
|
|
63
|
-
* base options for axios calls
|
|
64
|
-
*/
|
|
65
|
-
baseOptions?: any;
|
|
66
|
-
/**
|
|
67
|
-
* The FormData constructor that will be used to create multipart form data
|
|
68
|
-
* requests. You can inject this here so that execution environments that
|
|
69
|
-
* do not support the FormData class can still run the generated client.
|
|
70
|
-
*
|
|
71
|
-
* @type {new () => FormData}
|
|
72
|
-
*/
|
|
73
|
-
formDataCtor?: new () => any;
|
|
74
|
-
constructor(param?: ConfigurationParameters);
|
|
75
|
-
/**
|
|
76
|
-
* Check if the given MIME is a JSON MIME.
|
|
77
|
-
* JSON MIME examples:
|
|
78
|
-
* application/json
|
|
79
|
-
* application/json; charset=UTF8
|
|
80
|
-
* APPLICATION/JSON
|
|
81
|
-
* application/vnd.company+json
|
|
82
|
-
* @param mime - MIME (Multipurpose Internet Mail Extensions)
|
|
83
|
-
* @return True if the given MIME is JSON, false otherwise.
|
|
84
|
-
*/
|
|
85
|
-
isJsonMime(mime: string): boolean;
|
|
86
|
-
}
|
|
87
|
-
export {};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Configuration = void 0;
|
|
4
|
-
class Configuration {
|
|
5
|
-
constructor(param = {}) {
|
|
6
|
-
var _a;
|
|
7
|
-
this.apiKey = param.apiKey;
|
|
8
|
-
this.username = param.username;
|
|
9
|
-
this.password = param.password;
|
|
10
|
-
this.accessToken = param.accessToken;
|
|
11
|
-
this.awsv4 = param.awsv4;
|
|
12
|
-
this.basePath = param.basePath;
|
|
13
|
-
this.serverIndex = param.serverIndex;
|
|
14
|
-
this.baseOptions = {
|
|
15
|
-
...param.baseOptions,
|
|
16
|
-
headers: {
|
|
17
|
-
...(_a = param.baseOptions) === null || _a === void 0 ? void 0 : _a.headers,
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
this.formDataCtor = param.formDataCtor;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Check if the given MIME is a JSON MIME.
|
|
24
|
-
* JSON MIME examples:
|
|
25
|
-
* application/json
|
|
26
|
-
* application/json; charset=UTF8
|
|
27
|
-
* APPLICATION/JSON
|
|
28
|
-
* application/vnd.company+json
|
|
29
|
-
* @param mime - MIME (Multipurpose Internet Mail Extensions)
|
|
30
|
-
* @return True if the given MIME is JSON, false otherwise.
|
|
31
|
-
*/
|
|
32
|
-
isJsonMime(mime) {
|
|
33
|
-
const jsonMime = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
|
|
34
|
-
return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.Configuration = Configuration;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./api"), exports);
|
|
18
|
-
__exportStar(require("./base"), exports);
|
|
19
|
-
__exportStar(require("./common"), exports);
|
|
20
|
-
__exportStar(require("./configuration"), exports);
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Token bucket rate limiter for controlling request rate
|
|
3
|
-
* Prevents the SDK from sending too many requests too quickly
|
|
4
|
-
*/
|
|
5
|
-
export interface RateLimiterOptions {
|
|
6
|
-
/** Maximum number of requests allowed per time window */
|
|
7
|
-
maxRequests: number;
|
|
8
|
-
/** Time window in milliseconds */
|
|
9
|
-
windowMs: number;
|
|
10
|
-
/** Called when rate limit is exceeded */
|
|
11
|
-
onLimitExceeded?: (remaining: number) => void;
|
|
12
|
-
}
|
|
13
|
-
export declare class RateLimiter {
|
|
14
|
-
private maxRequests;
|
|
15
|
-
private windowMs;
|
|
16
|
-
private tokens;
|
|
17
|
-
private lastRefillTime;
|
|
18
|
-
private onLimitExceeded?;
|
|
19
|
-
constructor(options: RateLimiterOptions);
|
|
20
|
-
/**
|
|
21
|
-
* Try to consume one token
|
|
22
|
-
* Returns true if request should be allowed, false if rate limited
|
|
23
|
-
*/
|
|
24
|
-
tryConsume(): boolean;
|
|
25
|
-
/**
|
|
26
|
-
* Get current number of available tokens
|
|
27
|
-
*/
|
|
28
|
-
getAvailableTokens(): number;
|
|
29
|
-
/**
|
|
30
|
-
* Get milliseconds until next token becomes available
|
|
31
|
-
*/
|
|
32
|
-
getWaitTime(): number;
|
|
33
|
-
/**
|
|
34
|
-
* Reset the rate limiter
|
|
35
|
-
*/
|
|
36
|
-
reset(): void;
|
|
37
|
-
/**
|
|
38
|
-
* Refill tokens based on elapsed time
|
|
39
|
-
*/
|
|
40
|
-
private refill;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Pre-configured rate limiters for common scenarios
|
|
44
|
-
*/
|
|
45
|
-
export declare const RATE_LIMITER_PRESETS: {
|
|
46
|
-
/**
|
|
47
|
-
* Conservative: 10 requests per second (good for test/demo)
|
|
48
|
-
*/
|
|
49
|
-
readonly CONSERVATIVE: {
|
|
50
|
-
readonly maxRequests: 10;
|
|
51
|
-
readonly windowMs: 1000;
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* Standard: 100 requests per second (suitable for production)
|
|
55
|
-
*/
|
|
56
|
-
readonly STANDARD: {
|
|
57
|
-
readonly maxRequests: 100;
|
|
58
|
-
readonly windowMs: 1000;
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* Aggressive: 1000 requests per second (for high-volume scenarios)
|
|
62
|
-
*/
|
|
63
|
-
readonly AGGRESSIVE: {
|
|
64
|
-
readonly maxRequests: 1000;
|
|
65
|
-
readonly windowMs: 1000;
|
|
66
|
-
};
|
|
67
|
-
/**
|
|
68
|
-
* Unlimited: No rate limiting (use with caution)
|
|
69
|
-
*/
|
|
70
|
-
readonly UNLIMITED: {
|
|
71
|
-
readonly maxRequests: number;
|
|
72
|
-
readonly windowMs: 1000;
|
|
73
|
-
};
|
|
74
|
-
};
|
package/dist/src/rate-limiter.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Token bucket rate limiter for controlling request rate
|
|
4
|
-
* Prevents the SDK from sending too many requests too quickly
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.RATE_LIMITER_PRESETS = exports.RateLimiter = void 0;
|
|
8
|
-
class RateLimiter {
|
|
9
|
-
constructor(options) {
|
|
10
|
-
this.maxRequests = options.maxRequests;
|
|
11
|
-
this.windowMs = options.windowMs;
|
|
12
|
-
this.tokens = options.maxRequests;
|
|
13
|
-
this.lastRefillTime = Date.now();
|
|
14
|
-
this.onLimitExceeded = options.onLimitExceeded;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Try to consume one token
|
|
18
|
-
* Returns true if request should be allowed, false if rate limited
|
|
19
|
-
*/
|
|
20
|
-
tryConsume() {
|
|
21
|
-
this.refill();
|
|
22
|
-
if (this.tokens > 0) {
|
|
23
|
-
this.tokens -= 1;
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
if (this.onLimitExceeded) {
|
|
27
|
-
this.onLimitExceeded(this.tokens);
|
|
28
|
-
}
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Get current number of available tokens
|
|
33
|
-
*/
|
|
34
|
-
getAvailableTokens() {
|
|
35
|
-
this.refill();
|
|
36
|
-
return this.tokens;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Get milliseconds until next token becomes available
|
|
40
|
-
*/
|
|
41
|
-
getWaitTime() {
|
|
42
|
-
if (this.tokens > 0) {
|
|
43
|
-
return 0;
|
|
44
|
-
}
|
|
45
|
-
const timeSinceRefill = Date.now() - this.lastRefillTime;
|
|
46
|
-
const timePerToken = this.windowMs / this.maxRequests;
|
|
47
|
-
return Math.ceil(timePerToken - timeSinceRefill);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Reset the rate limiter
|
|
51
|
-
*/
|
|
52
|
-
reset() {
|
|
53
|
-
this.tokens = this.maxRequests;
|
|
54
|
-
this.lastRefillTime = Date.now();
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Refill tokens based on elapsed time
|
|
58
|
-
*/
|
|
59
|
-
refill() {
|
|
60
|
-
const now = Date.now();
|
|
61
|
-
const timePassed = now - this.lastRefillTime;
|
|
62
|
-
if (timePassed >= this.windowMs) {
|
|
63
|
-
// Full reset if entire window has passed
|
|
64
|
-
this.tokens = this.maxRequests;
|
|
65
|
-
this.lastRefillTime = now;
|
|
66
|
-
}
|
|
67
|
-
else if (timePassed > 0) {
|
|
68
|
-
// Partial refill based on time passed
|
|
69
|
-
const refillRate = this.maxRequests / this.windowMs;
|
|
70
|
-
const tokensToAdd = (timePassed * refillRate);
|
|
71
|
-
this.tokens = Math.min(this.maxRequests, this.tokens + tokensToAdd);
|
|
72
|
-
this.lastRefillTime = now;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
exports.RateLimiter = RateLimiter;
|
|
77
|
-
/**
|
|
78
|
-
* Pre-configured rate limiters for common scenarios
|
|
79
|
-
*/
|
|
80
|
-
exports.RATE_LIMITER_PRESETS = {
|
|
81
|
-
/**
|
|
82
|
-
* Conservative: 10 requests per second (good for test/demo)
|
|
83
|
-
*/
|
|
84
|
-
CONSERVATIVE: {
|
|
85
|
-
maxRequests: 10,
|
|
86
|
-
windowMs: 1000,
|
|
87
|
-
},
|
|
88
|
-
/**
|
|
89
|
-
* Standard: 100 requests per second (suitable for production)
|
|
90
|
-
*/
|
|
91
|
-
STANDARD: {
|
|
92
|
-
maxRequests: 100,
|
|
93
|
-
windowMs: 1000,
|
|
94
|
-
},
|
|
95
|
-
/**
|
|
96
|
-
* Aggressive: 1000 requests per second (for high-volume scenarios)
|
|
97
|
-
*/
|
|
98
|
-
AGGRESSIVE: {
|
|
99
|
-
maxRequests: 1000,
|
|
100
|
-
windowMs: 1000,
|
|
101
|
-
},
|
|
102
|
-
/**
|
|
103
|
-
* Unlimited: No rate limiting (use with caution)
|
|
104
|
-
*/
|
|
105
|
-
UNLIMITED: {
|
|
106
|
-
maxRequests: Infinity,
|
|
107
|
-
windowMs: 1000,
|
|
108
|
-
},
|
|
109
|
-
};
|
package/dist/src/validation.d.ts
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Input validation schemas using Zod
|
|
3
|
-
* Ensures all incoming data is sanitized and valid
|
|
4
|
-
*/
|
|
5
|
-
import { z } from "zod";
|
|
6
|
-
export declare const CMSConfigSchema: z.ZodObject<{
|
|
7
|
-
apiKey: z.ZodEffects<z.ZodString, string, string>;
|
|
8
|
-
baseUrl: z.ZodOptional<z.ZodString>;
|
|
9
|
-
timeout: z.ZodOptional<z.ZodNumber>;
|
|
10
|
-
maxRetries: z.ZodOptional<z.ZodNumber>;
|
|
11
|
-
retryDelayMs: z.ZodOptional<z.ZodNumber>;
|
|
12
|
-
retryMaxDelayMs: z.ZodOptional<z.ZodNumber>;
|
|
13
|
-
retryOnStatuses: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
14
|
-
retryOnNetworkError: z.ZodOptional<z.ZodBoolean>;
|
|
15
|
-
}, "strip", z.ZodTypeAny, {
|
|
16
|
-
apiKey: string;
|
|
17
|
-
timeout?: number | undefined;
|
|
18
|
-
baseUrl?: string | undefined;
|
|
19
|
-
maxRetries?: number | undefined;
|
|
20
|
-
retryDelayMs?: number | undefined;
|
|
21
|
-
retryMaxDelayMs?: number | undefined;
|
|
22
|
-
retryOnStatuses?: number[] | undefined;
|
|
23
|
-
retryOnNetworkError?: boolean | undefined;
|
|
24
|
-
}, {
|
|
25
|
-
apiKey: string;
|
|
26
|
-
timeout?: number | undefined;
|
|
27
|
-
baseUrl?: string | undefined;
|
|
28
|
-
maxRetries?: number | undefined;
|
|
29
|
-
retryDelayMs?: number | undefined;
|
|
30
|
-
retryMaxDelayMs?: number | undefined;
|
|
31
|
-
retryOnStatuses?: number[] | undefined;
|
|
32
|
-
retryOnNetworkError?: boolean | undefined;
|
|
33
|
-
}>;
|
|
34
|
-
export type CMSConfigInput = z.infer<typeof CMSConfigSchema>;
|
|
35
|
-
export declare const LeadPayloadSchema: z.ZodObject<{
|
|
36
|
-
clickId: z.ZodOptional<z.ZodString>;
|
|
37
|
-
eventName: z.ZodString;
|
|
38
|
-
customerExternalId: z.ZodString;
|
|
39
|
-
timestamp: z.ZodOptional<z.ZodString>;
|
|
40
|
-
customerId: z.ZodOptional<z.ZodString>;
|
|
41
|
-
customerName: z.ZodOptional<z.ZodString>;
|
|
42
|
-
customerEmail: z.ZodOptional<z.ZodString>;
|
|
43
|
-
customerAvatar: z.ZodOptional<z.ZodString>;
|
|
44
|
-
mode: z.ZodOptional<z.ZodEnum<["deferred"]>>;
|
|
45
|
-
}, "strip", z.ZodTypeAny, {
|
|
46
|
-
eventName: string;
|
|
47
|
-
customerExternalId: string;
|
|
48
|
-
clickId?: string | undefined;
|
|
49
|
-
timestamp?: string | undefined;
|
|
50
|
-
customerId?: string | undefined;
|
|
51
|
-
customerName?: string | undefined;
|
|
52
|
-
customerEmail?: string | undefined;
|
|
53
|
-
customerAvatar?: string | undefined;
|
|
54
|
-
mode?: "deferred" | undefined;
|
|
55
|
-
}, {
|
|
56
|
-
eventName: string;
|
|
57
|
-
customerExternalId: string;
|
|
58
|
-
clickId?: string | undefined;
|
|
59
|
-
timestamp?: string | undefined;
|
|
60
|
-
customerId?: string | undefined;
|
|
61
|
-
customerName?: string | undefined;
|
|
62
|
-
customerEmail?: string | undefined;
|
|
63
|
-
customerAvatar?: string | undefined;
|
|
64
|
-
mode?: "deferred" | undefined;
|
|
65
|
-
}>;
|
|
66
|
-
export type LeadPayloadInput = z.infer<typeof LeadPayloadSchema>;
|
|
67
|
-
export declare const SalePayloadSchema: z.ZodObject<{
|
|
68
|
-
clickId: z.ZodOptional<z.ZodString>;
|
|
69
|
-
eventName: z.ZodOptional<z.ZodString>;
|
|
70
|
-
invoiceId: z.ZodString;
|
|
71
|
-
amount: z.ZodNumber;
|
|
72
|
-
currency: z.ZodOptional<z.ZodString>;
|
|
73
|
-
timestamp: z.ZodOptional<z.ZodString>;
|
|
74
|
-
customerId: z.ZodOptional<z.ZodString>;
|
|
75
|
-
customerExternalId: z.ZodOptional<z.ZodString>;
|
|
76
|
-
customerName: z.ZodOptional<z.ZodString>;
|
|
77
|
-
customerEmail: z.ZodOptional<z.ZodString>;
|
|
78
|
-
mode: z.ZodOptional<z.ZodEnum<["deferred"]>>;
|
|
79
|
-
}, "strip", z.ZodTypeAny, {
|
|
80
|
-
invoiceId: string;
|
|
81
|
-
amount: number;
|
|
82
|
-
clickId?: string | undefined;
|
|
83
|
-
eventName?: string | undefined;
|
|
84
|
-
customerExternalId?: string | undefined;
|
|
85
|
-
timestamp?: string | undefined;
|
|
86
|
-
customerId?: string | undefined;
|
|
87
|
-
customerName?: string | undefined;
|
|
88
|
-
customerEmail?: string | undefined;
|
|
89
|
-
mode?: "deferred" | undefined;
|
|
90
|
-
currency?: string | undefined;
|
|
91
|
-
}, {
|
|
92
|
-
invoiceId: string;
|
|
93
|
-
amount: number;
|
|
94
|
-
clickId?: string | undefined;
|
|
95
|
-
eventName?: string | undefined;
|
|
96
|
-
customerExternalId?: string | undefined;
|
|
97
|
-
timestamp?: string | undefined;
|
|
98
|
-
customerId?: string | undefined;
|
|
99
|
-
customerName?: string | undefined;
|
|
100
|
-
customerEmail?: string | undefined;
|
|
101
|
-
mode?: "deferred" | undefined;
|
|
102
|
-
currency?: string | undefined;
|
|
103
|
-
}>;
|
|
104
|
-
export type SalePayloadInput = z.infer<typeof SalePayloadSchema>;
|
|
105
|
-
/**
|
|
106
|
-
* Validates input data and throws detailed error if invalid
|
|
107
|
-
*/
|
|
108
|
-
export declare function validateLeadPayload(data: unknown): LeadPayloadInput;
|
|
109
|
-
export declare function validateSalePayload(data: unknown): SalePayloadInput;
|
|
110
|
-
export declare function validateCMSConfig(data: unknown): CMSConfigInput;
|
|
111
|
-
/**
|
|
112
|
-
* Sanitizes sensitive data for logging/errors
|
|
113
|
-
* Removes API keys, tokens, and other credentials
|
|
114
|
-
*/
|
|
115
|
-
export declare function sanitizeForLogging(obj: any): any;
|
|
116
|
-
/**
|
|
117
|
-
* Redacts API key from error messages
|
|
118
|
-
*/
|
|
119
|
-
export declare function redactApiKey(message: string, apiKey?: string): string;
|
package/dist/src/validation.js
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SalePayloadSchema = exports.LeadPayloadSchema = exports.CMSConfigSchema = void 0;
|
|
4
|
-
exports.validateLeadPayload = validateLeadPayload;
|
|
5
|
-
exports.validateSalePayload = validateSalePayload;
|
|
6
|
-
exports.validateCMSConfig = validateCMSConfig;
|
|
7
|
-
exports.sanitizeForLogging = sanitizeForLogging;
|
|
8
|
-
exports.redactApiKey = redactApiKey;
|
|
9
|
-
/**
|
|
10
|
-
* Input validation schemas using Zod
|
|
11
|
-
* Ensures all incoming data is sanitized and valid
|
|
12
|
-
*/
|
|
13
|
-
const zod_1 = require("zod");
|
|
14
|
-
const constants_1 = require("./constants");
|
|
15
|
-
exports.CMSConfigSchema = zod_1.z.object({
|
|
16
|
-
apiKey: zod_1.z
|
|
17
|
-
.string()
|
|
18
|
-
.min(1, constants_1.ERROR_MESSAGES.API_KEY_REQUIRED)
|
|
19
|
-
.refine((key) => constants_1.VALIDATION_CONSTRAINTS.API_KEY.PATTERN.test(key), constants_1.ERROR_MESSAGES.API_KEY_INVALID_FORMAT),
|
|
20
|
-
baseUrl: zod_1.z
|
|
21
|
-
.string()
|
|
22
|
-
.url(constants_1.ERROR_MESSAGES.BASE_URL_INVALID)
|
|
23
|
-
.optional(),
|
|
24
|
-
timeout: zod_1.z
|
|
25
|
-
.number()
|
|
26
|
-
.int()
|
|
27
|
-
.min(constants_1.VALIDATION_CONSTRAINTS.TIMEOUT.MIN_MS, constants_1.ERROR_MESSAGES.TIMEOUT_TOO_LOW)
|
|
28
|
-
.max(constants_1.VALIDATION_CONSTRAINTS.TIMEOUT.MAX_MS, constants_1.ERROR_MESSAGES.TIMEOUT_TOO_HIGH)
|
|
29
|
-
.optional(),
|
|
30
|
-
maxRetries: zod_1.z
|
|
31
|
-
.number()
|
|
32
|
-
.int()
|
|
33
|
-
.min(constants_1.VALIDATION_CONSTRAINTS.MAX_RETRIES.MIN, constants_1.ERROR_MESSAGES.MAX_RETRIES_NEGATIVE)
|
|
34
|
-
.max(constants_1.VALIDATION_CONSTRAINTS.MAX_RETRIES.MAX, constants_1.ERROR_MESSAGES.MAX_RETRIES_TOO_HIGH)
|
|
35
|
-
.optional(),
|
|
36
|
-
retryDelayMs: zod_1.z
|
|
37
|
-
.number()
|
|
38
|
-
.int()
|
|
39
|
-
.min(constants_1.VALIDATION_CONSTRAINTS.RETRY_DELAY.MIN_MS, constants_1.ERROR_MESSAGES.RETRY_DELAY_TOO_LOW)
|
|
40
|
-
.max(constants_1.VALIDATION_CONSTRAINTS.RETRY_DELAY.MAX_MS, constants_1.ERROR_MESSAGES.RETRY_DELAY_TOO_HIGH)
|
|
41
|
-
.optional(),
|
|
42
|
-
retryMaxDelayMs: zod_1.z
|
|
43
|
-
.number()
|
|
44
|
-
.int()
|
|
45
|
-
.min(constants_1.VALIDATION_CONSTRAINTS.RETRY_MAX_DELAY.MIN_MS, constants_1.ERROR_MESSAGES.RETRY_MAX_DELAY_TOO_LOW)
|
|
46
|
-
.max(constants_1.VALIDATION_CONSTRAINTS.RETRY_MAX_DELAY.MAX_MS, constants_1.ERROR_MESSAGES.RETRY_MAX_DELAY_TOO_HIGH)
|
|
47
|
-
.optional(),
|
|
48
|
-
retryOnStatuses: zod_1.z
|
|
49
|
-
.array(zod_1.z.number().int().min(100).max(599))
|
|
50
|
-
.optional(),
|
|
51
|
-
retryOnNetworkError: zod_1.z.boolean().optional(),
|
|
52
|
-
});
|
|
53
|
-
// Lead payload validation
|
|
54
|
-
exports.LeadPayloadSchema = zod_1.z.object({
|
|
55
|
-
clickId: zod_1.z
|
|
56
|
-
.string()
|
|
57
|
-
.min(constants_1.VALIDATION_CONSTRAINTS.STRING_FIELDS.CLICK_ID.MIN)
|
|
58
|
-
.max(constants_1.VALIDATION_CONSTRAINTS.STRING_FIELDS.CLICK_ID.MAX)
|
|
59
|
-
.optional(),
|
|
60
|
-
eventName: zod_1.z
|
|
61
|
-
.string()
|
|
62
|
-
.min(constants_1.VALIDATION_CONSTRAINTS.STRING_FIELDS.EVENT_NAME.MIN, constants_1.ERROR_MESSAGES.EVENT_NAME_REQUIRED)
|
|
63
|
-
.max(constants_1.VALIDATION_CONSTRAINTS.STRING_FIELDS.EVENT_NAME.MAX, constants_1.ERROR_MESSAGES.EVENT_NAME_TOO_LONG),
|
|
64
|
-
customerExternalId: zod_1.z
|
|
65
|
-
.string()
|
|
66
|
-
.min(constants_1.VALIDATION_CONSTRAINTS.STRING_FIELDS.CUSTOMER_EXTERNAL_ID.MIN, constants_1.ERROR_MESSAGES.CUSTOMER_EXTERNAL_ID_REQUIRED)
|
|
67
|
-
.max(constants_1.VALIDATION_CONSTRAINTS.STRING_FIELDS.CUSTOMER_EXTERNAL_ID.MAX, constants_1.ERROR_MESSAGES.CUSTOMER_EXTERNAL_ID_TOO_LONG),
|
|
68
|
-
timestamp: zod_1.z
|
|
69
|
-
.string()
|
|
70
|
-
.datetime()
|
|
71
|
-
.optional(),
|
|
72
|
-
customerId: zod_1.z
|
|
73
|
-
.string()
|
|
74
|
-
.max(constants_1.VALIDATION_CONSTRAINTS.STRING_FIELDS.CUSTOMER_ID.MAX)
|
|
75
|
-
.optional(),
|
|
76
|
-
customerName: zod_1.z
|
|
77
|
-
.string()
|
|
78
|
-
.max(constants_1.VALIDATION_CONSTRAINTS.STRING_FIELDS.CUSTOMER_NAME.MAX)
|
|
79
|
-
.optional(),
|
|
80
|
-
customerEmail: zod_1.z
|
|
81
|
-
.string()
|
|
82
|
-
.email(constants_1.ERROR_MESSAGES.CUSTOMER_EMAIL_INVALID)
|
|
83
|
-
.max(constants_1.VALIDATION_CONSTRAINTS.STRING_FIELDS.CUSTOMER_EMAIL.MAX, constants_1.ERROR_MESSAGES.CUSTOMER_EMAIL_TOO_LONG)
|
|
84
|
-
.optional(),
|
|
85
|
-
customerAvatar: zod_1.z
|
|
86
|
-
.string()
|
|
87
|
-
.url(constants_1.ERROR_MESSAGES.CUSTOMER_AVATAR_INVALID)
|
|
88
|
-
.optional(),
|
|
89
|
-
mode: zod_1.z
|
|
90
|
-
.enum(["deferred"])
|
|
91
|
-
.optional(),
|
|
92
|
-
});
|
|
93
|
-
// Sale payload validation
|
|
94
|
-
exports.SalePayloadSchema = zod_1.z.object({
|
|
95
|
-
clickId: zod_1.z
|
|
96
|
-
.string()
|
|
97
|
-
.min(constants_1.VALIDATION_CONSTRAINTS.STRING_FIELDS.CLICK_ID.MIN)
|
|
98
|
-
.max(constants_1.VALIDATION_CONSTRAINTS.STRING_FIELDS.CLICK_ID.MAX)
|
|
99
|
-
.optional(),
|
|
100
|
-
eventName: zod_1.z
|
|
101
|
-
.string()
|
|
102
|
-
.optional(),
|
|
103
|
-
invoiceId: zod_1.z
|
|
104
|
-
.string()
|
|
105
|
-
.min(constants_1.VALIDATION_CONSTRAINTS.STRING_FIELDS.INVOICE_ID.MIN, constants_1.ERROR_MESSAGES.INVOICE_ID_REQUIRED)
|
|
106
|
-
.max(constants_1.VALIDATION_CONSTRAINTS.STRING_FIELDS.INVOICE_ID.MAX, constants_1.ERROR_MESSAGES.INVOICE_ID_TOO_LONG),
|
|
107
|
-
amount: zod_1.z
|
|
108
|
-
.number()
|
|
109
|
-
.int()
|
|
110
|
-
.min(constants_1.VALIDATION_CONSTRAINTS.AMOUNT.MIN, constants_1.ERROR_MESSAGES.AMOUNT_NEGATIVE),
|
|
111
|
-
currency: zod_1.z
|
|
112
|
-
.string()
|
|
113
|
-
.length(constants_1.VALIDATION_CONSTRAINTS.CURRENCY.LENGTH, constants_1.ERROR_MESSAGES.CURRENCY_INVALID_LENGTH)
|
|
114
|
-
.regex(constants_1.VALIDATION_CONSTRAINTS.CURRENCY.PATTERN, constants_1.ERROR_MESSAGES.CURRENCY_INVALID_FORMAT)
|
|
115
|
-
.optional(),
|
|
116
|
-
timestamp: zod_1.z
|
|
117
|
-
.string()
|
|
118
|
-
.datetime()
|
|
119
|
-
.optional(),
|
|
120
|
-
customerId: zod_1.z
|
|
121
|
-
.string()
|
|
122
|
-
.max(constants_1.VALIDATION_CONSTRAINTS.STRING_FIELDS.CUSTOMER_ID.MAX)
|
|
123
|
-
.optional(),
|
|
124
|
-
customerExternalId: zod_1.z
|
|
125
|
-
.string()
|
|
126
|
-
.max(constants_1.VALIDATION_CONSTRAINTS.STRING_FIELDS.CUSTOMER_EXTERNAL_ID.MAX)
|
|
127
|
-
.optional(),
|
|
128
|
-
customerName: zod_1.z
|
|
129
|
-
.string()
|
|
130
|
-
.max(constants_1.VALIDATION_CONSTRAINTS.STRING_FIELDS.CUSTOMER_NAME.MAX)
|
|
131
|
-
.optional(),
|
|
132
|
-
customerEmail: zod_1.z
|
|
133
|
-
.string()
|
|
134
|
-
.email(constants_1.ERROR_MESSAGES.CUSTOMER_EMAIL_INVALID)
|
|
135
|
-
.max(constants_1.VALIDATION_CONSTRAINTS.STRING_FIELDS.CUSTOMER_EMAIL.MAX, constants_1.ERROR_MESSAGES.CUSTOMER_EMAIL_TOO_LONG)
|
|
136
|
-
.optional(),
|
|
137
|
-
mode: zod_1.z
|
|
138
|
-
.enum(["deferred"])
|
|
139
|
-
.optional(),
|
|
140
|
-
});
|
|
141
|
-
/**
|
|
142
|
-
* Validates input data and throws detailed error if invalid
|
|
143
|
-
*/
|
|
144
|
-
function validateLeadPayload(data) {
|
|
145
|
-
return exports.LeadPayloadSchema.parse(data);
|
|
146
|
-
}
|
|
147
|
-
function validateSalePayload(data) {
|
|
148
|
-
return exports.SalePayloadSchema.parse(data);
|
|
149
|
-
}
|
|
150
|
-
function validateCMSConfig(data) {
|
|
151
|
-
return exports.CMSConfigSchema.parse(data);
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Sanitizes sensitive data for logging/errors
|
|
155
|
-
* Removes API keys, tokens, and other credentials
|
|
156
|
-
*/
|
|
157
|
-
function sanitizeForLogging(obj) {
|
|
158
|
-
if (!obj || typeof obj !== "object") {
|
|
159
|
-
return obj;
|
|
160
|
-
}
|
|
161
|
-
if (Array.isArray(obj)) {
|
|
162
|
-
return obj.map((item) => sanitizeForLogging(item));
|
|
163
|
-
}
|
|
164
|
-
const sanitized = {};
|
|
165
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
166
|
-
const lowerKey = key.toLowerCase();
|
|
167
|
-
// Mask sensitive field names
|
|
168
|
-
if (constants_1.SENSITIVE_FIELDS.PATTERNS.some((field) => lowerKey.includes(field))) {
|
|
169
|
-
sanitized[key] = typeof value === "string" ? constants_1.SENSITIVE_FIELDS.REDACTION_PLACEHOLDER : value;
|
|
170
|
-
}
|
|
171
|
-
else if (typeof value === "object" && value !== null) {
|
|
172
|
-
sanitized[key] = sanitizeForLogging(value);
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
sanitized[key] = value;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return sanitized;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Redacts API key from error messages
|
|
182
|
-
*/
|
|
183
|
-
function redactApiKey(message, apiKey) {
|
|
184
|
-
if (!apiKey)
|
|
185
|
-
return message;
|
|
186
|
-
// Replace the full key and common patterns
|
|
187
|
-
const patterns = [
|
|
188
|
-
apiKey,
|
|
189
|
-
apiKey.substring(0, 3) + "***" + apiKey.substring(apiKey.length - 3),
|
|
190
|
-
];
|
|
191
|
-
let result = message;
|
|
192
|
-
for (const pattern of patterns) {
|
|
193
|
-
result = result.replace(new RegExp(pattern, "g"), constants_1.SENSITIVE_FIELDS.API_KEY_REDACTION);
|
|
194
|
-
}
|
|
195
|
-
return result;
|
|
196
|
-
}
|