skyflow-js 1.3.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 CHANGED
@@ -1,6 +1,36 @@
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
+
14
+ ## [1.6.0] - 2021-11-16
15
+
16
+ ### Added
17
+ - `enableCardIcon` option to configure Card Icon visibility
18
+ - `INPUT_FIELD` Element type for custom UI elements
19
+ - `unmount` method to reset collect element to initial state
20
+
21
+ ### Changed
22
+ - New VISA Card Icon with updated Logo
23
+
24
+ ## [1.5.0] - 2021-11-10
25
+
26
+ ### Changed
27
+ - Renamed invokeGateway to invokeConnection
28
+ - Renamed gatewayURL to connectionURL
29
+ ## [1.4.0] - 2021-10-26
30
+
31
+ ### Added
32
+
33
+ Detecting card type and displaying icon in the card number element
4
34
 
5
35
  ## [1.3.0] - 2021-10-19
6
36
 
package/README.md CHANGED
@@ -8,7 +8,7 @@ Skyflow’s Javascript SDK can be used to securely collect, tokenize, and reveal
8
8
  - [**Initializing Skyflow.js**](#Initializing-Skyflowjs)
9
9
  - [**Securely collecting data client-side**](#Securely-collecting-data-client-side)
10
10
  - [**Securely revealing data client-side**](#Securely-revealing-data-client-side)
11
- - [**Securely invoking gateway client-side**](#Securely-invoking-gateway-client-side)
11
+ - [**Securely invoking Connections client-side**](#Securely-invoking-Connections-client-side)
12
12
 
13
13
  ---
14
14
 
@@ -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
- var records = {
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
- var options = {
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
- var collectElement = {
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,11 +210,12 @@ 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**:
215
217
  - Use dot delimited strings to specify columns nested inside JSON fields (e.g. `address.street.line1`)
216
- - `table` and `column` are optional only if the element is being used in invokeGateway()
218
+ - `table` and `column` are optional only if the element is being used in invokeConnection()
217
219
 
218
220
  The `inputStyles` field accepts a style object which consists of CSS properties that should be applied to the form element in the following states:
219
221
  - `base`: all other variants inherit from these styles
@@ -272,16 +274,20 @@ errorTextStyles: {
272
274
  }
273
275
  ```
274
276
 
275
- Finally, the `type` field takes a Skyflow ElementType. Each type applies the appropriate regex and validations to the form element. There are currently 4 types:
277
+ Finally, the `type` field takes a Skyflow ElementType. Each type applies the appropriate regex and validations to the form element. There are currently 5 types:
276
278
  - `CARDHOLDER_NAME`
277
279
  - `CARD_NUMBER`
278
280
  - `EXPIRATION_DATE`
279
281
  - `CVV`
282
+ - `INPUT_FIELD`
283
+ - `PIN`
284
+
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.
280
286
 
281
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:
282
288
 
283
289
  ```javascript
284
- var collectElement = {
290
+ const collectElement = {
285
291
  table: "string", //the table this data belongs to
286
292
  column: "string", //the column into which this data should be inserted
287
293
  type: Skyflow.ElementType, //Skyflow.ElementType enum
@@ -291,10 +297,12 @@ var collectElement = {
291
297
  label: "string", //optional label for the form element
292
298
  placeholder: "string", //optional placeholder for the form element
293
299
  altText: "string" //optional string that acts as an initial value for the collect element
300
+ validations:[] // optional array of validation rules
294
301
  }
295
302
 
296
- var options = {
297
- required: false //indicates whether the field is marked as required. Defaults to 'false'
303
+ const options = {
304
+ required: false, //indicates whether the field is marked as required. Defaults to 'false'
305
+ enableCardIcon: true // indicates whether card icon should be enabled (only for CARD_NUMBER type Element)
298
306
  }
299
307
 
300
308
  const element = container.create(collectElement, options)
@@ -322,7 +330,10 @@ Now, when the `mount(domElement)` method of the Element is called, the Element w
322
330
  ```javascript
323
331
  element.mount("#cardNumber")
324
332
  ```
325
-
333
+ you can use the `unmount` method to reset any collect element to it's initial state.
334
+ ```javascript
335
+ element.unmount();
336
+ ```
326
337
 
327
338
  ### Step 4: Collect data from Elements
328
339
 
@@ -332,7 +343,7 @@ When the form is ready to be submitted, call the `collect(options?)` method on t
332
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.
333
344
 
334
345
  ```javascript
335
- var options = {
346
+ const options = {
336
347
  tokens: true //optional, indicates whether tokens for the collected data should be returned. Defaults to 'true'
337
348
  additionalFields: {
338
349
  records: [
@@ -421,7 +432,126 @@ container.collect({
421
432
  }
422
433
  ```
423
434
 
435
+ ### Validations
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
+ });
424
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
+ ```
425
555
  ### Event Listener on Collect Elements
426
556
 
427
557
 
@@ -526,7 +656,7 @@ For non-PCI use-cases, retrieving data from the vault and revealing it in the br
526
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.
527
657
 
528
658
  ```javascript
529
- var records = {
659
+ const records = {
530
660
  "records": [
531
661
  {
532
662
  token: "string", // token for the record to be fetched
@@ -645,7 +775,7 @@ const container = skyflowClient.container(Skyflow.ContainerType.REVEAL)
645
775
  Then define a Skyflow Element to reveal data as shown below.
646
776
 
647
777
  ```javascript
648
- var revealElement = {
778
+ const revealElement = {
649
779
  token: "string", //optional, token of the data being revealed
650
780
  inputStyles: {}, //optional styles to be applied to the element
651
781
  labelStyles: {}, //optional, styles to be applied to the label of the reveal element
@@ -655,7 +785,7 @@ var revealElement = {
655
785
  }
656
786
  ```
657
787
  `Note`:
658
- - `token` is optional only if it is being used in invokeGateway()
788
+ - `token` is optional only if it is being used in invokeConnection()
659
789
 
660
790
  The `inputStyles`, `labelStyles` and `errorTextStyles` parameters accepts a styles object as described in the [previous section](#step-2-create-a-collect-element) for collecting data but only a single variant is available i.e. base.
661
791
 
@@ -693,7 +823,7 @@ errorTextStyles: {
693
823
  Once you've defined a Skyflow Element, you can use the `create(element)` method of the container to create the Element as shown below:
694
824
 
695
825
  ```javascript
696
- const element = container.create(revealElement, options={})
826
+ const element = container.create(revealElement)
697
827
  ```
698
828
 
699
829
  ### Step 3: Mount Elements to the DOM
@@ -792,12 +922,12 @@ The response below shows that some tokens assigned to the reveal elements get re
792
922
  }
793
923
  ```
794
924
 
795
- # Securely invoking gateway client-side
796
- Using Skyflow gateway, end-user applications can integrate checkout/card issuance flow without any of their apps/systems touching the PCI compliant fields like cvv, card number. To invoke gateway, use the `invokeGateway(gatewayConfig)` method of the Skyflow client.
925
+ # Securely invoking Connections client-side
926
+ Using Skyflow Connections, end-user applications can integrate checkout/card issuance flow without any of their apps/systems touching the PCI compliant fields like cvv, card number. To invoke Connections, use the `invokeConnection(connectionConfig)` method of the Skyflow client.
797
927
 
798
928
  ```javascript
799
- const gatewayConfig = {
800
- gatewayURL: string, // gateway url recevied when creating a skyflow gateway integration
929
+ const connectionConfig = {
930
+ connectionURL: string, // connection url recevied when creating a skyflow Connection integration
801
931
  methodName: Skyflow.RequestMethod,
802
932
  pathParams: any, // optional
803
933
  queryParams: any, // optional
@@ -806,7 +936,7 @@ const gatewayConfig = {
806
936
  responseBody: any // optional
807
937
  }
808
938
 
809
- const response = skyflowClient.invokeGateway(gatewayConfig);
939
+ const response = skyflowClient.invokeConnection(connectionConfig);
810
940
  ```
811
941
  `methodName` supports the following methods:
812
942
 
@@ -816,14 +946,14 @@ const response = skyflowClient.invokeGateway(gatewayConfig);
816
946
  - PATCH
817
947
  - DELETE
818
948
 
819
- **pathParams, queryParams, requestHeader, requestBody** are the JSON objects that will be sent through the gateway integration url.
949
+ **pathParams, queryParams, requestHeader, requestBody** are the JSON objects that will be sent through the Connection integration url.
820
950
 
821
951
  The values in the above parameters can contain collect elements, reveal elements or actual values. When elements are provided inplace of values, they get replaced with the value entered in the collect elements or value present in the reveal elements
822
952
 
823
953
  **responseBody**:
824
954
  It is a JSON object that specifies where to render the response in the UI. The values in the responseBody can contain collect elements or reveal elements.
825
955
 
826
- Sample use-cases on using invokeGateway():
956
+ Sample use-cases on using invokeConnection():
827
957
 
828
958
  ### Sample use-case 1:
829
959
 
@@ -852,8 +982,8 @@ const cvvElement = collectContainer.create({
852
982
  cvvElement.mount("#cvv")
853
983
 
854
984
  // step 4
855
- const gatewayConfig = {
856
- gatewayURL: "https://area51.gateway.skyflow.com/v1/gateway/inboundRoutes/abc-1213/v2/pay”,
985
+ const connectionConfig = {
986
+ connectionURL: <connection_url>,
857
987
  methodName: Skyflow.RequestMethod.POST,
858
988
  requestBody: {
859
989
  card_number: cardNumberElement, //it can be skyflow element(collect or reveal) or actual value
@@ -861,7 +991,7 @@ const gatewayConfig = {
861
991
  }
862
992
  }
863
993
 
864
- const response = skyflowClient.invokeGateway(gatewayConfig);
994
+ const response = skyflowClient.invokeConnection(connectionConfig);
865
995
  ```
866
996
 
867
997
  Sample Response:
@@ -875,7 +1005,7 @@ In the above example, CVV is being collected from the user input at the time of
875
1005
 
876
1006
  `Note:`
877
1007
  - card_number can be either container element or plain text value (tokens or actual value)
878
- - `table` and `column` names are not required for creating collect element, if it is used for invokeGateway method, since they will not be stored in the vault
1008
+ - `table` and `column` names are not required for creating collect element, if it is used for invokeConnection method, since they will not be stored in the vault
879
1009
 
880
1010
  ### Sample use-case 2:
881
1011
 
@@ -904,8 +1034,8 @@ const expiryDateElement = collectContainer.create({
904
1034
  expiryDateElement.mount("#expirationDate")
905
1035
 
906
1036
  //step 4
907
- const gatewayConfig = {
908
- gatewayURL: "https://area51.gateway.skyflow.com/v1/gateway/inboundRoutes/abc-1213/cards/{card_number}/cvv2generation",
1037
+ const connectionConfig = {
1038
+ connectionURL: <connection_url>,
909
1039
  methodName: Skyflow.RequestMethod.POST,
910
1040
  pathParams: {
911
1041
  card_number: "0905-8672-0773-0628" //it can be skyflow element(collect/reveal) or token or actual value
@@ -915,13 +1045,13 @@ const gatewayConfig = {
915
1045
  },
916
1046
  responseBody: {
917
1047
  resource: {
918
- cvv2: cvvElement // pass the element where the cvv response from the gateway will be mounted
1048
+ cvv2: cvvElement // pass the element where the cvv response from the Connection will be mounted
919
1049
  }
920
1050
  }
921
1051
  }
922
1052
  }
923
1053
 
924
- const response = skyflowClient.invokeGateway(gatewayConfig);
1054
+ const response = skyflowClient.invokeConnection(connectionConfig);
925
1055
  ```
926
1056
 
927
1057
  Sample Response:
@@ -933,5 +1063,5 @@ Sample Response:
933
1063
  ```
934
1064
 
935
1065
  `Note`:
936
- - `token` is optional for creating reveal element, if it is used for invokeGateway
937
- - responseBody contains collect or reveal elements to render the response from the gateway on UI
1066
+ - `token` is optional for creating reveal element, if it is used for invokeConnection
1067
+ - responseBody contains collect or reveal elements to render the response from the Connection on UI