@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.
Files changed (93) hide show
  1. package/.babelrc +5 -0
  2. package/.github/workflows/deploy-sdk-cf.yml +49 -0
  3. package/.github/workflows/release-sdk-cdn.yml +144 -0
  4. package/.github/workflows/release-sdk.yml +112 -0
  5. package/.prettierrc +6 -0
  6. package/CDN-DEPLOYMENT.md +175 -0
  7. package/DEMO.md +258 -0
  8. package/DEPLOYMENT.md +224 -0
  9. package/INTEGRATION-GUIDE.md +521 -0
  10. package/README.md +1013 -0
  11. package/coverage/base.css +224 -0
  12. package/coverage/block-navigation.js +87 -0
  13. package/coverage/easyflow-javascript-sdk/index.html +116 -0
  14. package/coverage/easyflow-javascript-sdk/libs/constants.mjs.html +268 -0
  15. package/coverage/easyflow-javascript-sdk/libs/errors.mjs.html +271 -0
  16. package/coverage/easyflow-javascript-sdk/libs/exception-handler.mjs.html +148 -0
  17. package/coverage/easyflow-javascript-sdk/libs/fingerprint.mjs.html +895 -0
  18. package/coverage/easyflow-javascript-sdk/libs/http.mjs.html +502 -0
  19. package/coverage/easyflow-javascript-sdk/libs/index.html +266 -0
  20. package/coverage/easyflow-javascript-sdk/libs/logger.mjs.html +568 -0
  21. package/coverage/easyflow-javascript-sdk/libs/sanitizer.mjs.html +1099 -0
  22. package/coverage/easyflow-javascript-sdk/libs/security.mjs.html +733 -0
  23. package/coverage/easyflow-javascript-sdk/libs/types.mjs.html +508 -0
  24. package/coverage/easyflow-javascript-sdk/libs/utils.mjs.html +379 -0
  25. package/coverage/easyflow-javascript-sdk/libs/validator.mjs.html +2623 -0
  26. package/coverage/easyflow-javascript-sdk/sdk.mjs.html +2434 -0
  27. package/coverage/favicon.png +0 -0
  28. package/coverage/index.html +131 -0
  29. package/coverage/lcov-report/base.css +224 -0
  30. package/coverage/lcov-report/block-navigation.js +87 -0
  31. package/coverage/lcov-report/easyflow-javascript-sdk/index.html +116 -0
  32. package/coverage/lcov-report/easyflow-javascript-sdk/libs/constants.mjs.html +268 -0
  33. package/coverage/lcov-report/easyflow-javascript-sdk/libs/errors.mjs.html +271 -0
  34. package/coverage/lcov-report/easyflow-javascript-sdk/libs/exception-handler.mjs.html +148 -0
  35. package/coverage/lcov-report/easyflow-javascript-sdk/libs/fingerprint.mjs.html +895 -0
  36. package/coverage/lcov-report/easyflow-javascript-sdk/libs/http.mjs.html +502 -0
  37. package/coverage/lcov-report/easyflow-javascript-sdk/libs/index.html +266 -0
  38. package/coverage/lcov-report/easyflow-javascript-sdk/libs/logger.mjs.html +568 -0
  39. package/coverage/lcov-report/easyflow-javascript-sdk/libs/sanitizer.mjs.html +1099 -0
  40. package/coverage/lcov-report/easyflow-javascript-sdk/libs/security.mjs.html +733 -0
  41. package/coverage/lcov-report/easyflow-javascript-sdk/libs/types.mjs.html +508 -0
  42. package/coverage/lcov-report/easyflow-javascript-sdk/libs/utils.mjs.html +379 -0
  43. package/coverage/lcov-report/easyflow-javascript-sdk/libs/validator.mjs.html +2623 -0
  44. package/coverage/lcov-report/easyflow-javascript-sdk/sdk.mjs.html +2434 -0
  45. package/coverage/lcov-report/favicon.png +0 -0
  46. package/coverage/lcov-report/index.html +131 -0
  47. package/coverage/lcov-report/prettify.css +1 -0
  48. package/coverage/lcov-report/prettify.js +2 -0
  49. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  50. package/coverage/lcov-report/sorter.js +196 -0
  51. package/coverage/lcov.info +1429 -0
  52. package/coverage/prettify.css +1 -0
  53. package/coverage/prettify.js +2 -0
  54. package/coverage/sort-arrow-sprite.png +0 -0
  55. package/coverage/sorter.js +196 -0
  56. package/dist/435.easyflow-sdk.min.js +1 -0
  57. package/dist/easyflow-sdk.min.js +1 -0
  58. package/dist/easyflow-sdk.min.js.LICENSE.txt +1 -0
  59. package/dist/index.html +756 -0
  60. package/docs/index.html +775 -0
  61. package/examples/lovable-integration.html +410 -0
  62. package/index.html +981 -0
  63. package/jest.config.js +37 -0
  64. package/jsdoc.json +42 -0
  65. package/libs/auto-integration.mjs +333 -0
  66. package/libs/constants.mjs +61 -0
  67. package/libs/constants.spec.js +198 -0
  68. package/libs/errors.mjs +62 -0
  69. package/libs/errors.spec.js +178 -0
  70. package/libs/exception-handler.mjs +21 -0
  71. package/libs/exception-handler.spec.js +237 -0
  72. package/libs/fingerprint.mjs +270 -0
  73. package/libs/http.mjs +163 -0
  74. package/libs/http.spec.js +427 -0
  75. package/libs/integration-wrapper.mjs +285 -0
  76. package/libs/logger.mjs +161 -0
  77. package/libs/logger.spec.js +389 -0
  78. package/libs/sanitizer.mjs +340 -0
  79. package/libs/sanitizer.spec.js +583 -0
  80. package/libs/security.mjs +217 -0
  81. package/libs/types.mjs +141 -0
  82. package/libs/utils.mjs +368 -0
  83. package/libs/utils.spec.js +231 -0
  84. package/libs/validator.mjs +952 -0
  85. package/libs/validator.spec.js +615 -0
  86. package/mocks/offer.mock.js +77 -0
  87. package/package.json +72 -0
  88. package/scripts/publish-npm.sh +82 -0
  89. package/sdk.mjs +945 -0
  90. package/sdk.spec.js +796 -0
  91. package/test-setup.cjs +211 -0
  92. package/test.html +154 -0
  93. package/webpack.config.cjs +41 -0
@@ -0,0 +1,615 @@
1
+ import { describe, expect, jest, test } from '@jest/globals'
2
+ import { Validator } from './validator.mjs'
3
+ import { EasyflowError } from './errors.mjs'
4
+
5
+ jest.mock('./exception-handler.mjs', () => ({
6
+ throwsError: jest.fn((error) => {
7
+ throw error
8
+ }),
9
+ }))
10
+
11
+ describe('Validator', () => {
12
+ describe('validateEmail', () => {
13
+ test('should validate correct email addresses', () => {
14
+ const validEmails = [
15
+ 'user@example.com',
16
+ 'user.name@example.com',
17
+ 'user+tag@example.co.uk',
18
+ '123@example.org',
19
+ 'user@subdomain.example.com',
20
+ ]
21
+
22
+ validEmails.forEach((email) => {
23
+ expect(() => Validator.validateEmail(email)).not.toThrow()
24
+ })
25
+ })
26
+
27
+ test('should reject invalid email addresses', () => {
28
+ const invalidEmails = [
29
+ 'invalid-email',
30
+ '@example.com',
31
+ 'user@',
32
+ 'user..name@example.com',
33
+ '.user@example.com',
34
+ 'user@example.com.',
35
+ 'user name@example.com',
36
+ 'user@example..com',
37
+ ]
38
+
39
+ invalidEmails.forEach((email) => {
40
+ expect(() => Validator.validateEmail(email)).toThrow(
41
+ EasyflowError
42
+ )
43
+ })
44
+ })
45
+
46
+ test('should reject emails that are too long', () => {
47
+ const longEmail = 'a'.repeat(250) + '@example.com'
48
+ expect(() => Validator.validateEmail(longEmail)).toThrow(
49
+ EasyflowError
50
+ )
51
+ })
52
+ })
53
+
54
+ describe('validateCPF', () => {
55
+ test('should validate correct CPFs', () => {
56
+ const validCPFs = ['12345678909', '11144477735']
57
+
58
+ validCPFs.forEach((cpf) => {
59
+ expect(() => Validator.validateCPF(cpf)).not.toThrow()
60
+ })
61
+ })
62
+
63
+ test('should reject invalid CPFs', () => {
64
+ const invalidCPFs = [
65
+ '12345678910',
66
+ '11111111111',
67
+ '00000000000',
68
+ '123',
69
+ '123456789012',
70
+ 'abc123def45',
71
+ ]
72
+
73
+ invalidCPFs.forEach((cpf) => {
74
+ expect(() => Validator.validateCPF(cpf)).toThrow(EasyflowError)
75
+ })
76
+ })
77
+ })
78
+
79
+ describe('validateCNPJ', () => {
80
+ test('should validate correct CNPJs', () => {
81
+ const validCNPJs = ['11222333000181', '00000000000191']
82
+
83
+ validCNPJs.forEach((cnpj) => {
84
+ expect(() => Validator.validateCNPJ(cnpj)).not.toThrow()
85
+ })
86
+ })
87
+
88
+ test('should reject invalid CNPJs', () => {
89
+ const invalidCNPJs = [
90
+ '11222333000182',
91
+ '11111111111111',
92
+ '00000000000000',
93
+ '123',
94
+ '123456789012345',
95
+ 'abc123def45678',
96
+ ]
97
+
98
+ invalidCNPJs.forEach((cnpj) => {
99
+ expect(() => Validator.validateCNPJ(cnpj)).toThrow(
100
+ EasyflowError
101
+ )
102
+ })
103
+ })
104
+ })
105
+
106
+ describe('validateLegalDocument', () => {
107
+ test('should validate correct legal documents', () => {
108
+ const validDocuments = [
109
+ { type: 'CPF', number: '12345678909' },
110
+ { type: 'CNPJ', number: '11222333000181' },
111
+ ]
112
+
113
+ validDocuments.forEach((doc) => {
114
+ expect(() => Validator.validateLegalDocument(doc)).not.toThrow()
115
+ })
116
+ })
117
+
118
+ test('should reject documents with non-digit numbers', () => {
119
+ expect(() =>
120
+ Validator.validateLegalDocument({
121
+ type: 'CPF',
122
+ number: '123.456.789-09',
123
+ })
124
+ ).toThrow(EasyflowError)
125
+
126
+ expect(() =>
127
+ Validator.validateLegalDocument({
128
+ type: 'CNPJ',
129
+ number: '11.222.333/0001-81',
130
+ })
131
+ ).toThrow(EasyflowError)
132
+ })
133
+
134
+ test('should reject invalid document types', () => {
135
+ expect(() =>
136
+ Validator.validateLegalDocument({
137
+ type: 'INVALID',
138
+ number: '12345678909',
139
+ })
140
+ ).toThrow(EasyflowError)
141
+ })
142
+
143
+ test('should reject missing fields', () => {
144
+ expect(() =>
145
+ Validator.validateLegalDocument({
146
+ type: 'CPF',
147
+ })
148
+ ).toThrow(EasyflowError)
149
+ })
150
+ })
151
+
152
+ describe('validatePhone', () => {
153
+ test('should validate correct phone numbers', () => {
154
+ const validPhones = [
155
+ {
156
+ areaCode: '+55',
157
+ ddd: '11',
158
+ number: '999999999',
159
+ isMobile: true,
160
+ },
161
+ {
162
+ areaCode: '+1',
163
+ ddd: '21',
164
+ number: '12345678',
165
+ isMobile: false,
166
+ },
167
+ ]
168
+
169
+ validPhones.forEach((phone) => {
170
+ expect(() => Validator.validatePhone(phone)).not.toThrow()
171
+ })
172
+ })
173
+
174
+ test('should reject invalid phone numbers', () => {
175
+ const invalidPhones = [
176
+ {
177
+ areaCode: '55',
178
+ ddd: '11',
179
+ number: '999999999',
180
+ isMobile: true,
181
+ },
182
+ {
183
+ areaCode: '+55',
184
+ ddd: '1',
185
+ number: '999999999',
186
+ isMobile: true,
187
+ },
188
+ {
189
+ areaCode: '+55',
190
+ ddd: '11',
191
+ number: '123',
192
+ isMobile: true,
193
+ },
194
+ ]
195
+
196
+ invalidPhones.forEach((phone) => {
197
+ expect(() => Validator.validatePhone(phone)).toThrow(
198
+ EasyflowError
199
+ )
200
+ })
201
+ })
202
+ })
203
+
204
+ describe('validateAddress', () => {
205
+ test('should validate correct addresses', () => {
206
+ const validAddress = {
207
+ zipCode: '01234567',
208
+ street: 'Main Street',
209
+ complement: 'Apt 123',
210
+ neighborhood: 'Downtown',
211
+ city: 'São Paulo',
212
+ state: 'SP',
213
+ number: '123',
214
+ }
215
+
216
+ expect(() => Validator.validateAddress(validAddress)).not.toThrow()
217
+ })
218
+
219
+ test('should reject invalid addresses', () => {
220
+ const invalidAddresses = [
221
+ {
222
+ zipCode: '123',
223
+ street: 'Main Street',
224
+ neighborhood: 'Downtown',
225
+ city: 'São Paulo',
226
+ state: 'SP',
227
+ number: '123',
228
+ },
229
+ {
230
+ zipCode: '01234-567',
231
+ street: 'Main Street',
232
+ neighborhood: 'Downtown',
233
+ city: 'São Paulo',
234
+ state: 'SP',
235
+ number: '123',
236
+ },
237
+ {
238
+ zipCode: '01234567',
239
+ street: 'Ma',
240
+ neighborhood: 'Downtown',
241
+ city: 'São Paulo',
242
+ state: 'SP',
243
+ number: '123',
244
+ },
245
+ {
246
+ zipCode: '01234567',
247
+ street: 'Main Street',
248
+ neighborhood: 'Downtown',
249
+ city: 'São Paulo',
250
+ state: 'INVALID',
251
+ number: '123',
252
+ },
253
+ ]
254
+
255
+ invalidAddresses.forEach((address) => {
256
+ expect(() => Validator.validateAddress(address)).toThrow(
257
+ EasyflowError
258
+ )
259
+ })
260
+ })
261
+ })
262
+
263
+ describe('validateCustomer', () => {
264
+ test('should validate correct customer data', () => {
265
+ const validCustomer = {
266
+ name: 'John Doe',
267
+ email: 'john@example.com',
268
+ document: { type: 'CPF', number: '12345678909' },
269
+ phone: {
270
+ areaCode: '+55',
271
+ ddd: '11',
272
+ number: '999999999',
273
+ isMobile: true,
274
+ },
275
+ }
276
+
277
+ expect(() =>
278
+ Validator.validateCustomer(validCustomer)
279
+ ).not.toThrow()
280
+ })
281
+
282
+ test('should reject invalid customer data', () => {
283
+ const invalidCustomer = {
284
+ name: 'J',
285
+ email: 'invalid-email',
286
+ document: { type: 'CPF', number: '12345678909' },
287
+ phone: {
288
+ areaCode: '+55',
289
+ ddd: '11',
290
+ number: '999999999',
291
+ isMobile: true,
292
+ },
293
+ }
294
+
295
+ expect(() => Validator.validateCustomer(invalidCustomer)).toThrow(
296
+ EasyflowError
297
+ )
298
+ })
299
+ })
300
+
301
+ describe('validatePagination', () => {
302
+ test('should validate correct pagination parameters', () => {
303
+ expect(() => Validator.validatePagination(1, 10)).not.toThrow()
304
+ expect(() => Validator.validatePagination(5, 50)).not.toThrow()
305
+ })
306
+
307
+ test('should reject invalid pagination parameters', () => {
308
+ expect(() => Validator.validatePagination(0, 10)).toThrow(
309
+ EasyflowError
310
+ )
311
+ expect(() => Validator.validatePagination(1, 0)).toThrow(
312
+ EasyflowError
313
+ )
314
+ expect(() => Validator.validatePagination(1, 101)).toThrow(
315
+ EasyflowError
316
+ )
317
+ })
318
+ })
319
+
320
+ describe('validateBusinessId', () => {
321
+ test('should validate correct business IDs', () => {
322
+ const validBusinessIds = [
323
+ 'business-123',
324
+ 'my-business',
325
+ 'company-456-789',
326
+ ]
327
+
328
+ validBusinessIds.forEach((id) => {
329
+ expect(() => Validator.validateBusinessId(id)).not.toThrow()
330
+ })
331
+ })
332
+
333
+ test('should reject invalid business IDs', () => {
334
+ const invalidBusinessIds = [
335
+ 'ab',
336
+ '-business',
337
+ 'business-',
338
+ 'business--123',
339
+ 'business_123',
340
+ 'business.123',
341
+ ]
342
+
343
+ invalidBusinessIds.forEach((id) => {
344
+ expect(() => Validator.validateBusinessId(id)).toThrow(
345
+ EasyflowError
346
+ )
347
+ })
348
+ })
349
+ })
350
+
351
+ describe('validateCreditCardToken', () => {
352
+ test('should validate correct credit card tokens', () => {
353
+ const validTokens = [
354
+ 'a'.repeat(32),
355
+ 'a'.repeat(64),
356
+ 'a'.repeat(128),
357
+ 'abc123_-def456'.repeat(3),
358
+ ]
359
+
360
+ validTokens.forEach((token) => {
361
+ expect(() =>
362
+ Validator.validateCreditCardToken(token)
363
+ ).not.toThrow()
364
+ })
365
+ })
366
+
367
+ test('should reject invalid credit card tokens', () => {
368
+ const invalidTokens = [
369
+ 'a'.repeat(31),
370
+ 'a'.repeat(129),
371
+ 'abc@123',
372
+ 'abc 123',
373
+ 'abc.123',
374
+ ]
375
+
376
+ invalidTokens.forEach((token) => {
377
+ expect(() => Validator.validateCreditCardToken(token)).toThrow(
378
+ EasyflowError
379
+ )
380
+ })
381
+ })
382
+ })
383
+
384
+ describe('validateOrderId', () => {
385
+ test('should validate correct order IDs', () => {
386
+ const validOrderIds = [
387
+ // UUID v4 examples (strict v4)
388
+ 'f47ac10b-58cc-4372-a567-0e02b2c3d479',
389
+ 'a8098c1a-f86e-4f4c-a9f5-0b8add7c7f3d',
390
+ '16fd2706-8baf-433b-82eb-8c7fada847da',
391
+ '58c8f2e0-3d22-4b5d-98ab-9c0a1f2b3c4d',
392
+ // UUID v7 examples
393
+ '01890b24-2d7f-7c3f-8f1a-123456789abc',
394
+ '01890b24-2d7f-7c3f-9f1a-123456789abc',
395
+ '01890b24-2d7f-7c3f-af1a-123456789abc',
396
+ '01890b24-2d7f-7c3f-bf1a-123456789abc',
397
+ // MongoDB ObjectId examples
398
+ '507f1f77bcf86cd799439011',
399
+ '507f1f77bcf86cd799439012',
400
+ '507f1f77bcf86cd799439013',
401
+ '507f1f77bcf86cd799439014',
402
+ ]
403
+
404
+ validOrderIds.forEach((id) => {
405
+ expect(() => Validator.validateOrderId(id)).not.toThrow()
406
+ })
407
+ })
408
+
409
+ test('should reject invalid order IDs', () => {
410
+ const invalidOrderIds = [
411
+ // Old format patterns
412
+ 'order-1234567890123456',
413
+ 'order-abcdefghijklmnop',
414
+ // Invalid UUIDs
415
+ '550e8400-e29b-41d4-a716-44665544000',
416
+ '550e8400-e29b-41d4-a716-4466554400000',
417
+ '550e8400-e29b-41d4-a716-44665544000g',
418
+ '550e8400-e29b-41d4-a716-44665544000',
419
+ // Invalid UUID v7 (wrong version)
420
+ '01890b24-2d7f-8c3f-8f1a-123456789abc',
421
+ '01890b24-2d7f-6c3f-8f1a-123456789abc',
422
+ // Invalid MongoDB ObjectId
423
+ '507f1f77bcf86cd79943901',
424
+ '507f1f77bcf86cd7994390111',
425
+ '507f1f77bcf86cd79943901g',
426
+ // Other invalid formats
427
+ 'invalid-uuid',
428
+ '12345678-1234-1234-1234-123456789012',
429
+ 'not-an-id',
430
+ '12345',
431
+ 'abc-def-ghi',
432
+ ]
433
+
434
+ invalidOrderIds.forEach((id) => {
435
+ expect(() => Validator.validateOrderId(id)).toThrow(
436
+ EasyflowError
437
+ )
438
+ })
439
+ })
440
+ })
441
+
442
+ describe('validateOfferId', () => {
443
+ test('should validate correct offer IDs', () => {
444
+ const validOfferIds = [
445
+ // UUID v4 examples (strict v4)
446
+ 'f47ac10b-58cc-4372-a567-0e02b2c3d479',
447
+ 'a8098c1a-f86e-4f4c-a9f5-0b8add7c7f3d',
448
+ '16fd2706-8baf-433b-82eb-8c7fada847da',
449
+ '58c8f2e0-3d22-4b5d-98ab-9c0a1f2b3c4d',
450
+ // UUID v7 examples
451
+ '01890b24-2d7f-7c3f-8f1a-123456789abc',
452
+ '01890b24-2d7f-7c3f-9f1a-123456789abc',
453
+ '01890b24-2d7f-7c3f-af1a-123456789abc',
454
+ '01890b24-2d7f-7c3f-bf1a-123456789abc',
455
+ // MongoDB ObjectId examples
456
+ '507f1f77bcf86cd799439011',
457
+ '507f1f77bcf86cd799439012',
458
+ '507f1f77bcf86cd799439013',
459
+ '507f1f77bcf86cd799439014',
460
+ ]
461
+
462
+ validOfferIds.forEach((id) => {
463
+ expect(() => Validator.validateOfferId(id)).not.toThrow()
464
+ })
465
+ })
466
+
467
+ test('should reject invalid offer IDs', () => {
468
+ const invalidOfferIds = [
469
+ // Old format patterns
470
+ 'offer-1234567890123456',
471
+ 'offer-abcdefghijklmnop',
472
+ // Invalid UUIDs
473
+ '550e8400-e29b-41d4-a716-44665544000',
474
+ '550e8400-e29b-41d4-a716-4466554400000',
475
+ '550e8400-e29b-41d4-a716-44665544000g',
476
+ '550e8400-e29b-41d4-a716-44665544000',
477
+ // Invalid UUID v7 (wrong version)
478
+ '01890b24-2d7f-8c3f-8f1a-123456789abc',
479
+ '01890b24-2d7f-6c3f-8f1a-123456789abc',
480
+ // Invalid MongoDB ObjectId
481
+ '507f1f77bcf86cd79943901',
482
+ '507f1f77bcf86cd7994390111',
483
+ '507f1f77bcf86cd79943901g',
484
+ // Other invalid formats
485
+ 'invalid-uuid',
486
+ '12345678-1234-1234-1234-123456789012',
487
+ 'not-an-id',
488
+ '12345',
489
+ 'abc-def-ghi',
490
+ ]
491
+
492
+ invalidOfferIds.forEach((id) => {
493
+ expect(() => Validator.validateOfferId(id)).toThrow(
494
+ EasyflowError
495
+ )
496
+ })
497
+ })
498
+ })
499
+
500
+ describe('validateCustomerId', () => {
501
+ test('should validate correct customer IDs', () => {
502
+ const validCustomerIds = [
503
+ // UUID v4 examples (strict v4)
504
+ 'f47ac10b-58cc-4372-a567-0e02b2c3d479',
505
+ 'a8098c1a-f86e-4f4c-a9f5-0b8add7c7f3d',
506
+ '16fd2706-8baf-433b-82eb-8c7fada847da',
507
+ '58c8f2e0-3d22-4b5d-98ab-9c0a1f2b3c4d',
508
+ // UUID v7 examples
509
+ '01890b24-2d7f-7c3f-8f1a-123456789abc',
510
+ '01890b24-2d7f-7c3f-9f1a-123456789abc',
511
+ '01890b24-2d7f-7c3f-af1a-123456789abc',
512
+ '01890b24-2d7f-7c3f-bf1a-123456789abc',
513
+ // MongoDB ObjectId examples
514
+ '507f1f77bcf86cd799439011',
515
+ '507f1f77bcf86cd799439012',
516
+ '507f1f77bcf86cd799439013',
517
+ '507f1f77bcf86cd799439014',
518
+ ]
519
+
520
+ validCustomerIds.forEach((id) => {
521
+ expect(() => Validator.validateCustomerId(id)).not.toThrow()
522
+ })
523
+ })
524
+
525
+ test('should reject invalid customer IDs', () => {
526
+ const invalidCustomerIds = [
527
+ // Old format patterns
528
+ 'customer-1234567890123456',
529
+ 'customer-abcdefghijklmnop',
530
+ // Invalid UUIDs
531
+ '550e8400-e29b-41d4-a716-44665544000',
532
+ '550e8400-e29b-41d4-a716-4466554400000',
533
+ '550e8400-e29b-41d4-a716-44665544000g',
534
+ '550e8400-e29b-41d4-a716-44665544000',
535
+ // Invalid UUID v7 (wrong version)
536
+ '01890b24-2d7f-8c3f-8f1a-123456789abc',
537
+ '01890b24-2d7f-6c3f-8f1a-123456789abc',
538
+ // Invalid MongoDB ObjectId
539
+ '507f1f77bcf86cd79943901',
540
+ '507f1f77bcf86cd7994390111',
541
+ '507f1f77bcf86cd79943901g',
542
+ // Other invalid formats
543
+ 'invalid-uuid',
544
+ '12345678-1234-1234-1234-123456789012',
545
+ 'not-an-id',
546
+ '12345',
547
+ 'abc-def-ghi',
548
+ ]
549
+
550
+ invalidCustomerIds.forEach((id) => {
551
+ expect(() => Validator.validateCustomerId(id)).toThrow(
552
+ EasyflowError
553
+ )
554
+ })
555
+ })
556
+ })
557
+
558
+ describe('validateCreditCardId', () => {
559
+ test('should validate correct credit card IDs', () => {
560
+ const validCreditCardIds = [
561
+ // UUID v4 examples (strict v4)
562
+ 'f47ac10b-58cc-4372-a567-0e02b2c3d479',
563
+ 'a8098c1a-f86e-4f4c-a9f5-0b8add7c7f3d',
564
+ '16fd2706-8baf-433b-82eb-8c7fada847da',
565
+ '58c8f2e0-3d22-4b5d-98ab-9c0a1f2b3c4d',
566
+ // UUID v7 examples
567
+ '01890b24-2d7f-7c3f-8f1a-123456789abc',
568
+ '01890b24-2d7f-7c3f-9f1a-123456789abc',
569
+ '01890b24-2d7f-7c3f-af1a-123456789abc',
570
+ '01890b24-2d7f-7c3f-bf1a-123456789abc',
571
+ // MongoDB ObjectId examples
572
+ '507f1f77bcf86cd799439011',
573
+ '507f1f77bcf86cd799439012',
574
+ '507f1f77bcf86cd799439013',
575
+ '507f1f77bcf86cd799439014',
576
+ ]
577
+
578
+ validCreditCardIds.forEach((id) => {
579
+ expect(() => Validator.validateCreditCardId(id)).not.toThrow()
580
+ })
581
+ })
582
+
583
+ test('should reject invalid credit card IDs', () => {
584
+ const invalidCreditCardIds = [
585
+ // Old format patterns
586
+ 'card-1234567890123456',
587
+ 'credit-card-abcdefghijklmnop',
588
+ // Invalid UUIDs
589
+ '550e8400-e29b-41d4-a716-44665544000',
590
+ '550e8400-e29b-41d4-a716-4466554400000',
591
+ '550e8400-e29b-41d4-a716-44665544000g',
592
+ '550e8400-e29b-41d4-a716-44665544000',
593
+ // Invalid UUID v7 (wrong version)
594
+ '01890b24-2d7f-8c3f-8f1a-123456789abc',
595
+ '01890b24-2d7f-6c3f-8f1a-123456789abc',
596
+ // Invalid MongoDB ObjectId
597
+ '507f1f77bcf86cd79943901',
598
+ '507f1f77bcf86cd7994390111',
599
+ '507f1f77bcf86cd79943901g',
600
+ // Other invalid formats
601
+ 'invalid-uuid',
602
+ '12345678-1234-1234-1234-123456789012',
603
+ 'not-an-id',
604
+ '12345',
605
+ 'abc-def-ghi',
606
+ ]
607
+
608
+ invalidCreditCardIds.forEach((id) => {
609
+ expect(() => Validator.validateCreditCardId(id)).toThrow(
610
+ EasyflowError
611
+ )
612
+ })
613
+ })
614
+ })
615
+ })
@@ -0,0 +1,77 @@
1
+ /* OFFER MODEL MOCK
2
+ {
3
+ id: string,
4
+ business: {
5
+ id: string,
6
+ owner: {
7
+ id: string,
8
+ name: string,
9
+ },
10
+ },
11
+ checkoutTemplate: {
12
+ id: string,
13
+ createdAt: string,
14
+ isDefault: boolean,
15
+ color: 'black-white' | 'blue-theme' | 'green-theme' | 'red-theme' | 'purple-theme' | 'yellow-theme',
16
+ theme: 'light-theme' | 'dark-theme',
17
+ name: string,
18
+ requestAddress: boolean,
19
+ requestDeliveryAddress: boolean,
20
+ showSellerName: boolean,
21
+ acceptNaturalPersonBuyer: boolean,
22
+ acceptCorporationBuyer: boolean,
23
+ creditCard: {
24
+ defaultInstallments?: number | null,
25
+ maxInstallments?: number | null,
26
+ },
27
+ billet: {
28
+ dueDateDelay?: number | null,
29
+ },
30
+ pix: {
31
+ expirationInMinutes?: number | null,
32
+ }
33
+ },
34
+ name: string,
35
+ warrantyInDays: number,
36
+ status: 'draft' | 'active' | 'inactive' | 'blocked',
37
+ createdAt: string,
38
+ items: Array<
39
+ {
40
+ id: string,
41
+ product: {
42
+ id: string,
43
+ name: string,
44
+ description: string,
45
+ type: 'Online-Course' | 'Mentoring' | 'Consultancy' | 'Subscription' | 'Community' | 'Online-Event' | 'Face-to-face-Event' | 'E-Book' | 'Downloadable-File' | 'App' | 'Physical-Product' | 'Services' | 'Others',
46
+ image: {
47
+ name: string | null,
48
+ path: string | null,
49
+ url: string | null,
50
+ isPublic: boolean,
51
+ extension: string | null,
52
+ },
53
+ supportContact: {
54
+ name: string | null,
55
+ email: string | null,
56
+ validated: boolean | null
57
+ },
58
+ },
59
+ priceInCents: number,
60
+ priceWithoutDiscountValueInCents: number,
61
+ offerItemType: 'unique-purchase' | 'recurrent',
62
+ optional: boolean,
63
+ recurrence?: {
64
+ periodicity: 'Monthly' | 'Quarterly' | 'Biannualy' | 'Annualy',
65
+ numberRecurrence: number,
66
+ recurrenceValueInCents: number,
67
+ repeatIndefinitely: boolean,
68
+ customValue: {
69
+ recurrenceFrom: number | null,
70
+ recurrenceTo: number | null,
71
+ valueInCents: number | null,
72
+ },
73
+ },
74
+ }
75
+ >,
76
+ }
77
+ */