@polyguard/sdk 1.2.3 → 1.2.4

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/package.json CHANGED
@@ -1,21 +1,24 @@
1
1
  {
2
2
  "name": "@polyguard/sdk",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "type": "module",
5
- "main": "dist/sdk.js",
6
- "module": "dist/sdk.js",
7
- "browser": "dist/sdk.js",
5
+ "main": "dist/sdk.esm.js",
6
+ "module": "dist/sdk.esm.js",
7
+ "browser": "dist/sdk.esm.js",
8
8
  "exports": {
9
9
  ".": {
10
- "import": "./dist/sdk.js",
11
- "require": "./dist/sdk.js",
12
- "default": "./dist/sdk.js"
10
+ "import": "./dist/sdk.esm.js",
11
+ "require": "./dist/sdk.esm.js",
12
+ "default": "./dist/sdk.esm.js"
13
13
  }
14
14
  },
15
15
  "scripts": {
16
- "build": "esbuild src/index.js --bundle --format=esm --outfile=dist/sdk.js",
16
+ "build": "npm run build:esm && npm run build:iife",
17
+ "build:esm": "esbuild src/index.js --bundle --format=esm --outfile=dist/sdk.esm.js",
18
+ "build:iife": "esbuild src/browser.js --bundle --format=iife --global-name=Polyguard --outfile=dist/sdk.js",
17
19
  "prepare": "npm run build",
18
- "test": "echo \"Error: no test specified\" && exit 1",
20
+ "test": "vitest run",
21
+ "test:watch": "vitest",
19
22
  "regenerate-client": "bash scripts/regenerate-client.sh"
20
23
  },
21
24
  "keywords": [],
@@ -28,7 +31,9 @@
28
31
  "superagent": "^10.3.0"
29
32
  },
30
33
  "devDependencies": {
31
- "esbuild": "^0.25.0"
34
+ "esbuild": "^0.25.0",
35
+ "jsdom": "^28.0.0",
36
+ "vitest": "^4.0.18"
32
37
  },
33
38
  "repository": {
34
39
  "type": "git",
@@ -66,12 +66,12 @@ export class PolyguardWebsocketClientImpl {
66
66
  modal.style.overflowY = 'auto';
67
67
  modal.style.paddingTop = '24px';
68
68
  modal.innerHTML = `
69
- <div id="polyguard-modal-content" style="background: #fff; border-radius: 16px; box-shadow: 0 8px 32px rgba(0,0,0,0.18); padding: 32px 24px 24px 24px; max-width: 340px; width: 100%; text-align: center; position: relative; font-family: 'Inter', 'Helvetica', 'Arial', sans-serif; margin: 0 auto; box-sizing: border-box;">
70
- <button id="polyguard-modal-close" style="position: absolute; top: 12px; right: 12px; background: none; border: none; font-size: 22px; cursor: pointer; z-index: 2;">&times;</button>
71
- <h2 style="margin-top: 0; font-size: 1.5rem; font-weight: 700;">Quick Identity Verification</h2>
69
+ <div id="polyguard-modal-content" style="background: #fff; color: #222; border-radius: 16px; box-shadow: 0 8px 32px rgba(0,0,0,0.18); padding: 32px 24px 24px 24px; max-width: 340px; width: 100%; text-align: center; position: relative; font-family: 'Inter', 'Helvetica', 'Arial', sans-serif; margin: 0 auto; box-sizing: border-box;">
70
+ <button id="polyguard-modal-close" style="position: absolute; top: 12px; right: 12px; background: none; border: none; font-size: 22px; color: #222; cursor: pointer; z-index: 2;">&times;</button>
71
+ <h2 style="margin-top: 0; font-size: 1.5rem; font-weight: 700; color: #222;">Quick Identity Verification</h2>
72
72
  <div style="font-size: 15px; color: #888; margin-bottom: 12px; font-weight: 500;">Powered by Polyguard</div>
73
73
  <div id="polyguard-qr" style="width: 200px; height: 200px; margin: 0 auto 16px auto; display: flex; align-items: center; justify-content: center; background: #f4f8fb; border-radius: 12px;"></div>
74
- <div style="margin-bottom: 12px; font-weight: 600;">Scan this QR code to verify your identity.</div>
74
+ <div style="margin-bottom: 12px; font-weight: 600; color: #222;">Scan this QR code to verify your identity.</div>
75
75
  <ul style="text-align: left; margin: 0 0 16px 0; padding-left: 20px; font-size: 14px; color: #444;">
76
76
  <li>We use the Polyguard service to verify your identity.</li>
77
77
  <li>If you do not have the Polyguard app, the QR code will redirect you to download it from the App Store or Google Play.</li>
@@ -0,0 +1,65 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { DEFAULT_PARAMS } from './helpers/fixtures.js';
3
+
4
+ // Mock the WebSocket impl so the facade tests never touch real internals
5
+ vi.mock('../PolyguardWebsocketClientImpl', () => {
6
+ class FakeImpl {
7
+ constructor(params = {}) {
8
+ this.appId = params.appId;
9
+ this.apiServer = params.apiServer;
10
+ this.integrationType = 'websocket';
11
+ this.blockingApi = { fake: true };
12
+ this.callsApi = { fake: true };
13
+ }
14
+ async verify(...args) {
15
+ return { args, result: 'fake-jwt' };
16
+ }
17
+ }
18
+ return { PolyguardWebsocketClientImpl: FakeImpl };
19
+ });
20
+
21
+ // Import after mock is set up
22
+ const { PolyguardClient } = await import('../PolyguardClient.js');
23
+
24
+ describe('PolyguardClient', () => {
25
+ beforeEach(() => {
26
+ vi.clearAllMocks();
27
+ });
28
+
29
+ it('defaults to websocket implementation', () => {
30
+ const client = new PolyguardClient(DEFAULT_PARAMS);
31
+ expect(client._impl).toBeDefined();
32
+ expect(client._impl.integrationType).toBe('websocket');
33
+ });
34
+
35
+ it('explicit integrationType websocket works the same', () => {
36
+ const client = new PolyguardClient({ ...DEFAULT_PARAMS, integrationType: 'websocket' });
37
+ expect(client._impl.integrationType).toBe('websocket');
38
+ });
39
+
40
+ it('copies properties from impl to facade', () => {
41
+ const client = new PolyguardClient(DEFAULT_PARAMS);
42
+ expect(client.appId).toBe(DEFAULT_PARAMS.appId);
43
+ expect(client.apiServer).toBe(DEFAULT_PARAMS.apiServer);
44
+ expect(client.integrationType).toBe('websocket');
45
+ expect(client.blockingApi).toEqual({ fake: true });
46
+ expect(client.callsApi).toEqual({ fake: true });
47
+ });
48
+
49
+ it('verify() delegates to _impl.verify() with all args forwarded', async () => {
50
+ const client = new PolyguardClient(DEFAULT_PARAMS);
51
+ const spy = vi.spyOn(client._impl, 'verify');
52
+ await client.verify('my-target', true);
53
+ expect(spy).toHaveBeenCalledWith('my-target', true);
54
+ });
55
+
56
+ it('verify() returns the impl result', async () => {
57
+ const client = new PolyguardClient(DEFAULT_PARAMS);
58
+ const result = await client.verify('t', false);
59
+ expect(result).toEqual({ args: ['t', false], result: 'fake-jwt' });
60
+ });
61
+
62
+ it('constructor with no params does not throw', () => {
63
+ expect(() => new PolyguardClient()).not.toThrow();
64
+ });
65
+ });