pipwave-ekyc-uikit 3.1.1 → 3.1.2-beta.2
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/.env.production +2 -2
- package/code-review-sc-341281.md +99 -0
- package/dist/pw-bundle.js +2 -4425
- package/dist/pw-bundle.js.LICENSE.txt +63 -0
- package/package.json +4 -2
- package/tsconfig.esm.json +7 -0
- package/vitest.config.ts +2 -0
package/.env.production
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
FACE_MODEL=https://assets.pipwave.com/ekyc/sdk/face-models
|
|
2
|
-
CARD_MODEL=https://assets.pipwave.com/ekyc/sdk/card-models
|
|
3
|
-
ORT=https://assets.pipwave.com/ekyc/sdk/ort
|
|
2
|
+
CARD_MODEL=https://staging-assets.pipwave.com/ekyc/sdk/card-models
|
|
3
|
+
ORT=https://staging-assets.pipwave.com/ekyc/sdk/ort
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Code Review — `hotfix-teojunjie-sc-341281-card-detection-csp`
|
|
2
|
+
|
|
3
|
+
**Base:** `origin/master`
|
|
4
|
+
**Scope:** card-detection CSP fix + worker→main-thread inference migration
|
|
5
|
+
|
|
6
|
+
## Summary
|
|
7
|
+
|
|
8
|
+
The branch does a solid job of the core migration: it moves ONNX inference off a
|
|
9
|
+
cross-origin Worker (which Chromium refuses to construct) onto the main thread, adds a
|
|
10
|
+
graceful manual-capture fallback, and introduces real unit tests for the box-decode math
|
|
11
|
+
and the load lifecycle. The lifecycle/generation guarding in `src/plugins/card-detection.ts`
|
|
12
|
+
is careful and well-tested. However, there are two blocking issues for anything targeting
|
|
13
|
+
production, plus a few things worth addressing.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## 🔴 Blocking
|
|
18
|
+
|
|
19
|
+
### 1. Production config points at staging infrastructure
|
|
20
|
+
|
|
21
|
+
`.env.production` (lines 2–3) was changed from `assets.pipwave.com` to
|
|
22
|
+
`staging-assets.pipwave.com` for both `CARD_MODEL` and `ORT` (face-models left on prod):
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
CARD_MODEL=https://staging-assets.pipwave.com/ekyc/sdk/card-models
|
|
26
|
+
ORT=https://staging-assets.pipwave.com/ekyc/sdk/ort
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Worse, the committed `dist/pw-bundle.js` — which is the package `main` and the actual
|
|
30
|
+
shipped artifact — has these **staging URLs baked in** (verified: `grep` finds
|
|
31
|
+
`staging-assets.pipwave.com/ekyc/sdk/{card-models,ort}` in the bundle, while face-models is
|
|
32
|
+
still prod). A production release would pull the model + ORT runtime from staging. Combined
|
|
33
|
+
with the `3.1.2-beta.1` version tag, this branch reads as not-yet-final. **Revert both to
|
|
34
|
+
`assets.pipwave.com` and rebuild the bundle before merge.**
|
|
35
|
+
|
|
36
|
+
### 2. `new Function(...import())` requires CSP `unsafe-eval` — on a CSP-fix branch
|
|
37
|
+
|
|
38
|
+
`src/plugins/card-detection.inference.ts:94` loads ORT via:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
const dynamicImport = new Function("specifier", "return import(specifier)") as ...
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
This is present in the shipped bundle. The `new Function` constructor requires
|
|
45
|
+
`script-src 'unsafe-eval'` in the **merchant's** CSP. This ticket exists precisely because
|
|
46
|
+
of strict-CSP merchants, and strict merchants very commonly block `unsafe-eval`. On those
|
|
47
|
+
sites this throws at the `ort-import` stage → classified retryable → 2 useless retries →
|
|
48
|
+
falls back to manual capture. So it degrades gracefully, but detection will be *unavailable
|
|
49
|
+
exactly on the sites this fix targets*, trading the Worker-construction CSP block for an
|
|
50
|
+
`unsafe-eval` CSP block.
|
|
51
|
+
|
|
52
|
+
The comment explains *why* (`"module": "commonjs"` makes tsc rewrite `import()` →
|
|
53
|
+
`require()` before webpack sees it — confirmed in `tsconfig.json`). The cleaner fix is to
|
|
54
|
+
let webpack emit a genuine dynamic `import()` (e.g. isolate this file with
|
|
55
|
+
`module: "esnext"`/`"es2020"`, or use webpack `output.module` + a magic-comment import)
|
|
56
|
+
rather than `new Function`. At minimum, **confirm the target merchants allow `unsafe-eval`**
|
|
57
|
+
before relying on this path — otherwise the CSP fix doesn't actually land where it's needed.
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## 🟡 Medium
|
|
62
|
+
|
|
63
|
+
### 3. Test suite can't run on the project's Node
|
|
64
|
+
|
|
65
|
+
`package.json` sets `"test": "vitest run"` with `vitest ^4.1.9`, which requires
|
|
66
|
+
Node ≥20.19/22.12. This machine runs Node 16.20.2, and `npx vitest run` fails at startup
|
|
67
|
+
(`node:util` has no `styleText` export). There's no `engines` field, no `.nvmrc`, and no CI.
|
|
68
|
+
The new tests are good but currently unrunnable for anyone on the repo's Node. Either pin
|
|
69
|
+
Node (`engines` + `.nvmrc`) or downgrade vitest to a Node-16-compatible line.
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## 🟢 Minor / nits
|
|
74
|
+
|
|
75
|
+
- **Dead classification branches** in `src/plugins/detection-failure.ts:5`: `importScripts`
|
|
76
|
+
(worker-only, no longer reachable from the main-thread engine) and `warmup` (warmup errors
|
|
77
|
+
are swallowed in `card-detection.inference.ts:124-128`, so they never reach
|
|
78
|
+
`classifyFailure`). Harmless, but stale now.
|
|
79
|
+
- **Retry has no in-progress feedback**: the Retry callback in `_showScannerUnavailableDialog`
|
|
80
|
+
(`card-camera.ts:585`) removes the overlay, then awaits `reloadModel()` (which itself can
|
|
81
|
+
back off up to several seconds) with no spinner. User sees the manual-capture UI with no
|
|
82
|
+
indication a retry is running.
|
|
83
|
+
- **Manual capture skips the success tick**: `triggerManualCapture` (`card-camera.ts:603`)
|
|
84
|
+
dispatches `captureImage` but doesn't call `showCaptureTick()` like the auto path does —
|
|
85
|
+
minor UX inconsistency.
|
|
86
|
+
- **Stale worker-era comments** in `card-detection.inference.ts:11,39` ("previously sent to
|
|
87
|
+
the worker as `wasmDir`", "Ported unchanged from the former worker's onmessage handler").
|
|
88
|
+
Fine as history, slightly noisy.
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## What's good
|
|
93
|
+
|
|
94
|
+
- Load-generation guarding (`_loadGeneration`) correctly handles dispose/reload racing an
|
|
95
|
+
in-flight `init()`, and the tests in `card-detection.test.ts` exercise exactly those races
|
|
96
|
+
(late-resolving init gets re-disposed, results dropped after dispose/stop).
|
|
97
|
+
- The stale-detection drain (`AUTO_CAPTURE_STALE_MS`) is a thoughtful fix for slow
|
|
98
|
+
single-thread devices where the border debounce lags the real card state.
|
|
99
|
+
- Extracting `decodeBestBox` as a pure function with unit coverage is the right call.
|