@easyflow/javascript-sdk 2.1.23 → 2.1.25

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.
@@ -0,0 +1,457 @@
1
+ # Easyflow SDK - Data Structures Reference
2
+
3
+ This document provides detailed information about the data structures expected by the Easyflow JavaScript SDK.
4
+
5
+ ## Table of Contents
6
+
7
+ 1. [Customer Data Structure](#customer-data-structure)
8
+ 2. [Payment Data Structure](#payment-data-structure)
9
+ 3. [Order Data Structure](#order-data-structure)
10
+ 4. [Credit Card Data Structure](#credit-card-data-structure)
11
+ 5. [Address Data Structure](#address-data-structure)
12
+ 6. [Phone Data Structure](#phone-data-structure)
13
+ 7. [Document Data Structure](#document-data-structure)
14
+ 8. [Item Data Structure](#item-data-structure)
15
+ 9. [Metadata Structure](#metadata-structure)
16
+ 10. [Error Response Structure](#error-response-structure)
17
+
18
+ ## Customer Data Structure
19
+
20
+ ### Required Fields
21
+
22
+ ```typescript
23
+ interface Customer {
24
+ name: string // Full name (min: 2, max: 100 characters)
25
+ email: string // Valid email address
26
+ document: Document // CPF or CNPJ information
27
+ }
28
+ ```
29
+
30
+ ### Optional Fields
31
+
32
+ ```typescript
33
+ interface CustomerExtended extends Customer {
34
+ phone?: Phone // Phone number information
35
+ address?: Address // Billing address
36
+ deliveryAddress?: Address // Delivery address (if different from billing)
37
+ metadata?: Metadata[] // Additional customer information
38
+ }
39
+ ```
40
+
41
+ ### Example
42
+
43
+ ```javascript
44
+ const customer = {
45
+ name: 'João Silva Santos',
46
+ email: 'joao.silva@exemplo.com',
47
+ document: {
48
+ type: 'CPF',
49
+ number: '12345678901',
50
+ },
51
+ phone: {
52
+ areaCode: '+55',
53
+ ddd: '11',
54
+ number: '9988776655',
55
+ isMobile: true,
56
+ },
57
+ address: {
58
+ zipCode: '01234567',
59
+ street: 'Rua das Flores',
60
+ complement: 'Apto 101',
61
+ neighborhood: 'Centro',
62
+ city: 'São Paulo',
63
+ state: 'SP',
64
+ number: '123',
65
+ },
66
+ }
67
+ ```
68
+
69
+ ## Payment Data Structure
70
+
71
+ ### Credit Card Payment
72
+
73
+ ```typescript
74
+ interface CreditCardPayment {
75
+ method: 'credit-card'
76
+ numberInstallments: number // 1-12 installments
77
+ valueInCents?: number // Required for charge(), optional for placeOrder()
78
+ creditCard: {
79
+ cardId?: string // Saved card ID
80
+ token?: string // Encrypted card token
81
+ last4Numbers?: string // Last 4 digits
82
+ holderName?: string // Card holder name
83
+ expiresAtMonth?: string // Expiration month (01-12)
84
+ expiresAtYear?: string // Expiration year (YYYY)
85
+ flag?: string // Card brand (visa, mastercard, etc.)
86
+ }
87
+ }
88
+ ```
89
+
90
+ ### PIX Payment
91
+
92
+ ```typescript
93
+ interface PixPayment {
94
+ method: 'pix'
95
+ numberInstallments: number // Always 1 for PIX
96
+ valueInCents?: number // Required for charge(), optional for placeOrder()
97
+ }
98
+ ```
99
+
100
+ ### Bank Billet Payment
101
+
102
+ ```typescript
103
+ interface BankBilletPayment {
104
+ method: 'bank-billet'
105
+ numberInstallments: number // Always 1 for bank billet
106
+ valueInCents?: number // Required for charge(), optional for placeOrder()
107
+ }
108
+ ```
109
+
110
+ ### Example
111
+
112
+ ```javascript
113
+ const payments = [
114
+ {
115
+ method: 'credit-card',
116
+ numberInstallments: 6,
117
+ creditCard: {
118
+ cardId: 'saved-card-123',
119
+ last4Numbers: '1234',
120
+ holderName: 'JOAO SILVA SANTOS',
121
+ expiresAtMonth: '12',
122
+ expiresAtYear: '2025',
123
+ flag: 'visa',
124
+ },
125
+ },
126
+ {
127
+ method: 'pix',
128
+ numberInstallments: 1,
129
+ },
130
+ ]
131
+ ```
132
+
133
+ ## Order Data Structure
134
+
135
+ ### Buyer Information
136
+
137
+ ```typescript
138
+ interface Buyer {
139
+ customerId?: string // Existing customer ID (optional)
140
+ name: string // Full name
141
+ email: string // Valid email
142
+ document: Document // CPF or CNPJ
143
+ phone: Phone // Phone number
144
+ address: Address // Billing address
145
+ }
146
+ ```
147
+
148
+ ### Complete Order Structure
149
+
150
+ ```typescript
151
+ interface OrderData {
152
+ buyer: Buyer
153
+ payments: Payment[]
154
+ offerItems?: OfferItem[] // For placeOrder()
155
+ items?: Item[] // For charge()
156
+ metadata?: Metadata[]
157
+ }
158
+ ```
159
+
160
+ ### Example
161
+
162
+ ```javascript
163
+ const orderData = {
164
+ buyer: {
165
+ customerId: 'existing-customer-123',
166
+ name: 'João Silva Santos',
167
+ email: 'joao.silva@exemplo.com',
168
+ document: {
169
+ type: 'CPF',
170
+ number: '12345678901',
171
+ },
172
+ phone: {
173
+ areaCode: '+55',
174
+ ddd: '11',
175
+ number: '9988776655',
176
+ isMobile: true,
177
+ },
178
+ address: {
179
+ zipCode: '01234567',
180
+ street: 'Rua das Flores',
181
+ complement: 'Apto 101',
182
+ neighborhood: 'Centro',
183
+ city: 'São Paulo',
184
+ state: 'SP',
185
+ number: '123',
186
+ },
187
+ },
188
+ payments: [
189
+ {
190
+ method: 'credit-card',
191
+ numberInstallments: 6,
192
+ creditCard: {
193
+ cardId: 'saved-card-123',
194
+ },
195
+ },
196
+ ],
197
+ offerItems: [
198
+ {
199
+ offerItemId: 'offer-item-123',
200
+ quantity: 1,
201
+ },
202
+ ],
203
+ metadata: [
204
+ {
205
+ key: 'source',
206
+ value: 'website',
207
+ },
208
+ ],
209
+ }
210
+ ```
211
+
212
+ ## Credit Card Data Structure
213
+
214
+ ### For Encryption
215
+
216
+ ```typescript
217
+ interface CreditCardData {
218
+ cardNumber: string // 13-19 digits
219
+ cvv: string // 3-4 digits
220
+ month: string // 01-12
221
+ year: string // YYYY format
222
+ holderName: string // Card holder name
223
+ }
224
+ ```
225
+
226
+ ### Example
227
+
228
+ ```javascript
229
+ const creditCardData = {
230
+ cardNumber: '4111111111111111',
231
+ cvv: '123',
232
+ month: '12',
233
+ year: '2025',
234
+ holderName: 'JOAO SILVA SANTOS',
235
+ }
236
+ ```
237
+
238
+ ## Address Data Structure
239
+
240
+ ```typescript
241
+ interface Address {
242
+ zipCode: string // Brazilian ZIP code (8 digits)
243
+ street: string // Street name
244
+ complement?: string // Apartment, building, etc.
245
+ neighborhood: string // Neighborhood name
246
+ city: string // City name
247
+ state: string // State abbreviation (SP, RJ, MG, etc.)
248
+ number: string // House/building number
249
+ }
250
+ ```
251
+
252
+ ### Example
253
+
254
+ ```javascript
255
+ const address = {
256
+ zipCode: '01234567',
257
+ street: 'Rua das Flores',
258
+ complement: 'Apto 101',
259
+ neighborhood: 'Centro',
260
+ city: 'São Paulo',
261
+ state: 'SP',
262
+ number: '123',
263
+ }
264
+ ```
265
+
266
+ ## Phone Data Structure
267
+
268
+ ```typescript
269
+ interface Phone {
270
+ areaCode: string // Country code (+55 for Brazil)
271
+ ddd: string // Area code (11, 21, 31, etc.)
272
+ number: string // Phone number (8-9 digits)
273
+ isMobile: boolean // Whether it's a mobile number
274
+ }
275
+ ```
276
+
277
+ ### Example
278
+
279
+ ```javascript
280
+ const phone = {
281
+ areaCode: '+55',
282
+ ddd: '11',
283
+ number: '9988776655',
284
+ isMobile: true,
285
+ }
286
+ ```
287
+
288
+ ## Document Data Structure
289
+
290
+ ```typescript
291
+ interface Document {
292
+ type: 'CPF' | 'CNPJ' // Document type
293
+ number: string // Document number (CPF: 11 digits, CNPJ: 14 digits)
294
+ }
295
+ ```
296
+
297
+ ### Example
298
+
299
+ ```javascript
300
+ const cpfDocument = {
301
+ type: 'CPF',
302
+ number: '12345678901',
303
+ }
304
+
305
+ const cnpjDocument = {
306
+ type: 'CNPJ',
307
+ number: '12345678000195',
308
+ }
309
+ ```
310
+
311
+ ## Item Data Structure
312
+
313
+ ### For charge() method
314
+
315
+ ```typescript
316
+ interface Item {
317
+ name: string // Product name
318
+ description: string // Product description
319
+ quantity: number // Quantity (positive integer)
320
+ priceInCents: number // Price in cents (positive integer)
321
+ }
322
+ ```
323
+
324
+ ### Example
325
+
326
+ ```javascript
327
+ const items = [
328
+ {
329
+ name: 'Carregador de Celular',
330
+ description: 'Carregador de celular com cabo USB-C',
331
+ quantity: 1,
332
+ priceInCents: 5000, // R$ 50,00
333
+ },
334
+ {
335
+ name: 'Cabo USB-C',
336
+ description: 'Cabo USB-C de alta velocidade',
337
+ quantity: 2,
338
+ priceInCents: 1500, // R$ 15,00 cada
339
+ },
340
+ ]
341
+ ```
342
+
343
+ ## Metadata Structure
344
+
345
+ ```typescript
346
+ interface Metadata {
347
+ key: string // Metadata key
348
+ value: string // Metadata value
349
+ }
350
+ ```
351
+
352
+ ### Example
353
+
354
+ ```javascript
355
+ const metadata = [
356
+ {
357
+ key: 'source',
358
+ value: 'website',
359
+ },
360
+ {
361
+ key: 'campaign',
362
+ value: 'black-friday-2024',
363
+ },
364
+ {
365
+ key: 'user_id',
366
+ value: 'user-12345',
367
+ },
368
+ ]
369
+ ```
370
+
371
+ ## Error Response Structure
372
+
373
+ ### Standard Error Format
374
+
375
+ ```typescript
376
+ interface ErrorResponse {
377
+ error: {
378
+ code: string // Error code
379
+ message: string // Human-readable error message
380
+ details?: string // Additional error details
381
+ field?: string // Field that caused the error
382
+ value?: any // Value that caused the error
383
+ }
384
+ timestamp: string // ISO timestamp
385
+ requestId?: string // Unique request identifier
386
+ }
387
+ ```
388
+
389
+ ### Common Error Codes
390
+
391
+ | Code | Description | HTTP Status |
392
+ | ------------------------ | ------------------------ | ----------- |
393
+ | `VALIDATION_ERROR` | Data validation failed | 400 |
394
+ | `SECURITY_ERROR` | Security violation | 403 |
395
+ | `RATE_LIMIT_EXCEEDED` | Too many requests | 429 |
396
+ | `NETWORK_ERROR` | Network/API error | 500+ |
397
+ | `BUSINESS_ID_INVALID` | Invalid business ID | 400 |
398
+ | `OFFER_NOT_FOUND` | Offer not found | 404 |
399
+ | `CUSTOMER_NOT_FOUND` | Customer not found | 404 |
400
+ | `PAYMENT_METHOD_INVALID` | Invalid payment method | 400 |
401
+ | `CREDIT_CARD_INVALID` | Invalid credit card data | 400 |
402
+
403
+ ### Example Error Response
404
+
405
+ ```javascript
406
+ {
407
+ "error": {
408
+ "code": "VALIDATION_ERROR",
409
+ "message": "Invalid email format",
410
+ "details": "Email must be a valid email address",
411
+ "field": "email",
412
+ "value": "invalid-email"
413
+ },
414
+ "timestamp": "2024-01-15T10:30:00.000Z",
415
+ "requestId": "req-12345-abcde"
416
+ }
417
+ ```
418
+
419
+ ## Validation Rules
420
+
421
+ ### String Lengths
422
+
423
+ - **Name**: 2-100 characters
424
+ - **Email**: 5-254 characters
425
+ - **Street**: 5-200 characters
426
+ - **City**: 2-100 characters
427
+ - **State**: 2 characters (Brazilian states)
428
+ - **ZIP Code**: 8 characters (Brazilian format)
429
+
430
+ ### Numeric Ranges
431
+
432
+ - **Phone DDD**: 11-99 (Brazilian area codes)
433
+ - **Phone Number**: 8-9 digits
434
+ - **Installments**: 1-12 for credit cards, 1 for PIX/bank billet
435
+ - **Price**: Positive integer in cents
436
+ - **Quantity**: Positive integer
437
+
438
+ ### Required vs Optional
439
+
440
+ - **Required for all operations**: name, email, document
441
+ - **Required for shipping**: address
442
+ - **Required for contact**: phone
443
+ - **Required for payments**: payment method and details
444
+ - **Optional**: complement, metadata, deliveryAddress
445
+
446
+ ## Best Practices
447
+
448
+ 1. **Always validate data** before sending to the SDK
449
+ 2. **Use proper error handling** to catch and display validation errors
450
+ 3. **Sanitize user input** to prevent XSS attacks
451
+ 4. **Store sensitive data securely** (never log credit card numbers)
452
+ 5. **Handle rate limiting** gracefully with exponential backoff
453
+ 6. **Use metadata** to track order sources and campaigns
454
+ 7. **Implement proper logging** for debugging and monitoring
455
+ 8. **Test with real data** in development environment
456
+ 9. **Follow Brazilian data regulations** (LGPD compliance)
457
+ 10. **Use HTTPS** in production environments
package/INDEX.md ADDED
@@ -0,0 +1,123 @@
1
+ # Easyflow JavaScript SDK - Documentation Hub
2
+
3
+ Welcome to the Easyflow JavaScript SDK documentation hub! This is your central access point to all SDK resources.
4
+
5
+ ## 📚 Core Documentation
6
+
7
+ ### [📖 Complete SDK Guide](README.md)
8
+
9
+ The main documentation file containing:
10
+
11
+ - **Quick Start** guide and installation
12
+ - **API Reference** for all methods
13
+ - **Complete Examples** for all use cases
14
+ - **Configuration** and development options
15
+ - **Error Handling** with standardized codes
16
+ - **Security Features** and best practices
17
+
18
+ ### [🔧 Data Structures Reference](DATA-STRUCTURES.md)
19
+
20
+ Comprehensive guide to all data structures:
21
+
22
+ - **TypeScript Interfaces** for all data types
23
+ - **Field-by-field documentation** with validation rules
24
+ - **Real-world examples** for each structure
25
+ - **Error codes and messages** reference
26
+ - **Best practices** for data handling
27
+
28
+ ### [🚀 Platform Integration Guide](PLATFORM-INTEGRATION.md)
29
+
30
+ Complete guide for platform integration:
31
+
32
+ - **`initializeForPlatform()`** method explanation
33
+ - **Traditional vs Platform** initialization approaches
34
+ - **Low-code/No-code** platform examples
35
+ - **Automatic callbacks** and validation
36
+ - **Performance considerations** and best practices
37
+
38
+ ## 🚀 Examples & Demos
39
+
40
+ ### [🐛 Development Mode Example](examples/development-mode-example.html)
41
+
42
+ Interactive demo showcasing:
43
+
44
+ - **Development mode** configuration
45
+ - **Debug features** and logging
46
+ - **Event system** (SDKReady, etc.)
47
+ - **Real-time monitoring** and status
48
+
49
+ ## 📦 Installation & Distribution
50
+
51
+ ### NPM Package (Recommended for Production)
52
+
53
+ ```bash
54
+ npm install @easyflow/javascript-sdk
55
+ ```
56
+
57
+ **What's included:**
58
+
59
+ - **Production-ready obfuscated code** - Same secure build as CDN
60
+ - **TypeScript definitions** - Full IntelliSense and type safety
61
+ - **Complete documentation** - README, INDEX, DATA-STRUCTURES, PLATFORM-INTEGRATION
62
+ - **Version management** - Easy updates via package.json
63
+
64
+ **Perfect for:**
65
+
66
+ - Modern build tools (Webpack, Vite, Rollup)
67
+ - TypeScript projects
68
+ - Node.js applications
69
+ - Offline development
70
+
71
+ ### CDN Scripts (Alternative)
72
+
73
+ ```html
74
+ <!-- Cloudflare Pages (Primary) -->
75
+ <script src="https://easyflow-sdk.pages.dev/easyflow-sdk.min.js"></script>
76
+
77
+ <!-- jsDelivr (Alternative) -->
78
+ <script src="https://cdn.jsdelivr.net/npm/@easyflow/javascript-sdk@latest/dist/easyflow-sdk.min.js"></script>
79
+ ```
80
+
81
+ **Perfect for:**
82
+
83
+ - Quick HTML integration0
84
+ - No build step required
85
+ - Global availability via `window.easyflowSDK`
86
+ - Simple prototyping
87
+
88
+ ### Security & Distribution Strategy
89
+
90
+ **🔒 Both NPM and CDN contain identical obfuscated code:**
91
+
92
+ - **Source code is obfuscated** and cannot be reverse-engineered
93
+ - **Security features are identical** in both distributions
94
+ - **Choose based on your workflow** - both are equally secure
95
+ - **NPM provides better developer experience** with TypeScript support
96
+
97
+ ## 🔗 Quick Links
98
+
99
+ - **[🌐 Official Website](https://www.easyflow.digital)**
100
+ - **[📦 NPM Package](https://www.npmjs.com/package/@easyflow/javascript-sdk)**
101
+ - **[🔧 CDN Scripts](https://easyflow-sdk.pages.dev)**
102
+ - **[📧 Contact Support](mailto:contato@easyflow.digital)**
103
+
104
+ ## 🎯 Getting Started
105
+
106
+ 1. **Choose your installation method** (CDN recommended for production)
107
+ 2. **Read the [Quick Start guide](README.md#quick-start)** in the main README
108
+ 3. **Reference [DATA-STRUCTURES.md](DATA-STRUCTURES.md)** for detailed field information
109
+ 4. **Try the [development example](examples/development-mode-example.html)** for hands-on experience
110
+
111
+ ## 📋 What's New in v2.1.24
112
+
113
+ - **Development Mode & Debug Features** - Automatic environment detection
114
+ - **SDK Ready Event System** - Proper initialization handling
115
+ - **Enhanced Error Handling** - 50+ standardized error codes
116
+ - **Comprehensive Data Documentation** - Complete structure reference
117
+ - **Interactive Examples** - Hands-on development experience
118
+
119
+ ---
120
+
121
+ **Built with ❤️ by the Easyflow Team**
122
+
123
+ _For questions and support, contact [contato@easyflow.digital](mailto:contato@easyflow.digital)_