@jolibox/implement 1.2.5-beta.3 → 1.2.5
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/.rush/temp/package-deps_build.json +17 -24
- package/dist/common/cache/request-cache-service.d.ts +111 -0
- package/dist/common/rewards/cached-fetch-reward.d.ts +2 -2
- package/dist/common/rewards/cached-reward-service.d.ts +2 -2
- package/dist/common/rewards/index.d.ts +0 -1
- package/dist/common/rewards/registers/utils/coins/jolicoin/cached-fetch-balance.d.ts +2 -2
- package/dist/common/rewards/registers/utils/coins/joligem/cached-fetch-gem-balance.d.ts +2 -2
- package/dist/common/rewards/reward-emitter.d.ts +0 -7
- package/dist/common/rewards/reward-helper.d.ts +1 -2
- package/dist/common/utils/index.d.ts +0 -18
- package/dist/h5/api/platformAdsHandle/JoliboxAdsHandler.d.ts +0 -1
- package/dist/index.js +9 -9
- package/dist/index.native.js +47 -47
- package/dist/native/payment/payment-service.d.ts +1 -1
- package/implement.build.log +2 -2
- package/package.json +7 -7
- package/src/common/cache/__tests__/request-cache-service.test.ts +686 -0
- package/src/common/cache/request-cache-service.ts +393 -0
- package/src/common/rewards/cached-fetch-reward.ts +2 -19
- package/src/common/rewards/cached-reward-service.ts +3 -3
- package/src/common/rewards/index.ts +0 -1
- package/src/common/rewards/registers/utils/coins/commands/use-payment.ts +8 -0
- package/src/common/rewards/registers/utils/coins/jolicoin/cached-fetch-balance.ts +1 -1
- package/src/common/rewards/registers/utils/coins/joligem/cached-fetch-gem-balance.ts +1 -1
- package/src/common/rewards/reward-emitter.ts +0 -8
- package/src/common/rewards/reward-helper.ts +1 -8
- package/src/common/utils/index.ts +0 -23
- package/src/h5/api/ads.ts +13 -14
- package/src/h5/api/platformAdsHandle/JoliboxAdsHandler.ts +1 -25
- package/src/h5/bootstrap/index.ts +19 -4
- package/src/h5/rewards/index.ts +1 -18
- package/src/native/payment/payment-service.ts +1 -1
- package/CHANGELOG.json +0 -11
- package/CHANGELOG.md +0 -9
- package/dist/common/rewards/registers/use-subscription.d.ts +0 -7
- package/dist/common/rewards/registers/utils/subscription/commands/index.d.ts +0 -1
- package/dist/common/rewards/registers/utils/subscription/commands/use-subscription.d.ts +0 -4
- package/dist/common/rewards/registers/utils/subscription/sub-handler.d.ts +0 -13
- package/dist/h5/bootstrap/auth/index.d.ts +0 -2
- package/dist/h5/bootstrap/auth/sub.d.ts +0 -2
- package/src/common/rewards/registers/use-subscription.ts +0 -34
- package/src/common/rewards/registers/utils/subscription/commands/index.ts +0 -1
- package/src/common/rewards/registers/utils/subscription/commands/use-subscription.ts +0 -29
- package/src/common/rewards/registers/utils/subscription/sub-handler.ts +0 -88
- package/src/h5/bootstrap/auth/__tests__/auth.test.ts +0 -308
- package/src/h5/bootstrap/auth/index.ts +0 -20
- package/src/h5/bootstrap/auth/sub.ts +0 -56
- /package/dist/{h5/bootstrap/auth/__tests__/auth.test.d.ts → common/cache/__tests__/request-cache-service.test.d.ts} +0 -0
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { onCustomEvent, notifyCustomEvent } from '@/common/utils';
|
|
2
|
-
import { uuidv4 as v4 } from '@jolibox/common';
|
|
3
|
-
// global event listener manager
|
|
4
|
-
interface PendingRequest {
|
|
5
|
-
resolve: (value: boolean) => void;
|
|
6
|
-
reject: (error: Error) => void;
|
|
7
|
-
timeoutId: NodeJS.Timeout;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const pendingRequests = new Map<string, PendingRequest>();
|
|
11
|
-
let isListenerInitialized = false;
|
|
12
|
-
|
|
13
|
-
// initialize global event listener
|
|
14
|
-
const initializeEventListener = () => {
|
|
15
|
-
if (isListenerInitialized) return;
|
|
16
|
-
|
|
17
|
-
onCustomEvent('ON_GET_USER_SUB_STATUS', (data) => {
|
|
18
|
-
const pendingRequest = pendingRequests.get(data.sequenceId);
|
|
19
|
-
if (pendingRequest) {
|
|
20
|
-
clearTimeout(pendingRequest.timeoutId);
|
|
21
|
-
pendingRequest.resolve(data.isSubUser);
|
|
22
|
-
pendingRequests.delete(data.sequenceId);
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
isListenerInitialized = true;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
// Reset function for testing
|
|
30
|
-
export const resetSubState = () => {
|
|
31
|
-
isListenerInitialized = false;
|
|
32
|
-
pendingRequests.clear();
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export async function getUserSubStatus(): Promise<boolean> {
|
|
36
|
-
initializeEventListener();
|
|
37
|
-
|
|
38
|
-
return new Promise((resolve, reject) => {
|
|
39
|
-
const sequenceId = v4();
|
|
40
|
-
|
|
41
|
-
const timeoutId = setTimeout(() => {
|
|
42
|
-
pendingRequests.delete(sequenceId);
|
|
43
|
-
reject(new Error('Timeout waiting for user sub status response'));
|
|
44
|
-
}, 3000); // 3 second timeout
|
|
45
|
-
|
|
46
|
-
pendingRequests.set(sequenceId, {
|
|
47
|
-
resolve,
|
|
48
|
-
reject,
|
|
49
|
-
timeoutId
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
notifyCustomEvent('JOLIBOX_GET_USER_SUB_STATUS', {
|
|
53
|
-
sequenceId
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
}
|
|
File without changes
|