@jolibox/implement 1.3.5-beta.9 → 1.3.6
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 +7 -7
- package/dist/common/utils/index.d.ts +1 -0
- package/dist/h5/bootstrap/auth/sub.d.ts +4 -1
- package/dist/index.js +7 -7
- package/dist/index.native.js +3 -3
- package/implement.build.log +2 -2
- package/package.json +7 -7
- package/src/common/report/base-tracker.ts +2 -1
- package/src/common/utils/index.ts +1 -0
- package/src/h5/bootstrap/auth/__tests__/auth.test.ts +22 -16
- package/src/h5/bootstrap/auth/sub.ts +7 -3
- package/src/h5/bootstrap/index.ts +5 -2
- package/src/native/subscription/registers/sub-app.ts +2 -2
package/implement.build.log
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Invoking: npm run clean && npm run build:esm && tsc
|
|
2
2
|
|
|
3
|
-
> @jolibox/implement@1.3.
|
|
3
|
+
> @jolibox/implement@1.3.6 clean
|
|
4
4
|
> rimraf ./dist
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
> @jolibox/implement@1.3.
|
|
7
|
+
> @jolibox/implement@1.3.6 build:esm
|
|
8
8
|
> BUILD_VERSION=$(node -p "require('./package.json').version") node esbuild.config.js --format=esm
|
|
9
9
|
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jolibox/implement",
|
|
3
3
|
"description": "This project is Jolibox JS-SDk implement for Native && H5",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.6",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@jolibox/common": "1.3.
|
|
10
|
-
"@jolibox/types": "1.3.
|
|
11
|
-
"@jolibox/native-bridge": "1.3.
|
|
12
|
-
"@jolibox/ads": "1.3.
|
|
9
|
+
"@jolibox/common": "1.3.6",
|
|
10
|
+
"@jolibox/types": "1.3.6",
|
|
11
|
+
"@jolibox/native-bridge": "1.3.6",
|
|
12
|
+
"@jolibox/ads": "1.3.6",
|
|
13
13
|
"localforage": "1.10.0",
|
|
14
|
-
"@jolibox/ui": "1.3.
|
|
14
|
+
"@jolibox/ui": "1.3.6",
|
|
15
15
|
"web-vitals": "4.2.4"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"@types/node": "18.0.0",
|
|
21
21
|
"rimraf": "6.0.1",
|
|
22
22
|
"esbuild": "0.24.2",
|
|
23
|
-
"@jolibox/eslint-config": "1.0.1-beta.
|
|
23
|
+
"@jolibox/eslint-config": "1.0.1-beta.19"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"clean": "rimraf ./dist",
|
|
@@ -81,6 +81,7 @@ export abstract class EventTracker {
|
|
|
81
81
|
const location = event.location ? event.location : await this.getLocation();
|
|
82
82
|
const target = event.target || null;
|
|
83
83
|
const extra = event.extra || null;
|
|
84
|
+
const { hostUserInfo } = context;
|
|
84
85
|
if (!this.deviceInfo) {
|
|
85
86
|
this.deviceInfo = await this.getDevice();
|
|
86
87
|
}
|
|
@@ -92,7 +93,7 @@ export abstract class EventTracker {
|
|
|
92
93
|
target,
|
|
93
94
|
extra,
|
|
94
95
|
timestamp: Date.now(),
|
|
95
|
-
userId: null
|
|
96
|
+
userId: hostUserInfo?.uid ?? null
|
|
96
97
|
}
|
|
97
98
|
];
|
|
98
99
|
const eventPackage: IEventPackage = {
|
|
@@ -30,6 +30,7 @@ import { getUserSubStatus, resetSubState } from '../sub';
|
|
|
30
30
|
interface EventData {
|
|
31
31
|
sequenceId: string;
|
|
32
32
|
isSubUser: boolean;
|
|
33
|
+
userId?: string;
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
describe('getUserSubStatus', () => {
|
|
@@ -68,12 +69,13 @@ describe('getUserSubStatus', () => {
|
|
|
68
69
|
if (eventHandler) {
|
|
69
70
|
(eventHandler as any)({
|
|
70
71
|
sequenceId: 'test-sequence-id',
|
|
71
|
-
isSubUser: true
|
|
72
|
+
isSubUser: true,
|
|
73
|
+
userId: 'user-123'
|
|
72
74
|
});
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
const result = await promise;
|
|
76
|
-
expect(result).
|
|
78
|
+
expect(result).toEqual({ isSubUser: true, userId: 'user-123' });
|
|
77
79
|
});
|
|
78
80
|
|
|
79
81
|
it('should resolve with false when isSubUser is false', async () => {
|
|
@@ -98,7 +100,7 @@ describe('getUserSubStatus', () => {
|
|
|
98
100
|
}
|
|
99
101
|
|
|
100
102
|
const result = await promise;
|
|
101
|
-
expect(result).
|
|
103
|
+
expect(result).toEqual({ isSubUser: false, userId: undefined });
|
|
102
104
|
});
|
|
103
105
|
|
|
104
106
|
it('should reject on timeout', async () => {
|
|
@@ -144,13 +146,13 @@ describe('getUserSubStatus', () => {
|
|
|
144
146
|
|
|
145
147
|
// Simulate responses with different sequence IDs
|
|
146
148
|
if (eventHandler) {
|
|
147
|
-
(eventHandler as any)({ sequenceId: 'uuid-1', isSubUser: true });
|
|
149
|
+
(eventHandler as any)({ sequenceId: 'uuid-1', isSubUser: true, userId: 'user-1' });
|
|
148
150
|
(eventHandler as any)({ sequenceId: 'uuid-2', isSubUser: false });
|
|
149
151
|
}
|
|
150
152
|
|
|
151
153
|
const [result1, result2] = await Promise.all([promise1, promise2]);
|
|
152
|
-
expect(result1).
|
|
153
|
-
expect(result2).
|
|
154
|
+
expect(result1).toEqual({ isSubUser: true, userId: 'user-1' });
|
|
155
|
+
expect(result2).toEqual({ isSubUser: false, userId: undefined });
|
|
154
156
|
});
|
|
155
157
|
|
|
156
158
|
it('should ignore responses with different sequenceId', async () => {
|
|
@@ -170,7 +172,8 @@ describe('getUserSubStatus', () => {
|
|
|
170
172
|
if (eventHandler) {
|
|
171
173
|
(eventHandler as any)({
|
|
172
174
|
sequenceId: 'wrong-sequence-id',
|
|
173
|
-
isSubUser: true
|
|
175
|
+
isSubUser: true,
|
|
176
|
+
userId: 'user-wrong'
|
|
174
177
|
});
|
|
175
178
|
}
|
|
176
179
|
|
|
@@ -194,12 +197,13 @@ describe('getUserSubStatus', () => {
|
|
|
194
197
|
if (eventHandler) {
|
|
195
198
|
(eventHandler as any)({
|
|
196
199
|
sequenceId: 'correct-sequence-id',
|
|
197
|
-
isSubUser: true
|
|
200
|
+
isSubUser: true,
|
|
201
|
+
userId: 'user-correct'
|
|
198
202
|
});
|
|
199
203
|
}
|
|
200
204
|
|
|
201
205
|
await promise;
|
|
202
|
-
expect(promiseResult).
|
|
206
|
+
expect(promiseResult).toEqual({ isSubUser: true, userId: 'user-correct' });
|
|
203
207
|
});
|
|
204
208
|
|
|
205
209
|
it('should handle multiple concurrent requests with different sequenceIds', async () => {
|
|
@@ -239,14 +243,14 @@ describe('getUserSubStatus', () => {
|
|
|
239
243
|
// Simulate responses in reverse order
|
|
240
244
|
if (eventHandler) {
|
|
241
245
|
(eventHandler as any)({ sequenceId: 'request-3', isSubUser: false });
|
|
242
|
-
(eventHandler as any)({ sequenceId: 'request-1', isSubUser: true });
|
|
243
|
-
(eventHandler as any)({ sequenceId: 'request-2', isSubUser: true });
|
|
246
|
+
(eventHandler as any)({ sequenceId: 'request-1', isSubUser: true, userId: 'user-1' });
|
|
247
|
+
(eventHandler as any)({ sequenceId: 'request-2', isSubUser: true, userId: 'user-2' });
|
|
244
248
|
}
|
|
245
249
|
|
|
246
250
|
const [result1, result2, result3] = await Promise.all([promise1, promise2, promise3]);
|
|
247
|
-
expect(result1).
|
|
248
|
-
expect(result2).
|
|
249
|
-
expect(result3).
|
|
251
|
+
expect(result1).toEqual({ isSubUser: true, userId: 'user-1' });
|
|
252
|
+
expect(result2).toEqual({ isSubUser: true, userId: 'user-2' });
|
|
253
|
+
expect(result3).toEqual({ isSubUser: false, userId: undefined });
|
|
250
254
|
});
|
|
251
255
|
|
|
252
256
|
it('should clean up timeout when response is received', async () => {
|
|
@@ -269,7 +273,8 @@ describe('getUserSubStatus', () => {
|
|
|
269
273
|
if (eventHandler) {
|
|
270
274
|
(eventHandler as any)({
|
|
271
275
|
sequenceId: 'cleanup-test-id',
|
|
272
|
-
isSubUser: true
|
|
276
|
+
isSubUser: true,
|
|
277
|
+
userId: 'user-cleanup'
|
|
273
278
|
});
|
|
274
279
|
}
|
|
275
280
|
|
|
@@ -305,7 +310,8 @@ describe('getUserSubStatus', () => {
|
|
|
305
310
|
if (eventHandler) {
|
|
306
311
|
(eventHandler as any)({
|
|
307
312
|
sequenceId: 'late-response-id',
|
|
308
|
-
isSubUser: true
|
|
313
|
+
isSubUser: true,
|
|
314
|
+
userId: 'user-late'
|
|
309
315
|
});
|
|
310
316
|
}
|
|
311
317
|
|
|
@@ -2,7 +2,7 @@ import { onCustomEvent, notifyCustomEvent } from '@/common/utils';
|
|
|
2
2
|
import { uuidv4 as v4 } from '@jolibox/common';
|
|
3
3
|
// global event listener manager
|
|
4
4
|
interface PendingRequest {
|
|
5
|
-
resolve: (value: boolean) => void;
|
|
5
|
+
resolve: (value: { isSubUser: boolean; userId?: string }) => void;
|
|
6
6
|
reject: (error: Error) => void;
|
|
7
7
|
timeoutId: NodeJS.Timeout;
|
|
8
8
|
}
|
|
@@ -18,7 +18,11 @@ const initializeEventListener = () => {
|
|
|
18
18
|
const pendingRequest = pendingRequests.get(data.sequenceId);
|
|
19
19
|
if (pendingRequest) {
|
|
20
20
|
clearTimeout(pendingRequest.timeoutId);
|
|
21
|
-
|
|
21
|
+
const { isSubUser, userId } = data;
|
|
22
|
+
pendingRequest.resolve({
|
|
23
|
+
isSubUser,
|
|
24
|
+
userId
|
|
25
|
+
});
|
|
22
26
|
pendingRequests.delete(data.sequenceId);
|
|
23
27
|
}
|
|
24
28
|
});
|
|
@@ -32,7 +36,7 @@ export const resetSubState = () => {
|
|
|
32
36
|
pendingRequests.clear();
|
|
33
37
|
};
|
|
34
38
|
|
|
35
|
-
export async function getUserSubStatus(): Promise<boolean> {
|
|
39
|
+
export async function getUserSubStatus(): Promise<{ isSubUser: boolean; userId?: string }> {
|
|
36
40
|
initializeEventListener();
|
|
37
41
|
|
|
38
42
|
return new Promise((resolve, reject) => {
|
|
@@ -33,8 +33,11 @@ function trackPerformance() {
|
|
|
33
33
|
function addDomContentLoaded() {
|
|
34
34
|
hostEmitter.on('onDocumentReady', async (startTime: number) => {
|
|
35
35
|
const isLogin = await checkSession();
|
|
36
|
-
const isSubUser = await getUserSubStatus().catch(() =>
|
|
37
|
-
|
|
36
|
+
const { isSubUser, userId } = await getUserSubStatus().catch(() => ({
|
|
37
|
+
isSubUser: false,
|
|
38
|
+
userId: undefined
|
|
39
|
+
}));
|
|
40
|
+
context.onEnvConfigChanged({ hostUserInfo: { isLogin, isSubUser, uid: userId } });
|
|
38
41
|
hostEmitter.emit('LifecycleEvent.onReady', {
|
|
39
42
|
...(context.hostUserInfo ? context.hostUserInfo : { isLogin: false })
|
|
40
43
|
});
|
|
@@ -32,7 +32,7 @@ export interface ISubAppSubscriptionContext {
|
|
|
32
32
|
onNative('onGlobalSubscriptionStateChange', (data) => {
|
|
33
33
|
const { status, orderResponse } = data;
|
|
34
34
|
console.log('[onGlobalSubscriptionStateChange] data', data);
|
|
35
|
-
if (status === 'SUCCESS' && (orderResponse?.subPlanId || orderResponse?.
|
|
35
|
+
if (status === 'SUCCESS' && (orderResponse?.subPlanId || orderResponse?.ticketId)) {
|
|
36
36
|
// user must be logined
|
|
37
37
|
context.onEnvConfigChanged({
|
|
38
38
|
hostUserInfo: {
|
|
@@ -58,7 +58,7 @@ onNative('onSubscritptionStateChange', (data) => {
|
|
|
58
58
|
deferred.resolve({
|
|
59
59
|
code: 'SUCCESS' as ResponseType,
|
|
60
60
|
message: 'jolicoin payment success',
|
|
61
|
-
data: { subPlanId: orderResponse?.subPlanId ?? orderResponse.
|
|
61
|
+
data: { subPlanId: orderResponse?.subPlanId ?? orderResponse.ticketId }
|
|
62
62
|
});
|
|
63
63
|
} else {
|
|
64
64
|
if (status === 'FAILED') {
|