@jolibox/implement 1.4.2 → 1.4.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 +4 -3
- package/dist/index.js +20 -20
- package/dist/index.native.js +79 -79
- package/dist/native/api/__tests__/getSpinSubscriptionPrice.test.d.ts +1 -0
- package/implement.build.log +2 -2
- package/package.json +6 -6
- package/src/native/api/__tests__/getSpinSubscriptionPrice.test.ts +155 -0
- package/src/native/api/payment.ts +43 -1
- package/src/native/api/task.ts +23 -29
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
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.4.
|
|
3
|
+
> @jolibox/implement@1.4.6 clean
|
|
4
4
|
> rimraf ./dist
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
> @jolibox/implement@1.4.
|
|
7
|
+
> @jolibox/implement@1.4.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.4.
|
|
4
|
+
"version": "1.4.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.4.
|
|
10
|
-
"@jolibox/types": "1.4.
|
|
11
|
-
"@jolibox/native-bridge": "1.4.
|
|
12
|
-
"@jolibox/ads": "1.4.
|
|
9
|
+
"@jolibox/common": "1.4.6",
|
|
10
|
+
"@jolibox/types": "1.4.6",
|
|
11
|
+
"@jolibox/native-bridge": "1.4.6",
|
|
12
|
+
"@jolibox/ads": "1.4.6",
|
|
13
13
|
"localforage": "1.10.0",
|
|
14
|
-
"@jolibox/ui": "1.4.
|
|
14
|
+
"@jolibox/ui": "1.4.6",
|
|
15
15
|
"web-vitals": "4.2.4"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { applyNative } from '@jolibox/native-bridge';
|
|
2
|
+
import { ISubscriptionPlanData } from '@/native/subscription/type';
|
|
3
|
+
|
|
4
|
+
jest.mock('@jolibox/native-bridge', () => ({
|
|
5
|
+
applyNative: jest.fn(),
|
|
6
|
+
onNative: jest.fn(),
|
|
7
|
+
invokeNative: jest.fn()
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
const mockApplyNative = applyNative as jest.Mock;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Replicate the core logic of getSpinSubscriptionPrice from payment.ts
|
|
14
|
+
* to test it in isolation without triggering the full module import chain.
|
|
15
|
+
*/
|
|
16
|
+
async function getSpinSubscriptionPriceImpl(params: { appStoreProductId: string }) {
|
|
17
|
+
const { data } = await applyNative('requestSubscriptionPlansAsync', {
|
|
18
|
+
appStoreProductIds: [params.appStoreProductId],
|
|
19
|
+
type: 'SPIN'
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
if (!data) {
|
|
23
|
+
throw new Error('[JoliboxSDK]: get spin subscription price failed');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const plans = Object.values(data as Record<string, ISubscriptionPlanData>).map((plan) => ({
|
|
27
|
+
basePlanId: plan.basePlanId,
|
|
28
|
+
productId: plan.productId,
|
|
29
|
+
formattedPrice: plan.pricing.formattedPrice,
|
|
30
|
+
originalPrice: plan.pricing.originalPrice,
|
|
31
|
+
trialDay: plan.trial?.duration ?? 0
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
return { plans };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
describe('getSpinSubscriptionPrice', () => {
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
jest.clearAllMocks();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should call applyNative with type SPIN and return formatted plans', async () => {
|
|
43
|
+
mockApplyNative.mockResolvedValue({
|
|
44
|
+
data: {
|
|
45
|
+
'spin-weekly': {
|
|
46
|
+
basePlanId: 'spin-weekly',
|
|
47
|
+
productId: 'jolibox_app_spin_sub',
|
|
48
|
+
pricing: {
|
|
49
|
+
formattedPrice: '$1.99',
|
|
50
|
+
originalPrice: '$1.99',
|
|
51
|
+
discountPercentage: null
|
|
52
|
+
},
|
|
53
|
+
trial: {
|
|
54
|
+
duration: 3,
|
|
55
|
+
description: ''
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const result = await getSpinSubscriptionPriceImpl({
|
|
62
|
+
appStoreProductId: 'jolibox_app_spin_sub'
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
expect(mockApplyNative).toHaveBeenCalledWith('requestSubscriptionPlansAsync', {
|
|
66
|
+
appStoreProductIds: ['jolibox_app_spin_sub'],
|
|
67
|
+
type: 'SPIN'
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
expect(result).toEqual({
|
|
71
|
+
plans: [
|
|
72
|
+
{
|
|
73
|
+
basePlanId: 'spin-weekly',
|
|
74
|
+
productId: 'jolibox_app_spin_sub',
|
|
75
|
+
formattedPrice: '$1.99',
|
|
76
|
+
originalPrice: '$1.99',
|
|
77
|
+
trialDay: 3
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('should handle multiple plans', async () => {
|
|
84
|
+
mockApplyNative.mockResolvedValue({
|
|
85
|
+
data: {
|
|
86
|
+
'spin-weekly': {
|
|
87
|
+
basePlanId: 'spin-weekly',
|
|
88
|
+
productId: 'jolibox_app_spin_sub',
|
|
89
|
+
pricing: { formattedPrice: '$1.99', originalPrice: '$1.99' },
|
|
90
|
+
trial: { duration: 3 }
|
|
91
|
+
},
|
|
92
|
+
'spin-monthly': {
|
|
93
|
+
basePlanId: 'spin-monthly',
|
|
94
|
+
productId: 'jolibox_app_spin_sub',
|
|
95
|
+
pricing: { formattedPrice: '$4.99', originalPrice: '$4.99' },
|
|
96
|
+
trial: { duration: 7 }
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const result = await getSpinSubscriptionPriceImpl({
|
|
102
|
+
appStoreProductId: 'jolibox_app_spin_sub'
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
expect(result.plans).toHaveLength(2);
|
|
106
|
+
expect(result.plans).toEqual(
|
|
107
|
+
expect.arrayContaining([
|
|
108
|
+
expect.objectContaining({ basePlanId: 'spin-weekly', formattedPrice: '$1.99' }),
|
|
109
|
+
expect.objectContaining({ basePlanId: 'spin-monthly', formattedPrice: '$4.99' })
|
|
110
|
+
])
|
|
111
|
+
);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('should default trialDay to 0 when trial is undefined', async () => {
|
|
115
|
+
mockApplyNative.mockResolvedValue({
|
|
116
|
+
data: {
|
|
117
|
+
'spin-weekly': {
|
|
118
|
+
basePlanId: 'spin-weekly',
|
|
119
|
+
productId: 'jolibox_app_spin_sub',
|
|
120
|
+
pricing: { formattedPrice: '$1.99', originalPrice: '$1.99' }
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const result = await getSpinSubscriptionPriceImpl({
|
|
126
|
+
appStoreProductId: 'jolibox_app_spin_sub'
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
expect(result.plans[0].trialDay).toBe(0);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('should throw error when native returns no data', async () => {
|
|
133
|
+
mockApplyNative.mockResolvedValue({ data: null });
|
|
134
|
+
|
|
135
|
+
await expect(getSpinSubscriptionPriceImpl({ appStoreProductId: 'jolibox_app_spin_sub' })).rejects.toThrow(
|
|
136
|
+
'get spin subscription price failed'
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('should throw error when native returns undefined data', async () => {
|
|
141
|
+
mockApplyNative.mockResolvedValue({});
|
|
142
|
+
|
|
143
|
+
await expect(getSpinSubscriptionPriceImpl({ appStoreProductId: 'jolibox_app_spin_sub' })).rejects.toThrow(
|
|
144
|
+
'get spin subscription price failed'
|
|
145
|
+
);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('should throw error when native call rejects', async () => {
|
|
149
|
+
mockApplyNative.mockRejectedValue(new Error('Native bridge unavailable'));
|
|
150
|
+
|
|
151
|
+
await expect(getSpinSubscriptionPriceImpl({ appStoreProductId: 'jolibox_app_spin_sub' })).rejects.toThrow(
|
|
152
|
+
'Native bridge unavailable'
|
|
153
|
+
);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
@@ -3,8 +3,10 @@ import { createAPI, registerCanIUse, t } from './base';
|
|
|
3
3
|
import { createJoliGemPaymentService } from '../payment/payment-service';
|
|
4
4
|
import { createAPIError } from '@/common/report/errors';
|
|
5
5
|
import { IPaymentChoice } from '@jolibox/ui/dist/bridge/coin';
|
|
6
|
-
import { ISubscriptionTierData } from '@jolibox/types';
|
|
6
|
+
import { ISpinSubscriptionPriceData, ISubscriptionTierData } from '@jolibox/types';
|
|
7
7
|
import { subscriptionService } from '@/native/subscription';
|
|
8
|
+
import { applyNative } from '@jolibox/native-bridge';
|
|
9
|
+
import { ISubscriptionPlanData } from '@/native/subscription/type';
|
|
8
10
|
|
|
9
11
|
const commands = createCommands();
|
|
10
12
|
const paymentService = createJoliGemPaymentService();
|
|
@@ -143,7 +145,43 @@ commands.registerCommand('PaymentSDK.getSubscriptionPlans', getSubscriptionPlans
|
|
|
143
145
|
commands.registerCommand('PaymentSDK.subscribe', subscribe);
|
|
144
146
|
commands.registerCommand('PaymentSDK.subscribeSpin', subscribeSpin);
|
|
145
147
|
|
|
148
|
+
const getSpinSubscriptionPrice = createAPI('getSpinSubscriptionPrice', {
|
|
149
|
+
paramsSchema: t.tuple(
|
|
150
|
+
t.object({
|
|
151
|
+
appStoreProductId: t.string()
|
|
152
|
+
})
|
|
153
|
+
),
|
|
154
|
+
implement: async (params: {
|
|
155
|
+
appStoreProductId: string;
|
|
156
|
+
}): Promise<{ plans: ISpinSubscriptionPriceData[] }> => {
|
|
157
|
+
const { data } = await applyNative('requestSubscriptionPlansAsync', {
|
|
158
|
+
appStoreProductIds: [params.appStoreProductId],
|
|
159
|
+
type: 'SPIN'
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
if (!data) {
|
|
163
|
+
throw createAPIError({
|
|
164
|
+
code: -1,
|
|
165
|
+
msg: '[JoliboxSDK]: get spin subscription price failed'
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const plans: ISpinSubscriptionPriceData[] = Object.values(
|
|
170
|
+
data as Record<string, ISubscriptionPlanData>
|
|
171
|
+
).map((plan) => ({
|
|
172
|
+
basePlanId: plan.basePlanId,
|
|
173
|
+
productId: plan.productId,
|
|
174
|
+
formattedPrice: plan.pricing.formattedPrice,
|
|
175
|
+
originalPrice: plan.pricing.originalPrice,
|
|
176
|
+
trialDay: plan.trial?.duration ?? 0
|
|
177
|
+
}));
|
|
178
|
+
|
|
179
|
+
return { plans };
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
|
|
146
183
|
commands.registerCommand('PaymentSDK.flushSubInfoCache', flushSubInfoCache);
|
|
184
|
+
commands.registerCommand('PaymentSDK.getSpinSubscriptionPrice', getSpinSubscriptionPrice);
|
|
147
185
|
|
|
148
186
|
registerCanIUse('payment.purchaseGem', {
|
|
149
187
|
version: '1.2.9'
|
|
@@ -168,3 +206,7 @@ registerCanIUse('payment.flushSubInfoCache', {
|
|
|
168
206
|
registerCanIUse('payment.subscribeSpin', {
|
|
169
207
|
version: '1.3.7'
|
|
170
208
|
});
|
|
209
|
+
|
|
210
|
+
registerCanIUse('payment.getSpinSubscriptionPrice', {
|
|
211
|
+
version: '1.4.3'
|
|
212
|
+
});
|
package/src/native/api/task.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createCommands } from '@jolibox/common';
|
|
2
|
-
import { createAPI, registerCanIUse, t } from './base';
|
|
2
|
+
import { createAPI, registerCanIUse, t, canIUseNative } from './base';
|
|
3
3
|
import { taskTracker } from '../report';
|
|
4
|
-
import { emitNative } from '@jolibox/native-bridge';
|
|
4
|
+
import { emitNative, invokeNative } from '@jolibox/native-bridge';
|
|
5
5
|
import { context } from '@/common/context';
|
|
6
6
|
|
|
7
7
|
const commands = createCommands();
|
|
@@ -35,6 +35,15 @@ function throttledEmitScore(data: any) {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
function reportTaskGameInfo(
|
|
39
|
+
event: 'COMPLETE_GAME_LEVEL' | 'GAME_ENDED' | 'GAME_LEVEL_UP',
|
|
40
|
+
inGameInfo: Record<string, any>
|
|
41
|
+
) {
|
|
42
|
+
return canIUseNative('notifyTaskGameInfoAsync')
|
|
43
|
+
? invokeNative('notifyTaskGameInfoAsync', { event, inGameInfo })
|
|
44
|
+
: taskTracker.reporter({ event, extraParams: { inGameInfo } });
|
|
45
|
+
}
|
|
46
|
+
|
|
38
47
|
const onLevelFinished = createAPI('levelFinished', {
|
|
39
48
|
paramsSchema: t.tuple(
|
|
40
49
|
t.object({
|
|
@@ -59,16 +68,11 @@ const onLevelFinished = createAPI('levelFinished', {
|
|
|
59
68
|
);
|
|
60
69
|
|
|
61
70
|
tasks.push(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
duration,
|
|
68
|
-
rating,
|
|
69
|
-
score
|
|
70
|
-
}
|
|
71
|
-
}
|
|
71
|
+
reportTaskGameInfo('COMPLETE_GAME_LEVEL', {
|
|
72
|
+
levelId,
|
|
73
|
+
duration,
|
|
74
|
+
rating,
|
|
75
|
+
score
|
|
72
76
|
})
|
|
73
77
|
);
|
|
74
78
|
throttledEmitScore({ levelId, duration, rating, score });
|
|
@@ -98,15 +102,10 @@ const onGamePlayEnded = createAPI('gamePlayEnded', {
|
|
|
98
102
|
);
|
|
99
103
|
|
|
100
104
|
tasks.push(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
duration,
|
|
106
|
-
rating,
|
|
107
|
-
score
|
|
108
|
-
}
|
|
109
|
-
}
|
|
105
|
+
reportTaskGameInfo('GAME_ENDED', {
|
|
106
|
+
duration,
|
|
107
|
+
rating,
|
|
108
|
+
score
|
|
110
109
|
})
|
|
111
110
|
);
|
|
112
111
|
throttledEmitScore({ duration, rating, score });
|
|
@@ -130,14 +129,9 @@ const onLevelUpgrade = createAPI('levelUpgrade', {
|
|
|
130
129
|
})
|
|
131
130
|
);
|
|
132
131
|
tasks.push(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
inGameInfo: {
|
|
137
|
-
levelId,
|
|
138
|
-
levelName: name
|
|
139
|
-
}
|
|
140
|
-
}
|
|
132
|
+
reportTaskGameInfo('GAME_LEVEL_UP', {
|
|
133
|
+
levelId,
|
|
134
|
+
levelName: name
|
|
141
135
|
})
|
|
142
136
|
);
|
|
143
137
|
emitNative('cpUpdateScoreEvent', { levelId }, context.webviewId);
|