@trustsig/client 1.1.6 → 1.1.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/index.cjs ADDED
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ TrustSigClient: () => TrustSigClient
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+ var import_types = require("@trustsig/types");
27
+ var TrustSigClient = class {
28
+ options;
29
+ scriptPromise = null;
30
+ constructor(options) {
31
+ if (!options.siteKey) {
32
+ throw new Error("SITE_KEY_REQUIRED");
33
+ }
34
+ this.options = options;
35
+ }
36
+ async load() {
37
+ if (this.scriptPromise) {
38
+ return this.scriptPromise;
39
+ }
40
+ if (typeof window === "undefined") {
41
+ return Promise.resolve();
42
+ }
43
+ if (window.TrustSig && typeof window.TrustSig.getResponse === "function") {
44
+ this.scriptPromise = Promise.resolve();
45
+ return this.scriptPromise;
46
+ }
47
+ this.scriptPromise = new Promise((resolve, reject) => {
48
+ const script = document.createElement("script");
49
+ script.src = "https://sdk.trustsig.com/trustsig.js";
50
+ script.setAttribute("data-site-key", this.options.siteKey);
51
+ if (this.options.endpoint) script.setAttribute("data-endpoint", this.options.endpoint);
52
+ if (this.options.wasmUrl) script.setAttribute("data-wasm-url", this.options.wasmUrl);
53
+ if (this.options.interceptRequests) script.setAttribute("data-intercept-requests", "true");
54
+ if (this.options.debug) script.setAttribute("data-debug", "true");
55
+ if (this.options.nonce) script.setAttribute("nonce", this.options.nonce);
56
+ script.onload = () => resolve();
57
+ script.onerror = () => {
58
+ this.scriptPromise = null;
59
+ reject(new Error("SCRIPT_LOAD_FAIL"));
60
+ };
61
+ document.head.appendChild(script);
62
+ });
63
+ return this.scriptPromise;
64
+ }
65
+ async getResponse() {
66
+ await this.load();
67
+ if (typeof window !== "undefined" && window.TrustSig) {
68
+ try {
69
+ return await window.TrustSig.getResponse();
70
+ } catch (e) {
71
+ return null;
72
+ }
73
+ }
74
+ return null;
75
+ }
76
+ };
77
+ // Annotate the CommonJS export names for ESM import in node:
78
+ 0 && (module.exports = {
79
+ TrustSigClient
80
+ });
@@ -0,0 +1,24 @@
1
+ declare global {
2
+ interface Window {
3
+ TrustSig: {
4
+ getResponse: () => Promise<string | null>;
5
+ };
6
+ }
7
+ }
8
+ interface ClientOptions {
9
+ siteKey: string;
10
+ endpoint?: string;
11
+ wasmUrl?: string;
12
+ interceptRequests?: boolean;
13
+ debug?: boolean;
14
+ nonce?: string;
15
+ }
16
+ declare class TrustSigClient {
17
+ private options;
18
+ private scriptPromise;
19
+ constructor(options: ClientOptions);
20
+ load(): Promise<void>;
21
+ getResponse(): Promise<string | null>;
22
+ }
23
+
24
+ export { type ClientOptions, TrustSigClient };
@@ -0,0 +1,24 @@
1
+ declare global {
2
+ interface Window {
3
+ TrustSig: {
4
+ getResponse: () => Promise<string | null>;
5
+ };
6
+ }
7
+ }
8
+ interface ClientOptions {
9
+ siteKey: string;
10
+ endpoint?: string;
11
+ wasmUrl?: string;
12
+ interceptRequests?: boolean;
13
+ debug?: boolean;
14
+ nonce?: string;
15
+ }
16
+ declare class TrustSigClient {
17
+ private options;
18
+ private scriptPromise;
19
+ constructor(options: ClientOptions);
20
+ load(): Promise<void>;
21
+ getResponse(): Promise<string | null>;
22
+ }
23
+
24
+ export { type ClientOptions, TrustSigClient };
package/dist/index.js ADDED
@@ -0,0 +1,55 @@
1
+ // src/index.ts
2
+ import "@trustsig/types";
3
+ var TrustSigClient = class {
4
+ options;
5
+ scriptPromise = null;
6
+ constructor(options) {
7
+ if (!options.siteKey) {
8
+ throw new Error("SITE_KEY_REQUIRED");
9
+ }
10
+ this.options = options;
11
+ }
12
+ async load() {
13
+ if (this.scriptPromise) {
14
+ return this.scriptPromise;
15
+ }
16
+ if (typeof window === "undefined") {
17
+ return Promise.resolve();
18
+ }
19
+ if (window.TrustSig && typeof window.TrustSig.getResponse === "function") {
20
+ this.scriptPromise = Promise.resolve();
21
+ return this.scriptPromise;
22
+ }
23
+ this.scriptPromise = new Promise((resolve, reject) => {
24
+ const script = document.createElement("script");
25
+ script.src = "https://sdk.trustsig.com/trustsig.js";
26
+ script.setAttribute("data-site-key", this.options.siteKey);
27
+ if (this.options.endpoint) script.setAttribute("data-endpoint", this.options.endpoint);
28
+ if (this.options.wasmUrl) script.setAttribute("data-wasm-url", this.options.wasmUrl);
29
+ if (this.options.interceptRequests) script.setAttribute("data-intercept-requests", "true");
30
+ if (this.options.debug) script.setAttribute("data-debug", "true");
31
+ if (this.options.nonce) script.setAttribute("nonce", this.options.nonce);
32
+ script.onload = () => resolve();
33
+ script.onerror = () => {
34
+ this.scriptPromise = null;
35
+ reject(new Error("SCRIPT_LOAD_FAIL"));
36
+ };
37
+ document.head.appendChild(script);
38
+ });
39
+ return this.scriptPromise;
40
+ }
41
+ async getResponse() {
42
+ await this.load();
43
+ if (typeof window !== "undefined" && window.TrustSig) {
44
+ try {
45
+ return await window.TrustSig.getResponse();
46
+ } catch (e) {
47
+ return null;
48
+ }
49
+ }
50
+ return null;
51
+ }
52
+ };
53
+ export {
54
+ TrustSigClient
55
+ };
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "@trustsig/client",
3
- "version": "1.1.6",
3
+ "version": "1.1.11",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
8
11
  "exports": {
9
12
  ".": {
10
13
  "types": "./dist/index.d.ts",
@@ -17,6 +20,6 @@
17
20
  "build": "tsup"
18
21
  },
19
22
  "dependencies": {
20
- "@trustsig/types": "^1.1.5"
23
+ "@trustsig/types": "^1.1.11"
21
24
  }
22
- }
25
+ }
package/src/index.ts DELETED
@@ -1,69 +0,0 @@
1
- import "@trustsig/types";
2
-
3
- export interface ClientOptions {
4
- siteKey: string;
5
- endpoint?: string;
6
- wasmUrl?: string;
7
- interceptRequests?: boolean;
8
- debug?: boolean;
9
- nonce?: string;
10
- }
11
-
12
- export class TrustSigClient {
13
- private options: ClientOptions;
14
- private scriptPromise: Promise<void> | null = null;
15
-
16
- constructor(options: ClientOptions) {
17
- if (!options.siteKey) {
18
- throw new Error("SITE_KEY_REQUIRED");
19
- }
20
- this.options = options;
21
- }
22
-
23
- public async load(): Promise<void> {
24
- if (this.scriptPromise) {
25
- return this.scriptPromise;
26
- }
27
- if (typeof window === 'undefined') {
28
- return Promise.resolve();
29
- }
30
- if (window.TrustSig && typeof window.TrustSig.getResponse === 'function') {
31
- this.scriptPromise = Promise.resolve();
32
- return this.scriptPromise;
33
- }
34
-
35
- this.scriptPromise = new Promise((resolve, reject) => {
36
- const script = document.createElement('script');
37
- script.src = 'https://sdk.trustsig.com/trustsig.js';
38
- script.setAttribute('data-site-key', this.options.siteKey);
39
-
40
- if (this.options.endpoint) script.setAttribute('data-endpoint', this.options.endpoint);
41
- if (this.options.wasmUrl) script.setAttribute('data-wasm-url', this.options.wasmUrl);
42
- if (this.options.interceptRequests) script.setAttribute('data-intercept-requests', 'true');
43
- if (this.options.debug) script.setAttribute('data-debug', 'true');
44
- if (this.options.nonce) script.setAttribute('nonce', this.options.nonce);
45
-
46
- script.onload = () => resolve();
47
- script.onerror = () => {
48
- this.scriptPromise = null;
49
- reject(new Error("SCRIPT_LOAD_FAIL"));
50
- };
51
-
52
- document.head.appendChild(script);
53
- });
54
-
55
- return this.scriptPromise;
56
- }
57
-
58
- public async getResponse(): Promise<string | null> {
59
- await this.load();
60
- if (typeof window !== 'undefined' && window.TrustSig) {
61
- try {
62
- return await window.TrustSig.getResponse();
63
- } catch (e) {
64
- return null;
65
- }
66
- }
67
- return null;
68
- }
69
- }
@@ -1,44 +0,0 @@
1
- import { describe, it, expect, beforeEach, vi } from 'vitest';
2
- import { TrustSigClient } from '../src/index';
3
-
4
- describe('TrustSig Client', () => {
5
- beforeEach(() => {
6
- document.head.innerHTML = '';
7
- delete (window as any).TrustSig;
8
- // Prevent happy-dom from actually trying to download the remote script
9
- vi.spyOn(document.head, 'appendChild').mockImplementation((node) => {
10
- if (node instanceof HTMLScriptElement) {
11
- // Trigger onload manually
12
- setTimeout(() => {
13
- if (node.onload) node.onload(new Event('load'));
14
- }, 10);
15
- }
16
- return node;
17
- });
18
- });
19
-
20
- it('requires siteKey', () => {
21
- expect(() => new TrustSigClient({ siteKey: '' })).toThrow('SITE_KEY_REQUIRED');
22
- });
23
-
24
- it('injects script tag', async () => {
25
- const client = new TrustSigClient({ siteKey: 'TEST_KEY' });
26
- const loadPromise = client.load();
27
- const appendCall = (document.head.appendChild as any).mock.calls[0][0];
28
-
29
- expect(appendCall).not.toBeNull();
30
- expect(appendCall.getAttribute('data-site-key')).toBe('TEST_KEY');
31
- expect(appendCall.src).toBe('https://sdk.trustsig.com/trustsig.js');
32
- await loadPromise;
33
- });
34
-
35
- it('returns response from window when loaded', async () => {
36
- const client = new TrustSigClient({ siteKey: 'TEST_KEY' });
37
- (window as any).TrustSig = {
38
- getResponse: vi.fn().mockResolvedValue('test-token')
39
- };
40
-
41
- const token = await client.getResponse();
42
- expect(token).toBe('test-token');
43
- });
44
- });
package/tsup.config.ts DELETED
@@ -1,2 +0,0 @@
1
- import { defineConfig } from 'tsup';
2
- export default defineConfig({ entry: ['src/index.ts'], format: ['cjs', 'esm'], dts: true, clean: true });