skyflow-js 1.6.0 → 1.7.0
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/CHANGELOG.md +10 -0
- package/README.md +131 -8
- package/dist/sdkNodeBuild/index.js +1 -1
- package/dist/sdkNodeBuild/index.js.gz +0 -0
- package/package.json +2 -1
- package/types/Skyflow.d.ts +3 -2
- package/types/container/constants.d.ts +23 -1
- package/types/container/external/CollectContainer.d.ts +3 -2
- package/types/container/internal/iFrameForm/index.d.ts +7 -3
- package/types/libs/element-options.d.ts +3 -0
- package/types/utils/common/index.d.ts +9 -0
- package/types/utils/constants.d.ts +44 -0
- package/types/utils/logs.d.ts +12 -0
- package/types/utils/logsHelper/index.d.ts +1 -1
- package/types/utils/validators/index.d.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
|
+
## [1.7.0] - 2021-11-24
|
|
5
|
+
### Added
|
|
6
|
+
- `validations` option in `CollectElementInput` that takes an array of validation rules
|
|
7
|
+
- `REGEX_MATCH_RULE`, `LENGTH_MATCH_RULE` & `ELEMENT_MATCH_RULE` Validation rules types
|
|
8
|
+
- `PIN` Element type
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- Card Number validation
|
|
12
|
+
|
|
13
|
+
|
|
4
14
|
## [1.6.0] - 2021-11-16
|
|
5
15
|
|
|
6
16
|
### Added
|
package/README.md
CHANGED
|
@@ -125,13 +125,14 @@ For `env` parameter, there are 2 accepted values in Skyflow.Env
|
|
|
125
125
|
# Securely collecting data client-side
|
|
126
126
|
- [**Inserting data into the vault**](#inserting-data-into-the-vault)
|
|
127
127
|
- [**Using Skyflow Elements to collect data**](#using-skyflow-elements-to-collect-data)
|
|
128
|
+
- [**Using validations on Collect Elements**](#validations)
|
|
128
129
|
- [**Event Listener on Collect Elements**](#event-listener-on-collect-elements)
|
|
129
130
|
## Inserting data into the vault
|
|
130
131
|
|
|
131
132
|
To insert data into the vault from the browser, use the `insert(records, options?)` method of the Skyflow client. The `records` parameter takes a JSON object of the records to be inserted in the below format. The `options` parameter takes a dictionary of optional parameters for the insertion. See below:
|
|
132
133
|
|
|
133
134
|
```javascript
|
|
134
|
-
|
|
135
|
+
const records = {
|
|
135
136
|
"records": [
|
|
136
137
|
{
|
|
137
138
|
table: "string", //table into which record should be inserted
|
|
@@ -144,7 +145,7 @@ var records = {
|
|
|
144
145
|
]
|
|
145
146
|
}
|
|
146
147
|
|
|
147
|
-
|
|
148
|
+
const options = {
|
|
148
149
|
tokens: true //indicates whether or not tokens should be returned for the inserted data. Defaults to 'true'
|
|
149
150
|
}
|
|
150
151
|
|
|
@@ -199,7 +200,7 @@ const container = skyflowClient.container(Skyflow.ContainerType.COLLECT)
|
|
|
199
200
|
A Skyflow collect Element is defined as shown below:
|
|
200
201
|
|
|
201
202
|
```javascript
|
|
202
|
-
|
|
203
|
+
const collectElement = {
|
|
203
204
|
table: "string", //optional, the table this data belongs to
|
|
204
205
|
column: "string", //optional, the column into which this data should be inserted
|
|
205
206
|
type: Skyflow.ElementType, //Skyflow.ElementType enum
|
|
@@ -209,6 +210,7 @@ var collectElement = {
|
|
|
209
210
|
label: "string", //optional label for the form element
|
|
210
211
|
placeholder: "string", //optional placeholder for the form element
|
|
211
212
|
altText: "string" //optional string that acts as an initial value for the collect element
|
|
213
|
+
validations:[] // optional array of validation rules
|
|
212
214
|
}
|
|
213
215
|
```
|
|
214
216
|
The `table` and `column` fields indicate which table and column in the vault the Element corresponds to. **Note**:
|
|
@@ -278,13 +280,14 @@ Finally, the `type` field takes a Skyflow ElementType. Each type applies the app
|
|
|
278
280
|
- `EXPIRATION_DATE`
|
|
279
281
|
- `CVV`
|
|
280
282
|
- `INPUT_FIELD`
|
|
283
|
+
- `PIN`
|
|
281
284
|
|
|
282
|
-
The `INPUT_FIELD` type is a custom UI element without any built-in validations.
|
|
285
|
+
The `INPUT_FIELD` type is a custom UI element without any built-in validations. See the section on [validations](#validations) for more information on validations.
|
|
283
286
|
|
|
284
287
|
Once the Element object has been defined, add it to the container using the `create(element, options)` method as shown below. The `element` param takes a Skyflow Element object as defined above and the `options` parameter takes a dictionary of optional parameters as described below:
|
|
285
288
|
|
|
286
289
|
```javascript
|
|
287
|
-
|
|
290
|
+
const collectElement = {
|
|
288
291
|
table: "string", //the table this data belongs to
|
|
289
292
|
column: "string", //the column into which this data should be inserted
|
|
290
293
|
type: Skyflow.ElementType, //Skyflow.ElementType enum
|
|
@@ -294,9 +297,10 @@ var collectElement = {
|
|
|
294
297
|
label: "string", //optional label for the form element
|
|
295
298
|
placeholder: "string", //optional placeholder for the form element
|
|
296
299
|
altText: "string" //optional string that acts as an initial value for the collect element
|
|
300
|
+
validations:[] // optional array of validation rules
|
|
297
301
|
}
|
|
298
302
|
|
|
299
|
-
|
|
303
|
+
const options = {
|
|
300
304
|
required: false, //indicates whether the field is marked as required. Defaults to 'false'
|
|
301
305
|
enableCardIcon: true // indicates whether card icon should be enabled (only for CARD_NUMBER type Element)
|
|
302
306
|
}
|
|
@@ -339,7 +343,7 @@ When the form is ready to be submitted, call the `collect(options?)` method on t
|
|
|
339
343
|
- `additionalFields`: Non-PCI elements data to be inserted into the vault which should be in the `records` object format as described in the above [Inserting data into vault](#inserting-data-into-the-vault) section.
|
|
340
344
|
|
|
341
345
|
```javascript
|
|
342
|
-
|
|
346
|
+
const options = {
|
|
343
347
|
tokens: true //optional, indicates whether tokens for the collected data should be returned. Defaults to 'true'
|
|
344
348
|
additionalFields: {
|
|
345
349
|
records: [
|
|
@@ -428,7 +432,126 @@ container.collect({
|
|
|
428
432
|
}
|
|
429
433
|
```
|
|
430
434
|
|
|
435
|
+
### Validations
|
|
431
436
|
|
|
437
|
+
Skyflow-JS provides two types of validations on Collect Elements
|
|
438
|
+
|
|
439
|
+
#### 1. Default Validations:
|
|
440
|
+
Every Collect Element except of type `INPUT_FIELD` has a set of default validations listed below:
|
|
441
|
+
- `CARD_NUMBER`: Card number validation with checkSum algorithm(Luhn algorithm), available card lengths for defined card types
|
|
442
|
+
- `CARD_HOLDER_NAME`: Name should be 2 or more symbols, valid characters should match pattern - `^([a-zA-Z\\ \\,\\.\\-\\']{2,})$`
|
|
443
|
+
- `CVV`: Card CVV can have 3-4 digits
|
|
444
|
+
- `EXPIRATION_DATE`: Any date starting from current month. By default valid expiration date should be in short year format - `MM/YYYY`
|
|
445
|
+
- `PIN`: Can have 4-12 digits
|
|
446
|
+
|
|
447
|
+
#### 2. Custom Validations:
|
|
448
|
+
Custom validations can be added to any element which will be checked after the default validations have passed. The following Custom validation rules are currently supported:
|
|
449
|
+
- `REGEX_MATCH_RULE`: You can use this rule to specify any Regular Expression to be matched with the input field value
|
|
450
|
+
|
|
451
|
+
```javascript
|
|
452
|
+
const regexMatchRule = {
|
|
453
|
+
type: Skyflow.ValidationRuleType.REGEX_MATCH_RULE,
|
|
454
|
+
params: {
|
|
455
|
+
regex: RegExp,
|
|
456
|
+
error: string // optional, default error is "VALIDATION FAILED"
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
- `LENGTH_MATCH_RULE`: You can use this rule to set the minimum and maximum permissible length of the input field value
|
|
462
|
+
|
|
463
|
+
```javascript
|
|
464
|
+
const lengthMatchRule = {
|
|
465
|
+
type: Skyflow.ValidationRuleType.LENGTH_MATCH_RULE,
|
|
466
|
+
params: {
|
|
467
|
+
min : number, // optional
|
|
468
|
+
max : number, // optional
|
|
469
|
+
error: string // optional, default error is "VALIDATION FAILED"
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
- `ELEMENT_VALUE_MATCH_RULE`: You can use this rule to match the value of one element with another element
|
|
475
|
+
|
|
476
|
+
```javascript
|
|
477
|
+
const elementValueMatchRule = {
|
|
478
|
+
type: Skyflow.ValidationRuleType.ELEMENT_VALUE_MATCH_RULE,
|
|
479
|
+
params: {
|
|
480
|
+
element: CollectElement,
|
|
481
|
+
error: string // optional, default error is "VALIDATION FAILED"
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
The Sample code snippet for using custom validations:
|
|
487
|
+
|
|
488
|
+
```javascript
|
|
489
|
+
/*
|
|
490
|
+
A simple example that illustrates custom validations.
|
|
491
|
+
Adding REGEX_MATCH_RULE , LENGTH_MATCH_RULE to collect element.
|
|
492
|
+
*/
|
|
493
|
+
|
|
494
|
+
// this rule allows 1 or more alphabets
|
|
495
|
+
const alphabetsOnlyRegexRule = {
|
|
496
|
+
type: Skyflow.ValidationRuleType.REGEX_MATCH_RULE,
|
|
497
|
+
params:{
|
|
498
|
+
regex: /^[A-Za-z]+$/,
|
|
499
|
+
error: "Only alphabets are allowed"
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
// this rule allows input length between 4 and 6 characters
|
|
504
|
+
const lengthRule = {
|
|
505
|
+
type: Skyflow.ValidationRuleType.LENGTH_MATCH_RULE,
|
|
506
|
+
params:{
|
|
507
|
+
min: 4,
|
|
508
|
+
max: 6,
|
|
509
|
+
error: "Must be between 4 and 6 alphabets"
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
const cardHolderNameElement = collectContainer.create({
|
|
514
|
+
table: "pii_fields",
|
|
515
|
+
column: "first_name",
|
|
516
|
+
...collectStylesOptions,
|
|
517
|
+
label: "Card Holder Name",
|
|
518
|
+
placeholder: "cardholder name",
|
|
519
|
+
type: Skyflow.ElementType.INPUT_FIELD,
|
|
520
|
+
validations: [alphabetsOnlyRegexRule, lengthRule]
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
/*
|
|
524
|
+
Reset PIN - A simple example that illustrates custom validations.
|
|
525
|
+
The below code shows an example of ELEMENT_VALUE_MATCH_RULE
|
|
526
|
+
*/
|
|
527
|
+
|
|
528
|
+
// for the PIN element
|
|
529
|
+
const pinElement = collectContainer.create({
|
|
530
|
+
label: "PIN",
|
|
531
|
+
placeholder: "****",
|
|
532
|
+
type: Skyflow.ElementType.PIN,
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
// this rule allows to match the value with pinElement
|
|
536
|
+
let elementMatchRule = {
|
|
537
|
+
type: Skyflow.ValidationRuleType.ELEMENT_VALUE_MATCH_RULE,
|
|
538
|
+
params:{
|
|
539
|
+
element: pinElement,
|
|
540
|
+
error: "PIN doesn't match"
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
const confirmPinElement = collectContainer.create({
|
|
544
|
+
label: "Confirm PIN",
|
|
545
|
+
placeholder: "****",
|
|
546
|
+
type: Skyflow.ElementType.PIN,
|
|
547
|
+
validations: [elementMatchRule]
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
// mount elements on screen - errors will be shown if any of the validaitons fail
|
|
551
|
+
pinElement.mount("#collectPIN");
|
|
552
|
+
confirmPinElement.mount("#collectConfirmPIN");
|
|
553
|
+
|
|
554
|
+
```
|
|
432
555
|
### Event Listener on Collect Elements
|
|
433
556
|
|
|
434
557
|
|
|
@@ -533,7 +656,7 @@ For non-PCI use-cases, retrieving data from the vault and revealing it in the br
|
|
|
533
656
|
For retrieving using tokens, use the `detokenize(records)` method. The records parameter takes a JSON object that contains `records` to be fetched as shown below.
|
|
534
657
|
|
|
535
658
|
```javascript
|
|
536
|
-
|
|
659
|
+
const records = {
|
|
537
660
|
"records": [
|
|
538
661
|
{
|
|
539
662
|
token: "string", // token for the record to be fetched
|