@akinon/pz-masterpass-rest 2.0.56-rc.0 → 2.0.56
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/CHANGELOG.md +2 -6
- package/jest/__mocks__/akinon-next-components.js +26 -0
- package/jest/__mocks__/akinon-next-redux-hooks.js +6 -0
- package/jest/__mocks__/akinon-next-rtk.js +4 -0
- package/jest/__mocks__/akinon-next-utils.js +4 -0
- package/jest/__mocks__/hookform-resolvers.js +6 -0
- package/jest/__mocks__/host-store.js +16 -0
- package/jest/file-mock.js +1 -0
- package/jest/setup.ts +37 -0
- package/jest/style-mock.js +1 -0
- package/jest.config.js +46 -0
- package/package.json +5 -2
- package/src/components/credit-card-form.tsx +1 -1
- package/src/components/installment-list.tsx +1 -1
- package/src/components/otp-modal.tsx +4 -12
- package/src/hooks/use-masterpass-account-otp.test.tsx +189 -0
- package/src/hooks/use-masterpass-payment-pending.test.tsx +255 -0
- package/src/hooks/useMasterpassAccount.ts +36 -27
- package/src/hooks/useMasterpassPayment.ts +75 -11
- package/src/hooks/useMasterpassToken.ts +13 -50
- package/src/index.ts +0 -1
- package/src/redux/reducer.ts +2 -0
- package/src/types/custom-render.types.ts +4 -0
- package/src/types/payment.types.ts +3 -0
- package/src/utils/card-utils.ts +1 -1
- package/src/utils/payment-pending.test.ts +89 -0
- package/src/utils/payment-utils.ts +47 -0
- package/src/views/masterpass-rest-option.tsx +56 -6
- package/src/views/order-no-mismatch.test.tsx +434 -0
- package/src/views/payment-pending-guard.test.tsx +276 -0
- package/src/utils/wait-for-utils-ready.ts +0 -64
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
const DEFAULT_TIMEOUT_MS = 10000;
|
|
2
|
-
const POLL_INTERVAL_MS = 100;
|
|
3
|
-
|
|
4
|
-
interface MasterpassUtils {
|
|
5
|
-
decodeJwt: (token: string) => any;
|
|
6
|
-
[key: string]: any;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// `window.Utils` is attached by the Masterpass REST SDK and is undefined until
|
|
10
|
-
// that script finishes loading, so it is resolved through this guarded getter
|
|
11
|
-
// rather than accessed directly.
|
|
12
|
-
const getMasterpassUtils = (): MasterpassUtils | undefined =>
|
|
13
|
-
(window as unknown as { Utils?: MasterpassUtils }).Utils;
|
|
14
|
-
|
|
15
|
-
// The Masterpass REST SDK (`/masterpass-javascript-sdk-web.min.js`) attaches
|
|
16
|
-
// both `window.Masterpass` and `window.Utils` when it finishes loading. That
|
|
17
|
-
// script is loaded asynchronously (see `useMasterpassScript`), so on slow
|
|
18
|
-
// networks the `/orders/masterpass-token` response can arrive before the SDK
|
|
19
|
-
// is ready. Calling `window.Utils.decodeJwt(...)` at that point crashes the
|
|
20
|
-
// checkout with `TypeError: Cannot read properties of undefined (reading
|
|
21
|
-
// 'decodeJwt')` (ZERO-4362 — same class of bug already fixed in the non-rest
|
|
22
|
-
// `@akinon/pz-masterpass` package).
|
|
23
|
-
//
|
|
24
|
-
// This helper polls until the SDK has exposed `window.Utils.decodeJwt`, so
|
|
25
|
-
// callers can await readiness before decoding instead of crashing.
|
|
26
|
-
export const waitForUtilsReady = (
|
|
27
|
-
timeoutMs: number = DEFAULT_TIMEOUT_MS
|
|
28
|
-
): Promise<boolean> =>
|
|
29
|
-
new Promise((resolve) => {
|
|
30
|
-
const start = Date.now();
|
|
31
|
-
|
|
32
|
-
const check = () => {
|
|
33
|
-
if (typeof getMasterpassUtils()?.decodeJwt === 'function') {
|
|
34
|
-
resolve(true);
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (Date.now() - start >= timeoutMs) {
|
|
39
|
-
resolve(false);
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
setTimeout(check, POLL_INTERVAL_MS);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
check();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
// Guarded `decodeJwt` wrapper. Returns `undefined` (instead of throwing) when
|
|
50
|
-
// the SDK is not yet available, so every callsite degrades gracefully.
|
|
51
|
-
export const decodeMasterpassToken = <T = any>(
|
|
52
|
-
token: string
|
|
53
|
-
): T | undefined => {
|
|
54
|
-
const utils = getMasterpassUtils();
|
|
55
|
-
|
|
56
|
-
if (typeof utils?.decodeJwt !== 'function') {
|
|
57
|
-
console.error(
|
|
58
|
-
'[pz-masterpass-rest] window.Utils.decodeJwt is not available'
|
|
59
|
-
);
|
|
60
|
-
return undefined;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return utils.decodeJwt(token);
|
|
64
|
-
};
|