skyflow-js 1.28.0 → 1.29.0-beta.2

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/README.md CHANGED
@@ -128,9 +128,10 @@ For `env` parameter, there are 2 accepted values in Skyflow.Env
128
128
  # Securely collecting data client-side
129
129
  - [**Insert data into the vault**](#insert-data-into-the-vault)
130
130
  - [**Using Skyflow Elements to collect data**](#using-skyflow-elements-to-collect-data)
131
+ - [**Using Skyflow Elements to update data**](#using-skyflow-elements-to-update-data)
131
132
  - [**Using validations on Collect Elements**](#validations)
132
133
  - [**Event Listener on Collect Elements**](#event-listener-on-collect-elements)
133
- - [**UI Error for Collect Eements**](#ui-error-for-collect-elements)
134
+ - [**UI Error for Collect Elements**](#ui-error-for-collect-elements)
134
135
  - [**Set and Clear value for Collect Elements (DEV ENV ONLY)**](#set-and-clear-value-for-collect-elements-dev-env-only)
135
136
  - [**Using Skyflow File Element to upload a file**](#using-skyflow-file-element-to-upload-a-file)
136
137
  ## Insert data into the vault
@@ -602,6 +603,211 @@ cvvElement.mount('#cvv'); //Assumes there is a div with id='#cvv' in the webpage
602
603
  ]
603
604
  }
604
605
  ```
606
+ ## Using Skyflow Elements to update data
607
+
608
+ You can update the data in a vault with Skyflow Elements. Use the following steps to securely update data.
609
+
610
+ ### Step 1: Create a container
611
+ Create a container for the form elements using the `container(Skyflow.ContainerType)` method of the Skyflow client:
612
+
613
+ ```javascript
614
+ const container = skyflowClient.container(Skyflow.ContainerType.COLLECT)
615
+ ```
616
+
617
+ ### Step 2: Create a collect Element
618
+ Create a collect element. Collect Elements are defined as follows:
619
+
620
+ ```javascript
621
+ const collectElement = {
622
+ table: "string", // Required, the table this data belongs to.
623
+ column: "string", // Required, the column into which this data should be updated.
624
+ type: Skyflow.ElementType, // Skyflow.ElementType enum.
625
+ inputStyles: {}, // Optional, styles that should be applied to the form element.
626
+ labelStyles: {}, // Optional, styles that will be applied to the label of the collect element.
627
+ errorTextStyles: {}, // Optional, styles that will be applied to the errorText of the collect element.
628
+ label: "string", // Optional, label for the form element.
629
+ placeholder: "string", // Optional, placeholder for the form element.
630
+ altText: "string", // (DEPRECATED) string that acts as an initial value for the collect element.
631
+ validations: [], // Optional, array of validation rules.
632
+ skyflowID: "string", // The skyflow_id of the record to be updated.
633
+ };
634
+ const options = {
635
+ required: false, // Optional, indicates whether the field is marked as required. Defaults to 'false'.
636
+ enableCardIcon: true, // Optional, indicates whether the element needs a card icon (only applicable for CARD_NUMBER ElementType).
637
+ format: String, // Optional, format for the element (only applicable currently for EXPIRATION_DATE ElementType).
638
+ enableCopy: false, // Optional, enables the copy icon in collect and reveal elements to copy text to clipboard. Defaults to 'false').
639
+ };
640
+ const element = container.create(collectElement, options);
641
+ ```
642
+ The `table` and `column` fields indicate which table and column the Element corresponds to.
643
+
644
+ `skyflowID` indicates the record that you want to update.
645
+
646
+ **Notes:**
647
+ - Use dot-delimited strings to specify columns nested inside JSON fields (for example, `address.street.line1`)
648
+
649
+ ### Step 3: Mount Elements to the DOM
650
+ To specify where the Elements are rendered on your page, create placeholder `<div>` elements with unique `id` tags. For instance, the form below has three empty elements with unique IDs as placeholders for three Skyflow Elements.
651
+ ```html
652
+ <form>
653
+ <div id="cardNumber" />
654
+ <br/>
655
+ <div id="expireDate" />
656
+ <br/>
657
+ <div id="cvv" />
658
+ <br/>
659
+ <button type="submit">Submit</button>
660
+ </form>
661
+ ```
662
+ Now, when you call the `mount(domElement)` method, the Elements is inserted in the specified divs. For instance, the call below inserts the Element into the div with the id "#cardNumber".
663
+ ```javascript
664
+ element.mount('#cardNumber');
665
+ ```
666
+ Use the `unmount` method to reset a Collect Element to its initial state.
667
+ ```javascript
668
+ element.unmount();
669
+ ```
670
+
671
+
672
+ ### Step 4: Update data from Elements
673
+ When the form is ready to submit, call the `collect(options?)` method on the container object. The `options` parameter takes a object of optional parameters as shown below:
674
+ - `tokens`: indicates whether tokens for the collected data should be returned or not. Defaults to 'true'
675
+ - `additionalFields`: Non-PCI elements data to update or insert into the vault which should be in the records object format.
676
+ - `upsert`: To support upsert operations while collecting data from Skyflow elements, pass the table and column marked as unique in the table.
677
+
678
+ ```javascript
679
+ const options = {
680
+ tokens: true, // Optional, indicates whether tokens for the collected data should be returned. Defaults to 'true'.
681
+ additionalFields: {
682
+ records: [
683
+ {
684
+ table: "string", // Table into which record should be updated.
685
+ fields: {
686
+ column1: "value", // Column names should match vault column names.
687
+ skyflowID: "value", // The skyflow_id of the record to be updated.
688
+ // ...additional fields here.
689
+ },
690
+ },
691
+ // ...additional records here.
692
+ ],
693
+ },// Optional
694
+ upsert: [ // Upsert operations support in the vault
695
+ {
696
+ table: "string", // Table name
697
+ column: "value", // Unique column in the table
698
+ },
699
+ ], // Optional
700
+ };
701
+ container.collect(options);
702
+ ```
703
+ **Note:** `skyflowID` is required if you want to update the data. If `skyflowID` isn't specified, the `collect(options?)` method creates a new record in the vault.
704
+
705
+ ### End to end example of updating data with Skyflow Elements
706
+
707
+ **Sample Code:**
708
+
709
+ ```javascript
710
+ //Step 1
711
+ const container = skyflowClient.container(Skyflow.ContainerType.COLLECT);
712
+
713
+ //Step 2
714
+ const cardNumberElement = container.create({
715
+ table: 'cards',
716
+ column: 'cardNumber',
717
+ inputStyles: {
718
+ base: {
719
+ color: '#1d1d1d',
720
+ },
721
+ cardIcon: {
722
+ position: 'absolute',
723
+ left: '8px',
724
+ bottom: 'calc(50% - 12px)',
725
+ },
726
+ },
727
+ labelStyles: {
728
+ base: {
729
+ fontSize: '12px',
730
+ fontWeight: 'bold',
731
+ },
732
+ },
733
+ errorTextStyles: {
734
+ base: {
735
+ color: '#f44336',
736
+ },
737
+ },
738
+ placeholder: 'Card Number',
739
+ label: 'Card Number',
740
+ type: Skyflow.ElementType.CARD_NUMBER,
741
+ skyflowID: '431eaa6c-5c15-4513-aa15-29f50babe882',
742
+ });
743
+ const cardHolderNameElement = container.create({
744
+ table: 'cards',
745
+ column: 'first_name',
746
+ inputStyles: {
747
+ base: {
748
+ color: '#1d1d1d',
749
+ },
750
+ cardIcon: {
751
+ position: 'absolute',
752
+ left: '8px',
753
+ bottom: 'calc(50% - 12px)',
754
+ },
755
+ },
756
+ labelStyles: {
757
+ base: {
758
+ fontSize: '12px',
759
+ fontWeight: 'bold',
760
+ },
761
+ },
762
+ errorTextStyles: {
763
+ base: {
764
+ color: '#f44336',
765
+ },
766
+ },
767
+ placeholder: 'Card Holder Name',
768
+ label: 'Card Holder Name',
769
+ type: Skyflow.ElementType.CARDHOLDER_NAME,
770
+ skyflowID: '431eaa6c-5c15-4513-aa15-29f50babe882',
771
+ });
772
+
773
+ // Step 3
774
+ cardNumberElement.mount('#cardNumber'); // Assumes there is a div with id='#cardNumber' in the webpage.
775
+ cardHolderNameElement.mount('#cardHolderName'); // Assumes there is a div with id='#cardHolderName' in the webpage.
776
+
777
+ // Step 4
778
+ const nonPCIRecords = {
779
+ records: [
780
+ {
781
+ table: 'cards',
782
+ fields: {
783
+ gender: 'MALE',
784
+ skyflowID: '431eaa6c-5c15-4513-aa15-29f50babe882',
785
+ },
786
+ },
787
+ ],
788
+ };
789
+
790
+ container.collect({
791
+ tokens: true,
792
+ additionalFields: nonPCIRecords,
793
+ });
794
+ ```
795
+ **Sample Response :**
796
+ ```javascript
797
+ {
798
+ "records": [
799
+ {
800
+ "table": "cards",
801
+ "fields": {
802
+ "skyflow_id": "431eaa6c-5c15-4513-aa15-29f50babe882",
803
+ "cardNumber": "f3907186-e7e2-466f-91e5-48e12c2bcbc1",
804
+ "first_name": "131e70dc-6f76-4319-bdd3-96281e051051",
805
+ "gender": "12f670af-6c7d-4837-83fb-30365fbc0b1e"
806
+ }
807
+ }
808
+ ]
809
+ }
810
+ ```
605
811
 
606
812
  ### Validations
607
813
 
@@ -1486,11 +1692,11 @@ composableContainer.on(Skyflow.EventName.SUBMIT, ()=> {
1486
1692
  - [**Using Skyflow Elements to reveal data**](#using-skyflow-elements-to-reveal-data)
1487
1693
  - [**UI Error for Reveal Elements**](#ui-error-for-reveal-elements)
1488
1694
  - [**Set token for Reveal Elements**](#set-token-for-reveal-elements)
1489
- - [**Set and clear altText for Reveal Elements**](#set-and-clear-alttext-for-reveal-elements)
1695
+ - [**Set and clear altText for Reveal Elements**](#set-and-clear-alttext-for-reveal-elements)
1490
1696
 
1491
1697
  ## Retrieving data from the vault
1492
1698
 
1493
- For non-PCI use-cases, retrieving data from the vault and revealing it in the browser can be done either using the SkyflowID's or tokens as described below
1699
+ For non-PCI use-cases, retrieving data from the vault and revealing it in the browser can be done either using the SkyflowID's, unique column values or tokens as described below
1494
1700
 
1495
1701
  - ### Using Skyflow tokens
1496
1702
  In order to retrieve data from your vault using tokens that you have previously generated for that data, you can use the `detokenize(records)` method. The records parameter takes a JSON object that contains `records` to be fetched as shown below.
@@ -1541,71 +1747,134 @@ The sample response:
1541
1747
  }
1542
1748
  ```
1543
1749
 
1544
- - ### Using Skyflow ID's
1545
- In order to retrieve data from your vault using SkyflowIDs, use the `getById(records)` method.The records parameter takes a JSON object that contains `records` to be fetched as shown below.
1750
+ - ### Using Skyflow ID's or Unique Column Values
1751
+ You can retrieve data from the vault with the get(records) method using either Skyflow IDs or unique column values.
1752
+
1753
+ The records parameter accepts a JSON object that contains an array of either Skyflow IDs or unique column names and values.
1754
+
1755
+ Note: You can use either Skyflow IDs or unique values to retrieve records. You can't use both at the same time.
1756
+
1757
+ Skyflow.RedactionTypes accepts four values:
1758
+ - `PLAIN_TEXT`
1759
+ - `MASKED`
1760
+ - `REDACTED`
1761
+ - `DEFAULT`
1762
+
1763
+ You must apply a redaction type to retrieve data.
1764
+
1765
+ #### Schema (Skyflow IDs)
1546
1766
 
1547
1767
  ```javascript
1548
- {
1549
- records: [
1550
- {
1551
- ids: string[], // Array of SkyflowID's of the records to be fetched.
1552
- table: string, // Table holding the above skyflow_id's.
1553
- redaction: Skyflow.RedactionType, // Redaction to be applied to retrieved data.
1554
- }
1555
- ]
1556
- }
1768
+ data = {
1769
+ records: [
1770
+ {
1771
+ ids: ["SKYFLOW_ID_1", "SKYFLOW_ID_2"], // List of skyflow_ids for the records to fetch.
1772
+ table: "NAME_OF_SKYFLOW_TABLE", // Name of table holding the records in the vault.
1773
+ redaction: Skyflow.RedactionType, // Redaction type to apply to retrieved data.
1774
+ },
1775
+ ],
1776
+ };
1557
1777
  ```
1778
+ #### Schema (Unique column values)
1558
1779
 
1559
- There are 4 accepted values in Skyflow.RedactionTypes:
1560
- - `PLAIN_TEXT`
1561
- - `MASKED`
1562
- - `REDACTED`
1563
- - `DEFAULT`
1780
+ ```javascript
1781
+ data = {
1782
+ records: [
1783
+ {
1784
+ table: "NAME_OF_SKYFLOW_TABLE", // Name of table holding the records in the vault.
1785
+ columnName: "UNIQUE_COLUMN_NAME", // Unique column name in the vault.
1786
+ columnValues: [ // List of given unique column values.
1787
+ "<COLUMN_VALUE_2>",
1788
+ "<COLUMN_VALUE_3>",
1789
+ ], // Required when specifying a unique column
1790
+ redaction: Skyflow.RedactionType, // Redaction type applies to retrieved data.
1564
1791
 
1565
- An example of getById call:
1792
+ },
1793
+ ],
1794
+ };
1795
+ ```
1796
+ [Example usage (Skyflow IDs)](https://github.com/skyflowapi/skyflow-js/blob/master/samples/using-script-tag/get-pure-js.html)
1566
1797
 
1567
1798
  ```javascript
1568
- skyflow.getById({
1569
- records: [
1570
- {
1571
- ids: ['f8d8a622-b557-4c6b-a12c-c5ebe0b0bfd9'],
1572
- table: 'cards',
1573
- redaction: Skyflow.RedactionType.PLAIN_TEXT,
1574
- },
1575
- {
1576
- ids: ['da26de53-95d5-4bdb-99db-8d8c66a35ff9'],
1577
- table: 'contacts',
1578
- redaction: Skyflow.RedactionType.PLAIN_TEXT,
1579
- },
1580
- ],
1799
+ skyflow.get({
1800
+ records: [
1801
+ {
1802
+ ids: ["f8d8a622-b557-4c6b-a12c-c5ebe0b0bfd9"],
1803
+ table: "cards",
1804
+ redaction: Skyflow.RedactionType.PLAIN_TEXT,
1805
+ },
1806
+ {
1807
+ ids: ["da26de53-95d5-4bdb-99db-8d8c66a35ff9"],
1808
+ table: "contacts",
1809
+ redaction: Skyflow.RedactionType.PLAIN_TEXT,
1810
+ },
1811
+ ],
1581
1812
  });
1582
1813
  ```
1814
+ Example response
1583
1815
 
1584
- The sample response:
1816
+ ```javascript
1817
+ {
1818
+ "records": [
1819
+ {
1820
+ "fields": {
1821
+ "card_number": "4111111111111111",
1822
+ "cvv": "127",
1823
+ "expiry_date": "11/2035",
1824
+ "fullname": "myname",
1825
+ "id": "f8d8a622-b557-4c6b-a12c-c5ebe0b0bfd9"
1826
+ },
1827
+ "table": "cards"
1828
+ }
1829
+ ],
1830
+ "errors": [
1831
+ {
1832
+ "error": {
1833
+ "code": "404",
1834
+ "description": "No Records Found"
1835
+ },
1836
+ "ids": ["da26de53-95d5-4bdb-99db-8d8c66a35ff9"]
1837
+ }
1838
+ ]
1839
+ }
1840
+ ```
1841
+ [Example usage (Unique column values)](https://github.com/skyflowapi/skyflow-js/blob/master/samples/using-script-tag/get-pure-js.html)
1585
1842
 
1843
+ ```javascript
1844
+ skyflow.get({
1845
+ records: [
1846
+ {
1847
+ table: "cards",
1848
+ redaction: RedactionType.PLAIN_TEXT,
1849
+ columnName: "card_id",
1850
+ columnValues: ["123", "456"],
1851
+ }
1852
+ ],
1853
+ });
1854
+ ```
1855
+ Sample response:
1586
1856
  ```javascript
1587
1857
  {
1588
- "records": [
1589
- {
1590
- "fields": {
1591
- "card_number": "4111111111111111",
1592
- "cvv": "127",
1593
- "expiry_date": "11/2035",
1594
- "fullname": "myname",
1595
- "id": "f8d8a622-b557-4c6b-a12c-c5ebe0b0bfd9"
1596
- },
1597
- "table": "cards"
1598
- }
1599
- ],
1600
- "errors": [
1601
- {
1602
- "error": {
1603
- "code": "404",
1604
- "description": "No Records Found"
1605
- },
1606
- "ids": ["da26de53-95d5-4bdb-99db-8d8c66a35ff9"]
1607
- }
1608
- ]
1858
+ "records": [
1859
+ {
1860
+ "fields": {
1861
+ "card_id": "123",
1862
+ "expiry_date": "11/35",
1863
+ "fullname": "myname",
1864
+ "id": "f8d2-b557-4c6b-a12c-c5ebfd9"
1865
+ },
1866
+ "table": "cards"
1867
+ },
1868
+ {
1869
+ "fields": {
1870
+ "card_id": "456",
1871
+ "expiry_date": "10/23",
1872
+ "fullname": "sam",
1873
+ "id": "da53-95d5-4bdb-99db-8d8c5ff9"
1874
+ },
1875
+ "table": "cards"
1876
+ }
1877
+ ]
1609
1878
  }
1610
1879
  ```
1611
1880