@jolibox/implement 1.2.4 → 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.
Files changed (40) hide show
  1. package/.rush/temp/package-deps_build.json +24 -18
  2. package/dist/common/cache/__tests__/request-cache-service.test.d.ts +1 -0
  3. package/dist/common/cache/request-cache-service.d.ts +111 -0
  4. package/dist/common/report/base-tracker.d.ts +2 -1
  5. package/dist/common/rewards/cached-fetch-reward.d.ts +46 -0
  6. package/dist/common/rewards/cached-reward-service.d.ts +24 -0
  7. package/dist/common/rewards/fetch-reward.d.ts +2 -3
  8. package/dist/common/rewards/index.d.ts +2 -0
  9. package/dist/common/rewards/registers/utils/coins/jolicoin/cached-fetch-balance.d.ts +34 -0
  10. package/dist/common/rewards/registers/utils/coins/jolicoin/fetch-balance.d.ts +2 -1
  11. package/dist/common/rewards/registers/utils/coins/joligem/cached-fetch-gem-balance.d.ts +34 -0
  12. package/dist/common/rewards/registers/utils/coins/joligem/fetch-gem-balance.d.ts +2 -1
  13. package/dist/index.js +9 -9
  14. package/dist/index.native.js +33 -33
  15. package/dist/native/payment/payment-service.d.ts +36 -30
  16. package/implement.build.log +2 -2
  17. package/package.json +5 -5
  18. package/src/common/cache/__tests__/request-cache-service.test.ts +686 -0
  19. package/src/common/cache/request-cache-service.ts +393 -0
  20. package/src/common/report/base-tracker.ts +2 -2
  21. package/src/common/rewards/cached-fetch-reward.ts +241 -0
  22. package/src/common/rewards/cached-reward-service.ts +255 -0
  23. package/src/common/rewards/fetch-reward.ts +17 -93
  24. package/src/common/rewards/index.ts +3 -0
  25. package/src/common/rewards/registers/utils/coins/commands/use-payment.ts +8 -0
  26. package/src/common/rewards/registers/utils/coins/jolicoin/cached-fetch-balance.ts +177 -0
  27. package/src/common/rewards/registers/utils/coins/jolicoin/fetch-balance.ts +13 -1
  28. package/src/common/rewards/registers/utils/coins/jolicoin/jolicoin-handler.ts +2 -0
  29. package/src/common/rewards/registers/utils/coins/joligem/cached-fetch-gem-balance.ts +181 -0
  30. package/src/common/rewards/registers/utils/coins/joligem/fetch-gem-balance.ts +13 -1
  31. package/src/common/rewards/registers/utils/coins/joligem/gem-handler.ts +2 -0
  32. package/src/h5/api/ads.ts +5 -0
  33. package/src/h5/api/storage.ts +2 -2
  34. package/src/h5/http/index.ts +2 -2
  35. package/src/h5/report/event-tracker.ts +2 -2
  36. package/src/native/api/ads.ts +7 -1
  37. package/src/native/api/payment.ts +4 -4
  38. package/src/native/payment/__tests__/payment-service-simple.test.ts +97 -31
  39. package/src/native/payment/payment-service.ts +224 -210
  40. package/src/native/rewards/ui/payment-modal.ts +14 -7
@@ -1,38 +1,44 @@
1
1
  import { IPaymentChoice } from '@/common/rewards/reward-emitter';
2
2
  import type { PaymentResult } from './payment-helper';
3
+ import { RequestCacheService } from '@/common/cache/request-cache-service';
3
4
  type PaymentPurchaseType = 'JOLI_COIN' | 'JOLI_GEM';
4
- export interface CachedPaymentChoices {
5
- choices: IPaymentChoice[];
6
- timestamp: number;
7
- expiresAt: number;
8
- productIds: string[];
5
+ type PaymentRequest = Record<string, never>;
6
+ interface PaymentResponse {
7
+ balance: number;
8
+ enableAutoDeduct: boolean;
9
+ paymentChoices: IPaymentChoice[];
9
10
  }
10
- export declare class PaymentService {
11
- private productInfoCache;
12
- private static paymentChoicesCache;
13
- private static readonly PAYMENT_CHOICES_CACHE_DURATION;
14
- getJolicoinProductsInfo(type: PaymentPurchaseType): Promise<IPaymentChoice[]>;
15
- purchase(type: PaymentPurchaseType, productId: string): Promise<PaymentResult<{
11
+ interface PaymentCacheData {
12
+ paymentChoices: IPaymentChoice[];
13
+ }
14
+ interface PaymentRealTimeData {
15
+ balance: number;
16
+ enableAutoDeduct: boolean;
17
+ }
18
+ declare class BasePaymentService extends RequestCacheService<PaymentRequest, PaymentResponse, PaymentCacheData, PaymentRealTimeData> {
19
+ private apiEndpoint;
20
+ private paymentType;
21
+ private static failureCounters;
22
+ private static readonly MAX_FAILURE_COUNT;
23
+ constructor(apiEndpoint: string, paymentType: PaymentPurchaseType);
24
+ getProductsInfo(): Promise<PaymentResponse | undefined>;
25
+ purchase(productId: string): Promise<PaymentResult<{
16
26
  totalAmount: string;
17
27
  }>>;
18
- private static mergeResponseData;
19
- static getProductsInfo(apiEndpoint: string): Promise<{
20
- balance: number;
21
- enableAutoDeduct: boolean;
22
- paymentChoices: IPaymentChoice[];
23
- } | undefined>;
24
- private static getProductsInfoInternal;
25
- private static getPaymentChoicesFromCache;
26
- private static cachePaymentChoices;
27
- private static extractProductIds;
28
- private static arraysEqual;
29
- private static updateChoicesWithServerData;
30
- static clearPaymentChoicesCache(apiEndpoint?: string): void;
31
- static getPaymentChoicesCacheStats(): {
32
- cacheCount: number;
33
- validCount: number;
34
- expiredCount: number;
35
- };
36
- static clearExpiredPaymentChoicesCache(): void;
28
+ getProductsInfoWithBalance(): Promise<PaymentResponse | undefined>;
29
+ refreshProductsInfo(): Promise<PaymentResponse | undefined>;
30
+ static resetFailureCounters(): void;
31
+ static getFailureCount(endpoint: string): number;
32
+ }
33
+ export declare class JoliCoinPaymentService extends BasePaymentService {
34
+ constructor();
35
+ }
36
+ export declare class JoliGemPaymentService extends BasePaymentService {
37
+ constructor();
37
38
  }
39
+ export declare const createJoliCoinPaymentService: () => JoliCoinPaymentService;
40
+ export declare const createJoliGemPaymentService: () => JoliGemPaymentService;
41
+ export declare const clearNativePriceCache: () => void;
42
+ export declare const resetFailureCounters: () => void;
43
+ export declare const getFailureCount: (endpoint: string) => number;
38
44
  export {};
@@ -1,9 +1,9 @@
1
1
  Invoking: npm run clean && npm run build:esm && tsc
2
2
 
3
- > @jolibox/implement@1.2.4 clean
3
+ > @jolibox/implement@1.2.5 clean
4
4
  > rimraf ./dist
5
5
 
6
6
 
7
- > @jolibox/implement@1.2.4 build:esm
7
+ > @jolibox/implement@1.2.5 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,15 +1,15 @@
1
1
  {
2
2
  "name": "@jolibox/implement",
3
3
  "description": "This project is Jolibox JS-SDk implement for Native && H5",
4
- "version": "1.2.4",
4
+ "version": "1.2.5",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
7
7
  "license": "MIT",
8
8
  "dependencies": {
9
- "@jolibox/common": "1.2.4",
10
- "@jolibox/types": "1.2.4",
11
- "@jolibox/native-bridge": "1.2.4",
12
- "@jolibox/ads": "1.2.4",
9
+ "@jolibox/common": "1.2.5",
10
+ "@jolibox/types": "1.2.5",
11
+ "@jolibox/native-bridge": "1.2.5",
12
+ "@jolibox/ads": "1.2.5",
13
13
  "localforage": "1.10.0",
14
14
  "@jolibox/ui": "1.0.0",
15
15
  "web-vitals": "4.2.4"