@easyflow/javascript-sdk 2.1.7 → 2.1.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 +294 -713
- package/dist/index.d.ts +421 -0
- package/package.json +19 -6
- package/.babelrc +0 -5
- package/.github/workflows/deploy-sdk-cf.yml +0 -49
- package/.github/workflows/release-sdk-cdn.yml +0 -144
- package/.github/workflows/release-sdk.yml +0 -112
- package/.prettierrc +0 -6
- package/CDN-DEPLOYMENT.md +0 -175
- package/DEMO.md +0 -258
- package/DEPLOYMENT.md +0 -224
- package/INTEGRATION-GUIDE.md +0 -521
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -87
- package/coverage/easyflow-javascript-sdk/index.html +0 -116
- package/coverage/easyflow-javascript-sdk/libs/constants.mjs.html +0 -268
- package/coverage/easyflow-javascript-sdk/libs/errors.mjs.html +0 -271
- package/coverage/easyflow-javascript-sdk/libs/exception-handler.mjs.html +0 -148
- package/coverage/easyflow-javascript-sdk/libs/fingerprint.mjs.html +0 -895
- package/coverage/easyflow-javascript-sdk/libs/http.mjs.html +0 -502
- package/coverage/easyflow-javascript-sdk/libs/index.html +0 -266
- package/coverage/easyflow-javascript-sdk/libs/logger.mjs.html +0 -568
- package/coverage/easyflow-javascript-sdk/libs/sanitizer.mjs.html +0 -1099
- package/coverage/easyflow-javascript-sdk/libs/security.mjs.html +0 -733
- package/coverage/easyflow-javascript-sdk/libs/types.mjs.html +0 -508
- package/coverage/easyflow-javascript-sdk/libs/utils.mjs.html +0 -379
- package/coverage/easyflow-javascript-sdk/libs/validator.mjs.html +0 -2623
- package/coverage/easyflow-javascript-sdk/sdk.mjs.html +0 -2434
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +0 -131
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/easyflow-javascript-sdk/index.html +0 -116
- package/coverage/lcov-report/easyflow-javascript-sdk/libs/constants.mjs.html +0 -268
- package/coverage/lcov-report/easyflow-javascript-sdk/libs/errors.mjs.html +0 -271
- package/coverage/lcov-report/easyflow-javascript-sdk/libs/exception-handler.mjs.html +0 -148
- package/coverage/lcov-report/easyflow-javascript-sdk/libs/fingerprint.mjs.html +0 -895
- package/coverage/lcov-report/easyflow-javascript-sdk/libs/http.mjs.html +0 -502
- package/coverage/lcov-report/easyflow-javascript-sdk/libs/index.html +0 -266
- package/coverage/lcov-report/easyflow-javascript-sdk/libs/logger.mjs.html +0 -568
- package/coverage/lcov-report/easyflow-javascript-sdk/libs/sanitizer.mjs.html +0 -1099
- package/coverage/lcov-report/easyflow-javascript-sdk/libs/security.mjs.html +0 -733
- package/coverage/lcov-report/easyflow-javascript-sdk/libs/types.mjs.html +0 -508
- package/coverage/lcov-report/easyflow-javascript-sdk/libs/utils.mjs.html +0 -379
- package/coverage/lcov-report/easyflow-javascript-sdk/libs/validator.mjs.html +0 -2623
- package/coverage/lcov-report/easyflow-javascript-sdk/sdk.mjs.html +0 -2434
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -131
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov.info +0 -1429
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -196
- package/dist/435.easyflow-sdk.min.js +0 -1
- package/dist/easyflow-sdk.min.js +0 -1
- package/dist/easyflow-sdk.min.js.LICENSE.txt +0 -1
- package/dist/index.html +0 -756
- package/docs/index.html +0 -775
- package/examples/lovable-integration.html +0 -410
- package/index.html +0 -981
- package/jest.config.js +0 -37
- package/jsdoc.json +0 -42
- package/libs/auto-integration.mjs +0 -333
- package/libs/constants.mjs +0 -61
- package/libs/constants.spec.js +0 -198
- package/libs/errors.mjs +0 -62
- package/libs/errors.spec.js +0 -178
- package/libs/exception-handler.mjs +0 -21
- package/libs/exception-handler.spec.js +0 -237
- package/libs/fingerprint.mjs +0 -270
- package/libs/http.mjs +0 -163
- package/libs/http.spec.js +0 -427
- package/libs/integration-wrapper.mjs +0 -285
- package/libs/logger.mjs +0 -161
- package/libs/logger.spec.js +0 -389
- package/libs/sanitizer.mjs +0 -340
- package/libs/sanitizer.spec.js +0 -583
- package/libs/security.mjs +0 -217
- package/libs/types.mjs +0 -141
- package/libs/utils.mjs +0 -368
- package/libs/utils.spec.js +0 -231
- package/libs/validator.mjs +0 -952
- package/libs/validator.spec.js +0 -615
- package/mocks/offer.mock.js +0 -77
- package/scripts/publish-npm.sh +0 -82
- package/sdk.mjs +0 -945
- package/sdk.spec.js +0 -796
- package/test-setup.cjs +0 -211
- package/test.html +0 -154
- package/webpack.config.cjs +0 -41
package/libs/sanitizer.mjs
DELETED
|
@@ -1,340 +0,0 @@
|
|
|
1
|
-
import { deepClone } from './utils.mjs'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Sanitizer class for cleaning and validating input data
|
|
5
|
-
*
|
|
6
|
-
* This class provides methods to sanitize various types of input data
|
|
7
|
-
* to prevent XSS attacks and ensure data integrity.
|
|
8
|
-
*
|
|
9
|
-
* @class Sanitizer
|
|
10
|
-
* @since 1.0.0
|
|
11
|
-
*/
|
|
12
|
-
export class Sanitizer {
|
|
13
|
-
/**
|
|
14
|
-
* Sanitizes HTTP headers by removing potentially dangerous headers
|
|
15
|
-
*
|
|
16
|
-
* @param {Object} [headers={}] - Headers object to sanitize
|
|
17
|
-
* @returns {Object} Sanitized headers object
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```javascript
|
|
21
|
-
* const sanitizedHeaders = Sanitizer.sanitizeHeaders({
|
|
22
|
-
* 'Content-Type': 'application/json',
|
|
23
|
-
* 'x-forwarded-for': 'malicious-value'
|
|
24
|
-
* });
|
|
25
|
-
* // Returns: { 'Content-Type': 'application/json' }
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
static sanitizeHeaders(headers = {}) {
|
|
29
|
-
const sanitized = {}
|
|
30
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
31
|
-
const dangerousHeaders = [
|
|
32
|
-
'x-forwarded-for',
|
|
33
|
-
'x-real-ip',
|
|
34
|
-
'x-forwarded-host',
|
|
35
|
-
'x-forwarded-proto',
|
|
36
|
-
'x-forwarded-port',
|
|
37
|
-
'x-forwarded-server',
|
|
38
|
-
'x-forwarded-uri',
|
|
39
|
-
'x-forwarded-method',
|
|
40
|
-
'x-forwarded-path',
|
|
41
|
-
'x-forwarded-query',
|
|
42
|
-
'x-forwarded-scheme',
|
|
43
|
-
'x-forwarded-ssl',
|
|
44
|
-
'x-forwarded-proto-version',
|
|
45
|
-
]
|
|
46
|
-
if (!dangerousHeaders.includes(key.toLowerCase())) {
|
|
47
|
-
sanitized[key] = value
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return sanitized
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Sanitizes string input by removing potentially dangerous characters
|
|
55
|
-
*
|
|
56
|
-
* @param {*} input - Input to sanitize (only strings are processed)
|
|
57
|
-
* @returns {*} Sanitized input (returns original value if not a string)
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```javascript
|
|
61
|
-
* const sanitized = Sanitizer.sanitizeInput('<script>alert("xss")</script>');
|
|
62
|
-
* // Returns: 'scriptalert("xss")/script'
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
static sanitizeInput(input) {
|
|
66
|
-
if (typeof input !== 'string' || !input) return input
|
|
67
|
-
return input
|
|
68
|
-
.replace(/[<>&]/g, '') // Remove <, >, & mas mantém aspas
|
|
69
|
-
.replace(/javascript:/gi, '')
|
|
70
|
-
.replace(/data:/gi, '')
|
|
71
|
-
.replace(/vbscript:/gi, '')
|
|
72
|
-
.trim()
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Sanitizes credit card data by cleaning all card-related fields
|
|
77
|
-
*
|
|
78
|
-
* @param {Object} creditCard - Credit card object to sanitize
|
|
79
|
-
* @param {string} creditCard.cardNumber - Card number
|
|
80
|
-
* @param {string} creditCard.cvv - Security code
|
|
81
|
-
* @param {string} creditCard.month - Expiration month
|
|
82
|
-
* @param {string} creditCard.year - Expiration year
|
|
83
|
-
* @param {string} creditCard.holderName - Cardholder name
|
|
84
|
-
* @returns {Object} Sanitized credit card object
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* ```javascript
|
|
88
|
-
* const sanitizedCard = Sanitizer.sanitizeCreditCard({
|
|
89
|
-
* cardNumber: '4111 1111 1111 1111',
|
|
90
|
-
* cvv: '123',
|
|
91
|
-
* month: '12',
|
|
92
|
-
* year: '2025',
|
|
93
|
-
* holderName: 'John Doe'
|
|
94
|
-
* });
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
static sanitizeCreditCard(creditCard) {
|
|
98
|
-
return {
|
|
99
|
-
cardNumber: this.sanitizeInput(creditCard.cardNumber),
|
|
100
|
-
cvv: this.sanitizeInput(creditCard.cvv),
|
|
101
|
-
month: this.sanitizeInput(creditCard.month),
|
|
102
|
-
year: this.sanitizeInput(creditCard.year),
|
|
103
|
-
holderName: this.sanitizeInput(creditCard.holderName),
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Recursively sanitizes all fields of an object using sanitizeInput
|
|
109
|
-
*
|
|
110
|
-
* This method traverses the entire object structure and sanitizes
|
|
111
|
-
* all string values found in any nested objects, arrays, or primitive values.
|
|
112
|
-
* It preserves the original object structure while ensuring all string data
|
|
113
|
-
* is properly sanitized.
|
|
114
|
-
*
|
|
115
|
-
* @param {*} obj - Object, array, or primitive value to sanitize
|
|
116
|
-
* @returns {*} Deep cloned and sanitized object with the same structure
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* ```javascript
|
|
120
|
-
* const userData = {
|
|
121
|
-
* name: '<script>alert("xss")</script>',
|
|
122
|
-
* email: 'user@example.com',
|
|
123
|
-
* profile: {
|
|
124
|
-
* bio: 'User bio with <strong>HTML</strong>',
|
|
125
|
-
* tags: ['tag1', '<script>malicious</script>']
|
|
126
|
-
* },
|
|
127
|
-
* settings: {
|
|
128
|
-
* theme: 'dark',
|
|
129
|
-
* notifications: true
|
|
130
|
-
* }
|
|
131
|
-
* };
|
|
132
|
-
*
|
|
133
|
-
* const sanitized = Sanitizer.sanitizeObjectFields(userData);
|
|
134
|
-
* // Result: All string fields are sanitized, structure preserved
|
|
135
|
-
* ```
|
|
136
|
-
*/
|
|
137
|
-
static sanitizeObjectFields(obj) {
|
|
138
|
-
return this._sanitizeObjectFieldsRecursive(obj, new WeakSet())
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Internal recursive method for sanitizing object fields
|
|
143
|
-
*
|
|
144
|
-
* @private
|
|
145
|
-
* @param {*} obj - Object to sanitize
|
|
146
|
-
* @param {WeakSet} processed - Set of already processed objects to prevent circular references
|
|
147
|
-
* @returns {*} Sanitized object
|
|
148
|
-
*/
|
|
149
|
-
static _sanitizeObjectFieldsRecursive(obj, processed) {
|
|
150
|
-
// Handle null and undefined
|
|
151
|
-
if (obj === null || obj === undefined) {
|
|
152
|
-
return obj
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Handle primitive types (only sanitize strings)
|
|
156
|
-
if (typeof obj !== 'object') {
|
|
157
|
-
return this.sanitizeInput(obj)
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Handle arrays
|
|
161
|
-
if (Array.isArray(obj)) {
|
|
162
|
-
return obj.map((item) =>
|
|
163
|
-
this._sanitizeObjectFieldsRecursive(item, processed)
|
|
164
|
-
)
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// Check for circular references
|
|
168
|
-
if (processed.has(obj)) {
|
|
169
|
-
return obj // Return original object to prevent infinite recursion
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// Mark this object as processed
|
|
173
|
-
processed.add(obj)
|
|
174
|
-
|
|
175
|
-
// Handle objects
|
|
176
|
-
const sanitized = {}
|
|
177
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
178
|
-
// Recursively sanitize nested values
|
|
179
|
-
sanitized[key] = this._sanitizeObjectFieldsRecursive(
|
|
180
|
-
value,
|
|
181
|
-
processed
|
|
182
|
-
)
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
return sanitized
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Sanitizes complete order data including buyer information, payments, and items
|
|
191
|
-
*
|
|
192
|
-
* @param {Object} order - Order object to sanitize
|
|
193
|
-
* @param {Object} [order.buyer] - Buyer information
|
|
194
|
-
* @param {Object} [order.payments] - Payment methods array
|
|
195
|
-
* @param {Object} [order.items] - Order items array
|
|
196
|
-
* @param {Object} [order.metadata] - Order metadata array
|
|
197
|
-
* @returns {Object} Deep cloned and sanitized order object
|
|
198
|
-
*
|
|
199
|
-
* @example
|
|
200
|
-
* ```javascript
|
|
201
|
-
* const sanitizedOrder = sanitizeOrderData({
|
|
202
|
-
* buyer: {
|
|
203
|
-
* name: '<script>alert("xss")</script>',
|
|
204
|
-
* email: 'user@example.com'
|
|
205
|
-
* },
|
|
206
|
-
* payments: [{
|
|
207
|
-
* method: 'credit-card',
|
|
208
|
-
* creditCard: { cardNumber: '4111 1111 1111 1111' }
|
|
209
|
-
* }]
|
|
210
|
-
* });
|
|
211
|
-
* ```
|
|
212
|
-
*/
|
|
213
|
-
function sanitizeOrderData(order) {
|
|
214
|
-
const sanitized = deepClone(order)
|
|
215
|
-
if (sanitized.cartId)
|
|
216
|
-
sanitized.cartId = Sanitizer.sanitizeInput(sanitized.cartId)
|
|
217
|
-
if (sanitized.buyer) {
|
|
218
|
-
sanitized.buyer.customerId = Sanitizer.sanitizeInput(
|
|
219
|
-
sanitized.buyer.customerId
|
|
220
|
-
)
|
|
221
|
-
sanitized.buyer.name = Sanitizer.sanitizeInput(sanitized.buyer.name)
|
|
222
|
-
sanitized.buyer.email = Sanitizer.sanitizeInput(sanitized.buyer.email)
|
|
223
|
-
if (sanitized.buyer.document) {
|
|
224
|
-
sanitized.buyer.document.number = Sanitizer.sanitizeInput(
|
|
225
|
-
sanitized.buyer.document.number
|
|
226
|
-
)
|
|
227
|
-
sanitized.buyer.document.type = Sanitizer.sanitizeInput(
|
|
228
|
-
sanitized.buyer.document.type
|
|
229
|
-
)
|
|
230
|
-
}
|
|
231
|
-
if (sanitized.buyer.phone) {
|
|
232
|
-
sanitized.buyer.phone.number = Sanitizer.sanitizeInput(
|
|
233
|
-
sanitized.buyer.phone.number
|
|
234
|
-
)
|
|
235
|
-
sanitized.buyer.phone.areaCode = Sanitizer.sanitizeInput(
|
|
236
|
-
sanitized.buyer.phone.areaCode
|
|
237
|
-
)
|
|
238
|
-
}
|
|
239
|
-
if (sanitized.buyer.address) {
|
|
240
|
-
sanitized.buyer.address.zipCode = Sanitizer.sanitizeInput(
|
|
241
|
-
sanitized.buyer.address.zipCode
|
|
242
|
-
)
|
|
243
|
-
sanitized.buyer.address.street = Sanitizer.sanitizeInput(
|
|
244
|
-
sanitized.buyer.address.street
|
|
245
|
-
)
|
|
246
|
-
sanitized.buyer.address.complement = Sanitizer.sanitizeInput(
|
|
247
|
-
sanitized.buyer.address.complement
|
|
248
|
-
)
|
|
249
|
-
sanitized.buyer.address.neighborhood = Sanitizer.sanitizeInput(
|
|
250
|
-
sanitized.buyer.address.neighborhood
|
|
251
|
-
)
|
|
252
|
-
sanitized.buyer.address.city = Sanitizer.sanitizeInput(
|
|
253
|
-
sanitized.buyer.address.city
|
|
254
|
-
)
|
|
255
|
-
sanitized.buyer.address.state = Sanitizer.sanitizeInput(
|
|
256
|
-
sanitized.buyer.address.state
|
|
257
|
-
)
|
|
258
|
-
sanitized.buyer.address.number = Sanitizer.sanitizeInput(
|
|
259
|
-
sanitized.buyer.address.number
|
|
260
|
-
)
|
|
261
|
-
}
|
|
262
|
-
if (sanitized.buyer.deliveryAddress) {
|
|
263
|
-
sanitized.buyer.deliveryAddress.zipCode = Sanitizer.sanitizeInput(
|
|
264
|
-
sanitized.buyer.deliveryAddress.zipCode
|
|
265
|
-
)
|
|
266
|
-
sanitized.buyer.deliveryAddress.street = Sanitizer.sanitizeInput(
|
|
267
|
-
sanitized.buyer.deliveryAddress.street
|
|
268
|
-
)
|
|
269
|
-
sanitized.buyer.deliveryAddress.complement =
|
|
270
|
-
Sanitizer.sanitizeInput(
|
|
271
|
-
sanitized.buyer.deliveryAddress.complement
|
|
272
|
-
)
|
|
273
|
-
sanitized.buyer.deliveryAddress.neighborhood =
|
|
274
|
-
Sanitizer.sanitizeInput(
|
|
275
|
-
sanitized.buyer.deliveryAddress.neighborhood
|
|
276
|
-
)
|
|
277
|
-
sanitized.buyer.deliveryAddress.city = Sanitizer.sanitizeInput(
|
|
278
|
-
sanitized.buyer.deliveryAddress.city
|
|
279
|
-
)
|
|
280
|
-
sanitized.buyer.deliveryAddress.state = Sanitizer.sanitizeInput(
|
|
281
|
-
sanitized.buyer.deliveryAddress.state
|
|
282
|
-
)
|
|
283
|
-
sanitized.buyer.deliveryAddress.number = Sanitizer.sanitizeInput(
|
|
284
|
-
sanitized.buyer.deliveryAddress.number
|
|
285
|
-
)
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
if (sanitized.payments && Array.isArray(sanitized.payments)) {
|
|
289
|
-
sanitized.payments = sanitized.payments.map((payment) => {
|
|
290
|
-
const sanitizedPayment = { ...payment }
|
|
291
|
-
if (sanitizedPayment.creditCard) {
|
|
292
|
-
sanitizedPayment.creditCard = {
|
|
293
|
-
cardId: Sanitizer.sanitizeInput(
|
|
294
|
-
sanitizedPayment.creditCard?.cardId
|
|
295
|
-
),
|
|
296
|
-
cardNumber: Sanitizer.sanitizeInput(
|
|
297
|
-
sanitizedPayment.creditCard.cardNumber
|
|
298
|
-
),
|
|
299
|
-
cvv: Sanitizer.sanitizeInput(
|
|
300
|
-
sanitizedPayment.creditCard.cvv
|
|
301
|
-
),
|
|
302
|
-
month: Sanitizer.sanitizeInput(
|
|
303
|
-
sanitizedPayment.creditCard.month
|
|
304
|
-
),
|
|
305
|
-
year: Sanitizer.sanitizeInput(
|
|
306
|
-
sanitizedPayment.creditCard.year
|
|
307
|
-
),
|
|
308
|
-
holderName: Sanitizer.sanitizeInput(
|
|
309
|
-
sanitizedPayment.creditCard.holderName
|
|
310
|
-
),
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
return sanitizedPayment
|
|
314
|
-
})
|
|
315
|
-
}
|
|
316
|
-
if (sanitized.items) {
|
|
317
|
-
sanitized.items = sanitized.items.map((item) => {
|
|
318
|
-
return {
|
|
319
|
-
externalReferenceId: Sanitizer.sanitizeInput(
|
|
320
|
-
item.externalReferenceId
|
|
321
|
-
),
|
|
322
|
-
description: Sanitizer.sanitizeInput(item.description),
|
|
323
|
-
name: Sanitizer.sanitizeInput(item.name),
|
|
324
|
-
quantity: item.quantity,
|
|
325
|
-
priceInCents: item.priceInCents,
|
|
326
|
-
}
|
|
327
|
-
})
|
|
328
|
-
}
|
|
329
|
-
if (sanitized.metadata && Array.isArray(sanitized.metadata)) {
|
|
330
|
-
sanitized.metadata = sanitized.metadata.map((metadata) => {
|
|
331
|
-
return {
|
|
332
|
-
key: Sanitizer.sanitizeInput(metadata.key),
|
|
333
|
-
value: Sanitizer.sanitizeInput(metadata.value),
|
|
334
|
-
}
|
|
335
|
-
})
|
|
336
|
-
}
|
|
337
|
-
return sanitized
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
export { sanitizeOrderData }
|