@polyguard/sdk 1.5.0 → 1.5.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.
Files changed (134) hide show
  1. package/LICENSE +200 -0
  2. package/README.md +328 -0
  3. package/package.json +7 -3
  4. package/coverage/base.css +0 -224
  5. package/coverage/block-navigation.js +0 -87
  6. package/coverage/clover.xml +0 -268
  7. package/coverage/coverage-final.json +0 -8
  8. package/coverage/favicon.png +0 -0
  9. package/coverage/index.html +0 -131
  10. package/coverage/prettify.css +0 -1
  11. package/coverage/prettify.js +0 -2
  12. package/coverage/sort-arrow-sprite.png +0 -0
  13. package/coverage/sorter.js +0 -210
  14. package/coverage/src/PolyguardClient.js.html +0 -160
  15. package/coverage/src/PolyguardWebsocketClientImpl.js.html +0 -634
  16. package/coverage/src/__tests__/helpers/fixtures.js.html +0 -166
  17. package/coverage/src/__tests__/helpers/index.html +0 -131
  18. package/coverage/src/__tests__/helpers/mockWebSocket.js.html +0 -283
  19. package/coverage/src/index.html +0 -176
  20. package/coverage/src/messageHandler.js.html +0 -448
  21. package/coverage/src/ticketService.js.html +0 -157
  22. package/coverage/src/ui.js.html +0 -349
  23. package/dist/sdk.global.js +0 -11256
  24. package/scripts/regenerate-client.sh +0 -59
  25. package/src/PolyguardClient.js +0 -25
  26. package/src/PolyguardWebsocketClientImpl.js +0 -198
  27. package/src/__tests__/PolyguardClient.test.js +0 -65
  28. package/src/__tests__/PolyguardWebsocketClientImpl.test.js +0 -617
  29. package/src/__tests__/helpers/fixtures.js +0 -27
  30. package/src/__tests__/helpers/mockWebSocket.js +0 -66
  31. package/src/__tests__/server.test.js +0 -148
  32. package/src/__tests__/sidebar.test.js +0 -289
  33. package/src/browser.js +0 -9
  34. package/src/generated/.babelrc +0 -33
  35. package/src/generated/.openapi-generator/FILES +0 -63
  36. package/src/generated/.openapi-generator/VERSION +0 -1
  37. package/src/generated/.openapi-generator-ignore +0 -23
  38. package/src/generated/.travis.yml +0 -5
  39. package/src/generated/README.md +0 -211
  40. package/src/generated/docs/ApiControllersPslStirCallRequest.md +0 -18
  41. package/src/generated/docs/ApiModelsApiCallModelsCallRequest.md +0 -12
  42. package/src/generated/docs/AppId.md +0 -8
  43. package/src/generated/docs/AppleApi.md +0 -88
  44. package/src/generated/docs/AuthApi.md +0 -1464
  45. package/src/generated/docs/BlockingApi.md +0 -208
  46. package/src/generated/docs/CallsApi.md +0 -140
  47. package/src/generated/docs/Certainty.md +0 -8
  48. package/src/generated/docs/CreateLinkRequest.md +0 -12
  49. package/src/generated/docs/DefaultApi.md +0 -128
  50. package/src/generated/docs/HTTPValidationError.md +0 -9
  51. package/src/generated/docs/InviteRequestModel.md +0 -10
  52. package/src/generated/docs/JWTRequest.md +0 -11
  53. package/src/generated/docs/LinksApi.md +0 -162
  54. package/src/generated/docs/NumberVerification.md +0 -10
  55. package/src/generated/docs/SdkApi.md +0 -54
  56. package/src/generated/docs/SecureLinksApi.md +0 -614
  57. package/src/generated/docs/StartAttestationRequest.md +0 -9
  58. package/src/generated/docs/StartMeetingRequest.md +0 -9
  59. package/src/generated/docs/StirApi.md +0 -52
  60. package/src/generated/docs/TwilioApi.md +0 -138
  61. package/src/generated/docs/UsersApi.md +0 -362
  62. package/src/generated/docs/ValidationError.md +0 -11
  63. package/src/generated/docs/ValidationErrorLocInner.md +0 -8
  64. package/src/generated/docs/VeriffApi.md +0 -188
  65. package/src/generated/docs/VeriffSessionRequest.md +0 -10
  66. package/src/generated/docs/VerifyRequest.md +0 -10
  67. package/src/generated/docs/WellKnownApi.md +0 -128
  68. package/src/generated/docs/ZoomApi.md +0 -848
  69. package/src/generated/git_push.sh +0 -57
  70. package/src/generated/mocha.opts +0 -1
  71. package/src/generated/package.json +0 -46
  72. package/src/generated/src/ApiClient.js +0 -677
  73. package/src/generated/src/api/AppleApi.js +0 -109
  74. package/src/generated/src/api/AuthApi.js +0 -1512
  75. package/src/generated/src/api/BlockingApi.js +0 -217
  76. package/src/generated/src/api/CallsApi.js +0 -164
  77. package/src/generated/src/api/DefaultApi.js +0 -145
  78. package/src/generated/src/api/LinksApi.js +0 -195
  79. package/src/generated/src/api/SdkApi.js +0 -81
  80. package/src/generated/src/api/SecureLinksApi.js +0 -670
  81. package/src/generated/src/api/StirApi.js +0 -80
  82. package/src/generated/src/api/TwilioApi.js +0 -158
  83. package/src/generated/src/api/UsersApi.js +0 -375
  84. package/src/generated/src/api/VeriffApi.js +0 -209
  85. package/src/generated/src/api/WellKnownApi.js +0 -145
  86. package/src/generated/src/api/ZoomApi.js +0 -823
  87. package/src/generated/src/index.js +0 -244
  88. package/src/generated/src/model/ApiControllersPslStirCallRequest.js +0 -211
  89. package/src/generated/src/model/ApiModelsApiCallModelsCallRequest.js +0 -119
  90. package/src/generated/src/model/CreateLinkRequest.js +0 -131
  91. package/src/generated/src/model/HTTPValidationError.js +0 -94
  92. package/src/generated/src/model/InviteRequestModel.js +0 -109
  93. package/src/generated/src/model/JWTRequest.js +0 -113
  94. package/src/generated/src/model/NumberVerification.js +0 -107
  95. package/src/generated/src/model/StartAttestationRequest.js +0 -95
  96. package/src/generated/src/model/StartMeetingRequest.js +0 -95
  97. package/src/generated/src/model/ValidationError.js +0 -130
  98. package/src/generated/src/model/VeriffSessionRequest.js +0 -107
  99. package/src/generated/src/model/VerifyRequest.js +0 -109
  100. package/src/generated/test/api/AppleApi.spec.js +0 -73
  101. package/src/generated/test/api/AuthApi.spec.js +0 -353
  102. package/src/generated/test/api/BlockingApi.spec.js +0 -103
  103. package/src/generated/test/api/CallsApi.spec.js +0 -83
  104. package/src/generated/test/api/DefaultApi.spec.js +0 -73
  105. package/src/generated/test/api/LinksApi.spec.js +0 -83
  106. package/src/generated/test/api/SdkApi.spec.js +0 -63
  107. package/src/generated/test/api/SecureLinksApi.spec.js +0 -143
  108. package/src/generated/test/api/StirApi.spec.js +0 -63
  109. package/src/generated/test/api/TwilioApi.spec.js +0 -83
  110. package/src/generated/test/api/UsersApi.spec.js +0 -133
  111. package/src/generated/test/api/VeriffApi.spec.js +0 -93
  112. package/src/generated/test/api/WellKnownApi.spec.js +0 -83
  113. package/src/generated/test/api/ZoomApi.spec.js +0 -213
  114. package/src/generated/test/model/ApiControllersPslStirCallRequest.spec.js +0 -119
  115. package/src/generated/test/model/ApiModelsApiCallModelsCallRequest.spec.js +0 -83
  116. package/src/generated/test/model/AppId.spec.js +0 -59
  117. package/src/generated/test/model/Certainty.spec.js +0 -59
  118. package/src/generated/test/model/CreateLinkRequest.spec.js +0 -83
  119. package/src/generated/test/model/HTTPValidationError.spec.js +0 -65
  120. package/src/generated/test/model/InviteRequestModel.spec.js +0 -71
  121. package/src/generated/test/model/JWTRequest.spec.js +0 -77
  122. package/src/generated/test/model/NumberVerification.spec.js +0 -71
  123. package/src/generated/test/model/StartAttestationRequest.spec.js +0 -65
  124. package/src/generated/test/model/StartMeetingRequest.spec.js +0 -65
  125. package/src/generated/test/model/ValidationError.spec.js +0 -77
  126. package/src/generated/test/model/ValidationErrorLocInner.spec.js +0 -59
  127. package/src/generated/test/model/VeriffSessionRequest.spec.js +0 -71
  128. package/src/generated/test/model/VerifyRequest.spec.js +0 -71
  129. package/src/index.js +0 -16
  130. package/src/messageHandler.js +0 -121
  131. package/src/server.js +0 -91
  132. package/src/ticketService.js +0 -28
  133. package/src/ui.js +0 -88
  134. package/vitest.config.js +0 -10
package/LICENSE ADDED
@@ -0,0 +1,200 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may accept support,
167
+ warranty, indemnity, or other liability obligations and/or rights
168
+ consistent with this License. However, in accepting such obligations,
169
+ You may act only on Your own behalf and on Your sole responsibility,
170
+ not on behalf of any other Contributor, and only if You agree to
171
+ indemnify, defend, and hold each Contributor harmless for any
172
+ liability incurred by, or claims asserted against, such Contributor
173
+ by reason of your accepting any such warranty or additional liability.
174
+
175
+ END OF TERMS AND CONDITIONS
176
+
177
+ APPENDIX: How to apply the Apache License to your work.
178
+
179
+ To apply the Apache License to your work, attach the following
180
+ boilerplate notice, with the fields enclosed by brackets "[]"
181
+ replaced with your own identifying information. (Don't include
182
+ the brackets!) The text should be enclosed in the appropriate
183
+ comment syntax for the file format. We also recommend that a
184
+ file or class name and description of purpose be included on the
185
+ same "printed page" as the copyright notice for easier
186
+ identification within third-party archives.
187
+
188
+ Copyright 2026 Polyguard, Inc.
189
+
190
+ Licensed under the Apache License, Version 2.0 (the "License");
191
+ you may not use this file except in compliance with the License.
192
+ You may obtain a copy of the License at
193
+
194
+ http://www.apache.org/licenses/LICENSE-2.0
195
+
196
+ Unless required by applicable law or agreed to in writing, software
197
+ distributed under the License is distributed on an "AS IS" BASIS,
198
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
199
+ implied. See the License for the specific language governing
200
+ permissions and limitations under the License.
package/README.md ADDED
@@ -0,0 +1,328 @@
1
+ # @polyguard/sdk
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@polyguard/sdk.svg)](https://www.npmjs.com/package/@polyguard/sdk)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@polyguard/sdk.svg)](https://www.npmjs.com/package/@polyguard/sdk)
5
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
6
+
7
+ The official JavaScript SDK for [Polyguard](https://polyguard.ai) — drop-in identity verification for web applications. Users scan a QR code with the Polyguard mobile app and your site receives a signed JWT containing the verified claims.
8
+
9
+ ## Features
10
+
11
+ - QR-code based identity verification
12
+ - Real-time WebSocket session with automatic reconnection
13
+ - Two UI modes: full-screen modal or embedded into your own DOM
14
+ - Mobile-aware: deep-links into the Polyguard app on the same device
15
+ - Configurable required proofs (e.g. `Full Name`, age, document type)
16
+ - Signed JWT response — verifiable with your Polyguard public key
17
+ - Convenience `require()` helper for one-call proof matching
18
+ - Server-side proxy helper for safe API-key usage (Next.js, Express, Workers, Bun, Deno)
19
+ - Ships as both an ESM module (npm) and a browser IIFE (CDN)
20
+
21
+ ## Requirements
22
+
23
+ - Browser runtime with `WebSocket`, `fetch`, and ES2020 features
24
+ - Node.js 18+ for any server-side proxy code
25
+ - A Polyguard account with an `appId` and API key — sign up at [console.polyguard.ai](https://console.polyguard.ai)
26
+
27
+ ## Installation
28
+
29
+ ### npm
30
+
31
+ ```bash
32
+ npm install @polyguard/sdk
33
+ ```
34
+
35
+ ### CDN
36
+
37
+ ```html
38
+ <script src="https://cdn.polyguard.ai/sdk/latest/sdk.js"></script>
39
+ ```
40
+
41
+ Pin to a specific version in production:
42
+
43
+ ```html
44
+ <script src="https://cdn.polyguard.ai/sdk/1.5.0/sdk.js"></script>
45
+ ```
46
+
47
+ ## Quick start
48
+
49
+ ### ESM (bundlers, frameworks)
50
+
51
+ ```js
52
+ import { PolyguardClient } from '@polyguard/sdk';
53
+
54
+ const client = new PolyguardClient({
55
+ appId: 'your-app-id',
56
+ apiServer: 'api.polyguard.ai', // optional
57
+ proxyUrl: '/api/polyguard', // your server-side proxy — see below
58
+ });
59
+
60
+ try {
61
+ const jwt = await client.verify();
62
+ // jwt is a signed token containing the verified identity claims
63
+ } catch (err) {
64
+ // The user closed the modal or cancelled.
65
+ }
66
+ ```
67
+
68
+ ### Browser (CDN)
69
+
70
+ ```html
71
+ <script src="https://cdn.polyguard.ai/sdk/latest/sdk.js"></script>
72
+ <script>
73
+ const client = new window.Polyguard.Client({
74
+ appId: 'your-app-id',
75
+ apiServer: 'api.polyguard.ai', // optional
76
+ proxyUrl: '/api/polyguard',
77
+ });
78
+
79
+ client.verify().then((jwt) => {
80
+ // jwt is a signed token containing the verified identity claims
81
+ });
82
+ </script>
83
+ ```
84
+
85
+ ## Security: never ship an API key to the browser
86
+
87
+ API keys grant role-based access to your Polyguard tenant. Passing `apiKey` to `PolyguardClient` in a browser context **throws** by design:
88
+
89
+ ```
90
+ Error: apiKey is forbidden in browser code; use proxyUrl with a server-side proxy
91
+ (see @polyguard/sdk/server). Set iKnowThisIsInsecure: true to bypass.
92
+ ```
93
+
94
+ The supported pattern is:
95
+
96
+ 1. Run a tiny proxy on your own server that injects the API key.
97
+ 2. Point the browser SDK at that proxy with `proxyUrl`.
98
+
99
+ The SDK provides `createProxyHandler` from the `@polyguard/sdk/server` entry point. It is a Fetch-API request handler that runs on Node 18+, Cloudflare Workers, Bun, Deno, Vercel Edge, Netlify Edge, and any framework that accepts a `(Request) => Response` function.
100
+
101
+ ### Server proxy with Next.js (App Router)
102
+
103
+ ```ts
104
+ // app/api/polyguard/[...path]/route.ts
105
+ import { createProxyHandler } from '@polyguard/sdk/server';
106
+
107
+ const handler = createProxyHandler({
108
+ apiKey: process.env.POLYGUARD_API_KEY,
109
+ apiServer: 'api.polyguard.ai',
110
+ pathPrefix: '/api/polyguard',
111
+ });
112
+
113
+ export const GET = handler;
114
+ export const POST = handler;
115
+ export const PUT = handler;
116
+ ```
117
+
118
+ ### Server proxy with Cloudflare Workers / Bun / Deno
119
+
120
+ ```js
121
+ import { createProxyHandler } from '@polyguard/sdk/server';
122
+
123
+ const polyguardProxy = createProxyHandler({
124
+ apiKey: globalThis.POLYGUARD_API_KEY, // bind in wrangler.toml / env
125
+ apiServer: 'api.polyguard.ai',
126
+ });
127
+
128
+ export default { fetch: polyguardProxy };
129
+ ```
130
+
131
+ ### Server proxy with Express
132
+
133
+ ```js
134
+ import express from 'express';
135
+ import { createProxyHandler } from '@polyguard/sdk/server';
136
+
137
+ const app = express();
138
+ const polyguardProxy = createProxyHandler({
139
+ apiKey: process.env.POLYGUARD_API_KEY,
140
+ apiServer: 'api.polyguard.ai',
141
+ });
142
+
143
+ // Wrap the Fetch-style handler for Express
144
+ app.all('/api/polyguard/*', async (req, res) => {
145
+ const url = `http://${req.headers.host}${req.originalUrl}`;
146
+ const request = new Request(url, {
147
+ method: req.method,
148
+ headers: req.headers,
149
+ body: ['GET', 'HEAD'].includes(req.method) ? undefined : req,
150
+ duplex: 'half',
151
+ });
152
+ const response = await polyguardProxy(request);
153
+ res.status(response.status);
154
+ response.headers.forEach((v, k) => res.setHeader(k, v));
155
+ if (response.body) {
156
+ const reader = response.body.getReader();
157
+ while (true) {
158
+ const { value, done } = await reader.read();
159
+ if (done) break;
160
+ res.write(value);
161
+ }
162
+ }
163
+ res.end();
164
+ });
165
+ ```
166
+
167
+ ### Proxy options
168
+
169
+ | Option | Type | Default | Description |
170
+ |---|---|---|---|
171
+ | `apiKey` | string | **required** | Your Polyguard API key — must come from a secret store / env var. |
172
+ | `apiServer` | string | `api.polyguard.ai` | Hostname of the Polyguard API. |
173
+ | `pathPrefix` | string | `/api/polyguard` | Prefix stripped from incoming requests before forwarding. |
174
+ | `allowedPaths` | string[] | `['POST /v2/ticket/', 'PUT /link/', 'GET /v2/preview/']` | Whitelist of `METHOD path-prefix` patterns. Requests that do not match return `404`. |
175
+
176
+ The default whitelist is the minimum surface the browser SDK calls. **Do not broaden `allowedPaths` without reason** — the proxy attaches your API key to every forwarded request, so each entry is an open door to that part of the Polyguard API.
177
+
178
+ ## Usage
179
+
180
+ ### Modal verification
181
+
182
+ The default `verify()` call opens an overlay modal with the QR code, a spinner, and a cancel button. It returns the JWT once the user completes verification on their phone.
183
+
184
+ ```js
185
+ const jwt = await client.verify();
186
+ ```
187
+
188
+ ### Embedded verification
189
+
190
+ Pass the `id` of an element you already render. The SDK injects the QR code there instead of opening a modal:
191
+
192
+ ```html
193
+ <div id="pg-qr"></div>
194
+ ```
195
+
196
+ ```js
197
+ const jwt = await client.verify('pg-qr');
198
+ ```
199
+
200
+ Embedded mode does **not** render a close button — you control the surrounding UI.
201
+
202
+ ### Proof matching with `require()`
203
+
204
+ `require()` runs `verify()` and then checks the decoded JWT payload for specific expected values. It is a convenience wrapper for the common "is this the user who claims to be X?" pattern:
205
+
206
+ ```js
207
+ const isJane = await client.require({ 'Full Name': 'Jane Doe' });
208
+ if (isJane) {
209
+ // proceed
210
+ }
211
+ ```
212
+
213
+ `require()` resolves to `false` if the user cancels, the server is unreachable, or any expected claim does not match. It never throws.
214
+
215
+ > **Always verify the JWT signature on your backend** before trusting any claim. You can also receive the complete JWT in your backend from a Polyguard webhook. `require()` decodes the payload client-side for UX gating only, and can be used to begin polling the backend for the webhook response.
216
+
217
+ ### Raw response
218
+
219
+ For target/embedded mode, pass `rawJwt: true` (second argument to `verify`) to get the full JWT string instead of the decoded object:
220
+
221
+ ```js
222
+ const response = await client.verify('pg-qr', true);
223
+ ```
224
+
225
+ ### Error handling
226
+
227
+ The behavior differs by UI mode — this is intentional:
228
+
229
+ | Scenario | Modal mode | Embedded / target mode |
230
+ |---|---|---|
231
+ | User clicks the close button | rejects with `Error('User cancelled')` | n/a (no close button) |
232
+ | Verification succeeds | resolves with the decoded JWT object (or raw JWT string if `rawJwt: true`) | resolves with the decoded JWT object (or raw JWT string if `rawJwt: true`) |
233
+
234
+ Always handle both a rejected promise and a `FAIL` result.
235
+
236
+ ## Configuration
237
+
238
+ ```js
239
+ new PolyguardClient(options)
240
+ ```
241
+
242
+ | Option | Type | Default | Description |
243
+ |---|---|---|---|
244
+ | `appId` | string | — | Your Polyguard application ID. |
245
+ | `apiServer` | string | — | Hostname of the Polyguard API (e.g. `api.polyguard.ai`). |
246
+ | `proxyUrl` | string | — | URL of your server-side proxy. **Recommended** for all browser deployments. |
247
+ | `baseUrl` | string | — | Direct API base URL. Mutually exclusive with `proxyUrl`. |
248
+ | `apiKey` | string | — | API key. **Throws in browser code.** Use a proxy instead. |
249
+ | `iKnowThisIsInsecure` | boolean | `false` | Escape hatch that disables the browser `apiKey` check. Do not use in production. |
250
+ | `requiredProofs` | string[] | `['Full Name']` | Claims the user must satisfy during verification. |
251
+ | `scanType` | string | `'single'` | Verification mode — `single` is the standard one-shot flow. `multi` should be used for trust checks with PG-Presence enabled. |
252
+ | `link_uuid` | string | — | UUID for a pre-created (semi-dynamic / "Adhoc") verification link. Omit for fully dynamic flows. |
253
+ | `integrationType` | string | `'websocket'` | Reserved for future transports. Leave at the default. |
254
+
255
+ ## API reference
256
+
257
+ ### `new PolyguardClient(options)`
258
+
259
+ Creates a client and instantiates all underlying API services. See **Configuration** above.
260
+
261
+ ### `client.verify(target?, rawJwt?) → Promise<string | object>`
262
+
263
+ Starts the verification flow.
264
+
265
+ - `target` (string, optional) — DOM element id to render the QR into. Omit for modal mode.
266
+ - `rawJwt` (boolean, optional) — when `true`, resolve with the full response object instead of the JWT string.
267
+
268
+ ### `client.require(expectedProofs, target?) → Promise<boolean>`
269
+
270
+ Runs `verify()` and returns `true` only if every key in `expectedProofs` matches the decoded JWT payload exactly. Returns `false` on cancellation, server errors, or any mismatch. Never throws.
271
+
272
+ ### Browser global
273
+
274
+ When loaded via `<script>`, the SDK is exposed as:
275
+
276
+ - `window.Polyguard.Client` — the `PolyguardClient` constructor
277
+ - `window.Polyguard.ApiClient` — the underlying API client class
278
+ - `window.Polyguard.<ServiceName>Api` — every generated API service (e.g. `TicketApi`)
279
+
280
+ ## Verifying JWTs on your backend
281
+
282
+ The SDK's job ends when it hands you a JWT. To trust the contents you must verify the signature using Polyguard's public key. A minimal Node example:
283
+
284
+ ```js
285
+ import jwt from 'jsonwebtoken';
286
+
287
+ const POLYGUARD_PUBKEY = process.env.POLYGUARD_PUBKEY;
288
+
289
+ const payload = jwt.verify(tokenFromBrowser, POLYGUARD_PUBKEY, {
290
+ algorithms: ['RS256'],
291
+ });
292
+
293
+ // payload['Full Name'], payload.iat, payload.exp, ...
294
+ ```
295
+
296
+ See the [Polyguard documentation](https://polyguard.ai/docs) for the canonical key distribution and claim list.
297
+
298
+ ## Module entry points
299
+
300
+ | Import | Use it for |
301
+ |---|---|
302
+ | `@polyguard/sdk` | Browser code — `PolyguardClient`, generated API services. |
303
+ | `@polyguard/sdk/server` | Server code — `createProxyHandler`. Has no browser-only dependencies. |
304
+
305
+ The CDN bundle (`https://cdn.polyguard.ai/sdk/<version>/sdk.js`) is browser-only and exposes the `window.Polyguard` global.
306
+
307
+ ## Versioning and distribution
308
+
309
+ `@polyguard/sdk` follows semantic versioning. Each release ships in two places:
310
+
311
+ - **npm** — `@polyguard/sdk` (ESM)
312
+ - **CDN** — `https://cdn.polyguard.ai/sdk/<version>/sdk.js` (IIFE) and `https://cdn.polyguard.ai/sdk/latest/sdk.js` (latest)
313
+
314
+ The `latest/` path tracks the most recent published tag. For production deployments, pin to a specific version.
315
+
316
+ ## Browser support
317
+
318
+ Modern evergreen browsers (Chrome, Edge, Firefox, Safari). The SDK relies on `WebSocket`, `fetch`, `Promise`, and ES2020 syntax. Internet Explorer is not supported.
319
+
320
+ ## Support
321
+
322
+ - Issues and feature requests: <https://github.com/polyguard-ai/web-sdk/issues>
323
+ - Product documentation: <[https://dev.polyguard.ai/documentation](https://dev.polyguard.ai/documentation)>
324
+ - Email: <support@polyguard.ai>
325
+
326
+ ## License
327
+
328
+ Apache License 2.0 © Polyguard, Inc. See [LICENSE](./LICENSE) for the full text.
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "@polyguard/sdk",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "type": "module",
5
5
  "main": "dist/sdk.esm.js",
6
6
  "module": "dist/sdk.esm.js",
7
7
  "browser": "dist/sdk.esm.js",
8
+ "files": [
9
+ "dist/",
10
+ "README.md"
11
+ ],
8
12
  "exports": {
9
13
  ".": {
10
14
  "import": "./dist/sdk.esm.js",
@@ -17,7 +21,7 @@
17
21
  }
18
22
  },
19
23
  "scripts": {
20
- "build": "npm run build:esm && npm run build:iife && npm run build:server",
24
+ "build": "rm -f dist/* && npm run build:esm && npm run build:iife && npm run build:server",
21
25
  "build:esm": "esbuild src/index.js --bundle --format=esm --outfile=dist/sdk.esm.js",
22
26
  "build:iife": "esbuild src/browser.js --bundle --format=iife --global-name=Polyguard --outfile=dist/sdk.js",
23
27
  "build:server": "esbuild src/server.js --bundle --format=esm --platform=neutral --outfile=dist/server.esm.js",
@@ -29,7 +33,7 @@
29
33
  },
30
34
  "keywords": [],
31
35
  "author": "Joshua McKenty",
32
- "license": "ISC",
36
+ "license": "Apache-2.0",
33
37
  "description": "Web SDK for Polyguard",
34
38
  "dependencies": {
35
39
  "qrcode": "^1.5.4",