@easyflow/javascript-sdk 2.1.7
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/.babelrc +5 -0
- package/.github/workflows/deploy-sdk-cf.yml +49 -0
- package/.github/workflows/release-sdk-cdn.yml +144 -0
- package/.github/workflows/release-sdk.yml +112 -0
- package/.prettierrc +6 -0
- package/CDN-DEPLOYMENT.md +175 -0
- package/DEMO.md +258 -0
- package/DEPLOYMENT.md +224 -0
- package/INTEGRATION-GUIDE.md +521 -0
- package/README.md +1013 -0
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/easyflow-javascript-sdk/index.html +116 -0
- package/coverage/easyflow-javascript-sdk/libs/constants.mjs.html +268 -0
- package/coverage/easyflow-javascript-sdk/libs/errors.mjs.html +271 -0
- package/coverage/easyflow-javascript-sdk/libs/exception-handler.mjs.html +148 -0
- package/coverage/easyflow-javascript-sdk/libs/fingerprint.mjs.html +895 -0
- package/coverage/easyflow-javascript-sdk/libs/http.mjs.html +502 -0
- package/coverage/easyflow-javascript-sdk/libs/index.html +266 -0
- package/coverage/easyflow-javascript-sdk/libs/logger.mjs.html +568 -0
- package/coverage/easyflow-javascript-sdk/libs/sanitizer.mjs.html +1099 -0
- package/coverage/easyflow-javascript-sdk/libs/security.mjs.html +733 -0
- package/coverage/easyflow-javascript-sdk/libs/types.mjs.html +508 -0
- package/coverage/easyflow-javascript-sdk/libs/utils.mjs.html +379 -0
- package/coverage/easyflow-javascript-sdk/libs/validator.mjs.html +2623 -0
- package/coverage/easyflow-javascript-sdk/sdk.mjs.html +2434 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +131 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/easyflow-javascript-sdk/index.html +116 -0
- package/coverage/lcov-report/easyflow-javascript-sdk/libs/constants.mjs.html +268 -0
- package/coverage/lcov-report/easyflow-javascript-sdk/libs/errors.mjs.html +271 -0
- package/coverage/lcov-report/easyflow-javascript-sdk/libs/exception-handler.mjs.html +148 -0
- package/coverage/lcov-report/easyflow-javascript-sdk/libs/fingerprint.mjs.html +895 -0
- package/coverage/lcov-report/easyflow-javascript-sdk/libs/http.mjs.html +502 -0
- package/coverage/lcov-report/easyflow-javascript-sdk/libs/index.html +266 -0
- package/coverage/lcov-report/easyflow-javascript-sdk/libs/logger.mjs.html +568 -0
- package/coverage/lcov-report/easyflow-javascript-sdk/libs/sanitizer.mjs.html +1099 -0
- package/coverage/lcov-report/easyflow-javascript-sdk/libs/security.mjs.html +733 -0
- package/coverage/lcov-report/easyflow-javascript-sdk/libs/types.mjs.html +508 -0
- package/coverage/lcov-report/easyflow-javascript-sdk/libs/utils.mjs.html +379 -0
- package/coverage/lcov-report/easyflow-javascript-sdk/libs/validator.mjs.html +2623 -0
- package/coverage/lcov-report/easyflow-javascript-sdk/sdk.mjs.html +2434 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +131 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov.info +1429 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +196 -0
- package/dist/435.easyflow-sdk.min.js +1 -0
- package/dist/easyflow-sdk.min.js +1 -0
- package/dist/easyflow-sdk.min.js.LICENSE.txt +1 -0
- package/dist/index.html +756 -0
- package/docs/index.html +775 -0
- package/examples/lovable-integration.html +410 -0
- package/index.html +981 -0
- package/jest.config.js +37 -0
- package/jsdoc.json +42 -0
- package/libs/auto-integration.mjs +333 -0
- package/libs/constants.mjs +61 -0
- package/libs/constants.spec.js +198 -0
- package/libs/errors.mjs +62 -0
- package/libs/errors.spec.js +178 -0
- package/libs/exception-handler.mjs +21 -0
- package/libs/exception-handler.spec.js +237 -0
- package/libs/fingerprint.mjs +270 -0
- package/libs/http.mjs +163 -0
- package/libs/http.spec.js +427 -0
- package/libs/integration-wrapper.mjs +285 -0
- package/libs/logger.mjs +161 -0
- package/libs/logger.spec.js +389 -0
- package/libs/sanitizer.mjs +340 -0
- package/libs/sanitizer.spec.js +583 -0
- package/libs/security.mjs +217 -0
- package/libs/types.mjs +141 -0
- package/libs/utils.mjs +368 -0
- package/libs/utils.spec.js +231 -0
- package/libs/validator.mjs +952 -0
- package/libs/validator.spec.js +615 -0
- package/mocks/offer.mock.js +77 -0
- package/package.json +72 -0
- package/scripts/publish-npm.sh +82 -0
- package/sdk.mjs +945 -0
- package/sdk.spec.js +796 -0
- package/test-setup.cjs +211 -0
- package/test.html +154 -0
- package/webpack.config.cjs +41 -0
package/jest.config.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
testEnvironment: 'node',
|
|
3
|
+
globals: {
|
|
4
|
+
'ts-jest': {
|
|
5
|
+
useESM: true,
|
|
6
|
+
},
|
|
7
|
+
},
|
|
8
|
+
moduleNameMapper: {
|
|
9
|
+
'^(\\.{1,2}/.*)\\.js$': '$1',
|
|
10
|
+
},
|
|
11
|
+
transform: {},
|
|
12
|
+
testMatch: [
|
|
13
|
+
'**/test.js',
|
|
14
|
+
'**/__tests__/**/*.js',
|
|
15
|
+
'**/?(*.)+(spec|test).js',
|
|
16
|
+
],
|
|
17
|
+
collectCoverageFrom: [
|
|
18
|
+
'sdk.mjs',
|
|
19
|
+
'libs/*.mjs',
|
|
20
|
+
'!**/node_modules/**',
|
|
21
|
+
'!**/dist/**',
|
|
22
|
+
'!**/docs/**',
|
|
23
|
+
],
|
|
24
|
+
coverageReporters: ['text', 'lcov', 'html'],
|
|
25
|
+
coverageThreshold: {
|
|
26
|
+
global: {
|
|
27
|
+
branches: 80,
|
|
28
|
+
functions: 80,
|
|
29
|
+
lines: 80,
|
|
30
|
+
statements: 80,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
setupFilesAfterEnv: ['<rootDir>/test-setup.cjs'],
|
|
34
|
+
verbose: true,
|
|
35
|
+
clearMocks: true,
|
|
36
|
+
restoreMocks: true,
|
|
37
|
+
}
|
package/jsdoc.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"tags": {
|
|
3
|
+
"allowUnknownTags": true,
|
|
4
|
+
"dictionaries": [
|
|
5
|
+
"jsdoc",
|
|
6
|
+
"closure"
|
|
7
|
+
]
|
|
8
|
+
},
|
|
9
|
+
"source": {
|
|
10
|
+
"include": [
|
|
11
|
+
"sdk.mjs",
|
|
12
|
+
"http.mjs"
|
|
13
|
+
],
|
|
14
|
+
"includePattern": "\\.mjs$",
|
|
15
|
+
"excludePattern": "(node_modules/|docs)"
|
|
16
|
+
},
|
|
17
|
+
"plugins": [],
|
|
18
|
+
"templates": {
|
|
19
|
+
"cleverLinks": false,
|
|
20
|
+
"monospaceLinks": false,
|
|
21
|
+
"default": {
|
|
22
|
+
"outputSourceFiles": true
|
|
23
|
+
},
|
|
24
|
+
"path": "node_modules/clean-jsdoc-theme",
|
|
25
|
+
"theme_opts": {
|
|
26
|
+
"title": "Easyflow SDK Documentation",
|
|
27
|
+
"menu": {
|
|
28
|
+
"GitHub repo": {
|
|
29
|
+
"href": "https://github.com/easyflow/sdk-javascript",
|
|
30
|
+
"target": "_blank",
|
|
31
|
+
"class": "menu-item",
|
|
32
|
+
"id": "repository"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"opts": {
|
|
38
|
+
"destination": "./docs",
|
|
39
|
+
"recurse": true,
|
|
40
|
+
"readme": "./README.md"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-Integration Script for Easyflow SDK
|
|
3
|
+
*
|
|
4
|
+
* Este script detecta automaticamente a plataforma e configura
|
|
5
|
+
* a integração de forma otimizada para cada ambiente.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { EasyflowIntegrationWrapper } from './integration-wrapper.mjs'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Detector de plataformas
|
|
12
|
+
*/
|
|
13
|
+
class PlatformDetector {
|
|
14
|
+
static detect() {
|
|
15
|
+
// Detectar Lovable.dev
|
|
16
|
+
if (this.isLovable()) {
|
|
17
|
+
return {
|
|
18
|
+
name: 'Lovable.dev',
|
|
19
|
+
type: 'low-code',
|
|
20
|
+
features: ['chat-ai', 'visual-editor', 'workflows'],
|
|
21
|
+
integration: 'automatic',
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Detectar Bubble
|
|
26
|
+
if (this.isBubble()) {
|
|
27
|
+
return {
|
|
28
|
+
name: 'Bubble',
|
|
29
|
+
type: 'low-code',
|
|
30
|
+
features: ['visual-editor', 'database', 'workflows'],
|
|
31
|
+
integration: 'javascript',
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Detectar Webflow
|
|
36
|
+
if (this.isWebflow()) {
|
|
37
|
+
return {
|
|
38
|
+
name: 'Webflow',
|
|
39
|
+
type: 'design-platform',
|
|
40
|
+
features: ['visual-editor', 'cms', 'ecommerce'],
|
|
41
|
+
integration: 'javascript',
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Detectar Zapier
|
|
46
|
+
if (this.isZapier()) {
|
|
47
|
+
return {
|
|
48
|
+
name: 'Zapier',
|
|
49
|
+
type: 'automation',
|
|
50
|
+
features: ['webhooks', 'integrations', 'workflows'],
|
|
51
|
+
integration: 'webhook',
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Detectar Make.com
|
|
56
|
+
if (this.isMake()) {
|
|
57
|
+
return {
|
|
58
|
+
name: 'Make.com',
|
|
59
|
+
type: 'automation',
|
|
60
|
+
features: ['visual-workflows', 'integrations'],
|
|
61
|
+
integration: 'webhook',
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Plataforma genérica
|
|
66
|
+
return {
|
|
67
|
+
name: 'Generic Platform',
|
|
68
|
+
type: 'unknown',
|
|
69
|
+
features: ['javascript-support'],
|
|
70
|
+
integration: 'manual',
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static isLovable() {
|
|
75
|
+
return (
|
|
76
|
+
window.location.hostname.includes('lovable') ||
|
|
77
|
+
document.querySelector('[data-lovable]') ||
|
|
78
|
+
window.lovableConfig
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static isBubble() {
|
|
83
|
+
return (
|
|
84
|
+
window.location.hostname.includes('bubble') ||
|
|
85
|
+
window.bubble ||
|
|
86
|
+
document.querySelector('[data-bubble]')
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
static isWebflow() {
|
|
91
|
+
return (
|
|
92
|
+
window.location.hostname.includes('webflow') ||
|
|
93
|
+
window.Webflow ||
|
|
94
|
+
document.querySelector('[data-wf-site]')
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
static isZapier() {
|
|
99
|
+
return (
|
|
100
|
+
window.location.hostname.includes('zapier') ||
|
|
101
|
+
window.zapier ||
|
|
102
|
+
document.querySelector('[data-zapier]')
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
static isMake() {
|
|
107
|
+
return (
|
|
108
|
+
window.location.hostname.includes('make') ||
|
|
109
|
+
window.make ||
|
|
110
|
+
document.querySelector('[data-make]')
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Configurador automático de integração
|
|
117
|
+
*/
|
|
118
|
+
class AutoIntegrationConfigurator {
|
|
119
|
+
constructor() {
|
|
120
|
+
this.platform = PlatformDetector.detect()
|
|
121
|
+
this.wrapper = null
|
|
122
|
+
this.config = this.getDefaultConfig()
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Obter configuração padrão baseada na plataforma
|
|
127
|
+
*/
|
|
128
|
+
getDefaultConfig() {
|
|
129
|
+
const baseConfig = {
|
|
130
|
+
autoInitialize: true,
|
|
131
|
+
exposeGlobally: true,
|
|
132
|
+
enableDebug: false,
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
switch (this.platform.name) {
|
|
136
|
+
case 'Lovable.dev':
|
|
137
|
+
return {
|
|
138
|
+
...baseConfig,
|
|
139
|
+
globalScope: 'window',
|
|
140
|
+
enableDebug: true,
|
|
141
|
+
platform: 'lovable',
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
case 'Bubble':
|
|
145
|
+
return {
|
|
146
|
+
...baseConfig,
|
|
147
|
+
globalScope: 'window',
|
|
148
|
+
enableDebug: false,
|
|
149
|
+
platform: 'bubble',
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
case 'Webflow':
|
|
153
|
+
return {
|
|
154
|
+
...baseConfig,
|
|
155
|
+
globalScope: 'window',
|
|
156
|
+
enableDebug: false,
|
|
157
|
+
platform: 'webflow',
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
case 'Zapier':
|
|
161
|
+
case 'Make.com':
|
|
162
|
+
return {
|
|
163
|
+
...baseConfig,
|
|
164
|
+
globalScope: 'global',
|
|
165
|
+
enableDebug: false,
|
|
166
|
+
platform: this.platform.name.toLowerCase(),
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
default:
|
|
170
|
+
return {
|
|
171
|
+
...baseConfig,
|
|
172
|
+
globalScope: 'window',
|
|
173
|
+
enableDebug: false,
|
|
174
|
+
platform: 'generic',
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Configurar integração automaticamente
|
|
181
|
+
*/
|
|
182
|
+
async configure(config = {}) {
|
|
183
|
+
try {
|
|
184
|
+
// Mesclar configurações
|
|
185
|
+
this.config = { ...this.config, ...config }
|
|
186
|
+
|
|
187
|
+
// Criar wrapper
|
|
188
|
+
this.wrapper = new EasyflowIntegrationWrapper(this.config)
|
|
189
|
+
|
|
190
|
+
// Configurar callbacks específicos da plataforma
|
|
191
|
+
this.configurePlatformCallbacks()
|
|
192
|
+
|
|
193
|
+
// Log de sucesso
|
|
194
|
+
if (this.config.enableDebug) {
|
|
195
|
+
console.log(
|
|
196
|
+
`🚀 Easyflow SDK configurado automaticamente para ${this.platform.name}`
|
|
197
|
+
)
|
|
198
|
+
console.log(`📋 Configurações:`, this.config)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return this.wrapper
|
|
202
|
+
} catch (error) {
|
|
203
|
+
console.error('❌ Erro na configuração automática:', error)
|
|
204
|
+
throw error
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Configurar callbacks específicos da plataforma
|
|
210
|
+
*/
|
|
211
|
+
configurePlatformCallbacks() {
|
|
212
|
+
if (!this.wrapper) return
|
|
213
|
+
|
|
214
|
+
switch (this.platform.name) {
|
|
215
|
+
case 'Lovable.dev':
|
|
216
|
+
this.configureLovableCallbacks()
|
|
217
|
+
break
|
|
218
|
+
|
|
219
|
+
case 'Bubble':
|
|
220
|
+
this.configureBubbleCallbacks()
|
|
221
|
+
break
|
|
222
|
+
|
|
223
|
+
case 'Webflow':
|
|
224
|
+
this.configureWebflowCallbacks()
|
|
225
|
+
break
|
|
226
|
+
|
|
227
|
+
case 'Zapier':
|
|
228
|
+
case 'Make.com':
|
|
229
|
+
this.configureAutomationCallbacks()
|
|
230
|
+
break
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Callbacks específicos para Lovable
|
|
236
|
+
*/
|
|
237
|
+
configureLovableCallbacks() {
|
|
238
|
+
this.wrapper.on('customerCreated', (customer) => {
|
|
239
|
+
console.log('🎉 Cliente criado no Lovable:', customer)
|
|
240
|
+
// Aqui você pode adicionar lógica específica do Lovable
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
this.wrapper.on('paymentProcessed', (result) => {
|
|
244
|
+
console.log('💳 Pagamento processado no Lovable:', result)
|
|
245
|
+
// Aqui você pode adicionar lógica específica do Lovable
|
|
246
|
+
})
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Callbacks específicos para Bubble
|
|
251
|
+
*/
|
|
252
|
+
configureBubbleCallbacks() {
|
|
253
|
+
this.wrapper.on('customerCreated', (customer) => {
|
|
254
|
+
console.log('🎉 Cliente criado no Bubble:', customer)
|
|
255
|
+
// Aqui você pode adicionar lógica específica do Bubble
|
|
256
|
+
if (window.bubble_fn_updateCustomer) {
|
|
257
|
+
window.bubble_fn_updateCustomer(customer)
|
|
258
|
+
}
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
this.wrapper.on('paymentProcessed', (result) => {
|
|
262
|
+
console.log('💳 Pagamento processado no Bubble:', result)
|
|
263
|
+
// Aqui você pode adicionar lógica específica do Bubble
|
|
264
|
+
if (window.bubble_fn_updatePaymentStatus) {
|
|
265
|
+
window.bubble_fn_updatePaymentStatus(result)
|
|
266
|
+
}
|
|
267
|
+
})
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Callbacks específicos para Webflow
|
|
272
|
+
*/
|
|
273
|
+
configureWebflowCallbacks() {
|
|
274
|
+
this.wrapper.on('customerCreated', (customer) => {
|
|
275
|
+
console.log('🎉 Cliente criado no Webflow:', customer)
|
|
276
|
+
// Aqui você pode adicionar lógica específica do Webflow
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
this.wrapper.on('paymentProcessed', (result) => {
|
|
280
|
+
console.log('💳 Pagamento processado no Webflow:', result)
|
|
281
|
+
// Aqui você pode adicionar lógica específica do Webflow
|
|
282
|
+
})
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Callbacks para plataformas de automação
|
|
287
|
+
*/
|
|
288
|
+
configureAutomationCallbacks() {
|
|
289
|
+
this.wrapper.on('customerCreated', (customer) => {
|
|
290
|
+
console.log('🎉 Cliente criado via automação:', customer)
|
|
291
|
+
// Aqui você pode adicionar lógica para webhooks
|
|
292
|
+
})
|
|
293
|
+
|
|
294
|
+
this.wrapper.on('paymentProcessed', (result) => {
|
|
295
|
+
console.log('💳 Pagamento processado via automação:', result)
|
|
296
|
+
// Aqui você pode adicionar lógica para webhooks
|
|
297
|
+
})
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Obter informações da plataforma
|
|
302
|
+
*/
|
|
303
|
+
getPlatformInfo() {
|
|
304
|
+
return {
|
|
305
|
+
...this.platform,
|
|
306
|
+
config: this.config,
|
|
307
|
+
wrapper: this.wrapper,
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Função de inicialização automática
|
|
314
|
+
*/
|
|
315
|
+
function autoConfigureEasyflow(config = {}) {
|
|
316
|
+
const configurator = new AutoIntegrationConfigurator()
|
|
317
|
+
return configurator.configure(config)
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Função para obter informações da plataforma
|
|
322
|
+
*/
|
|
323
|
+
function getPlatformInfo() {
|
|
324
|
+
const configurator = new AutoIntegrationConfigurator()
|
|
325
|
+
return configurator.getPlatformInfo()
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export {
|
|
329
|
+
PlatformDetector,
|
|
330
|
+
AutoIntegrationConfigurator,
|
|
331
|
+
autoConfigureEasyflow,
|
|
332
|
+
getPlatformInfo,
|
|
333
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default configuration for Easyflow SDK
|
|
3
|
+
*/
|
|
4
|
+
export const DEFAULT_CONFIG = {
|
|
5
|
+
baseUrl: 'https://pay.easyflow.digital',
|
|
6
|
+
timeout: 30000,
|
|
7
|
+
headers: {},
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Payment method constants
|
|
12
|
+
*/
|
|
13
|
+
export const PAYMENT_METHODS = {
|
|
14
|
+
CREDIT_CARD: 'credit-card',
|
|
15
|
+
PIX: 'pix',
|
|
16
|
+
BANK_BILLET: 'bank-billet',
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* API target constants
|
|
21
|
+
*/
|
|
22
|
+
export const TARGETS = {
|
|
23
|
+
CHARGE: 'charge',
|
|
24
|
+
PLACE_ORDER: 'place-order',
|
|
25
|
+
ENCRYPT: 'encrypt',
|
|
26
|
+
GET_OFFER: 'get-offer',
|
|
27
|
+
GET_ORDER: 'get-order',
|
|
28
|
+
CREATE_CUSTOMER: 'create-customer',
|
|
29
|
+
GET_CUSTOMER: 'get-customer',
|
|
30
|
+
UPDATE_CUSTOMER: 'update-customer',
|
|
31
|
+
ADD_CREDIT_CARD: 'add-credit-card',
|
|
32
|
+
REMOVE_CREDIT_CARD: 'delete-credit-card',
|
|
33
|
+
GET_CREDIT_CARD: 'get-credit-card',
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* HTTP status codes used in the SDK
|
|
38
|
+
* @type {{OK: number, CREATED: number, NO_CONTENT: number, BAD_REQUEST: number, UNAUTHORIZED: number, FORBIDDEN: number, NOT_FOUND: number, INTERNAL_SERVER_ERROR: number}}
|
|
39
|
+
*/
|
|
40
|
+
export const HTTP_STATUS_CODES = {
|
|
41
|
+
OK: 200,
|
|
42
|
+
CREATED: 201,
|
|
43
|
+
NO_CONTENT: 204,
|
|
44
|
+
BAD_REQUEST: 400,
|
|
45
|
+
UNAUTHORIZED: 401,
|
|
46
|
+
FORBIDDEN: 403,
|
|
47
|
+
NOT_FOUND: 404,
|
|
48
|
+
INTERNAL_SERVER_ERROR: 500,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* HTTP request methods used in the SDK
|
|
53
|
+
* @type {{GET: string, POST: string, PATCH: string, DELETE: string, PUT: string}}
|
|
54
|
+
*/
|
|
55
|
+
export const HTTP_REQUEST_METHODS = {
|
|
56
|
+
GET: 'GET',
|
|
57
|
+
POST: 'POST',
|
|
58
|
+
PATCH: 'PATCH',
|
|
59
|
+
DELETE: 'DELETE',
|
|
60
|
+
PUT: 'PUT',
|
|
61
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { describe, expect, test } from '@jest/globals'
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_CONFIG,
|
|
4
|
+
HTTP_REQUEST_METHODS,
|
|
5
|
+
HTTP_STATUS_CODES,
|
|
6
|
+
PAYMENT_METHODS,
|
|
7
|
+
TARGETS,
|
|
8
|
+
} from './constants.mjs'
|
|
9
|
+
|
|
10
|
+
describe('Constants', () => {
|
|
11
|
+
describe('DEFAULT_CONFIG', () => {
|
|
12
|
+
test('should have correct default configuration', () => {
|
|
13
|
+
expect(DEFAULT_CONFIG).toEqual({
|
|
14
|
+
baseUrl: 'https://pay.easyflow.digital',
|
|
15
|
+
timeout: 30000,
|
|
16
|
+
headers: {},
|
|
17
|
+
})
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
test('should have baseUrl property', () => {
|
|
21
|
+
expect(DEFAULT_CONFIG.baseUrl).toBe('https://pay.easyflow.digital')
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('should have timeout property', () => {
|
|
25
|
+
expect(DEFAULT_CONFIG.timeout).toBe(30000)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
test('should have headers property', () => {
|
|
29
|
+
expect(DEFAULT_CONFIG.headers).toEqual({})
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
describe('PAYMENT_METHODS', () => {
|
|
34
|
+
test('should contain all expected payment methods', () => {
|
|
35
|
+
expect(PAYMENT_METHODS).toEqual({
|
|
36
|
+
CREDIT_CARD: 'credit-card',
|
|
37
|
+
PIX: 'pix',
|
|
38
|
+
BANK_BILLET: 'bank-billet',
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
test('should have CREDIT_CARD method', () => {
|
|
43
|
+
expect(PAYMENT_METHODS.CREDIT_CARD).toBe('credit-card')
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('should have PIX method', () => {
|
|
47
|
+
expect(PAYMENT_METHODS.PIX).toBe('pix')
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test('should have BANK_BILLET method', () => {
|
|
51
|
+
expect(PAYMENT_METHODS.BANK_BILLET).toBe('bank-billet')
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
describe('TARGETS', () => {
|
|
56
|
+
test('should contain all expected API targets', () => {
|
|
57
|
+
expect(TARGETS).toEqual({
|
|
58
|
+
CHARGE: 'charge',
|
|
59
|
+
PLACE_ORDER: 'place-order',
|
|
60
|
+
ENCRYPT: 'encrypt',
|
|
61
|
+
GET_OFFER: 'get-offer',
|
|
62
|
+
GET_ORDER: 'get-order',
|
|
63
|
+
CREATE_CUSTOMER: 'create-customer',
|
|
64
|
+
GET_CUSTOMER: 'get-customer',
|
|
65
|
+
UPDATE_CUSTOMER: 'update-customer',
|
|
66
|
+
ADD_CREDIT_CARD: 'add-credit-card',
|
|
67
|
+
REMOVE_CREDIT_CARD: 'delete-credit-card',
|
|
68
|
+
GET_CREDIT_CARD: 'get-credit-card',
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
test('should have CHARGE target', () => {
|
|
73
|
+
expect(TARGETS.CHARGE).toBe('charge')
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
test('should have PLACE_ORDER target', () => {
|
|
77
|
+
expect(TARGETS.PLACE_ORDER).toBe('place-order')
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
test('should have ENCRYPT target', () => {
|
|
81
|
+
expect(TARGETS.ENCRYPT).toBe('encrypt')
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
test('should have GET_OFFER target', () => {
|
|
85
|
+
expect(TARGETS.GET_OFFER).toBe('get-offer')
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
test('should have GET_ORDER target', () => {
|
|
89
|
+
expect(TARGETS.GET_ORDER).toBe('get-order')
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
describe('HTTP_STATUS_CODES', () => {
|
|
94
|
+
test('should contain all expected HTTP status codes', () => {
|
|
95
|
+
expect(HTTP_STATUS_CODES).toEqual({
|
|
96
|
+
OK: 200,
|
|
97
|
+
CREATED: 201,
|
|
98
|
+
NO_CONTENT: 204,
|
|
99
|
+
BAD_REQUEST: 400,
|
|
100
|
+
UNAUTHORIZED: 401,
|
|
101
|
+
FORBIDDEN: 403,
|
|
102
|
+
NOT_FOUND: 404,
|
|
103
|
+
INTERNAL_SERVER_ERROR: 500,
|
|
104
|
+
})
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
test('should have correct status code values', () => {
|
|
108
|
+
expect(HTTP_STATUS_CODES.OK).toBe(200)
|
|
109
|
+
expect(HTTP_STATUS_CODES.CREATED).toBe(201)
|
|
110
|
+
expect(HTTP_STATUS_CODES.NO_CONTENT).toBe(204)
|
|
111
|
+
expect(HTTP_STATUS_CODES.BAD_REQUEST).toBe(400)
|
|
112
|
+
expect(HTTP_STATUS_CODES.UNAUTHORIZED).toBe(401)
|
|
113
|
+
expect(HTTP_STATUS_CODES.FORBIDDEN).toBe(403)
|
|
114
|
+
expect(HTTP_STATUS_CODES.NOT_FOUND).toBe(404)
|
|
115
|
+
expect(HTTP_STATUS_CODES.INTERNAL_SERVER_ERROR).toBe(500)
|
|
116
|
+
})
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
describe('HTTP_REQUEST_METHODS', () => {
|
|
120
|
+
test('should contain all expected HTTP request methods', () => {
|
|
121
|
+
expect(HTTP_REQUEST_METHODS).toEqual({
|
|
122
|
+
GET: 'GET',
|
|
123
|
+
POST: 'POST',
|
|
124
|
+
PATCH: 'PATCH',
|
|
125
|
+
DELETE: 'DELETE',
|
|
126
|
+
PUT: 'PUT',
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
test('should have correct HTTP method values', () => {
|
|
131
|
+
expect(HTTP_REQUEST_METHODS.GET).toBe('GET')
|
|
132
|
+
expect(HTTP_REQUEST_METHODS.POST).toBe('POST')
|
|
133
|
+
expect(HTTP_REQUEST_METHODS.PATCH).toBe('PATCH')
|
|
134
|
+
expect(HTTP_REQUEST_METHODS.DELETE).toBe('DELETE')
|
|
135
|
+
expect(HTTP_REQUEST_METHODS.PUT).toBe('PUT')
|
|
136
|
+
})
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
describe('Constants Structure', () => {
|
|
140
|
+
test('all constants should be objects', () => {
|
|
141
|
+
expect(typeof DEFAULT_CONFIG).toBe('object')
|
|
142
|
+
expect(typeof PAYMENT_METHODS).toBe('object')
|
|
143
|
+
expect(typeof TARGETS).toBe('object')
|
|
144
|
+
expect(typeof HTTP_STATUS_CODES).toBe('object')
|
|
145
|
+
expect(typeof HTTP_REQUEST_METHODS).toBe('object')
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
test('all constants should not be null', () => {
|
|
149
|
+
expect(DEFAULT_CONFIG).not.toBeNull()
|
|
150
|
+
expect(PAYMENT_METHODS).not.toBeNull()
|
|
151
|
+
expect(TARGETS).not.toBeNull()
|
|
152
|
+
expect(HTTP_STATUS_CODES).not.toBeNull()
|
|
153
|
+
expect(HTTP_REQUEST_METHODS).not.toBeNull()
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
test('all constants should be defined', () => {
|
|
157
|
+
expect(DEFAULT_CONFIG).toBeDefined()
|
|
158
|
+
expect(PAYMENT_METHODS).toBeDefined()
|
|
159
|
+
expect(TARGETS).toBeDefined()
|
|
160
|
+
expect(HTTP_STATUS_CODES).toBeDefined()
|
|
161
|
+
expect(HTTP_REQUEST_METHODS).toBeDefined()
|
|
162
|
+
})
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
describe('Constants Values', () => {
|
|
166
|
+
test('DEFAULT_CONFIG should have valid URL', () => {
|
|
167
|
+
expect(DEFAULT_CONFIG.baseUrl).toMatch(/^https?:\/\/.+/)
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
test('DEFAULT_CONFIG timeout should be positive number', () => {
|
|
171
|
+
expect(DEFAULT_CONFIG.timeout).toBeGreaterThan(0)
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
test('PAYMENT_METHODS should have string values', () => {
|
|
175
|
+
Object.values(PAYMENT_METHODS).forEach((value) => {
|
|
176
|
+
expect(typeof value).toBe('string')
|
|
177
|
+
})
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
test('TARGETS should have string values', () => {
|
|
181
|
+
Object.values(TARGETS).forEach((value) => {
|
|
182
|
+
expect(typeof value).toBe('string')
|
|
183
|
+
})
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
test('HTTP_STATUS_CODES should have number values', () => {
|
|
187
|
+
Object.values(HTTP_STATUS_CODES).forEach((value) => {
|
|
188
|
+
expect(typeof value).toBe('number')
|
|
189
|
+
})
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
test('HTTP_REQUEST_METHODS should have string values', () => {
|
|
193
|
+
Object.values(HTTP_REQUEST_METHODS).forEach((value) => {
|
|
194
|
+
expect(typeof value).toBe('string')
|
|
195
|
+
})
|
|
196
|
+
})
|
|
197
|
+
})
|
|
198
|
+
})
|