skyflow-js 1.23.0 → 1.24.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/README.md +432 -433
- package/dist/sdkNodeBuild/index.js +1 -1
- package/dist/sdkNodeBuild/index.js.LICENSE.txt +9 -0
- package/dist/sdkNodeBuild/index.js.LICENSE.txt.gz +0 -0
- package/dist/sdkNodeBuild/index.js.gz +0 -0
- package/package.json +3 -3
- package/types/core/constants.d.ts +24 -0
- package/types/core/external/collect/collect-container.d.ts +1 -0
- package/types/core/external/collect/collect-element.d.ts +3 -1
- package/types/core/external/collect/compose-collect-container.d.ts +32 -0
- package/types/core/external/collect/compose-collect-element.d.ts +7 -0
- package/types/core/external/reveal/reveal-container.d.ts +1 -0
- package/types/core/external/skyflow-container.d.ts +2 -1
- package/types/core/internal/iframe-form/index.d.ts +1 -0
- package/types/core-utils/reveal.d.ts +2 -1
- package/types/skyflow.d.ts +6 -4
- package/types/utils/common/index.d.ts +9 -1
- package/types/utils/constants.d.ts +88 -0
- package/types/utils/helpers/index.d.ts +2 -0
- package/types/utils/logs.d.ts +27 -0
- package/types/utils/validators/index.d.ts +3 -1
package/README.md
CHANGED
|
@@ -34,17 +34,17 @@ npm install skyflow-js
|
|
|
34
34
|
# Initializing Skyflow.js
|
|
35
35
|
Use the `init()` method to initialize a Skyflow client as shown below.
|
|
36
36
|
```javascript
|
|
37
|
-
import Skyflow from
|
|
37
|
+
import Skyflow from 'skyflow-js' // If using script tag, this line is not required.
|
|
38
38
|
|
|
39
39
|
const skyflowClient = Skyflow.init({
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
})
|
|
40
|
+
vaultID: 'string', // Id of the vault that the client should connect to.
|
|
41
|
+
vaultURL: 'string', // URL of the vault that the client should connect to.
|
|
42
|
+
getBearerToken: helperFunc, // Helper function that retrieves a Skyflow bearer token from your backend.
|
|
43
|
+
options: {
|
|
44
|
+
logLevel: Skyflow.LogLevel, // Optional, if not specified default is ERROR.
|
|
45
|
+
env: Skyflow.Env // Optional, if not specified default is PROD.
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
48
|
```
|
|
49
49
|
For the `getBearerToken` parameter, pass in a helper function that retrieves a Skyflow bearer token from your backend. This function will be invoked when the SDK needs to insert or retrieve data from the vault. A sample implementation is shown below:
|
|
50
50
|
|
|
@@ -52,39 +52,38 @@ For example, if the response of the consumer tokenAPI is in the below format
|
|
|
52
52
|
|
|
53
53
|
```
|
|
54
54
|
{
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
"accessToken": string,
|
|
56
|
+
"tokenType": string
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
```
|
|
60
60
|
then, your getBearerToken Implementation should be as below
|
|
61
61
|
|
|
62
62
|
```javascript
|
|
63
|
-
getBearerToken
|
|
63
|
+
const getBearerToken = () => {
|
|
64
64
|
return new Promise((resolve, reject) => {
|
|
65
65
|
const Http = new XMLHttpRequest();
|
|
66
66
|
|
|
67
67
|
Http.onreadystatechange = () => {
|
|
68
|
-
if (Http.readyState
|
|
69
|
-
if (Http.status
|
|
68
|
+
if (Http.readyState === 4) {
|
|
69
|
+
if (Http.status === 200) {
|
|
70
70
|
const response = JSON.parse(Http.responseText);
|
|
71
71
|
resolve(response.accessToken);
|
|
72
72
|
} else {
|
|
73
|
-
reject(
|
|
73
|
+
reject('Error occured');
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
};
|
|
77
77
|
|
|
78
|
-
Http.onerror =
|
|
79
|
-
reject(
|
|
78
|
+
Http.onerror = error => {
|
|
79
|
+
reject('Error occured');
|
|
80
80
|
};
|
|
81
81
|
|
|
82
|
-
const url =
|
|
83
|
-
Http.open(
|
|
82
|
+
const url = 'https://api.acmecorp.com/skyflowToken';
|
|
83
|
+
Http.open('GET', url);
|
|
84
84
|
Http.send();
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
}
|
|
85
|
+
});
|
|
86
|
+
};
|
|
88
87
|
|
|
89
88
|
```
|
|
90
89
|
For `logLevel` parameter, there are 4 accepted values in Skyflow.LogLevel
|
|
@@ -139,42 +138,43 @@ To insert data into the vault, use the `insert(records, options?)` method of the
|
|
|
139
138
|
|
|
140
139
|
```javascript
|
|
141
140
|
const records = {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
table:
|
|
141
|
+
records: [
|
|
142
|
+
{
|
|
143
|
+
table: 'string', // Table into which record should be inserted.
|
|
145
144
|
fields: {
|
|
146
|
-
column1:
|
|
145
|
+
column1: 'value', // Column names should match vault column names.
|
|
147
146
|
//...additional fields here
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
]
|
|
152
|
-
}
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
// ...additional records here.
|
|
150
|
+
],
|
|
151
|
+
};
|
|
153
152
|
|
|
154
153
|
const options = {
|
|
155
|
-
tokens: true, //
|
|
156
|
-
upsert: [ //
|
|
154
|
+
tokens: true, // Indicates whether or not tokens should be returned for the inserted data. Defaults to 'true'
|
|
155
|
+
upsert: [ // Upsert operations support in the vault
|
|
157
156
|
{
|
|
158
|
-
table:
|
|
159
|
-
column:
|
|
157
|
+
table: 'string', // Table name
|
|
158
|
+
column: 'value', // Unique column in the table
|
|
160
159
|
}
|
|
161
160
|
]
|
|
162
161
|
}
|
|
163
162
|
|
|
164
|
-
skyflowClient.insert(records, options)
|
|
163
|
+
skyflowClient.insert(records, options);
|
|
165
164
|
```
|
|
166
165
|
|
|
167
166
|
An [example](https://github.com/skyflowapi/skyflow-js/blob/master/samples/using-script-tag/pure-js.html) of an insert call:
|
|
168
167
|
```javascript
|
|
169
168
|
skyflowClient.insert({
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
169
|
+
records: [
|
|
170
|
+
{
|
|
171
|
+
table: 'cards',
|
|
172
|
+
fields: {
|
|
173
|
+
cardNumber: '41111111111',
|
|
174
|
+
cvv: '123',
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
178
|
});
|
|
179
179
|
```
|
|
180
180
|
|
|
@@ -210,17 +210,17 @@ const container = skyflowClient.container(Skyflow.ContainerType.COLLECT)
|
|
|
210
210
|
A Skyflow collect Element is defined as shown below:
|
|
211
211
|
|
|
212
212
|
```javascript
|
|
213
|
-
const collectElement =
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
213
|
+
const collectElement = {
|
|
214
|
+
table: 'string', // Required, the table this data belongs to.
|
|
215
|
+
column: 'string', // Required, the column into which this data should be inserted.
|
|
216
|
+
type: Skyflow.ElementType, // Skyflow.ElementType enum.
|
|
217
|
+
inputStyles: {}, // Optional, styles that should be applied to the form element.
|
|
218
|
+
labelStyles: {}, // Optional, styles that will be applied to the label of the collect element.
|
|
219
|
+
errorTextStyles: {}, // Optional, styles that will be applied to the errorText of the collect element.
|
|
220
|
+
label: 'string', // Optional, label for the form element.
|
|
221
|
+
placeholder: 'string', // Optional, placeholder for the form element.
|
|
222
|
+
altText: 'string', // (DEPRECATED) string that acts as an initial value for the collect element.
|
|
223
|
+
validations: [], // Optional, array of validation rules.
|
|
224
224
|
}
|
|
225
225
|
```
|
|
226
226
|
The `table` and `column` fields indicate which table and column in the vault the Element corresponds to.
|
|
@@ -241,31 +241,31 @@ Styles are specified with [JSS](https://cssinjs.org/?v=v10.7.1).
|
|
|
241
241
|
|
|
242
242
|
An example of a inputStyles object:
|
|
243
243
|
```javascript
|
|
244
|
-
inputStyles:{
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
244
|
+
inputStyles: {
|
|
245
|
+
base: {
|
|
246
|
+
border: '1px solid #eae8ee',
|
|
247
|
+
padding: '10px 16px',
|
|
248
|
+
borderRadius: '4px',
|
|
249
|
+
color: '#1d1d1d',
|
|
250
|
+
},
|
|
251
|
+
complete: {
|
|
252
|
+
color: '#4caf50',
|
|
253
|
+
},
|
|
254
|
+
empty: {},
|
|
255
|
+
focus: {},
|
|
256
|
+
invalid: {
|
|
257
|
+
color: '#f44336',
|
|
258
|
+
},
|
|
259
|
+
cardIcon: {
|
|
260
|
+
position: 'absolute',
|
|
261
|
+
left: '8px',
|
|
262
|
+
bottom: 'calc(50% - 12px)',
|
|
263
|
+
},
|
|
264
|
+
copyIcon: {
|
|
265
|
+
position: 'absolute',
|
|
266
|
+
right: '8px',
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
269
|
```
|
|
270
270
|
The states that are available for `labelStyles` are `base` and `focus`.
|
|
271
271
|
|
|
@@ -273,14 +273,14 @@ An example of a labelStyles object:
|
|
|
273
273
|
|
|
274
274
|
```javascript
|
|
275
275
|
labelStyles: {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
276
|
+
base: {
|
|
277
|
+
fontSize: '12px',
|
|
278
|
+
fontWeight: 'bold',
|
|
279
|
+
},
|
|
280
|
+
focus: {
|
|
281
|
+
color: '#1d1d1d',
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
284
|
```
|
|
285
285
|
|
|
286
286
|
The state that is available for `errorTextStyles` is only the `base` state, it shows up when there is some error in the collect element.
|
|
@@ -289,10 +289,10 @@ An example of a errorTextStyles object:
|
|
|
289
289
|
|
|
290
290
|
```javascript
|
|
291
291
|
errorTextStyles: {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
}
|
|
292
|
+
base: {
|
|
293
|
+
color: '#f44336',
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
296
|
```
|
|
297
297
|
|
|
298
298
|
Finally, the `type` field takes a Skyflow ElementType. Each type applies the appropriate regex and validations to the form element. There are currently 8 types:
|
|
@@ -313,11 +313,11 @@ Along with CollectElement we can define other options which takes a object of op
|
|
|
313
313
|
|
|
314
314
|
```javascript
|
|
315
315
|
const options = {
|
|
316
|
-
required: false,
|
|
317
|
-
enableCardIcon: true, //
|
|
318
|
-
format: String,
|
|
319
|
-
enableCopy: false
|
|
320
|
-
}
|
|
316
|
+
required: false, // Optional, indicates whether the field is marked as required. Defaults to 'false'.
|
|
317
|
+
enableCardIcon: true, // Optional, indicates whether card icon should be enabled (only applicable for CARD_NUMBER ElementType).
|
|
318
|
+
format: String, // Optional, format for the element (only applicable currently for EXPIRATION_DATE ElementType).
|
|
319
|
+
enableCopy: false, // Optional, enables the copy icon in collect and reveal elements to copy text to clipboard. Defaults to 'false').
|
|
320
|
+
};
|
|
321
321
|
```
|
|
322
322
|
|
|
323
323
|
`required` parameter indicates whether the field is marked as required or not. If not provided, it defaults to false
|
|
@@ -343,27 +343,27 @@ The values that are accepted for `EXPIRATION_YEAR` are
|
|
|
343
343
|
Once the Element object and options 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 and options as defined above:
|
|
344
344
|
|
|
345
345
|
```javascript
|
|
346
|
-
const collectElement =
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
346
|
+
const collectElement = {
|
|
347
|
+
table: 'string', // Required, the table this data belongs to.
|
|
348
|
+
column: 'string', // Required, the column into which this data should be inserted.
|
|
349
|
+
type: Skyflow.ElementType, // Skyflow.ElementType enum.
|
|
350
|
+
inputStyles: {}, // Optional, styles that should be applied to the form element.
|
|
351
|
+
labelStyles: {}, // Optional, styles that will be applied to the label of the collect element.
|
|
352
|
+
errorTextStyles: {}, // Optional, styles that will be applied to the errorText of the collect element.
|
|
353
|
+
label: 'string', // Optional, label for the form element.
|
|
354
|
+
placeholder: 'string', // Optional, placeholder for the form element.
|
|
355
|
+
altText: 'string', // (DEPRECATED) string that acts as an initial value for the collect element.
|
|
356
|
+
validations: [], // Optional, array of validation rules.
|
|
357
357
|
}
|
|
358
358
|
|
|
359
359
|
const options = {
|
|
360
|
-
required: false,
|
|
361
|
-
enableCardIcon: true, //
|
|
362
|
-
format: String,
|
|
363
|
-
enableCopy: false
|
|
364
|
-
}
|
|
360
|
+
required: false, // Optional, indicates whether the field is marked as required. Defaults to 'false'.
|
|
361
|
+
enableCardIcon: true, // Optional, indicates whether card icon should be enabled (only applicable for CARD_NUMBER ElementType).
|
|
362
|
+
format: String, // Optional, format for the element (only applicable currently for EXPIRATION_DATE ElementType).
|
|
363
|
+
enableCopy: false, // Optional, enables the copy icon in collect and reveal elements to copy text to clipboard. Defaults to 'false').
|
|
364
|
+
};
|
|
365
365
|
|
|
366
|
-
const element = container.create(collectElement, options)
|
|
366
|
+
const element = container.create(collectElement, options);
|
|
367
367
|
```
|
|
368
368
|
|
|
369
369
|
### Step 3: Mount Elements to the DOM
|
|
@@ -386,7 +386,7 @@ To specify where the Elements will be rendered on your page, create placeholder
|
|
|
386
386
|
Now, when the `mount(domElement)` method of the Element is called, the Element will be inserted in the specified div. For instance, the call below will insert the Element into the div with the id "#cardNumber".
|
|
387
387
|
|
|
388
388
|
```javascript
|
|
389
|
-
element.mount(
|
|
389
|
+
element.mount('#cardNumber');
|
|
390
390
|
```
|
|
391
391
|
you can use the `unmount` method to reset any collect element to it's initial state.
|
|
392
392
|
```javascript
|
|
@@ -403,22 +403,29 @@ When the form is ready to be submitted, call the `collect(options?)` method on t
|
|
|
403
403
|
|
|
404
404
|
```javascript
|
|
405
405
|
const options = {
|
|
406
|
-
tokens: true
|
|
407
|
-
additionalFields: {
|
|
406
|
+
tokens: true, // Optional, indicates whether tokens for the collected data should be returned. Defaults to 'true'.
|
|
407
|
+
additionalFields: {
|
|
408
408
|
records: [
|
|
409
409
|
{
|
|
410
|
-
table:
|
|
410
|
+
table: 'string', // Table into which record should be inserted.
|
|
411
411
|
fields: {
|
|
412
|
-
column1:
|
|
413
|
-
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
]
|
|
418
|
-
}, //
|
|
419
|
-
|
|
412
|
+
column1: 'value', // Column names should match vault column names.
|
|
413
|
+
// ...additional fields here.
|
|
414
|
+
},
|
|
415
|
+
},
|
|
416
|
+
// ...additional records here.
|
|
417
|
+
],
|
|
418
|
+
}, // Optional
|
|
419
|
+
upsert: [
|
|
420
|
+
// Upsert operations support in the vault
|
|
421
|
+
{
|
|
422
|
+
table: 'string', // Table name
|
|
423
|
+
column: 'value', // Unique column in the table
|
|
424
|
+
},
|
|
425
|
+
], // Optional
|
|
426
|
+
};
|
|
420
427
|
|
|
421
|
-
container.collect(options)
|
|
428
|
+
container.collect(options);
|
|
422
429
|
```
|
|
423
430
|
|
|
424
431
|
### End to end example of collecting data with Skyflow Elements
|
|
@@ -427,58 +434,59 @@ container.collect(options)
|
|
|
427
434
|
|
|
428
435
|
```javascript
|
|
429
436
|
//Step 1
|
|
430
|
-
const container = skyflowClient.container(Skyflow.ContainerType.COLLECT)
|
|
437
|
+
const container = skyflowClient.container(Skyflow.ContainerType.COLLECT);
|
|
431
438
|
|
|
432
439
|
//Step 2
|
|
433
|
-
const element = container.create({
|
|
434
|
-
table:
|
|
435
|
-
column:
|
|
440
|
+
const element = container.create({
|
|
441
|
+
table: 'cards',
|
|
442
|
+
column: 'cardNumber',
|
|
436
443
|
inputstyles: {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
+
base: {
|
|
445
|
+
color: '#1d1d1d',
|
|
446
|
+
},
|
|
447
|
+
cardIcon: {
|
|
448
|
+
position: 'absolute',
|
|
449
|
+
left: '8px',
|
|
450
|
+
bottom: 'calc(50% - 12px)',
|
|
444
451
|
},
|
|
445
452
|
},
|
|
446
453
|
labelStyles: {
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
454
|
+
base: {
|
|
455
|
+
fontSize: '12px',
|
|
456
|
+
fontWeight: 'bold',
|
|
457
|
+
},
|
|
451
458
|
},
|
|
452
459
|
errorTextStyles: {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
460
|
+
base: {
|
|
461
|
+
color: '#f44336',
|
|
462
|
+
},
|
|
456
463
|
},
|
|
457
|
-
placeholder:
|
|
458
|
-
label:
|
|
459
|
-
type: Skyflow.ElementType.CARD_NUMBER
|
|
460
|
-
})
|
|
464
|
+
placeholder: 'Card Number',
|
|
465
|
+
label: 'card_number',
|
|
466
|
+
type: Skyflow.ElementType.CARD_NUMBER,
|
|
467
|
+
});
|
|
461
468
|
|
|
462
469
|
// Step 3
|
|
463
|
-
element.mount(
|
|
470
|
+
element.mount('#cardNumber'); // Assumes there is a div with id='#cardNumber' in the webpage.
|
|
464
471
|
|
|
465
472
|
// Step 4
|
|
466
473
|
|
|
467
474
|
const nonPCIRecords = {
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
475
|
+
records: [
|
|
476
|
+
{
|
|
477
|
+
table: 'cards',
|
|
478
|
+
fields: {
|
|
479
|
+
gender: 'MALE',
|
|
480
|
+
},
|
|
481
|
+
},
|
|
482
|
+
],
|
|
483
|
+
};
|
|
477
484
|
|
|
478
485
|
container.collect({
|
|
479
486
|
tokens: true,
|
|
480
|
-
additionalFields: nonPCIRecords
|
|
481
|
-
})
|
|
487
|
+
additionalFields: nonPCIRecords,
|
|
488
|
+
});
|
|
489
|
+
|
|
482
490
|
```
|
|
483
491
|
|
|
484
492
|
**Sample Response :**
|
|
@@ -563,7 +571,7 @@ const cvvElement = container.create({
|
|
|
563
571
|
|
|
564
572
|
// Step 3
|
|
565
573
|
cardNumberElement.mount("#cardNumber") //Assumes there is a div with id="#cardNumber" in the webpage.
|
|
566
|
-
cvvElement.mount("#cvv"); //
|
|
574
|
+
cvvElement.mount("#cvv"); //Assumes there is a div with id="#cvv" in the webpage.
|
|
567
575
|
|
|
568
576
|
// Step 4
|
|
569
577
|
container.collect({
|
|
@@ -615,7 +623,7 @@ const regexMatchRule = {
|
|
|
615
623
|
type: Skyflow.ValidationRuleType.REGEX_MATCH_RULE,
|
|
616
624
|
params: {
|
|
617
625
|
regex: RegExp,
|
|
618
|
-
error: string //
|
|
626
|
+
error: string // Optional, default error is 'VALIDATION FAILED'.
|
|
619
627
|
}
|
|
620
628
|
}
|
|
621
629
|
```
|
|
@@ -626,9 +634,9 @@ const regexMatchRule = {
|
|
|
626
634
|
const lengthMatchRule = {
|
|
627
635
|
type: Skyflow.ValidationRuleType.LENGTH_MATCH_RULE,
|
|
628
636
|
params: {
|
|
629
|
-
min : number, //
|
|
630
|
-
max : number, //
|
|
631
|
-
error: string //
|
|
637
|
+
min : number, // Optional.
|
|
638
|
+
max : number, // Optional.
|
|
639
|
+
error: string // Optional, default error is 'VALIDATION FAILED'.
|
|
632
640
|
}
|
|
633
641
|
}
|
|
634
642
|
```
|
|
@@ -640,7 +648,7 @@ const elementValueMatchRule = {
|
|
|
640
648
|
type: Skyflow.ValidationRuleType.ELEMENT_VALUE_MATCH_RULE,
|
|
641
649
|
params: {
|
|
642
650
|
element: CollectElement,
|
|
643
|
-
error: string //
|
|
651
|
+
error: string // Optional, default error is 'VALIDATION FAILED'.
|
|
644
652
|
}
|
|
645
653
|
}
|
|
646
654
|
```
|
|
@@ -653,71 +661,72 @@ The Sample [code snippet](https://github.com/skyflowapi/skyflow-js/blob/master/s
|
|
|
653
661
|
Adding REGEX_MATCH_RULE , LENGTH_MATCH_RULE to collect element.
|
|
654
662
|
*/
|
|
655
663
|
|
|
656
|
-
//
|
|
664
|
+
// This rule allows 1 or more alphabets.
|
|
657
665
|
const alphabetsOnlyRegexRule = {
|
|
658
666
|
type: Skyflow.ValidationRuleType.REGEX_MATCH_RULE,
|
|
659
|
-
params:{
|
|
667
|
+
params: {
|
|
660
668
|
regex: /^[A-Za-z]+$/,
|
|
661
|
-
error:
|
|
662
|
-
}
|
|
663
|
-
};
|
|
669
|
+
error: 'Only alphabets are allowed',
|
|
670
|
+
},
|
|
671
|
+
};
|
|
664
672
|
|
|
665
|
-
//
|
|
673
|
+
// This rule allows input length between 4 and 6 characters.
|
|
666
674
|
const lengthRule = {
|
|
667
675
|
type: Skyflow.ValidationRuleType.LENGTH_MATCH_RULE,
|
|
668
|
-
params:{
|
|
676
|
+
params: {
|
|
669
677
|
min: 4,
|
|
670
678
|
max: 6,
|
|
671
|
-
error:
|
|
672
|
-
}
|
|
673
|
-
};
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
679
|
+
error: 'Must be between 4 and 6 alphabets',
|
|
680
|
+
},
|
|
681
|
+
};
|
|
682
|
+
|
|
683
|
+
const cardHolderNameElement = collectContainer.create({
|
|
684
|
+
table: 'pii_fields',
|
|
685
|
+
column: 'first_name',
|
|
686
|
+
...collectStylesOptions,
|
|
687
|
+
label: 'Card Holder Name',
|
|
688
|
+
placeholder: 'cardholder name',
|
|
689
|
+
type: Skyflow.ElementType.INPUT_FIELD,
|
|
690
|
+
validations: [alphabetsOnlyRegexRule, lengthRule],
|
|
691
|
+
});
|
|
684
692
|
|
|
685
693
|
/*
|
|
686
694
|
Reset PIN - A simple example that illustrates custom validations.
|
|
687
695
|
The below code shows an example of ELEMENT_VALUE_MATCH_RULE
|
|
688
696
|
*/
|
|
689
697
|
|
|
690
|
-
//
|
|
698
|
+
// For the PIN element
|
|
691
699
|
const pinElement = collectContainer.create({
|
|
692
|
-
label:
|
|
693
|
-
placeholder:
|
|
700
|
+
label: 'PIN',
|
|
701
|
+
placeholder: '****',
|
|
694
702
|
type: Skyflow.ElementType.PIN,
|
|
695
703
|
});
|
|
696
704
|
|
|
697
|
-
//
|
|
698
|
-
|
|
705
|
+
// This rule allows to match the value with pinElement.
|
|
706
|
+
const elementMatchRule = {
|
|
699
707
|
type: Skyflow.ValidationRuleType.ELEMENT_VALUE_MATCH_RULE,
|
|
700
|
-
params:{
|
|
708
|
+
params: {
|
|
701
709
|
element: pinElement,
|
|
702
|
-
error: "PIN doesn't match"
|
|
703
|
-
}
|
|
704
|
-
}
|
|
710
|
+
error: "PIN doesn't match",
|
|
711
|
+
},
|
|
712
|
+
};
|
|
713
|
+
|
|
705
714
|
const confirmPinElement = collectContainer.create({
|
|
706
|
-
label:
|
|
707
|
-
placeholder:
|
|
715
|
+
label: 'Confirm PIN',
|
|
716
|
+
placeholder: '****',
|
|
708
717
|
type: Skyflow.ElementType.PIN,
|
|
709
|
-
validations: [elementMatchRule]
|
|
718
|
+
validations: [elementMatchRule],
|
|
710
719
|
});
|
|
711
720
|
|
|
712
|
-
//
|
|
713
|
-
pinElement.mount(
|
|
714
|
-
confirmPinElement.mount(
|
|
721
|
+
// Mount elements on screen - errors will be shown if any of the validaitons fail.
|
|
722
|
+
pinElement.mount('#collectPIN');
|
|
723
|
+
confirmPinElement.mount('#collectConfirmPIN');
|
|
715
724
|
|
|
716
725
|
```
|
|
717
726
|
### Event Listener on Collect Elements
|
|
718
727
|
|
|
719
728
|
|
|
720
|
-
Helps to communicate with
|
|
729
|
+
Helps to communicate with Skyflow elements / iframes by listening to an event
|
|
721
730
|
|
|
722
731
|
```javascript
|
|
723
732
|
element.on(Skyflow.EventName,handler:function)
|
|
@@ -753,82 +762,80 @@ values of SkyflowElements will be returned in elementstate object only when `env
|
|
|
753
762
|
|
|
754
763
|
##### Sample [code snippet](https://github.com/skyflowapi/skyflow-js/blob/master/samples/using-script-tag/collect-element-listeners.html) for using listeners
|
|
755
764
|
```javascript
|
|
756
|
-
//
|
|
765
|
+
// Create Skyflow client.
|
|
757
766
|
const skyflowClient = Skyflow.init({
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
})
|
|
767
|
+
vaultID: '<VAULT_ID>',
|
|
768
|
+
vaultURL: '<VAULT_URL>',
|
|
769
|
+
getBearerToken: () => {},
|
|
770
|
+
options: {
|
|
771
|
+
env: Skyflow.Env.DEV,
|
|
772
|
+
},
|
|
773
|
+
});
|
|
765
774
|
|
|
766
|
-
const container = skyflowClient.container(Skyflow.ContainerType.COLLECT)
|
|
775
|
+
const container = skyflowClient.container(Skyflow.ContainerType.COLLECT);
|
|
767
776
|
|
|
768
777
|
const cardNumber = container.create({
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
778
|
+
table: 'pii_fields',
|
|
779
|
+
column: 'primary_card.card_number',
|
|
780
|
+
type: Skyflow.ElementType.CARD_NUMBER,
|
|
781
|
+
});
|
|
773
782
|
|
|
774
|
-
cardNumber.mount(
|
|
783
|
+
cardNumber.mount('#cardNumberContainer');
|
|
775
784
|
|
|
776
|
-
//
|
|
777
|
-
cardNumber.on(Skyflow.EventName.CHANGE,
|
|
778
|
-
// Your implementation when Change event occurs
|
|
779
|
-
console.log(state)
|
|
785
|
+
// Subscribing to CHANGE event, which gets triggered when element changes.
|
|
786
|
+
cardNumber.on(Skyflow.EventName.CHANGE, state => {
|
|
787
|
+
// Your implementation when Change event occurs.
|
|
788
|
+
console.log(state);
|
|
780
789
|
});
|
|
790
|
+
|
|
781
791
|
```
|
|
782
792
|
##### Sample Element state object when `env` is `DEV`
|
|
783
793
|
|
|
784
794
|
```javascript
|
|
785
795
|
{
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
}
|
|
792
|
-
|
|
796
|
+
elementType: 'CARD_NUMBER',
|
|
797
|
+
isEmpty: false,
|
|
798
|
+
isFocused: true,
|
|
799
|
+
isValid: false,
|
|
800
|
+
value: '411',
|
|
801
|
+
};
|
|
793
802
|
```
|
|
794
803
|
##### Sample Element state object when `env` is `PROD`
|
|
795
804
|
|
|
796
805
|
```javascript
|
|
797
806
|
{
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
}
|
|
807
|
+
elementType: 'CARD_NUMBER',
|
|
808
|
+
isEmpty: false,
|
|
809
|
+
isFocused: true,
|
|
810
|
+
isValid: false,
|
|
811
|
+
value: '',
|
|
812
|
+
};
|
|
804
813
|
```
|
|
805
814
|
|
|
806
815
|
### UI Error for Collect Elements
|
|
807
816
|
|
|
808
817
|
Helps to display custom error messages on the Skyflow Elements through the methods `setError` and `resetError` on the elements.
|
|
809
818
|
|
|
810
|
-
`setError(error: string)` method is used to set the error text for the element, when this method is
|
|
819
|
+
`setError(error: string)` method is used to set the error text for the element, when this method is triggered, all the current errors present on the element will be overridden with the custom error message passed. This error will be displayed on the element until `resetError()` is triggered on the same element.
|
|
811
820
|
|
|
812
821
|
`resetError()` method is used to clear the custom error message that is set using `setError`.
|
|
813
822
|
|
|
814
823
|
##### Sample code snippet for setError and resetError
|
|
815
824
|
|
|
816
825
|
```javascript
|
|
817
|
-
|
|
818
|
-
const container = skyflowClient.container(Skyflow.ContainerType.COLLECT)
|
|
826
|
+
const container = skyflowClient.container(Skyflow.ContainerType.COLLECT);
|
|
819
827
|
|
|
820
828
|
const cardNumber = container.create({
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
829
|
+
table: 'pii_fields',
|
|
830
|
+
column: 'primary_card.card_number',
|
|
831
|
+
type: Skyflow.ElementType.CARD_NUMBER,
|
|
824
832
|
});
|
|
825
833
|
|
|
826
|
-
//Set custom error
|
|
827
|
-
cardNumber.setError(
|
|
834
|
+
// Set custom error.
|
|
835
|
+
cardNumber.setError('custom error');
|
|
828
836
|
|
|
829
|
-
//
|
|
837
|
+
// Reset custom error.
|
|
830
838
|
cardNumber.resetError();
|
|
831
|
-
|
|
832
839
|
```
|
|
833
840
|
|
|
834
841
|
### Set and Clear value for Collect Elements (DEV ENV ONLY)
|
|
@@ -842,18 +849,18 @@ cardNumber.resetError();
|
|
|
842
849
|
##### Sample code snippet for setValue and clearValue
|
|
843
850
|
|
|
844
851
|
```javascript
|
|
845
|
-
const container = skyflowClient.container(Skyflow.ContainerType.COLLECT)
|
|
852
|
+
const container = skyflowClient.container(Skyflow.ContainerType.COLLECT);
|
|
846
853
|
|
|
847
854
|
const cardNumber = container.create({
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
855
|
+
table: 'pii_fields',
|
|
856
|
+
column: 'primary_card.card_number',
|
|
857
|
+
type: Skyflow.ElementType.CARD_NUMBER,
|
|
851
858
|
});
|
|
852
859
|
|
|
853
|
-
// Set a value programatically
|
|
854
|
-
cardNumber.setValue(
|
|
860
|
+
// Set a value programatically.
|
|
861
|
+
cardNumber.setValue('4111111111111111');
|
|
855
862
|
|
|
856
|
-
// Clear the value
|
|
863
|
+
// Clear the value.
|
|
857
864
|
cardNumber.clearValue();
|
|
858
865
|
|
|
859
866
|
```
|
|
@@ -877,25 +884,25 @@ For non-PCI use-cases, retrieving data from the vault and revealing it in the br
|
|
|
877
884
|
|
|
878
885
|
```javascript
|
|
879
886
|
const records = {
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
]
|
|
885
|
-
}
|
|
887
|
+
records: [
|
|
888
|
+
{
|
|
889
|
+
token: 'string', // Token for the record to be fetched.
|
|
890
|
+
},
|
|
891
|
+
],
|
|
892
|
+
};
|
|
886
893
|
|
|
887
|
-
skyflow.detokenize(records)
|
|
894
|
+
skyflow.detokenize(records);
|
|
888
895
|
```
|
|
889
896
|
An [example](https://github.com/skyflowapi/skyflow-js/blob/master/samples/using-script-tag/pure-js.html) of a detokenize call:
|
|
890
897
|
|
|
891
898
|
```javascript
|
|
892
899
|
skyflow.detokenize({
|
|
893
|
-
|
|
900
|
+
records: [
|
|
894
901
|
{
|
|
895
|
-
token:
|
|
896
|
-
}
|
|
897
|
-
]
|
|
898
|
-
})
|
|
902
|
+
token: '131e70dc-6f76-4319-bdd3-96281e051051',
|
|
903
|
+
},
|
|
904
|
+
],
|
|
905
|
+
});
|
|
899
906
|
```
|
|
900
907
|
|
|
901
908
|
The sample response:
|
|
@@ -915,11 +922,11 @@ The sample response:
|
|
|
915
922
|
|
|
916
923
|
```javascript
|
|
917
924
|
{
|
|
918
|
-
|
|
925
|
+
records: [
|
|
919
926
|
{
|
|
920
|
-
ids: string[], //
|
|
921
|
-
table: string
|
|
922
|
-
redaction: Skyflow.RedactionType
|
|
927
|
+
ids: string[], // Array of SkyflowID's of the records to be fetched.
|
|
928
|
+
table: string, // Table holding the above skyflow_id's.
|
|
929
|
+
redaction: Skyflow.RedactionType, // Redaction to be applied to retrieved data.
|
|
923
930
|
}
|
|
924
931
|
]
|
|
925
932
|
}
|
|
@@ -934,17 +941,16 @@ There are 4 accepted values in Skyflow.RedactionTypes:
|
|
|
934
941
|
An example of getById call:
|
|
935
942
|
|
|
936
943
|
```javascript
|
|
937
|
-
|
|
938
944
|
skyflow.getById({
|
|
939
945
|
records: [
|
|
940
946
|
{
|
|
941
|
-
ids: [
|
|
942
|
-
table:
|
|
947
|
+
ids: ['f8d8a622-b557-4c6b-a12c-c5ebe0b0bfd9'],
|
|
948
|
+
table: 'cards',
|
|
943
949
|
redaction: Skyflow.RedactionType.PLAIN_TEXT,
|
|
944
950
|
},
|
|
945
951
|
{
|
|
946
|
-
ids: [
|
|
947
|
-
table:
|
|
952
|
+
ids: ['da26de53-95d5-4bdb-99db-8d8c66a35ff9'],
|
|
953
|
+
table: 'contacts',
|
|
948
954
|
redaction: Skyflow.RedactionType.PLAIN_TEXT,
|
|
949
955
|
},
|
|
950
956
|
],
|
|
@@ -996,14 +1002,13 @@ Then define a Skyflow Element to reveal data as shown below.
|
|
|
996
1002
|
|
|
997
1003
|
```javascript
|
|
998
1004
|
const revealElement = {
|
|
999
|
-
token:
|
|
1000
|
-
inputStyles: {},
|
|
1001
|
-
labelStyles: {},
|
|
1002
|
-
errorTextStyles: {},
|
|
1003
|
-
label:
|
|
1004
|
-
altText:
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1005
|
+
token: 'string', // Required, token of the data being revealed.
|
|
1006
|
+
inputStyles: {}, // Optional, styles to be applied to the element.
|
|
1007
|
+
labelStyles: {}, // Optional, styles to be applied to the label of the reveal element.
|
|
1008
|
+
errorTextStyles: {}, // Optional, styles that will be applied to the errorText of the reveal element.
|
|
1009
|
+
label: 'string', // Optional, label for the form element.
|
|
1010
|
+
altText: 'string', // Optional, string that is shown before reveal, will show token if altText is not provided.
|
|
1011
|
+
};
|
|
1007
1012
|
```
|
|
1008
1013
|
|
|
1009
1014
|
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 for reveal element, `inputStyles` accepts only `base` variant and `copyIcon` style object.
|
|
@@ -1012,36 +1017,36 @@ An example of a inputStyles object:
|
|
|
1012
1017
|
|
|
1013
1018
|
```javascript
|
|
1014
1019
|
inputStyles: {
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
}
|
|
1020
|
+
base: {
|
|
1021
|
+
color: '#1d1d1d',
|
|
1022
|
+
},
|
|
1023
|
+
copyIcon: {
|
|
1024
|
+
position: 'absolute',
|
|
1025
|
+
right: '8px',
|
|
1026
|
+
top: 'calc(50% - 10px)',
|
|
1027
|
+
},
|
|
1028
|
+
},
|
|
1024
1029
|
```
|
|
1025
1030
|
|
|
1026
1031
|
An example of a labelStyles object:
|
|
1027
1032
|
|
|
1028
1033
|
```javascript
|
|
1029
1034
|
labelStyles: {
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
}
|
|
1035
|
+
base: {
|
|
1036
|
+
fontSize: '12px',
|
|
1037
|
+
fontWeight: 'bold',
|
|
1038
|
+
},
|
|
1039
|
+
},
|
|
1035
1040
|
```
|
|
1036
1041
|
|
|
1037
1042
|
An example of a errorTextStyles object:
|
|
1038
1043
|
|
|
1039
1044
|
```javascript
|
|
1040
1045
|
errorTextStyles: {
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
}
|
|
1046
|
+
base: {
|
|
1047
|
+
color: '#f44336',
|
|
1048
|
+
},
|
|
1049
|
+
},
|
|
1045
1050
|
```
|
|
1046
1051
|
|
|
1047
1052
|
Once you've defined a Skyflow Element, you can use the `create(element)` method of the container to create the Element as shown below:
|
|
@@ -1059,13 +1064,14 @@ Elements used for revealing data are mounted to the DOM the same way as Elements
|
|
|
1059
1064
|
When the sensitive data is ready to be retrieved and revealed, call the `reveal()` method on the container as shown below:
|
|
1060
1065
|
|
|
1061
1066
|
```javascript
|
|
1062
|
-
container
|
|
1063
|
-
.
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
.catch((err) => {
|
|
1067
|
-
//handle error
|
|
1067
|
+
container
|
|
1068
|
+
.reveal()
|
|
1069
|
+
.then(data => {
|
|
1070
|
+
// Handle success.
|
|
1068
1071
|
})
|
|
1072
|
+
.catch(err => {
|
|
1073
|
+
// Handle error.
|
|
1074
|
+
});
|
|
1069
1075
|
```
|
|
1070
1076
|
|
|
1071
1077
|
|
|
@@ -1073,55 +1079,55 @@ container.reveal()
|
|
|
1073
1079
|
|
|
1074
1080
|
**[Sample Code:](https://github.com/skyflowapi/skyflow-js/blob/master/samples/using-script-tag/skyflow-elements.html)**
|
|
1075
1081
|
```javascript
|
|
1076
|
-
//Step 1
|
|
1077
|
-
const container = skyflowClient.container(Skyflow.ContainerType.REVEAL)
|
|
1082
|
+
// Step 1.
|
|
1083
|
+
const container = skyflowClient.container(Skyflow.ContainerType.REVEAL);
|
|
1078
1084
|
|
|
1079
|
-
//Step 2
|
|
1080
|
-
const cardNumberElement = container.create({
|
|
1081
|
-
token:
|
|
1085
|
+
// Step 2.
|
|
1086
|
+
const cardNumberElement = container.create({
|
|
1087
|
+
token: 'b63ec4e0-bbad-4e43-96e6-6bd50f483f75',
|
|
1082
1088
|
inputStyles: {
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1089
|
+
base: {
|
|
1090
|
+
color: '#1d1d1d',
|
|
1091
|
+
},
|
|
1086
1092
|
},
|
|
1087
1093
|
labelStyles: {
|
|
1088
1094
|
base: {
|
|
1089
|
-
fontSize:
|
|
1090
|
-
}
|
|
1095
|
+
fontSize: '12px',
|
|
1096
|
+
},
|
|
1091
1097
|
},
|
|
1092
1098
|
errorTextStyles: {
|
|
1093
1099
|
base: {
|
|
1094
|
-
color:
|
|
1095
|
-
}
|
|
1096
|
-
},
|
|
1097
|
-
label:
|
|
1098
|
-
altText:
|
|
1099
|
-
})
|
|
1100
|
+
color: '#f44336',
|
|
1101
|
+
},
|
|
1102
|
+
},
|
|
1103
|
+
label: 'card_number',
|
|
1104
|
+
altText: 'XXXX XXXX XXXX XXXX',
|
|
1105
|
+
});
|
|
1100
1106
|
|
|
1101
|
-
const cvvElement = container.create({
|
|
1102
|
-
token:
|
|
1107
|
+
const cvvElement = container.create({
|
|
1108
|
+
token: '89024714-6a26-4256-b9d4-55ad69aa4047',
|
|
1103
1109
|
inputStyles: {
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
},
|
|
1110
|
+
base: {
|
|
1111
|
+
color: '#1d1d1d',
|
|
1107
1112
|
},
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1113
|
+
},
|
|
1114
|
+
label: 'cvv',
|
|
1115
|
+
altText: 'XXX',
|
|
1116
|
+
});
|
|
1111
1117
|
|
|
1112
|
-
//Step 3
|
|
1113
|
-
cardNumberElement.mount(
|
|
1114
|
-
cvvElement.mount(
|
|
1115
|
-
|
|
1116
|
-
//Step 4
|
|
1117
|
-
container
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1118
|
+
// Step 3.
|
|
1119
|
+
cardNumberElement.mount('#cardNumber'); // Assumes there is a placeholder div with id='cardNumber' on the page
|
|
1120
|
+
cvvElement.mount('#cvv'); // Assumes there is a placeholder div with id='cvv' on the page
|
|
1121
|
+
|
|
1122
|
+
// Step 4.
|
|
1123
|
+
container
|
|
1124
|
+
.reveal()
|
|
1125
|
+
.then(data => {
|
|
1126
|
+
// Handle success.
|
|
1127
|
+
})
|
|
1128
|
+
.catch(err => {
|
|
1129
|
+
// Handle error.
|
|
1130
|
+
});
|
|
1125
1131
|
```
|
|
1126
1132
|
|
|
1127
1133
|
The response below shows that some tokens assigned to the reveal elements get revealed successfully, while others fail and remain unrevealed.
|
|
@@ -1150,26 +1156,24 @@ The response below shows that some tokens assigned to the reveal elements get re
|
|
|
1150
1156
|
### UI Error for Reveal Elements
|
|
1151
1157
|
Helps to display custom error messages on the Skyflow Elements through the methods `setError` and `resetError` on the elements.
|
|
1152
1158
|
|
|
1153
|
-
`setError(error: string)` method is used to set the error text for the element, when this method is
|
|
1159
|
+
`setError(error: string)` method is used to set the error text for the element, when this method is triggered, all the current errors present on the element will be overridden with the custom error message passed. This error will be displayed on the element until `resetError()` is triggered on the same element.
|
|
1154
1160
|
|
|
1155
1161
|
`resetError()` method is used to clear the custom error message that is set using `setError`.
|
|
1156
1162
|
|
|
1157
1163
|
##### Sample code snippet for setError and resetError
|
|
1158
1164
|
|
|
1159
1165
|
```javascript
|
|
1160
|
-
|
|
1161
|
-
const container = skyflowClient.container(Skyflow.ContainerType.REVEAL)
|
|
1166
|
+
const container = skyflowClient.container(Skyflow.ContainerType.REVEAL);
|
|
1162
1167
|
|
|
1163
1168
|
const cardNumber = container.create({
|
|
1164
|
-
|
|
1169
|
+
token: '89024714-6a26-4256-b9d4-55ad69aa4047',
|
|
1165
1170
|
});
|
|
1166
1171
|
|
|
1167
|
-
//Set custom error
|
|
1168
|
-
cardNumber.setError(
|
|
1172
|
+
// Set custom error.
|
|
1173
|
+
cardNumber.setError('custom error');
|
|
1169
1174
|
|
|
1170
|
-
//
|
|
1175
|
+
// Reset custom error.
|
|
1171
1176
|
cardNumber.resetError();
|
|
1172
|
-
|
|
1173
1177
|
```
|
|
1174
1178
|
### Set token for Reveal Elements
|
|
1175
1179
|
|
|
@@ -1177,15 +1181,14 @@ The `setToken(value: string)` method can be used to set the token of the Reveal
|
|
|
1177
1181
|
|
|
1178
1182
|
##### Sample code snippet for setToken
|
|
1179
1183
|
```javascript
|
|
1180
|
-
const container = skyflowClient.container(Skyflow.ContainerType.REVEAL)
|
|
1184
|
+
const container = skyflowClient.container(Skyflow.ContainerType.REVEAL);
|
|
1181
1185
|
|
|
1182
1186
|
const cardNumber = container.create({
|
|
1183
|
-
|
|
1187
|
+
altText: 'Card Number',
|
|
1184
1188
|
});
|
|
1185
1189
|
|
|
1186
|
-
//
|
|
1187
|
-
cardNumber.setToken(
|
|
1188
|
-
|
|
1190
|
+
// Set token.
|
|
1191
|
+
cardNumber.setToken('89024714-6a26-4256-b9d4-55ad69aa4047');
|
|
1189
1192
|
```
|
|
1190
1193
|
### Set and Clear altText for Reveal Elements
|
|
1191
1194
|
The `setAltText(value: string)` method can be used to set the altText of the Reveal Element. This will cause the altText to be displayed in the UI regardless of whether the token or value is currently being displayed.
|
|
@@ -1194,17 +1197,18 @@ The `setAltText(value: string)` method can be used to set the altText of the Rev
|
|
|
1194
1197
|
##### Sample code snippet for setAltText and clearAltText
|
|
1195
1198
|
|
|
1196
1199
|
```javascript
|
|
1197
|
-
const container = skyflowClient.container(Skyflow.ContainerType.REVEAL)
|
|
1200
|
+
const container = skyflowClient.container(Skyflow.ContainerType.REVEAL);
|
|
1198
1201
|
|
|
1199
1202
|
const cardNumber = container.create({
|
|
1200
|
-
|
|
1203
|
+
token: '89024714-6a26-4256-b9d4-55ad69aa4047',
|
|
1201
1204
|
});
|
|
1202
1205
|
|
|
1203
|
-
//
|
|
1204
|
-
cardNumber.setAltText(
|
|
1206
|
+
// Set altText.
|
|
1207
|
+
cardNumber.setAltText('Card Number');
|
|
1208
|
+
|
|
1209
|
+
// Clear altText.
|
|
1210
|
+
cardNumber.clearAltText();
|
|
1205
1211
|
|
|
1206
|
-
//clear altText
|
|
1207
|
-
cardNumber.clearAltText();
|
|
1208
1212
|
```
|
|
1209
1213
|
|
|
1210
1214
|
## Using Skyflow File Element to upload a file
|
|
@@ -1224,13 +1228,13 @@ Skyflow Collect Elements are defined as follows:
|
|
|
1224
1228
|
|
|
1225
1229
|
```javascript
|
|
1226
1230
|
const collectElement = {
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1231
|
+
type: Skyflow.ElementType.FILE_INPUT, // Skyflow.ElementType enum.
|
|
1232
|
+
table: 'string', // The table this data belongs to.
|
|
1233
|
+
column: 'string', // The column into which this data should be inserted.
|
|
1234
|
+
skyflowID: 'string', // The skyflow_id of the record.
|
|
1235
|
+
inputStyles: {}, // Optional, styles that should be applied to the form element.
|
|
1236
|
+
labelStyles: {}, // Optional, styles that will be applied to the label of the collect element.
|
|
1237
|
+
errorTextStyles:{}, // Optional, styles that will be applied to the errorText of the collect element.
|
|
1234
1238
|
}
|
|
1235
1239
|
```
|
|
1236
1240
|
The `table` and `column` fields indicate which table and column the Element corresponds to.
|
|
@@ -1256,7 +1260,7 @@ To specify where to render Elements on your page, create placeholder `<div>` ele
|
|
|
1256
1260
|
Now, when the `mount(domElement)` method of the Element is called, the Element is inserted in the specified div. For instance, the call below inserts the Element into the div with the id "#file".
|
|
1257
1261
|
|
|
1258
1262
|
```javascript
|
|
1259
|
-
element.mount(
|
|
1263
|
+
element.mount('#file');
|
|
1260
1264
|
```
|
|
1261
1265
|
Use the `unmount` method to reset a Collect Element to its initial state.
|
|
1262
1266
|
|
|
@@ -1268,7 +1272,7 @@ element.unmount();
|
|
|
1268
1272
|
When the file is ready to be uploaded, call the `uploadFiles()` method on the container object.
|
|
1269
1273
|
|
|
1270
1274
|
```javascript
|
|
1271
|
-
container.uploadFiles()
|
|
1275
|
+
container.uploadFiles();
|
|
1272
1276
|
```
|
|
1273
1277
|
### File upload limitations:
|
|
1274
1278
|
|
|
@@ -1281,38 +1285,38 @@ container.uploadFiles()
|
|
|
1281
1285
|
### End-to-end file upload
|
|
1282
1286
|
|
|
1283
1287
|
```javascript
|
|
1284
|
-
//Step 1
|
|
1285
|
-
const container = skyflowClient.container(Skyflow.ContainerType.COLLECT)
|
|
1288
|
+
// Step 1.
|
|
1289
|
+
const container = skyflowClient.container(Skyflow.ContainerType.COLLECT);
|
|
1286
1290
|
|
|
1287
|
-
//Step 2
|
|
1288
|
-
const element = container.create({
|
|
1289
|
-
table:
|
|
1290
|
-
column:
|
|
1291
|
-
skyflowID:
|
|
1291
|
+
// Step 2.
|
|
1292
|
+
const element = container.create({
|
|
1293
|
+
table: 'pii_fields',
|
|
1294
|
+
column: 'file',
|
|
1295
|
+
skyflowID: '431eaa6c-5c15-4513-aa15-29f50babe882',
|
|
1292
1296
|
inputstyles: {
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1297
|
+
base: {
|
|
1298
|
+
color: '#1d1d1d',
|
|
1299
|
+
},
|
|
1296
1300
|
},
|
|
1297
1301
|
labelStyles: {
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
+
base: {
|
|
1303
|
+
fontSize: '12px',
|
|
1304
|
+
fontWeight: 'bold',
|
|
1305
|
+
},
|
|
1302
1306
|
},
|
|
1303
1307
|
errorTextStyles: {
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1308
|
+
base: {
|
|
1309
|
+
color: '#f44336',
|
|
1310
|
+
},
|
|
1307
1311
|
},
|
|
1308
|
-
type: Skyflow.ElementType.FILE_INPUT
|
|
1309
|
-
})
|
|
1312
|
+
type: Skyflow.ElementType.FILE_INPUT,
|
|
1313
|
+
});
|
|
1310
1314
|
|
|
1311
|
-
// Step 3
|
|
1312
|
-
element.mount(
|
|
1315
|
+
// Step 3.
|
|
1316
|
+
element.mount('#file'); // Assumes there is a div with id='#file' in the webpage.
|
|
1313
1317
|
|
|
1314
|
-
// Step 4
|
|
1315
|
-
container.uploadFiles()
|
|
1318
|
+
// Step 4.
|
|
1319
|
+
container.uploadFiles();
|
|
1316
1320
|
```
|
|
1317
1321
|
|
|
1318
1322
|
**Sample Response :**
|
|
@@ -1328,69 +1332,64 @@ container.uploadFiles()
|
|
|
1328
1332
|
#### File upload with additional elements
|
|
1329
1333
|
|
|
1330
1334
|
```javascript
|
|
1331
|
-
// Create collect Container
|
|
1332
|
-
|
|
1335
|
+
// Create collect Container.
|
|
1333
1336
|
const collectContainer = skyflow.container(Skyflow.ContainerType.COLLECT);
|
|
1334
1337
|
|
|
1335
|
-
|
|
1336
|
-
// Create collect elements
|
|
1337
|
-
|
|
1338
|
+
// Create collect elements.
|
|
1338
1339
|
const cardNumberElement = collectContainer.create({
|
|
1339
|
-
table:
|
|
1340
|
-
column:
|
|
1340
|
+
table: 'newTable',
|
|
1341
|
+
column: 'card_number',
|
|
1341
1342
|
inputstyles: {
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1343
|
+
base: {
|
|
1344
|
+
color: '#1d1d1d',
|
|
1345
|
+
},
|
|
1345
1346
|
},
|
|
1346
1347
|
labelStyles: {
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1348
|
+
base: {
|
|
1349
|
+
fontSize: '12px',
|
|
1350
|
+
fontWeight: 'bold',
|
|
1351
|
+
},
|
|
1351
1352
|
},
|
|
1352
1353
|
errorTextStyles: {
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
}
|
|
1357
|
-
placeholder:
|
|
1358
|
-
label:
|
|
1354
|
+
base: {
|
|
1355
|
+
color: '#f44336',
|
|
1356
|
+
},
|
|
1357
|
+
},
|
|
1358
|
+
placeholder: 'card number',
|
|
1359
|
+
label: 'Card Number',
|
|
1359
1360
|
type: Skyflow.ElementType.CARD_NUMBER,
|
|
1360
1361
|
});
|
|
1361
1362
|
|
|
1362
1363
|
const fileElement = collectContainer.create({
|
|
1363
|
-
table:
|
|
1364
|
-
column:
|
|
1364
|
+
table: 'newTable',
|
|
1365
|
+
column: 'file',
|
|
1365
1366
|
skyflowID: '431eaa6c-5c15-4513-aa15-29f50babe882',
|
|
1366
1367
|
inputstyles: {
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1368
|
+
base: {
|
|
1369
|
+
color: '#1d1d1d',
|
|
1370
|
+
},
|
|
1370
1371
|
},
|
|
1371
1372
|
labelStyles: {
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1373
|
+
base: {
|
|
1374
|
+
fontSize: '12px',
|
|
1375
|
+
fontWeight: 'bold',
|
|
1376
|
+
},
|
|
1376
1377
|
},
|
|
1377
1378
|
errorTextStyles: {
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
}
|
|
1379
|
+
base: {
|
|
1380
|
+
color: '#f44336',
|
|
1381
|
+
},
|
|
1382
|
+
},
|
|
1382
1383
|
type: Skyflow.ElementType.FILE_INPUT,
|
|
1383
1384
|
});
|
|
1384
1385
|
|
|
1385
|
-
// Mount the elements
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
fileElement.mount("#collectFile");
|
|
1389
|
-
|
|
1390
|
-
// Collect and upload methods
|
|
1386
|
+
// Mount the elements.
|
|
1387
|
+
cardNumberElement.mount('#collectCardNumber');
|
|
1388
|
+
fileElement.mount('#collectFile');
|
|
1391
1389
|
|
|
1392
|
-
|
|
1393
|
-
container.
|
|
1390
|
+
// Collect and upload methods.
|
|
1391
|
+
container.collect({});
|
|
1392
|
+
container.uploadFiles();
|
|
1394
1393
|
|
|
1395
1394
|
```
|
|
1396
1395
|
**Sample Response for collect():**
|