@easyflow/javascript-sdk 2.1.9 → 2.1.11
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 +179 -75
- package/package.json +1 -1
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,26 @@ 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.11
|
|
88
|
+
|
|
89
|
+
### Credit Card Token Validation Fix
|
|
90
|
+
|
|
91
|
+
- **Real Token Support**: Now accepts real encrypted/ciphered credit card tokens
|
|
92
|
+
- **Flexible Format**: Supports Base64, URL-safe, and mixed character tokens
|
|
93
|
+
- **Variable Length**: Accepts tokens from 16 to 2048 characters
|
|
94
|
+
- **Enhanced Security**: Maintains security while accepting real-world tokens
|
|
95
|
+
- **Backward Compatibility**: Works with all existing token formats
|
|
96
|
+
|
|
97
|
+
### Workflow Corrections
|
|
98
|
+
|
|
99
|
+
### Workflow Corrections
|
|
100
|
+
|
|
101
|
+
- **GitHub Actions Fixed**: Resolved release workflow permissions and SRI hash generation
|
|
102
|
+
- **CDN Deployment**: Automated deployment to Cloudflare Pages working correctly
|
|
103
|
+
- **Release Automation**: GitHub releases created automatically with proper SRI hashes
|
|
104
|
+
- **Build Process**: Streamlined build and deployment pipeline
|
|
105
|
+
|
|
106
|
+
### Hybrid Distribution Strategy
|
|
88
107
|
|
|
89
108
|
### Hybrid Distribution Strategy
|
|
90
109
|
|
|
@@ -158,7 +177,7 @@ Add this script tag to your HTML:
|
|
|
158
177
|
<script src="https://easyflow-sdk.pages.dev/easyflow-sdk.min.js"></script>
|
|
159
178
|
|
|
160
179
|
<!-- Specific version -->
|
|
161
|
-
<script src="https://easyflow-sdk.pages.dev/easyflow-sdk.v2.1.
|
|
180
|
+
<script src="https://easyflow-sdk.pages.dev/easyflow-sdk.v2.1.11.min.js"></script>
|
|
162
181
|
```
|
|
163
182
|
|
|
164
183
|
#### Option 2: NPM Package (Documentation Only)
|
|
@@ -175,33 +194,81 @@ Download the latest obfuscated build from [GitHub Releases](https://github.com/e
|
|
|
175
194
|
|
|
176
195
|
### Basic Usage
|
|
177
196
|
|
|
178
|
-
|
|
179
|
-
import { EasyflowSDK } from '@easyflow/javascript-sdk'
|
|
197
|
+
#### Method 1: CDN Script (Recommended for Production)
|
|
180
198
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
})
|
|
199
|
+
```html
|
|
200
|
+
<!-- Load SDK via script tag -->
|
|
201
|
+
<script src="https://easyflow-sdk.pages.dev/easyflow-sdk.min.js"></script>
|
|
185
202
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
+
<script>
|
|
204
|
+
// Configure the global instance
|
|
205
|
+
easyflowSDK.configure({
|
|
206
|
+
businessId: 'demo-business-12345',
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
// Process a payment
|
|
210
|
+
easyflowSDK
|
|
211
|
+
.placeOrder('demo-offer-67890', {
|
|
212
|
+
customer: {
|
|
213
|
+
name: 'João Silva',
|
|
214
|
+
email: 'joao@exemplo.com',
|
|
215
|
+
document: {
|
|
216
|
+
type: 'CPF',
|
|
217
|
+
number: '12345678901',
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
payments: [
|
|
221
|
+
{
|
|
222
|
+
method: 'credit-card',
|
|
223
|
+
numberInstallments: 1,
|
|
224
|
+
},
|
|
225
|
+
],
|
|
226
|
+
})
|
|
227
|
+
.then((orderId) => {
|
|
228
|
+
console.log('Pedido criado:', orderId)
|
|
229
|
+
})
|
|
230
|
+
.catch((error) => {
|
|
231
|
+
console.error('Erro ao criar pedido:', error.message)
|
|
232
|
+
})
|
|
233
|
+
</script>
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
#### Method 2: Global Instance (For Low-Code Platforms & Simple HTML)
|
|
237
|
+
|
|
238
|
+
```html
|
|
239
|
+
<!-- Load SDK via script tag -->
|
|
240
|
+
<script src="https://easyflow-sdk.pages.dev/easyflow-sdk.min.js"></script>
|
|
203
241
|
|
|
204
|
-
|
|
242
|
+
<script>
|
|
243
|
+
// Configure the global instance
|
|
244
|
+
easyflowSDK.configure({
|
|
245
|
+
businessId: 'demo-business-12345',
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
// Now you can use all methods directly
|
|
249
|
+
easyflowSDK
|
|
250
|
+
.createCustomer({
|
|
251
|
+
name: 'Maria Silva',
|
|
252
|
+
email: 'maria@exemplo.com',
|
|
253
|
+
document: { type: 'CPF', number: '12345678901' },
|
|
254
|
+
})
|
|
255
|
+
.then((customer) => {
|
|
256
|
+
console.log('Cliente criado:', customer)
|
|
257
|
+
})
|
|
258
|
+
.catch((error) => {
|
|
259
|
+
console.error('Erro ao criar cliente:', error.message)
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
// Validation methods are always available
|
|
263
|
+
if (easyflowSDK.validate.email('teste@exemplo.com')) {
|
|
264
|
+
console.log('Email válido!')
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// Listen to events
|
|
268
|
+
easyflowSDK.on('customerCreated', (data) => {
|
|
269
|
+
console.log('Evento cliente criado:', data)
|
|
270
|
+
})
|
|
271
|
+
</script>
|
|
205
272
|
```
|
|
206
273
|
|
|
207
274
|
## Features
|
|
@@ -228,6 +295,14 @@ console.log('Order created:', orderId)
|
|
|
228
295
|
- **Obfuscated Builds**: Production builds are obfuscated for enhanced security
|
|
229
296
|
- **Controlled Distribution**: Secure distribution via CDN and GitHub Releases
|
|
230
297
|
|
|
298
|
+
### Low-Code Platform Support
|
|
299
|
+
|
|
300
|
+
- **Lovable Integration**: Full compatibility with Lovable platform
|
|
301
|
+
- **Global Instance**: `window.easyflowSDK` for easy integration
|
|
302
|
+
- **Event System**: Built-in event handling for `on()` and `off()`
|
|
303
|
+
- **Validation Methods**: Always available validation functions
|
|
304
|
+
- **Configuration**: Simple setup with `easyflowSDK.configure()`
|
|
305
|
+
|
|
231
306
|
## API Reference
|
|
232
307
|
|
|
233
308
|
### Core Methods
|
|
@@ -237,13 +312,13 @@ console.log('Order created:', orderId)
|
|
|
237
312
|
Creates an order using an existing offer.
|
|
238
313
|
|
|
239
314
|
```javascript
|
|
240
|
-
const orderId = await
|
|
315
|
+
const orderId = await easyflowSDK.placeOrder('demo-offer-67890', {
|
|
241
316
|
customer: {
|
|
242
|
-
|
|
317
|
+
name: 'João Silva',
|
|
318
|
+
email: 'joao@exemplo.com',
|
|
319
|
+
document: { type: 'CPF', number: '12345678901' },
|
|
243
320
|
},
|
|
244
|
-
payments: [
|
|
245
|
-
/* payment methods */
|
|
246
|
-
],
|
|
321
|
+
payments: [{ method: 'credit-card', numberInstallments: 1 }],
|
|
247
322
|
})
|
|
248
323
|
```
|
|
249
324
|
|
|
@@ -252,8 +327,8 @@ const orderId = await sdk.placeOrder('offer-id', {
|
|
|
252
327
|
Processes a direct charge without using an offer.
|
|
253
328
|
|
|
254
329
|
```javascript
|
|
255
|
-
const orderId = await
|
|
256
|
-
items: [{ name: '
|
|
330
|
+
const orderId = await easyflowSDK.charge({
|
|
331
|
+
items: [{ name: 'Produto Demo', price: 1000 }],
|
|
257
332
|
payments: [{ method: 'pix', numberInstallments: 1 }],
|
|
258
333
|
})
|
|
259
334
|
```
|
|
@@ -263,9 +338,9 @@ const orderId = await sdk.charge({
|
|
|
263
338
|
Encrypts credit card data for secure processing.
|
|
264
339
|
|
|
265
340
|
```javascript
|
|
266
|
-
const token = await
|
|
341
|
+
const token = await easyflowSDK.encrypt({
|
|
267
342
|
number: '4111111111111111',
|
|
268
|
-
holderName: '
|
|
343
|
+
holderName: 'João Silva',
|
|
269
344
|
expirationMonth: '12',
|
|
270
345
|
expirationYear: '2025',
|
|
271
346
|
cvv: '123',
|
|
@@ -279,9 +354,9 @@ const token = await sdk.encrypt({
|
|
|
279
354
|
Creates a new customer.
|
|
280
355
|
|
|
281
356
|
```javascript
|
|
282
|
-
const customer = await
|
|
283
|
-
name: '
|
|
284
|
-
email: '
|
|
357
|
+
const customer = await easyflowSDK.createCustomer({
|
|
358
|
+
name: 'João Silva',
|
|
359
|
+
email: 'joao@exemplo.com',
|
|
285
360
|
document: { type: 'CPF', number: '12345678901' },
|
|
286
361
|
})
|
|
287
362
|
```
|
|
@@ -291,7 +366,7 @@ const customer = await sdk.createCustomer({
|
|
|
291
366
|
Retrieves customer information.
|
|
292
367
|
|
|
293
368
|
```javascript
|
|
294
|
-
const customer = await
|
|
369
|
+
const customer = await easyflowSDK.getCustomer('demo-customer-12345')
|
|
295
370
|
```
|
|
296
371
|
|
|
297
372
|
#### `updateCustomer(customerId, updateData, headers)`
|
|
@@ -299,9 +374,9 @@ const customer = await sdk.getCustomer('customer-id')
|
|
|
299
374
|
Updates existing customer information.
|
|
300
375
|
|
|
301
376
|
```javascript
|
|
302
|
-
const result = await
|
|
303
|
-
name: '
|
|
304
|
-
email: '
|
|
377
|
+
const result = await easyflowSDK.updateCustomer('demo-customer-12345', {
|
|
378
|
+
name: 'João Atualizado',
|
|
379
|
+
email: 'joao.atualizado@exemplo.com',
|
|
305
380
|
})
|
|
306
381
|
```
|
|
307
382
|
|
|
@@ -312,7 +387,10 @@ const result = await sdk.updateCustomer('customer-id', {
|
|
|
312
387
|
Adds a credit card to a customer.
|
|
313
388
|
|
|
314
389
|
```javascript
|
|
315
|
-
const result = await
|
|
390
|
+
const result = await easyflowSDK.addCreditCard(
|
|
391
|
+
'demo-customer-12345',
|
|
392
|
+
'encrypted-token-demo'
|
|
393
|
+
)
|
|
316
394
|
```
|
|
317
395
|
|
|
318
396
|
#### `getCreditCard(customerId, creditCardId, headers)`
|
|
@@ -320,7 +398,10 @@ const result = await sdk.addCreditCard('customer-id', 'encrypted-token')
|
|
|
320
398
|
Retrieves credit card information.
|
|
321
399
|
|
|
322
400
|
```javascript
|
|
323
|
-
const creditCard = await
|
|
401
|
+
const creditCard = await easyflowSDK.getCreditCard(
|
|
402
|
+
'demo-customer-12345',
|
|
403
|
+
'demo-card-67890'
|
|
404
|
+
)
|
|
324
405
|
```
|
|
325
406
|
|
|
326
407
|
#### `removeCreditCard(customerId, creditCardId, headers)`
|
|
@@ -328,7 +409,10 @@ const creditCard = await sdk.getCreditCard('customer-id', 'credit-card-id')
|
|
|
328
409
|
Removes a credit card from a customer.
|
|
329
410
|
|
|
330
411
|
```javascript
|
|
331
|
-
const result = await
|
|
412
|
+
const result = await easyflowSDK.removeCreditCard(
|
|
413
|
+
'demo-customer-12345',
|
|
414
|
+
'demo-card-67890'
|
|
415
|
+
)
|
|
332
416
|
```
|
|
333
417
|
|
|
334
418
|
## Validation
|
|
@@ -373,20 +457,20 @@ The SDK provides an event system for monitoring operations:
|
|
|
373
457
|
|
|
374
458
|
```javascript
|
|
375
459
|
// Listen to events
|
|
376
|
-
|
|
377
|
-
console.log('
|
|
460
|
+
easyflowSDK.on('customerCreated', (data) => {
|
|
461
|
+
console.log('Cliente criado:', data)
|
|
378
462
|
})
|
|
379
463
|
|
|
380
|
-
|
|
381
|
-
console.log('
|
|
464
|
+
easyflowSDK.on('orderPlaced', (data) => {
|
|
465
|
+
console.log('Pedido criado:', data)
|
|
382
466
|
})
|
|
383
467
|
|
|
384
|
-
|
|
385
|
-
console.log('
|
|
468
|
+
easyflowSDK.on('paymentProcessed', (data) => {
|
|
469
|
+
console.log('Pagamento processado:', data)
|
|
386
470
|
})
|
|
387
471
|
|
|
388
472
|
// Remove event listeners
|
|
389
|
-
|
|
473
|
+
easyflowSDK.off('customerCreated', callback)
|
|
390
474
|
```
|
|
391
475
|
|
|
392
476
|
## Error Handling
|
|
@@ -395,25 +479,26 @@ The SDK provides comprehensive error handling:
|
|
|
395
479
|
|
|
396
480
|
```javascript
|
|
397
481
|
try {
|
|
398
|
-
const result = await
|
|
482
|
+
const result = await easyflowSDK.placeOrder('demo-offer-67890', orderData)
|
|
399
483
|
} catch (error) {
|
|
400
484
|
if (error.name === 'ValidationError') {
|
|
401
|
-
console.log('
|
|
485
|
+
console.log('Falha na validação:', error.message)
|
|
402
486
|
} else if (error.name === 'NetworkError') {
|
|
403
|
-
console.log('
|
|
487
|
+
console.log('Erro de rede:', error.message)
|
|
404
488
|
} else if (error.name === 'SecurityError') {
|
|
405
|
-
console.log('
|
|
489
|
+
console.log('Violação de segurança:', error.message)
|
|
406
490
|
}
|
|
407
491
|
}
|
|
408
492
|
```
|
|
409
493
|
|
|
410
494
|
## Configuration
|
|
411
495
|
|
|
412
|
-
### SDK Options
|
|
496
|
+
### SDK Options (CDN Implementation)
|
|
413
497
|
|
|
414
498
|
```javascript
|
|
415
|
-
|
|
416
|
-
|
|
499
|
+
// Configure the global instance
|
|
500
|
+
easyflowSDK.configure({
|
|
501
|
+
businessId: 'demo-business-12345',
|
|
417
502
|
environment: 'production', // 'production' or 'sandbox'
|
|
418
503
|
debug: false, // Enable debug logging
|
|
419
504
|
timeout: 30000, // Request timeout in milliseconds
|
|
@@ -423,7 +508,7 @@ const sdk = new EasyflowSDK({
|
|
|
423
508
|
### Environment Variables
|
|
424
509
|
|
|
425
510
|
```bash
|
|
426
|
-
EASYFLOW_BUSINESS_ID=
|
|
511
|
+
EASYFLOW_BUSINESS_ID=demo-business-12345
|
|
427
512
|
EASYFLOW_ENVIRONMENT=production
|
|
428
513
|
EASYFLOW_DEBUG=false
|
|
429
514
|
```
|
|
@@ -434,26 +519,26 @@ EASYFLOW_DEBUG=false
|
|
|
434
519
|
|
|
435
520
|
```javascript
|
|
436
521
|
// 1. Create customer
|
|
437
|
-
const customer = await
|
|
438
|
-
name: '
|
|
439
|
-
email: '
|
|
522
|
+
const customer = await easyflowSDK.createCustomer({
|
|
523
|
+
name: 'João Silva',
|
|
524
|
+
email: 'joao@exemplo.com',
|
|
440
525
|
document: { type: 'CPF', number: '12345678901' },
|
|
441
526
|
})
|
|
442
527
|
|
|
443
528
|
// 2. Encrypt credit card
|
|
444
|
-
const token = await
|
|
529
|
+
const token = await easyflowSDK.encrypt({
|
|
445
530
|
number: '4111111111111111',
|
|
446
|
-
holderName: '
|
|
531
|
+
holderName: 'João Silva',
|
|
447
532
|
expirationMonth: '12',
|
|
448
533
|
expirationYear: '2025',
|
|
449
534
|
cvv: '123',
|
|
450
535
|
})
|
|
451
536
|
|
|
452
537
|
// 3. Add credit card to customer
|
|
453
|
-
const creditCard = await
|
|
538
|
+
const creditCard = await easyflowSDK.addCreditCard(customer.id, token)
|
|
454
539
|
|
|
455
540
|
// 4. Place order
|
|
456
|
-
const orderId = await
|
|
541
|
+
const orderId = await easyflowSDK.placeOrder('demo-offer-67890', {
|
|
457
542
|
customer: customer,
|
|
458
543
|
payments: [
|
|
459
544
|
{
|
|
@@ -468,9 +553,11 @@ const orderId = await sdk.placeOrder('offer-id', {
|
|
|
468
553
|
### PIX Payment
|
|
469
554
|
|
|
470
555
|
```javascript
|
|
471
|
-
const orderId = await
|
|
556
|
+
const orderId = await easyflowSDK.placeOrder('demo-offer-67890', {
|
|
472
557
|
customer: {
|
|
473
|
-
|
|
558
|
+
name: 'Maria Santos',
|
|
559
|
+
email: 'maria@exemplo.com',
|
|
560
|
+
document: { type: 'CPF', number: '98765432100' },
|
|
474
561
|
},
|
|
475
562
|
payments: [
|
|
476
563
|
{
|
|
@@ -481,16 +568,18 @@ const orderId = await sdk.placeOrder('offer-id', {
|
|
|
481
568
|
})
|
|
482
569
|
|
|
483
570
|
// Get PIX data
|
|
484
|
-
const pixData = await
|
|
571
|
+
const pixData = await easyflowSDK.getPix(orderId)
|
|
485
572
|
console.log('PIX QR Code:', pixData.qrCode)
|
|
486
573
|
```
|
|
487
574
|
|
|
488
575
|
### Bank Billet Payment
|
|
489
576
|
|
|
490
577
|
```javascript
|
|
491
|
-
const orderId = await
|
|
578
|
+
const orderId = await easyflowSDK.placeOrder('demo-offer-67890', {
|
|
492
579
|
customer: {
|
|
493
|
-
|
|
580
|
+
name: 'Pedro Costa',
|
|
581
|
+
email: 'pedro@exemplo.com',
|
|
582
|
+
document: { type: 'CPF', number: '11122233344' },
|
|
494
583
|
},
|
|
495
584
|
payments: [
|
|
496
585
|
{
|
|
@@ -501,7 +590,7 @@ const orderId = await sdk.placeOrder('offer-id', {
|
|
|
501
590
|
})
|
|
502
591
|
|
|
503
592
|
// Get bank billet data
|
|
504
|
-
const bankBillet = await
|
|
593
|
+
const bankBillet = await easyflowSDK.getBankBillet(orderId)
|
|
505
594
|
console.log('Bank Billet Link:', bankBillet.link)
|
|
506
595
|
```
|
|
507
596
|
|
|
@@ -525,7 +614,7 @@ console.log('Bank Billet Link:', bankBillet.link)
|
|
|
525
614
|
|
|
526
615
|
<!-- With SRI (Subresource Integrity) -->
|
|
527
616
|
<script
|
|
528
|
-
src="https://easyflow-sdk.pages.dev/easyflow-sdk.v2.1.
|
|
617
|
+
src="https://easyflow-sdk.pages.dev/easyflow-sdk.v2.1.11.min.js"
|
|
529
618
|
integrity="sha384-[hash]"
|
|
530
619
|
crossorigin="anonymous"
|
|
531
620
|
></script>
|
|
@@ -555,6 +644,21 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
|
555
644
|
|
|
556
645
|
## Changelog
|
|
557
646
|
|
|
647
|
+
### v2.1.11
|
|
648
|
+
|
|
649
|
+
- **Credit Card Token Fix**: Accepts real encrypted/ciphered tokens from vault services
|
|
650
|
+
- **Flexible Validation**: Supports Base64, URL-safe, and mixed character formats
|
|
651
|
+
- **Variable Length**: Accepts tokens from 16 to 2048 characters
|
|
652
|
+
- **Enhanced Security**: Maintains security while accepting real-world tokens
|
|
653
|
+
- **Backward Compatibility**: Works with all existing token formats
|
|
654
|
+
|
|
655
|
+
### v2.1.10
|
|
656
|
+
|
|
657
|
+
- **Workflow Fixed**: Resolved GitHub Actions permissions and SRI hash generation
|
|
658
|
+
- **CDN Automation**: Automated deployment to Cloudflare Pages working correctly
|
|
659
|
+
- **Release Process**: GitHub releases created automatically with proper SRI hashes
|
|
660
|
+
- **Build Pipeline**: Streamlined build and deployment process
|
|
661
|
+
|
|
558
662
|
### v2.1.9
|
|
559
663
|
|
|
560
664
|
- **Hybrid Distribution**: NPM for docs, CDN for secure obfuscated code
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easyflow/javascript-sdk",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.11",
|
|
4
4
|
"description": "Easyflow JavaScript SDK - Documentation and TypeScript definitions. For production use, use the CDN script: https://easyflow-sdk.pages.dev/easyflow-sdk.min.js",
|
|
5
5
|
"main": "README.md",
|
|
6
6
|
"module": "README.md",
|