@trustsig/client 1.1.11 → 1.2.1
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/index.cjs +37 -5
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +38 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -31,7 +31,21 @@ var TrustSigClient = class {
|
|
|
31
31
|
if (!options.siteKey) {
|
|
32
32
|
throw new Error("SITE_KEY_REQUIRED");
|
|
33
33
|
}
|
|
34
|
-
this.options =
|
|
34
|
+
this.options = {
|
|
35
|
+
env: import_types.TrustSigEnv.PROD,
|
|
36
|
+
...options
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
getUrls() {
|
|
40
|
+
const env = this.options.env || import_types.TrustSigEnv.PROD;
|
|
41
|
+
let prefix = "";
|
|
42
|
+
if (env === import_types.TrustSigEnv.DEV) prefix = "dev-";
|
|
43
|
+
if (env === import_types.TrustSigEnv.DEMO) prefix = "demo-";
|
|
44
|
+
return {
|
|
45
|
+
script: this.options.scriptUrl || `https://${prefix}sdk.trustsig.eu/trustsig.js`,
|
|
46
|
+
wasm: this.options.wasmUrl || `https://${prefix}sdk.trustsig.eu/trustsig.wasm`,
|
|
47
|
+
endpoint: this.options.endpoint || `https://${prefix}edge.trustsig.eu`
|
|
48
|
+
};
|
|
35
49
|
}
|
|
36
50
|
async load() {
|
|
37
51
|
if (this.scriptPromise) {
|
|
@@ -40,20 +54,32 @@ var TrustSigClient = class {
|
|
|
40
54
|
if (typeof window === "undefined") {
|
|
41
55
|
return Promise.resolve();
|
|
42
56
|
}
|
|
57
|
+
const urls = this.getUrls();
|
|
43
58
|
if (window.TrustSig && typeof window.TrustSig.getResponse === "function") {
|
|
59
|
+
if (this.options.customData) {
|
|
60
|
+
window.TrustSig.setCustomData(this.options.customData);
|
|
61
|
+
}
|
|
44
62
|
this.scriptPromise = Promise.resolve();
|
|
45
63
|
return this.scriptPromise;
|
|
46
64
|
}
|
|
47
65
|
this.scriptPromise = new Promise((resolve, reject) => {
|
|
48
66
|
const script = document.createElement("script");
|
|
49
|
-
script.src =
|
|
67
|
+
script.src = urls.script;
|
|
50
68
|
script.setAttribute("data-site-key", this.options.siteKey);
|
|
51
|
-
|
|
52
|
-
|
|
69
|
+
script.setAttribute("data-endpoint", urls.endpoint);
|
|
70
|
+
script.setAttribute("data-wasm-url", urls.wasm);
|
|
53
71
|
if (this.options.interceptRequests) script.setAttribute("data-intercept-requests", "true");
|
|
54
72
|
if (this.options.debug) script.setAttribute("data-debug", "true");
|
|
55
73
|
if (this.options.nonce) script.setAttribute("nonce", this.options.nonce);
|
|
56
|
-
|
|
74
|
+
if (this.options.customData) {
|
|
75
|
+
script.setAttribute("data-custom", JSON.stringify(this.options.customData));
|
|
76
|
+
}
|
|
77
|
+
script.onload = () => {
|
|
78
|
+
if (this.options.customData && window.TrustSig?.setCustomData) {
|
|
79
|
+
window.TrustSig.setCustomData(this.options.customData);
|
|
80
|
+
}
|
|
81
|
+
resolve();
|
|
82
|
+
};
|
|
57
83
|
script.onerror = () => {
|
|
58
84
|
this.scriptPromise = null;
|
|
59
85
|
reject(new Error("SCRIPT_LOAD_FAIL"));
|
|
@@ -73,6 +99,12 @@ var TrustSigClient = class {
|
|
|
73
99
|
}
|
|
74
100
|
return null;
|
|
75
101
|
}
|
|
102
|
+
setCustomData(data) {
|
|
103
|
+
this.options.customData = data;
|
|
104
|
+
if (typeof window !== "undefined" && window.TrustSig?.setCustomData) {
|
|
105
|
+
window.TrustSig.setCustomData(data);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
76
108
|
};
|
|
77
109
|
// Annotate the CommonJS export names for ESM import in node:
|
|
78
110
|
0 && (module.exports = {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { TrustSigEnv } from '@trustsig/types';
|
|
2
|
+
|
|
1
3
|
declare global {
|
|
2
4
|
interface Window {
|
|
3
5
|
TrustSig: {
|
|
4
6
|
getResponse: () => Promise<string | null>;
|
|
7
|
+
setCustomData: (data: Record<string, any>) => void;
|
|
5
8
|
};
|
|
6
9
|
}
|
|
7
10
|
}
|
|
@@ -9,16 +12,21 @@ interface ClientOptions {
|
|
|
9
12
|
siteKey: string;
|
|
10
13
|
endpoint?: string;
|
|
11
14
|
wasmUrl?: string;
|
|
15
|
+
scriptUrl?: string;
|
|
12
16
|
interceptRequests?: boolean;
|
|
13
17
|
debug?: boolean;
|
|
14
18
|
nonce?: string;
|
|
19
|
+
env?: TrustSigEnv;
|
|
20
|
+
customData?: Record<string, any>;
|
|
15
21
|
}
|
|
16
22
|
declare class TrustSigClient {
|
|
17
23
|
private options;
|
|
18
24
|
private scriptPromise;
|
|
19
25
|
constructor(options: ClientOptions);
|
|
26
|
+
private getUrls;
|
|
20
27
|
load(): Promise<void>;
|
|
21
28
|
getResponse(): Promise<string | null>;
|
|
29
|
+
setCustomData(data: Record<string, any>): void;
|
|
22
30
|
}
|
|
23
31
|
|
|
24
32
|
export { type ClientOptions, TrustSigClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { TrustSigEnv } from '@trustsig/types';
|
|
2
|
+
|
|
1
3
|
declare global {
|
|
2
4
|
interface Window {
|
|
3
5
|
TrustSig: {
|
|
4
6
|
getResponse: () => Promise<string | null>;
|
|
7
|
+
setCustomData: (data: Record<string, any>) => void;
|
|
5
8
|
};
|
|
6
9
|
}
|
|
7
10
|
}
|
|
@@ -9,16 +12,21 @@ interface ClientOptions {
|
|
|
9
12
|
siteKey: string;
|
|
10
13
|
endpoint?: string;
|
|
11
14
|
wasmUrl?: string;
|
|
15
|
+
scriptUrl?: string;
|
|
12
16
|
interceptRequests?: boolean;
|
|
13
17
|
debug?: boolean;
|
|
14
18
|
nonce?: string;
|
|
19
|
+
env?: TrustSigEnv;
|
|
20
|
+
customData?: Record<string, any>;
|
|
15
21
|
}
|
|
16
22
|
declare class TrustSigClient {
|
|
17
23
|
private options;
|
|
18
24
|
private scriptPromise;
|
|
19
25
|
constructor(options: ClientOptions);
|
|
26
|
+
private getUrls;
|
|
20
27
|
load(): Promise<void>;
|
|
21
28
|
getResponse(): Promise<string | null>;
|
|
29
|
+
setCustomData(data: Record<string, any>): void;
|
|
22
30
|
}
|
|
23
31
|
|
|
24
32
|
export { type ClientOptions, TrustSigClient };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import "@trustsig/types";
|
|
2
|
+
import { TrustSigEnv } from "@trustsig/types";
|
|
3
3
|
var TrustSigClient = class {
|
|
4
4
|
options;
|
|
5
5
|
scriptPromise = null;
|
|
@@ -7,7 +7,21 @@ var TrustSigClient = class {
|
|
|
7
7
|
if (!options.siteKey) {
|
|
8
8
|
throw new Error("SITE_KEY_REQUIRED");
|
|
9
9
|
}
|
|
10
|
-
this.options =
|
|
10
|
+
this.options = {
|
|
11
|
+
env: TrustSigEnv.PROD,
|
|
12
|
+
...options
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
getUrls() {
|
|
16
|
+
const env = this.options.env || TrustSigEnv.PROD;
|
|
17
|
+
let prefix = "";
|
|
18
|
+
if (env === TrustSigEnv.DEV) prefix = "dev-";
|
|
19
|
+
if (env === TrustSigEnv.DEMO) prefix = "demo-";
|
|
20
|
+
return {
|
|
21
|
+
script: this.options.scriptUrl || `https://${prefix}sdk.trustsig.eu/trustsig.js`,
|
|
22
|
+
wasm: this.options.wasmUrl || `https://${prefix}sdk.trustsig.eu/trustsig.wasm`,
|
|
23
|
+
endpoint: this.options.endpoint || `https://${prefix}edge.trustsig.eu`
|
|
24
|
+
};
|
|
11
25
|
}
|
|
12
26
|
async load() {
|
|
13
27
|
if (this.scriptPromise) {
|
|
@@ -16,20 +30,32 @@ var TrustSigClient = class {
|
|
|
16
30
|
if (typeof window === "undefined") {
|
|
17
31
|
return Promise.resolve();
|
|
18
32
|
}
|
|
33
|
+
const urls = this.getUrls();
|
|
19
34
|
if (window.TrustSig && typeof window.TrustSig.getResponse === "function") {
|
|
35
|
+
if (this.options.customData) {
|
|
36
|
+
window.TrustSig.setCustomData(this.options.customData);
|
|
37
|
+
}
|
|
20
38
|
this.scriptPromise = Promise.resolve();
|
|
21
39
|
return this.scriptPromise;
|
|
22
40
|
}
|
|
23
41
|
this.scriptPromise = new Promise((resolve, reject) => {
|
|
24
42
|
const script = document.createElement("script");
|
|
25
|
-
script.src =
|
|
43
|
+
script.src = urls.script;
|
|
26
44
|
script.setAttribute("data-site-key", this.options.siteKey);
|
|
27
|
-
|
|
28
|
-
|
|
45
|
+
script.setAttribute("data-endpoint", urls.endpoint);
|
|
46
|
+
script.setAttribute("data-wasm-url", urls.wasm);
|
|
29
47
|
if (this.options.interceptRequests) script.setAttribute("data-intercept-requests", "true");
|
|
30
48
|
if (this.options.debug) script.setAttribute("data-debug", "true");
|
|
31
49
|
if (this.options.nonce) script.setAttribute("nonce", this.options.nonce);
|
|
32
|
-
|
|
50
|
+
if (this.options.customData) {
|
|
51
|
+
script.setAttribute("data-custom", JSON.stringify(this.options.customData));
|
|
52
|
+
}
|
|
53
|
+
script.onload = () => {
|
|
54
|
+
if (this.options.customData && window.TrustSig?.setCustomData) {
|
|
55
|
+
window.TrustSig.setCustomData(this.options.customData);
|
|
56
|
+
}
|
|
57
|
+
resolve();
|
|
58
|
+
};
|
|
33
59
|
script.onerror = () => {
|
|
34
60
|
this.scriptPromise = null;
|
|
35
61
|
reject(new Error("SCRIPT_LOAD_FAIL"));
|
|
@@ -49,6 +75,12 @@ var TrustSigClient = class {
|
|
|
49
75
|
}
|
|
50
76
|
return null;
|
|
51
77
|
}
|
|
78
|
+
setCustomData(data) {
|
|
79
|
+
this.options.customData = data;
|
|
80
|
+
if (typeof window !== "undefined" && window.TrustSig?.setCustomData) {
|
|
81
|
+
window.TrustSig.setCustomData(data);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
52
84
|
};
|
|
53
85
|
export {
|
|
54
86
|
TrustSigClient
|