@descope/flow-scripts 1.0.10 → 1.0.11
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/dist/darwinium.js +1 -0
- package/package.json +2 -2
- package/src/darwinium.ts +82 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):((e="undefined"!=typeof globalThis?globalThis:e||self).descope=e.descope||{},e.descope.darwinium=t())}(this,(function(){"use strict";const e={email:"EMAIL",givenName:"FIRST_NAME",familyName:"LAST_NAME",displayName:"FULL_NAME",phone:"TELEPHONE",externalId:"USER_NAME",password:"PASSWORD",newPassword:"PASSWORD",address:"ADDRESS_STREET1"};return(t,n,o)=>{let s=null;const r=()=>{let t=[];var o;n.ref.getInputs?t=null==(o=n.ref.getInputs())?void 0:o.flatMap((t=>{const n=t.getAttribute("name")||"";return[{selector:`${t.localName} input`,context:e[n]},{selector:`input[name="${n}"]`,context:e[n]}]})):console.warn("getInputs function is missing, expected the ref to be a Descope Web Component"),s=(e=>{var t;return null===(t=window.dwn)||void 0===t?void 0:t.start({mouse:!0,use_deep_query_selector:!0,key_bm:e})})(t)};return((e,t)=>{const n=document.createElement("script");n.src=e,n.async=!0,n.id="darwinium-script",n.defer=!0,n.onload=t,document.body.appendChild(n)})(t.profilingTagsScriptUrl||"https://cy-began.com/dwnfp.js",(()=>{o(null),r()})),{stop:()=>{null==s||s.stop()},start:r,refresh:()=>{const e=null==s?void 0:s.tryCollect();o(e)}}}}));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@descope/flow-scripts",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.11",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/descope/content"
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"eslint-plugin-import": "2.32.0",
|
|
26
26
|
"jest": "29.7.0",
|
|
27
27
|
"jest-environment-jsdom": "29.7.0",
|
|
28
|
-
"rollup": "4.45.
|
|
28
|
+
"rollup": "4.45.1",
|
|
29
29
|
"ts-jest": "29.4.0",
|
|
30
30
|
"ts-node": "10.9.2",
|
|
31
31
|
"typescript": "5.8.3"
|
package/src/darwinium.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// A mapping of input names to Darwinium context names
|
|
2
|
+
// https://dahibthxi6hbt.cloudfront.net/dwn-api-docs/javascript/docs/global.html#Contexts
|
|
3
|
+
const CONTEXT_MAPPING = {
|
|
4
|
+
email: "EMAIL",
|
|
5
|
+
givenName: "FIRST_NAME",
|
|
6
|
+
familyName: "LAST_NAME",
|
|
7
|
+
displayName: "FULL_NAME",
|
|
8
|
+
phone: "TELEPHONE",
|
|
9
|
+
externalId: "USER_NAME",
|
|
10
|
+
password: "PASSWORD",
|
|
11
|
+
newPassword: "PASSWORD",
|
|
12
|
+
address: "ADDRESS_STREET1",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const loadScript = (src: string, onLoad: () => void) => {
|
|
16
|
+
const script = document.createElement("script");
|
|
17
|
+
script.src = src;
|
|
18
|
+
script.async = true;
|
|
19
|
+
script.id = "darwinium-script";
|
|
20
|
+
script.defer = true;
|
|
21
|
+
script.onload = onLoad;
|
|
22
|
+
document.body.appendChild(script);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const createProfilingInstance = (selectors: any[]) => {
|
|
26
|
+
return (<any>window).dwn?.start({
|
|
27
|
+
mouse: true,
|
|
28
|
+
use_deep_query_selector: true,
|
|
29
|
+
key_bm: selectors,
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const createSelectors = (inputs: HTMLInputElement[]) => {
|
|
34
|
+
return inputs?.flatMap((input) => {
|
|
35
|
+
const name = input.getAttribute("name") || "";
|
|
36
|
+
return [
|
|
37
|
+
{ selector: `${input.localName} input`, context: CONTEXT_MAPPING[name] },
|
|
38
|
+
{ selector: `input[name="${name}"]`, context: CONTEXT_MAPPING[name] },
|
|
39
|
+
];
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const loadDarwinium = (
|
|
44
|
+
initArgs: { profilingTagsScriptUrl?: string; geoLocationEnabled?: boolean },
|
|
45
|
+
_inputs: { baseUrl?: string; ref: any },
|
|
46
|
+
onTokenReady: (token: string | null) => void
|
|
47
|
+
) => {
|
|
48
|
+
let profilingInstance: any = null;
|
|
49
|
+
|
|
50
|
+
// on flow state update, start profiling
|
|
51
|
+
const start = () => {
|
|
52
|
+
let selectors: any[] = [];
|
|
53
|
+
if (_inputs.ref.getInputs) {
|
|
54
|
+
selectors = createSelectors(_inputs.ref.getInputs());
|
|
55
|
+
} else {
|
|
56
|
+
console.warn("getInputs function is missing, expected the ref to be a Descope Web Component");
|
|
57
|
+
}
|
|
58
|
+
profilingInstance = createProfilingInstance(selectors);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// before submit, we need to collect profiling data
|
|
62
|
+
const refresh = () => {
|
|
63
|
+
const webProfilingBlob = profilingInstance?.tryCollect();
|
|
64
|
+
onTokenReady(webProfilingBlob);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// after submit, we stop profiling
|
|
68
|
+
const stop = () => {
|
|
69
|
+
profilingInstance?.stop();
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
loadScript(initArgs.profilingTagsScriptUrl || "https://cy-began.com/dwnfp.js", () => {
|
|
73
|
+
// on the first time, the SDK is waiting for onTokenReady to be called
|
|
74
|
+
// so we are using it to wait for the Darwinium script to load
|
|
75
|
+
onTokenReady(null);
|
|
76
|
+
start();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
return { stop, start, refresh };
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export default loadDarwinium;
|