@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/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Easyflow JavaScript SDK
|
|
2
2
|
|
|
3
3
|
[](https://github.com/easyflow-cash/easyflow-javascript-sdk/actions)
|
|
4
|
-
[](https://easyflow-sdk.pages.dev)
|
|
5
5
|
[](LICENSE)
|
|
6
6
|
[](https://github.com/easyflow-cash/easyflow-javascript-sdk)
|
|
7
7
|
[](https://github.com/easyflow-cash/easyflow-javascript-sdk)
|
|
@@ -84,7 +84,36 @@ The **Easyflow JavaScript SDK** is the official tool for developers to integrate
|
|
|
84
84
|
- **High Performance**: Optimized for production
|
|
85
85
|
- **Complete Documentation**: Practical examples for all use cases
|
|
86
86
|
|
|
87
|
-
## What's New in v2.1.
|
|
87
|
+
## What's New in v2.1.9
|
|
88
|
+
|
|
89
|
+
### Hybrid Distribution Strategy
|
|
90
|
+
|
|
91
|
+
- **NPM Package**: Contains only documentation and TypeScript definitions
|
|
92
|
+
- **CDN Scripts**: Production-ready obfuscated builds via Cloudflare Pages
|
|
93
|
+
- **Enhanced Security**: Code source protected while maintaining accessibility
|
|
94
|
+
- **Better UX**: Easy discovery via NPM, secure usage via CDN
|
|
95
|
+
|
|
96
|
+
### Security & Privacy Improvements
|
|
97
|
+
|
|
98
|
+
- **README Anonymization**: Removed all personal information and sensitive data
|
|
99
|
+
- **Privacy Protection**: No personal emails, URLs, or contact information exposed
|
|
100
|
+
- **Professional Documentation**: Clean, business-focused documentation
|
|
101
|
+
- **NPM Safety**: Safe for public NPM publication
|
|
102
|
+
|
|
103
|
+
### Security & Privacy Improvements
|
|
104
|
+
|
|
105
|
+
- **README Anonymization**: Removed all personal information and sensitive data
|
|
106
|
+
- **Privacy Protection**: No personal emails, URLs, or contact information exposed
|
|
107
|
+
- **Professional Documentation**: Clean, business-focused documentation
|
|
108
|
+
- **NPM Safety**: Safe for public NPM publication
|
|
109
|
+
|
|
110
|
+
### Test Suite Improvements
|
|
111
|
+
|
|
112
|
+
- **Test Coverage Optimization**: Fixed all failing unit tests for complete 250 test coverage
|
|
113
|
+
- **Mock Structure Corrections**: Updated test mocks to align with actual API response patterns
|
|
114
|
+
- **Customer Management Tests**: Corrected mock structures for `createCustomer` and `getCustomer` methods
|
|
115
|
+
- **Credit Card Tests**: Fixed mock data structures for `addCreditCard` and `getCreditCard` methods
|
|
116
|
+
- **Consistent Test Patterns**: Standardized mock response structures across all endpoints
|
|
88
117
|
|
|
89
118
|
### Test Suite Improvements
|
|
90
119
|
|
|
@@ -109,12 +138,6 @@ The **Easyflow JavaScript SDK** is the official tool for developers to integrate
|
|
|
109
138
|
- **MongoDB ObjectId**: 24-character hexadecimal format `507f1f77bcf86cd799439011`
|
|
110
139
|
- **Strict Validation**: Rejects any other formats for enhanced security
|
|
111
140
|
|
|
112
|
-
### ID Validation Corrections
|
|
113
|
-
|
|
114
|
-
- **UUID v4 Validation**: All entity IDs (order, offer, customer, credit card) now use proper UUID v4 validation instead of incorrect format patterns
|
|
115
|
-
- **Consistent Validation**: Standardized validation across all ID types with proper error messages
|
|
116
|
-
- **Improved Security**: More robust ID validation prevents format-based attacks
|
|
117
|
-
|
|
118
141
|
### Lovable Integration Fixes
|
|
119
142
|
|
|
120
143
|
- **Event System Implementation**: Complete event system with `on()` and `off()` methods
|
|
@@ -122,196 +145,57 @@ The **Easyflow JavaScript SDK** is the official tool for developers to integrate
|
|
|
122
145
|
- **Global Instance**: `window.easyflowSDK` instance with all methods and events
|
|
123
146
|
- **Event Emissions**: Automatic events for `customerCreated`, `orderPlaced`, and `paymentProcessed`
|
|
124
147
|
|
|
125
|
-
### What's New in v2.1.4
|
|
126
|
-
|
|
127
|
-
### New Customer Management Features
|
|
128
|
-
|
|
129
|
-
- **Complete Customer CRUD**: Create, read, and update customers
|
|
130
|
-
- **Brazilian Data Validation**: Full validation for CPF/CNPJ, phone, address
|
|
131
|
-
- **Address Management**: Support for delivery and billing addresses
|
|
132
|
-
- **Phone Number Support**: Brazilian DDD format with international support
|
|
133
|
-
|
|
134
|
-
### Advanced Credit Card Management
|
|
135
|
-
|
|
136
|
-
- **Credit Card Operations**: Add, remove, and get credit cards
|
|
137
|
-
- **Secure Token Handling**: Encrypted credit card token management
|
|
138
|
-
- **Customer Association**: Link credit cards to specific customers
|
|
139
|
-
- **Card Information Retrieval**: Get detailed credit card information
|
|
140
|
-
|
|
141
|
-
### Enhanced HTTP Helper
|
|
142
|
-
|
|
143
|
-
- **Query Parameter Support**: Proper handling of URL parameters
|
|
144
|
-
- **Target-Specific Logic**: Optimized API calls for each endpoint
|
|
145
|
-
- **Parameter Separation**: Clean separation of body and query data
|
|
146
|
-
- **URL Building**: Dynamic URL construction with parameters
|
|
147
|
-
|
|
148
|
-
### Enhanced Security & Validation
|
|
149
|
-
|
|
150
|
-
- **Robust Input Validation**: 15+ validation methods for all data types
|
|
151
|
-
- **Brazilian Compliance**: CPF/CNPJ validation with official algorithms
|
|
152
|
-
- **Address Validation**: Complete Brazilian address structure validation
|
|
153
|
-
- **Phone Validation**: International + Brazilian DDD format support
|
|
154
|
-
- **Email Security**: Advanced email validation with security checks
|
|
155
|
-
|
|
156
|
-
### Advanced Data Protection
|
|
157
|
-
|
|
158
|
-
- **Recursive Sanitization**: Deep object sanitization with circular reference protection
|
|
159
|
-
- **XSS Prevention**: Enhanced sanitization preserving legitimate quotes
|
|
160
|
-
- **Protocol Filtering**: Protection against dangerous protocols
|
|
161
|
-
- **Input Length Validation**: Comprehensive length and format validation
|
|
162
|
-
|
|
163
|
-
### Improved Testing & Quality
|
|
164
|
-
|
|
165
|
-
- **256 Tests Passing**: 100% test success rate
|
|
166
|
-
- **Comprehensive Validation Tests**: All new validation methods tested
|
|
167
|
-
- **Mock System**: Robust mocking for reliable testing
|
|
168
|
-
- **Error Handling**: Enhanced error scenarios coverage
|
|
169
|
-
|
|
170
|
-
## Key Features
|
|
171
|
-
|
|
172
|
-
- **Enterprise Security**: Multi-layered security framework
|
|
173
|
-
- **Brazilian Compliance**: CPF, CNPJ, phone, address validation
|
|
174
|
-
- **Multi-Payment**: Credit card, PIX, bank billet support
|
|
175
|
-
- **Customer Management**: Complete CRM functionality with CRUD operations
|
|
176
|
-
- **Credit Card Management**: Secure add, remove, and get operations
|
|
177
|
-
- **Address Management**: Support for delivery and billing addresses
|
|
178
|
-
- **Phone Validation**: Brazilian DDD format with international support
|
|
179
|
-
- **High Performance**: Optimized for production use
|
|
180
|
-
- **PCI DSS Ready**: Payment industry compliance
|
|
181
|
-
- **Comprehensive Docs**: Complete API documentation
|
|
182
|
-
|
|
183
148
|
## Quick Start
|
|
184
149
|
|
|
185
|
-
###
|
|
150
|
+
### Installation
|
|
151
|
+
|
|
152
|
+
#### Option 1: CDN Script (Recommended)
|
|
186
153
|
|
|
187
|
-
|
|
154
|
+
Add this script tag to your HTML:
|
|
188
155
|
|
|
189
156
|
```html
|
|
190
157
|
<!-- Latest version -->
|
|
191
158
|
<script src="https://easyflow-sdk.pages.dev/easyflow-sdk.min.js"></script>
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
#### jsDelivr CDN
|
|
195
159
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
<script src="https://cdn.jsdelivr.net/npm/@easyflow/javascript-sdk"></script>
|
|
160
|
+
<!-- Specific version -->
|
|
161
|
+
<script src="https://easyflow-sdk.pages.dev/easyflow-sdk.v2.1.9.min.js"></script>
|
|
199
162
|
```
|
|
200
163
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
#### For Low-Code/No-Code Platforms (Lovable, Bubble, Webflow, etc.)
|
|
204
|
-
|
|
205
|
-
The SDK configures **automatically** and exposes all functionalities:
|
|
206
|
-
|
|
207
|
-
```javascript
|
|
208
|
-
// Functionalities available automatically
|
|
209
|
-
window.easyflowSDK = {
|
|
210
|
-
// Customers
|
|
211
|
-
createCustomer: function (data) {
|
|
212
|
-
/* ... */
|
|
213
|
-
},
|
|
214
|
-
getCustomer: function (id) {
|
|
215
|
-
/* ... */
|
|
216
|
-
},
|
|
217
|
-
updateCustomer: function (id, data) {
|
|
218
|
-
/* ... */
|
|
219
|
-
},
|
|
220
|
-
|
|
221
|
-
// Payments
|
|
222
|
-
placeOrder: function (offerId, data) {
|
|
223
|
-
/* ... */
|
|
224
|
-
},
|
|
225
|
-
charge: function (data) {
|
|
226
|
-
/* ... */
|
|
227
|
-
},
|
|
164
|
+
#### Option 2: NPM Package (Documentation Only)
|
|
228
165
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
/* ... */
|
|
233
|
-
},
|
|
234
|
-
},
|
|
166
|
+
```bash
|
|
167
|
+
npm install @easyflow/javascript-sdk
|
|
168
|
+
```
|
|
235
169
|
|
|
236
|
-
|
|
237
|
-
on: function (event, callback) {
|
|
238
|
-
/* ... */
|
|
239
|
-
},
|
|
240
|
-
}
|
|
170
|
+
**Note**: The NPM package contains only documentation. For production use, use the CDN script above.
|
|
241
171
|
|
|
242
|
-
|
|
243
|
-
easyflowSDK.on('customerCreated', function (customer) {
|
|
244
|
-
console.log('Customer created:', customer)
|
|
245
|
-
// Update platform UI
|
|
246
|
-
})
|
|
172
|
+
#### Option 3: Direct Download
|
|
247
173
|
|
|
248
|
-
|
|
249
|
-
console.log('Payment processed:', result)
|
|
250
|
-
// Redirect or update status
|
|
251
|
-
})
|
|
252
|
-
```
|
|
174
|
+
Download the latest obfuscated build from [GitHub Releases](https://github.com/easyflow-cash/easyflow-javascript-sdk/releases).
|
|
253
175
|
|
|
254
|
-
|
|
176
|
+
### Basic Usage
|
|
255
177
|
|
|
256
178
|
```javascript
|
|
257
|
-
|
|
258
|
-
const sdk = new EasyflowSDK('your-business-id')
|
|
179
|
+
import { EasyflowSDK } from '@easyflow/javascript-sdk'
|
|
259
180
|
|
|
260
|
-
//
|
|
261
|
-
const
|
|
181
|
+
// Initialize SDK
|
|
182
|
+
const sdk = new EasyflowSDK({
|
|
262
183
|
businessId: 'your-business-id',
|
|
263
|
-
enableDebug: true,
|
|
264
184
|
})
|
|
265
|
-
```
|
|
266
185
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
- **API Reference** - All methods and parameters
|
|
273
|
-
- **Practical Examples** - Ready-to-use code
|
|
274
|
-
- **Supported Platforms** - Lovable, Bubble, Webflow, Zapier
|
|
275
|
-
- **Troubleshooting** - Solutions for common problems
|
|
276
|
-
|
|
277
|
-
### 3. Process Payment with Full Validation
|
|
278
|
-
|
|
279
|
-
```javascript
|
|
280
|
-
// Create order with comprehensive validation
|
|
281
|
-
const orderId = await sdk.placeOrder('f47ac10b-58cc-4372-a567-0e02b2c3d479', {
|
|
282
|
-
buyer: {
|
|
283
|
-
name: 'João Silva',
|
|
284
|
-
email: 'joao@exemplo.com',
|
|
186
|
+
// Process a payment
|
|
187
|
+
const orderId = await sdk.placeOrder('offer-id', {
|
|
188
|
+
customer: {
|
|
189
|
+
name: 'John Doe',
|
|
190
|
+
email: 'john@example.com',
|
|
285
191
|
document: {
|
|
286
192
|
type: 'CPF',
|
|
287
|
-
number: '
|
|
288
|
-
},
|
|
289
|
-
phone: {
|
|
290
|
-
areaCode: '+55',
|
|
291
|
-
ddd: '11',
|
|
292
|
-
number: '999999999', // Only digits
|
|
293
|
-
isMobile: true,
|
|
294
|
-
},
|
|
295
|
-
address: {
|
|
296
|
-
zipCode: '01234567', // Only digits, no hyphens
|
|
297
|
-
street: 'Rua das Flores',
|
|
298
|
-
number: '123',
|
|
299
|
-
complement: 'Apto 45',
|
|
300
|
-
neighborhood: 'Centro',
|
|
301
|
-
city: 'São Paulo',
|
|
302
|
-
state: 'SP', // Validated against Brazilian states
|
|
193
|
+
number: '12345678901',
|
|
303
194
|
},
|
|
304
195
|
},
|
|
305
196
|
payments: [
|
|
306
197
|
{
|
|
307
198
|
method: 'credit-card',
|
|
308
|
-
creditCard: {
|
|
309
|
-
number: '4111111111111111',
|
|
310
|
-
holderName: 'João Silva',
|
|
311
|
-
month: '12',
|
|
312
|
-
year: '2025',
|
|
313
|
-
cvv: '123',
|
|
314
|
-
},
|
|
315
199
|
numberInstallments: 1,
|
|
316
200
|
},
|
|
317
201
|
],
|
|
@@ -320,694 +204,391 @@ const orderId = await sdk.placeOrder('f47ac10b-58cc-4372-a567-0e02b2c3d479', {
|
|
|
320
204
|
console.log('Order created:', orderId)
|
|
321
205
|
```
|
|
322
206
|
|
|
323
|
-
##
|
|
207
|
+
## Features
|
|
324
208
|
|
|
325
|
-
|
|
209
|
+
### Payment Processing
|
|
326
210
|
|
|
327
|
-
|
|
211
|
+
- **Credit Card**: Highest approval rate with advanced fraud detection
|
|
212
|
+
- **PIX**: Instant Brazilian payment method
|
|
213
|
+
- **Bank Billet**: Traditional bank payment option
|
|
214
|
+
- **Recurring Payments**: Custom subscription rules
|
|
328
215
|
|
|
329
|
-
|
|
330
|
-
// Advanced email validation with security checks
|
|
331
|
-
Validator.validateEmail('user@example.com') // Valid
|
|
332
|
-
Validator.validateEmail('user..name@example.com') // Invalid (consecutive dots)
|
|
333
|
-
Validator.validateEmail('a'.repeat(250) + '@example.com') // Too long
|
|
334
|
-
```
|
|
216
|
+
### Customer Management
|
|
335
217
|
|
|
336
|
-
|
|
218
|
+
- **Complete Validation**: CPF/CNPJ, phone, address validation
|
|
219
|
+
- **Data Sanitization**: XSS protection and input cleaning
|
|
220
|
+
- **Secure Storage**: Encrypted sensitive data handling
|
|
337
221
|
|
|
338
|
-
|
|
339
|
-
// CPF validation with official Brazilian algorithm
|
|
340
|
-
Validator.validateCPF('12345678909') // Valid CPF (only digits)
|
|
341
|
-
Validator.validateCPF('11111111111') // Invalid (all same digits)
|
|
342
|
-
|
|
343
|
-
// CNPJ validation with official algorithm
|
|
344
|
-
Validator.validateCNPJ('11222333000181') // Valid CNPJ (only digits)
|
|
345
|
-
Validator.validateCNPJ('00000000000000') // Invalid (all zeros)
|
|
346
|
-
|
|
347
|
-
// Document object format for API
|
|
348
|
-
const document = {
|
|
349
|
-
type: 'CPF',
|
|
350
|
-
number: '12345678909', // Only digits, no formatting
|
|
351
|
-
}
|
|
352
|
-
```
|
|
222
|
+
### Security Features
|
|
353
223
|
|
|
354
|
-
|
|
224
|
+
- **PCI Compliance**: Bank-level security standards
|
|
225
|
+
- **Fingerprinting**: Advanced fraud detection
|
|
226
|
+
- **Rate Limiting**: Protection against abuse
|
|
227
|
+
- **Input Validation**: Comprehensive data validation
|
|
228
|
+
- **Obfuscated Builds**: Production builds are obfuscated for enhanced security
|
|
229
|
+
- **Controlled Distribution**: Secure distribution via CDN and GitHub Releases
|
|
355
230
|
|
|
356
|
-
|
|
357
|
-
// Brazilian phone validation
|
|
358
|
-
Validator.validatePhone({
|
|
359
|
-
areaCode: '+55', // International format
|
|
360
|
-
ddd: '11', // 2-digit DDD (only digits)
|
|
361
|
-
number: '999999999', // 8-9 digit number (only digits)
|
|
362
|
-
isMobile: true, // Boolean flag
|
|
363
|
-
})
|
|
364
|
-
```
|
|
231
|
+
## API Reference
|
|
365
232
|
|
|
366
|
-
###
|
|
233
|
+
### Core Methods
|
|
367
234
|
|
|
368
|
-
|
|
369
|
-
// Complete Brazilian address validation
|
|
370
|
-
Validator.validateAddress({
|
|
371
|
-
zipCode: '01234567', // Brazilian ZIP format (8 digits only)
|
|
372
|
-
street: 'Rua das Flores', // 3-100 characters
|
|
373
|
-
neighborhood: 'Centro', // 2-50 characters
|
|
374
|
-
city: 'São Paulo', // 2-50 characters
|
|
375
|
-
state: 'SP', // Valid Brazilian state
|
|
376
|
-
number: '123', // Valid street number
|
|
377
|
-
})
|
|
378
|
-
```
|
|
235
|
+
#### `placeOrder(offerId, data, headers)`
|
|
379
236
|
|
|
380
|
-
|
|
237
|
+
Creates an order using an existing offer.
|
|
381
238
|
|
|
382
239
|
```javascript
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
email: 'joao@exemplo.com', // Valid email
|
|
387
|
-
document: {
|
|
388
|
-
// Valid CPF/CNPJ (only digits)
|
|
389
|
-
type: 'CPF',
|
|
390
|
-
number: '12345678909',
|
|
391
|
-
},
|
|
392
|
-
phone: {
|
|
393
|
-
// Valid phone (only digits)
|
|
394
|
-
areaCode: '+55',
|
|
395
|
-
ddd: '11',
|
|
396
|
-
number: '999999999',
|
|
397
|
-
isMobile: true,
|
|
240
|
+
const orderId = await sdk.placeOrder('offer-id', {
|
|
241
|
+
customer: {
|
|
242
|
+
/* customer data */
|
|
398
243
|
},
|
|
244
|
+
payments: [
|
|
245
|
+
/* payment methods */
|
|
246
|
+
],
|
|
399
247
|
})
|
|
400
248
|
```
|
|
401
249
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
```javascript
|
|
405
|
-
// Business ID validation
|
|
406
|
-
Validator.validateBusinessId('my-business-123') // Valid format
|
|
407
|
-
Validator.validateBusinessId('-business') // Starts with hyphen
|
|
250
|
+
#### `charge(data, headers)`
|
|
408
251
|
|
|
409
|
-
|
|
410
|
-
Validator.validateOrderId('f47ac10b-58cc-4372-a567-0e02b2c3d479') // UUID v4
|
|
411
|
-
Validator.validateOrderId('01890b24-2d7f-7c3f-8f1a-123456789abc') // UUID v7
|
|
412
|
-
Validator.validateOrderId('507f1f77bcf86cd799439011') // MongoDB ObjectId
|
|
252
|
+
Processes a direct charge without using an offer.
|
|
413
253
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
254
|
+
```javascript
|
|
255
|
+
const orderId = await sdk.charge({
|
|
256
|
+
items: [{ name: 'Product', price: 1000 }],
|
|
257
|
+
payments: [{ method: 'pix', numberInstallments: 1 }],
|
|
258
|
+
})
|
|
259
|
+
```
|
|
417
260
|
|
|
418
|
-
|
|
419
|
-
Validator.validateCustomerId('01890b24-2d7f-7c3f-af1a-123456789abc') // UUID v7
|
|
420
|
-
Validator.validateCustomerId('507f1f77bcf86cd799439013') // MongoDB ObjectId
|
|
261
|
+
#### `encrypt(creditCardData, headers)`
|
|
421
262
|
|
|
422
|
-
|
|
423
|
-
Validator.validateCreditCardId('01890b24-2d7f-7c3f-bf1a-123456789abc') // UUID v7
|
|
424
|
-
Validator.validateCreditCardId('507f1f77bcf86cd799439014') // MongoDB ObjectId
|
|
263
|
+
Encrypts credit card data for secure processing.
|
|
425
264
|
|
|
426
|
-
|
|
427
|
-
|
|
265
|
+
```javascript
|
|
266
|
+
const token = await sdk.encrypt({
|
|
267
|
+
number: '4111111111111111',
|
|
268
|
+
holderName: 'John Doe',
|
|
269
|
+
expirationMonth: '12',
|
|
270
|
+
expirationYear: '2025',
|
|
271
|
+
cvv: '123',
|
|
272
|
+
})
|
|
428
273
|
```
|
|
429
274
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
- **UUID v4**: Must follow pattern `xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx` where `y` is 8, 9, A, or B
|
|
433
|
-
- **UUID v7**: Must follow pattern `xxxxxxxx-xxxx-7xxx-yxxx-xxxxxxxxxxxx` where `y` is 8, 9, A, or B
|
|
434
|
-
- **MongoDB ObjectId**: Must be exactly 24 hexadecimal characters
|
|
435
|
-
- **Business ID**: Must be 3-50 characters, alphanumeric with hyphens, no consecutive hyphens
|
|
275
|
+
### Customer Management
|
|
436
276
|
|
|
437
|
-
|
|
277
|
+
#### `createCustomer(customerData, headers)`
|
|
438
278
|
|
|
439
|
-
|
|
279
|
+
Creates a new customer.
|
|
440
280
|
|
|
441
281
|
```javascript
|
|
442
282
|
const customer = await sdk.createCustomer({
|
|
443
|
-
name: '
|
|
444
|
-
email: '
|
|
445
|
-
|
|
446
|
-
zipCode: '37540114',
|
|
447
|
-
street: 'Rua Marechal Deodoro',
|
|
448
|
-
complement: 'Apt',
|
|
449
|
-
neighborhood: 'Centro',
|
|
450
|
-
city: 'Pouso Alegre',
|
|
451
|
-
state: 'MG',
|
|
452
|
-
number: '33',
|
|
453
|
-
},
|
|
454
|
-
address: {
|
|
455
|
-
zipCode: '37540114',
|
|
456
|
-
street: 'Rua Marechal Deodoro',
|
|
457
|
-
complement: 'Apt',
|
|
458
|
-
neighborhood: 'Centro',
|
|
459
|
-
city: 'Pouso Alegre',
|
|
460
|
-
state: 'MG',
|
|
461
|
-
number: '33',
|
|
462
|
-
},
|
|
463
|
-
document: {
|
|
464
|
-
type: 'CPF',
|
|
465
|
-
number: '01234567890',
|
|
466
|
-
},
|
|
467
|
-
phone: {
|
|
468
|
-
areaCode: '+55',
|
|
469
|
-
ddd: '11',
|
|
470
|
-
number: '998862782',
|
|
471
|
-
isMobile: true,
|
|
472
|
-
},
|
|
283
|
+
name: 'John Doe',
|
|
284
|
+
email: 'john@example.com',
|
|
285
|
+
document: { type: 'CPF', number: '12345678901' },
|
|
473
286
|
})
|
|
474
|
-
|
|
475
|
-
console.log('Customer created:', customer.id)
|
|
476
287
|
```
|
|
477
288
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
```javascript
|
|
481
|
-
const customerInfo = await sdk.getCustomer(
|
|
482
|
-
'16fd2706-8baf-433b-82eb-8c7fada847da'
|
|
483
|
-
)
|
|
484
|
-
console.log('Name:', customerInfo.name)
|
|
485
|
-
console.log('Email:', customerInfo.email)
|
|
486
|
-
console.log('Document:', customerInfo.document)
|
|
487
|
-
```
|
|
289
|
+
#### `getCustomer(customerId, headers)`
|
|
488
290
|
|
|
489
|
-
|
|
291
|
+
Retrieves customer information.
|
|
490
292
|
|
|
491
293
|
```javascript
|
|
492
|
-
const
|
|
493
|
-
'16fd2706-8baf-433b-82eb-8c7fada847da',
|
|
494
|
-
{
|
|
495
|
-
name: 'Diego Moura Updated',
|
|
496
|
-
email: 'diegomoura637+21@gmail.com',
|
|
497
|
-
phone: {
|
|
498
|
-
areaCode: '+55',
|
|
499
|
-
ddd: '11',
|
|
500
|
-
number: '998862783',
|
|
501
|
-
isMobile: true,
|
|
502
|
-
},
|
|
503
|
-
}
|
|
504
|
-
)
|
|
505
|
-
|
|
506
|
-
console.log('Customer updated:', updateResult.success)
|
|
294
|
+
const customer = await sdk.getCustomer('customer-id')
|
|
507
295
|
```
|
|
508
296
|
|
|
509
|
-
|
|
297
|
+
#### `updateCustomer(customerId, updateData, headers)`
|
|
510
298
|
|
|
511
|
-
|
|
299
|
+
Updates existing customer information.
|
|
512
300
|
|
|
513
301
|
```javascript
|
|
514
|
-
const
|
|
515
|
-
'
|
|
516
|
-
'
|
|
517
|
-
)
|
|
518
|
-
|
|
519
|
-
console.log('Credit card added:', cardResult.creditCardId)
|
|
302
|
+
const result = await sdk.updateCustomer('customer-id', {
|
|
303
|
+
name: 'John Updated',
|
|
304
|
+
email: 'john.updated@example.com',
|
|
305
|
+
})
|
|
520
306
|
```
|
|
521
307
|
|
|
522
|
-
###
|
|
308
|
+
### Credit Card Management
|
|
523
309
|
|
|
524
|
-
|
|
525
|
-
const creditCard = await sdk.getCreditCard(
|
|
526
|
-
'16fd2706-8baf-433b-82eb-8c7fada847da',
|
|
527
|
-
'58c8f2e0-3d22-4b5d-98ab-9c0a1f2b3c4d'
|
|
528
|
-
)
|
|
529
|
-
|
|
530
|
-
console.log('Brand:', creditCard.brand)
|
|
531
|
-
console.log('Last 4 digits:', creditCard.last4Numbers)
|
|
532
|
-
console.log(
|
|
533
|
-
'Expires:',
|
|
534
|
-
`${creditCard.expiresAtMonth}/${creditCard.expiresAtYear}`
|
|
535
|
-
)
|
|
536
|
-
```
|
|
310
|
+
#### `addCreditCard(customerId, creditCardToken, headers)`
|
|
537
311
|
|
|
538
|
-
|
|
312
|
+
Adds a credit card to a customer.
|
|
539
313
|
|
|
540
314
|
```javascript
|
|
541
|
-
const
|
|
542
|
-
'16fd2706-8baf-433b-82eb-8c7fada847da',
|
|
543
|
-
'58c8f2e0-3d22-4b5d-98ab-9c0a1f2b3c4d'
|
|
544
|
-
)
|
|
545
|
-
|
|
546
|
-
console.log('Credit card removed:', removeResult.success)
|
|
315
|
+
const result = await sdk.addCreditCard('customer-id', 'encrypted-token')
|
|
547
316
|
```
|
|
548
317
|
|
|
549
|
-
|
|
318
|
+
#### `getCreditCard(customerId, creditCardId, headers)`
|
|
550
319
|
|
|
551
|
-
|
|
320
|
+
Retrieves credit card information.
|
|
552
321
|
|
|
553
322
|
```javascript
|
|
554
|
-
|
|
555
|
-
const sanitizedData = Sanitizer.sanitizeObjectFields({
|
|
556
|
-
user: {
|
|
557
|
-
name: '<script>alert("xss")</script>John',
|
|
558
|
-
profile: {
|
|
559
|
-
bio: 'Bio with <strong>HTML</strong>',
|
|
560
|
-
website: 'javascript:alert("xss")',
|
|
561
|
-
},
|
|
562
|
-
},
|
|
563
|
-
})
|
|
564
|
-
// Result: All dangerous content removed, structure preserved
|
|
323
|
+
const creditCard = await sdk.getCreditCard('customer-id', 'credit-card-id')
|
|
565
324
|
```
|
|
566
325
|
|
|
567
|
-
|
|
326
|
+
#### `removeCreditCard(customerId, creditCardId, headers)`
|
|
327
|
+
|
|
328
|
+
Removes a credit card from a customer.
|
|
568
329
|
|
|
569
330
|
```javascript
|
|
570
|
-
|
|
571
|
-
Sanitizer.sanitizeInput('<script>alert("xss")</script>')
|
|
572
|
-
// Returns: 'scriptalert("xss")/script' (quotes preserved)
|
|
331
|
+
const result = await sdk.removeCreditCard('customer-id', 'credit-card-id')
|
|
573
332
|
```
|
|
574
333
|
|
|
575
|
-
|
|
334
|
+
## Validation
|
|
576
335
|
|
|
577
|
-
|
|
578
|
-
// Safe handling of circular references
|
|
579
|
-
const obj = { name: 'test' }
|
|
580
|
-
obj.self = obj
|
|
581
|
-
const sanitized = Sanitizer.sanitizeObjectFields(obj)
|
|
582
|
-
// No infinite recursion, safe processing
|
|
583
|
-
```
|
|
336
|
+
### ID Validation
|
|
584
337
|
|
|
585
|
-
|
|
338
|
+
All entity IDs must follow specific formats:
|
|
586
339
|
|
|
587
|
-
|
|
340
|
+
- **UUID v4**: `xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx` (y = 8,9,A,B)
|
|
341
|
+
- **UUID v7**: `xxxxxxxx-xxxx-7xxx-yxxx-xxxxxxxxxxxx` (y = 8,9,A,B)
|
|
342
|
+
- **MongoDB ObjectId**: 24-character hexadecimal format
|
|
588
343
|
|
|
589
344
|
```javascript
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
price: 1000, // R$ 10.00
|
|
595
|
-
quantity: 1,
|
|
596
|
-
},
|
|
597
|
-
],
|
|
598
|
-
payments: [
|
|
599
|
-
{
|
|
600
|
-
method: 'pix',
|
|
601
|
-
numberInstallments: 1,
|
|
602
|
-
},
|
|
603
|
-
],
|
|
604
|
-
buyer: {
|
|
605
|
-
name: 'João Silva',
|
|
606
|
-
email: 'joao@exemplo.com',
|
|
607
|
-
document: { type: 'CPF', number: '12345678909' }, // Only digits
|
|
608
|
-
},
|
|
609
|
-
})
|
|
345
|
+
// Valid IDs
|
|
346
|
+
Validator.validateOrderId('f47ac10b-58cc-4372-a567-0e02b2c3d479') // UUID v4
|
|
347
|
+
Validator.validateOrderId('01890b24-2d7f-7c3f-8f1a-123456789abc') // UUID v7
|
|
348
|
+
Validator.validateOrderId('507f1f77bcf86cd799439011') // MongoDB ObjectId
|
|
610
349
|
```
|
|
611
350
|
|
|
612
|
-
###
|
|
351
|
+
### Data Validation
|
|
352
|
+
|
|
353
|
+
Comprehensive validation for all input data:
|
|
613
354
|
|
|
614
355
|
```javascript
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
cvv: '123',
|
|
356
|
+
// Customer validation
|
|
357
|
+
Validator.validateCustomer({
|
|
358
|
+
name: 'John Doe',
|
|
359
|
+
email: 'john@example.com',
|
|
360
|
+
document: { type: 'CPF', number: '12345678901' },
|
|
621
361
|
})
|
|
622
|
-
// All data automatically validated before encryption
|
|
623
|
-
```
|
|
624
362
|
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
console.log('QR Code:', pix.qrCode)
|
|
631
|
-
console.log('PIX Code:', pix.copyAndPasteCode)
|
|
632
|
-
console.log('Expiration:', pix.expirationDate)
|
|
633
|
-
}
|
|
363
|
+
// Payment validation
|
|
364
|
+
Validator.validateOrderData({
|
|
365
|
+
items: [{ name: 'Product', price: 1000 }],
|
|
366
|
+
payments: [{ method: 'credit-card', numberInstallments: 1 }],
|
|
367
|
+
})
|
|
634
368
|
```
|
|
635
369
|
|
|
636
|
-
##
|
|
370
|
+
## Events
|
|
637
371
|
|
|
638
|
-
|
|
372
|
+
The SDK provides an event system for monitoring operations:
|
|
639
373
|
|
|
640
374
|
```javascript
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
'
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
375
|
+
// Listen to events
|
|
376
|
+
sdk.on('customerCreated', (data) => {
|
|
377
|
+
console.log('Customer created:', data)
|
|
378
|
+
})
|
|
379
|
+
|
|
380
|
+
sdk.on('orderPlaced', (data) => {
|
|
381
|
+
console.log('Order placed:', data)
|
|
382
|
+
})
|
|
383
|
+
|
|
384
|
+
sdk.on('paymentProcessed', (data) => {
|
|
385
|
+
console.log('Payment processed:', data)
|
|
386
|
+
})
|
|
647
387
|
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
data,
|
|
651
|
-
headers
|
|
652
|
-
)
|
|
388
|
+
// Remove event listeners
|
|
389
|
+
sdk.off('customerCreated', callback)
|
|
653
390
|
```
|
|
654
391
|
|
|
655
|
-
|
|
392
|
+
## Error Handling
|
|
393
|
+
|
|
394
|
+
The SDK provides comprehensive error handling:
|
|
656
395
|
|
|
657
396
|
```javascript
|
|
658
397
|
try {
|
|
659
|
-
const
|
|
660
|
-
'f47ac10b-58cc-4372-a567-0e02b2c3d479',
|
|
661
|
-
data
|
|
662
|
-
)
|
|
663
|
-
console.log('Success:', orderId)
|
|
398
|
+
const result = await sdk.placeOrder('offer-id', orderData)
|
|
664
399
|
} catch (error) {
|
|
665
|
-
if (error
|
|
666
|
-
console.
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
console.error('Security error:', error.message)
|
|
672
|
-
} else {
|
|
673
|
-
console.error('Unexpected error:', error)
|
|
400
|
+
if (error.name === 'ValidationError') {
|
|
401
|
+
console.log('Validation failed:', error.message)
|
|
402
|
+
} else if (error.name === 'NetworkError') {
|
|
403
|
+
console.log('Network error:', error.message)
|
|
404
|
+
} else if (error.name === 'SecurityError') {
|
|
405
|
+
console.log('Security violation:', error.message)
|
|
674
406
|
}
|
|
675
407
|
}
|
|
676
408
|
```
|
|
677
409
|
|
|
678
|
-
##
|
|
679
|
-
|
|
680
|
-
### Run Tests
|
|
681
|
-
|
|
682
|
-
```bash
|
|
683
|
-
# All tests
|
|
684
|
-
npm test
|
|
685
|
-
|
|
686
|
-
# Watch mode
|
|
687
|
-
npm run test:watch
|
|
410
|
+
## Configuration
|
|
688
411
|
|
|
689
|
-
|
|
690
|
-
npm run test:coverage
|
|
412
|
+
### SDK Options
|
|
691
413
|
|
|
692
|
-
|
|
693
|
-
|
|
414
|
+
```javascript
|
|
415
|
+
const sdk = new EasyflowSDK({
|
|
416
|
+
businessId: 'your-business-id',
|
|
417
|
+
environment: 'production', // 'production' or 'sandbox'
|
|
418
|
+
debug: false, // Enable debug logging
|
|
419
|
+
timeout: 30000, // Request timeout in milliseconds
|
|
420
|
+
})
|
|
694
421
|
```
|
|
695
422
|
|
|
696
|
-
###
|
|
423
|
+
### Environment Variables
|
|
697
424
|
|
|
698
|
-
|
|
699
|
-
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
### Test Structure
|
|
704
|
-
|
|
705
|
-
```
|
|
706
|
-
sdk.spec.js - Main SDK tests
|
|
707
|
-
libs/validator.spec.js - Validation framework tests
|
|
708
|
-
libs/sanitizer.spec.js - Sanitization tests
|
|
709
|
-
libs/errors.spec.js - Error handling tests
|
|
710
|
-
libs/constants.spec.js - Constants tests
|
|
711
|
-
libs/utils.spec.js - Utilities tests
|
|
712
|
-
libs/http.spec.js - HTTP communication tests
|
|
713
|
-
libs/logger.spec.js - Logging tests
|
|
714
|
-
libs/exception-handler.spec.js - Exception handling tests
|
|
425
|
+
```bash
|
|
426
|
+
EASYFLOW_BUSINESS_ID=your-business-id
|
|
427
|
+
EASYFLOW_ENVIRONMENT=production
|
|
428
|
+
EASYFLOW_DEBUG=false
|
|
715
429
|
```
|
|
716
430
|
|
|
717
|
-
##
|
|
718
|
-
|
|
719
|
-
### Core Methods
|
|
720
|
-
|
|
721
|
-
| Method | Description | Validation |
|
|
722
|
-
| ------------------------------------ | ----------------------- | -------------------- |
|
|
723
|
-
| `placeOrder(offerId, data, headers)` | Create order from offer | Full data validation |
|
|
724
|
-
| `charge(data, headers)` | Process direct charge | Full data validation |
|
|
725
|
-
| `encrypt(creditCard, headers)` | Encrypt card data | Card validation |
|
|
726
|
-
| `getOffer(offerId, headers)` | Get offer details | ID validation |
|
|
727
|
-
| `getOrder(orderId)` | Get order details | ID validation |
|
|
728
|
-
| `getPix(orderId, headers)` | Get PIX data | ID validation |
|
|
729
|
-
| `getBankBillet(orderId, headers)` | Get billet data | ID validation |
|
|
730
|
-
|
|
731
|
-
### Customer Management
|
|
732
|
-
|
|
733
|
-
| Method | Description | Validation |
|
|
734
|
-
| --------------------------------------- | --------------- | ------------------------ |
|
|
735
|
-
| `createCustomer(customer, headers)` | Create customer | Full customer validation |
|
|
736
|
-
| `getCustomer(id, headers)` | Get customer | ID validation |
|
|
737
|
-
| `updateCustomer(id, customer, headers)` | Update customer | Full validation |
|
|
738
|
-
|
|
739
|
-
### Credit Card Management
|
|
431
|
+
## Examples
|
|
740
432
|
|
|
741
|
-
|
|
742
|
-
| ----------------------------------------------- | ----------- | --------------------- |
|
|
743
|
-
| `addCreditCard(customerId, token, headers)` | Add card | ID + token validation |
|
|
744
|
-
| `getCreditCard(customerId, cardId, headers)` | Get card | ID validation |
|
|
745
|
-
| `removeCreditCard(customerId, cardId, headers)` | Remove card | ID validation |
|
|
433
|
+
### Complete Checkout Flow
|
|
746
434
|
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
| `Validator.validatePhone(phone)` | Phone validation | Contact information |
|
|
755
|
-
| `Validator.validateAddress(address)` | Address validation | Shipping/billing |
|
|
756
|
-
| `Validator.validateCustomer(customer)` | Customer validation | Complete profile |
|
|
757
|
-
| `Validator.validateBusinessId(id)` | Business ID validation | SDK initialization |
|
|
758
|
-
| `Validator.validateOrderId(id)` | Order ID validation | Order operations |
|
|
759
|
-
| `Validator.validateOfferId(id)` | Offer ID validation | Offer operations |
|
|
760
|
-
| `Validator.validateCreditCardToken(token)` | Token validation | Card operations |
|
|
761
|
-
| `Validator.validatePagination(page, limit)` | Pagination validation | List operations |
|
|
435
|
+
```javascript
|
|
436
|
+
// 1. Create customer
|
|
437
|
+
const customer = await sdk.createCustomer({
|
|
438
|
+
name: 'John Doe',
|
|
439
|
+
email: 'john@example.com',
|
|
440
|
+
document: { type: 'CPF', number: '12345678901' },
|
|
441
|
+
})
|
|
762
442
|
|
|
763
|
-
|
|
443
|
+
// 2. Encrypt credit card
|
|
444
|
+
const token = await sdk.encrypt({
|
|
445
|
+
number: '4111111111111111',
|
|
446
|
+
holderName: 'John Doe',
|
|
447
|
+
expirationMonth: '12',
|
|
448
|
+
expirationYear: '2025',
|
|
449
|
+
cvv: '123',
|
|
450
|
+
})
|
|
764
451
|
|
|
765
|
-
|
|
452
|
+
// 3. Add credit card to customer
|
|
453
|
+
const creditCard = await sdk.addCreditCard(customer.id, token)
|
|
766
454
|
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
notifications: true,
|
|
776
|
-
language: 'pt-BR<script>alert("xss")</script>',
|
|
777
|
-
},
|
|
455
|
+
// 4. Place order
|
|
456
|
+
const orderId = await sdk.placeOrder('offer-id', {
|
|
457
|
+
customer: customer,
|
|
458
|
+
payments: [
|
|
459
|
+
{
|
|
460
|
+
method: 'credit-card',
|
|
461
|
+
creditCardId: creditCard.creditCardId,
|
|
462
|
+
numberInstallments: 1,
|
|
778
463
|
},
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
tags: ['tag1', '<script>alert("xss")</script>tag2'],
|
|
782
|
-
},
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
const sanitized = Sanitizer.sanitizeObjectFields(complexData)
|
|
786
|
-
// All dangerous content removed, structure preserved
|
|
464
|
+
],
|
|
465
|
+
})
|
|
787
466
|
```
|
|
788
467
|
|
|
789
|
-
###
|
|
468
|
+
### PIX Payment
|
|
790
469
|
|
|
791
470
|
```javascript
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
phone: { areaCode: '+55', ddd: '11', number: '999999999' }, // Only digits
|
|
796
|
-
address: {
|
|
797
|
-
zipCode: '01234567', // Only digits, no hyphens
|
|
798
|
-
state: 'SP', // Validated against 27 Brazilian states
|
|
799
|
-
city: 'São Paulo',
|
|
471
|
+
const orderId = await sdk.placeOrder('offer-id', {
|
|
472
|
+
customer: {
|
|
473
|
+
/* customer data */
|
|
800
474
|
},
|
|
801
|
-
|
|
475
|
+
payments: [
|
|
476
|
+
{
|
|
477
|
+
method: 'pix',
|
|
478
|
+
numberInstallments: 1,
|
|
479
|
+
},
|
|
480
|
+
],
|
|
481
|
+
})
|
|
802
482
|
|
|
803
|
-
//
|
|
804
|
-
|
|
483
|
+
// Get PIX data
|
|
484
|
+
const pixData = await sdk.getPix(orderId)
|
|
485
|
+
console.log('PIX QR Code:', pixData.qrCode)
|
|
805
486
|
```
|
|
806
487
|
|
|
807
|
-
###
|
|
488
|
+
### Bank Billet Payment
|
|
808
489
|
|
|
809
490
|
```javascript
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
491
|
+
const orderId = await sdk.placeOrder('offer-id', {
|
|
492
|
+
customer: {
|
|
493
|
+
/* customer data */
|
|
494
|
+
},
|
|
495
|
+
payments: [
|
|
496
|
+
{
|
|
497
|
+
method: 'bank-billet',
|
|
498
|
+
numberInstallments: 1,
|
|
499
|
+
},
|
|
500
|
+
],
|
|
501
|
+
})
|
|
502
|
+
|
|
503
|
+
// Get bank billet data
|
|
504
|
+
const bankBillet = await sdk.getBankBillet(orderId)
|
|
505
|
+
console.log('Bank Billet Link:', bankBillet.link)
|
|
818
506
|
```
|
|
819
507
|
|
|
820
|
-
##
|
|
508
|
+
## Distribution & Security
|
|
821
509
|
|
|
822
|
-
###
|
|
510
|
+
### Why CDN Scripts?
|
|
823
511
|
|
|
824
|
-
- **
|
|
825
|
-
- **
|
|
826
|
-
- **
|
|
827
|
-
- **
|
|
512
|
+
- **Obfuscated Builds**: Production code is obfuscated for security
|
|
513
|
+
- **Controlled Access**: Secure distribution via Cloudflare Pages
|
|
514
|
+
- **Version Control**: Specific versions available for stability
|
|
515
|
+
- **Performance**: Global CDN for fast loading
|
|
828
516
|
|
|
829
|
-
### CDN
|
|
517
|
+
### Available CDN URLs
|
|
830
518
|
|
|
831
519
|
```html
|
|
832
520
|
<!-- Latest version -->
|
|
833
521
|
<script src="https://easyflow-sdk.pages.dev/easyflow-sdk.min.js"></script>
|
|
834
522
|
|
|
835
523
|
<!-- Versioned (recommended for production) -->
|
|
836
|
-
<script src="https://easyflow-sdk.pages.dev/easyflow-sdk.v2.1.
|
|
524
|
+
<script src="https://easyflow-sdk.pages.dev/easyflow-sdk.v2.1.8.min.js"></script>
|
|
837
525
|
|
|
838
526
|
<!-- With SRI (Subresource Integrity) -->
|
|
839
527
|
<script
|
|
840
|
-
src="https://easyflow-sdk.pages.dev/easyflow-sdk.v2.1.
|
|
841
|
-
integrity="sha384-
|
|
528
|
+
src="https://easyflow-sdk.pages.dev/easyflow-sdk.v2.1.9.min.js"
|
|
529
|
+
integrity="sha384-[hash]"
|
|
842
530
|
crossorigin="anonymous"
|
|
843
531
|
></script>
|
|
844
532
|
```
|
|
845
533
|
|
|
846
|
-
## Development & Contributing
|
|
847
|
-
|
|
848
|
-
### Local Development
|
|
849
|
-
|
|
850
|
-
```bash
|
|
851
|
-
# Clone repository
|
|
852
|
-
git clone https://github.com/easyflow-cash/easyflow-javascript-sdk.git
|
|
853
|
-
cd easyflow-javascript-sdk
|
|
854
|
-
|
|
855
|
-
# Install dependencies
|
|
856
|
-
npm install
|
|
857
|
-
|
|
858
|
-
# Start development server
|
|
859
|
-
npm run dev
|
|
860
|
-
|
|
861
|
-
# Run tests
|
|
862
|
-
npm test
|
|
863
|
-
|
|
864
|
-
# Build for production
|
|
865
|
-
npm run build
|
|
866
|
-
```
|
|
867
|
-
|
|
868
|
-
### Project Structure
|
|
869
|
-
|
|
870
|
-
```
|
|
871
|
-
├── libs/ # Core libraries
|
|
872
|
-
│ ├── validator.mjs # Validation framework
|
|
873
|
-
│ ├── sanitizer.mjs # Data sanitization
|
|
874
|
-
│ ├── security.mjs # Security features
|
|
875
|
-
│ ├── http.mjs # HTTP communication
|
|
876
|
-
│ ├── errors.mjs # Error handling
|
|
877
|
-
│ ├── constants.mjs # Constants
|
|
878
|
-
│ ├── utils.mjs # Utilities
|
|
879
|
-
│ ├── logger.mjs # Logging
|
|
880
|
-
│ └── exception-handler.mjs # Exception handling
|
|
881
|
-
├── sdk.mjs # Main SDK class
|
|
882
|
-
├── tests/ # Test files
|
|
883
|
-
├── dist/ # Built files
|
|
884
|
-
└── docs/ # Documentation
|
|
885
|
-
```
|
|
886
|
-
|
|
887
|
-
## Quality Metrics
|
|
888
|
-
|
|
889
|
-
### Code Quality
|
|
890
|
-
|
|
891
|
-
- **ESLint**: 0 warnings, 0 errors
|
|
892
|
-
- **Prettier**: Consistent formatting
|
|
893
|
-
- **TypeScript**: JSDoc type definitions
|
|
894
|
-
- **Coverage**: 95% test coverage
|
|
895
|
-
|
|
896
|
-
### Security Score
|
|
897
|
-
|
|
898
|
-
- **Input Validation**: 95/100
|
|
899
|
-
- **Data Sanitization**: 98/100
|
|
900
|
-
- **Error Handling**: 92/100
|
|
901
|
-
- **Rate Limiting**: 90/100
|
|
902
|
-
- **Overall Security**: 92/100
|
|
903
|
-
|
|
904
|
-
### Performance Score
|
|
905
|
-
|
|
906
|
-
- **Bundle Size**: 95/100
|
|
907
|
-
- **Execution Speed**: 92/100
|
|
908
|
-
- **Memory Usage**: 90/100
|
|
909
|
-
- **Network Efficiency**: 88/100
|
|
910
|
-
- **Overall Performance**: 95/100
|
|
911
|
-
|
|
912
534
|
## Browser Support
|
|
913
535
|
|
|
914
|
-
|
|
915
|
-
- **Firefox**: 75+
|
|
916
|
-
- **Safari**: 13+
|
|
917
|
-
- **Edge**: 80+
|
|
918
|
-
- **Node.js**: 16+
|
|
919
|
-
|
|
920
|
-
## Mobile Support
|
|
921
|
-
|
|
922
|
-
- **iOS Safari**: 13+
|
|
923
|
-
- **Android Chrome**: 80+
|
|
924
|
-
- **Mobile WebView**: 80+
|
|
925
|
-
|
|
926
|
-
## Support & Contact
|
|
927
|
-
|
|
928
|
-
### Need Help?
|
|
536
|
+
## Node.js Support
|
|
929
537
|
|
|
930
|
-
- **
|
|
931
|
-
- **
|
|
932
|
-
- **
|
|
933
|
-
- **Issues**: [GitHub Issues](https://github.com/easyflow-cash/easyflow-javascript-sdk/issues)
|
|
538
|
+
- **Node.js**: 18+
|
|
539
|
+
- **npm**: 8+
|
|
540
|
+
- **yarn**: 1.22+
|
|
934
541
|
|
|
935
|
-
|
|
542
|
+
## Contributing
|
|
936
543
|
|
|
937
|
-
|
|
938
|
-
- **No Bureaucracy**: Product live in 1 minute
|
|
939
|
-
- **100% Plug & Play**: Works for any type of business
|
|
940
|
-
- **Scales with You**: Grow without limits
|
|
544
|
+
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
941
545
|
|
|
942
|
-
##
|
|
546
|
+
## Support
|
|
943
547
|
|
|
944
|
-
- **Official Website**: [https://www.easyflow.digital](https://www.easyflow.digital)
|
|
945
|
-
- **Live Demo**: [https://easyflow-sdk.pages.dev](https://easyflow-sdk.pages.dev)
|
|
946
548
|
- **Documentation**: [https://docs.easyflow.digital](https://docs.easyflow.digital)
|
|
947
|
-
- **
|
|
948
|
-
- **
|
|
949
|
-
- **Repository**: [GitHub Repository](https://github.com/easyflow-cash/easyflow-javascript-sdk)
|
|
950
|
-
|
|
951
|
-
## CDN URLs
|
|
952
|
-
|
|
953
|
-
### Cloudflare Pages CDN
|
|
954
|
-
|
|
955
|
-
- **Latest**: [https://easyflow-sdk.pages.dev/easyflow-sdk.min.js](https://easyflow-sdk.pages.dev/easyflow-sdk.min.js)
|
|
956
|
-
- **Versioned**: [https://easyflow-sdk.pages.dev/easyflow-sdk.v2.1.4.min.js](https://easyflow-sdk.pages.dev/easyflow-sdk.v2.1.4.min.js)
|
|
957
|
-
|
|
958
|
-
### jsDelivr CDN
|
|
959
|
-
|
|
960
|
-
- **Latest**: [https://cdn.jsdelivr.net/npm/@easyflow/javascript-sdk@latest/dist/easyflow-sdk.min.js](https://cdn.jsdelivr.net/npm/@easyflow/javascript-sdk@latest/dist/easyflow-sdk.min.js)
|
|
961
|
-
- **Versioned**: [https://cdn.jsdelivr.net/npm/@easyflow/javascript-sdk@2.1.4/dist/easyflow-sdk.min.js](https://cdn.jsdelivr.net/npm/@easyflow/javascript-sdk@2.1.4/dist/easyflow-sdk.min.js)
|
|
962
|
-
|
|
963
|
-
## Author & Maintainer
|
|
549
|
+
- **GitHub Issues**: [https://github.com/easyflow-cash/easyflow-javascript-sdk/issues](https://github.com/easyflow-cash/easyflow-javascript-sdk/issues)
|
|
550
|
+
- **Website**: [https://www.easyflow.digital](https://www.easyflow.digital)
|
|
964
551
|
|
|
965
|
-
|
|
552
|
+
## License
|
|
966
553
|
|
|
967
|
-
-
|
|
968
|
-
- **Email**: [diego@easyflow.digital](mailto:diego@easyflow.digital)
|
|
969
|
-
- **Website**: [diegomoura.pro](https://diegomoura.pro)
|
|
970
|
-
- **LinkedIn**: [diego-moura-8499a664](https://www.linkedin.com/in/diego-moura-8499a664/)
|
|
971
|
-
- **Medium**: [@diego_moura](https://medium.com/@diego_moura)
|
|
554
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
972
555
|
|
|
973
|
-
|
|
556
|
+
## Changelog
|
|
974
557
|
|
|
975
|
-
|
|
558
|
+
### v2.1.9
|
|
976
559
|
|
|
977
|
-
|
|
560
|
+
- **Hybrid Distribution**: NPM for docs, CDN for secure obfuscated code
|
|
561
|
+
- **Enhanced Security**: Code source protected while maintaining accessibility
|
|
562
|
+
- **Better UX**: Easy discovery via NPM, secure usage via CDN
|
|
563
|
+
- **Documentation**: Complete setup and usage instructions
|
|
978
564
|
|
|
979
|
-
|
|
565
|
+
### v2.1.8
|
|
980
566
|
|
|
981
|
-
|
|
567
|
+
- **Security & Privacy**: Anonymized README.md for safe NPM publication
|
|
568
|
+
- **Documentation**: Removed all personal information and sensitive data
|
|
569
|
+
- **Professional**: Clean, business-focused documentation
|
|
982
570
|
|
|
983
|
-
|
|
571
|
+
### v2.1.7
|
|
984
572
|
|
|
985
|
-
|
|
573
|
+
- Fixed all failing unit tests for complete 250 test coverage
|
|
574
|
+
- Corrected mock structures for customer and credit card management
|
|
575
|
+
- Standardized API response patterns across all endpoints
|
|
576
|
+
- Enhanced test reliability and maintainability
|
|
986
577
|
|
|
987
|
-
|
|
578
|
+
### v2.1.6
|
|
988
579
|
|
|
989
|
-
|
|
580
|
+
- Enhanced ID validation with UUID v4, UUID v7, and MongoDB ObjectId support
|
|
581
|
+
- Fixed iframe compatibility issues for low-code platforms
|
|
582
|
+
- Implemented complete event system with `on()` and `off()` methods
|
|
583
|
+
- Added global SDK instance for easier integration
|
|
990
584
|
|
|
991
|
-
|
|
585
|
+
### v2.1.5
|
|
992
586
|
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
**Performance score:** 95/100
|
|
587
|
+
- Added browser fingerprinting for enhanced security
|
|
588
|
+
- Implemented automatic `x-fingerprint-id` header generation
|
|
589
|
+
- Enhanced security validation and error handling
|
|
590
|
+
- Improved documentation and examples
|
|
998
591
|
|
|
999
592
|
---
|
|
1000
593
|
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
**Find your own flow in digital**
|
|
1004
|
-
|
|
1005
|
-
_Easyflow Payment Solutions_
|
|
1006
|
-
_CNPJ 53.833.178/0001-80_
|
|
1007
|
-
|
|
1008
|
-
---
|
|
1009
|
-
|
|
1010
|
-
**Developed and maintained by [Diego Moura](https://github.com/dmourainatel)**
|
|
1011
|
-
_Solutions Architect & CTO_
|
|
1012
|
-
|
|
1013
|
-
</div>
|
|
594
|
+
**Built with ❤️ by the Easyflow Team**
|