@ad-execute-manager/helper 2.0.0-alpha.1
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/dist/ad/InterstitialAdFather.d.ts +131 -0
- package/dist/ad/InterstitialAdNovel.d.ts +457 -0
- package/dist/ad/RewardAdFather.d.ts +131 -0
- package/dist/ad/RewardAdNovel.d.ts +464 -0
- package/dist/ad/index.d.ts +4 -0
- package/dist/const/const.d.ts +20 -0
- package/dist/core/AdExecuteManager.d.ts +129 -0
- package/dist/core/compose.d.ts +12 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/helper/AdAnalyticsJS.d.ts +132 -0
- package/dist/helper/CountRecorder.d.ts +59 -0
- package/dist/helper/EventEmitter.d.ts +15 -0
- package/dist/helper/Logger.d.ts +35 -0
- package/dist/helper/LovelUnlockManager.d.ts +233 -0
- package/dist/helper/PubSub.d.ts +9 -0
- package/dist/helper/RewardAdGlobalRecorder.d.ts +109 -0
- package/dist/helper/RewardAdSceneTriggerManager.d.ts +71 -0
- package/dist/helper/SerializableError.d.ts +9 -0
- package/dist/helper/Storage.d.ts +124 -0
- package/dist/helper/index.d.ts +10 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +1 -0
- package/dist/typings/ad.d.ts +188 -0
- package/dist/typings/common.d.ts +14 -0
- package/dist/typings/tracker.d.ts +1 -0
- package/dist/utils/functional.d.ts +13 -0
- package/package.json +24 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
export default RewardAdGlobalRecorder;
|
|
2
|
+
export type RecordType = "halfway" | "finished" | "completed";
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {'halfway' | 'finished' | 'completed'} RecordType
|
|
5
|
+
*/
|
|
6
|
+
declare class RewardAdGlobalRecorder {
|
|
7
|
+
static instance: any;
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param {object} args
|
|
11
|
+
* @param {string} args.sign 初始化标识
|
|
12
|
+
* @returns {RewardAdGlobalRecorder}
|
|
13
|
+
*/
|
|
14
|
+
static build(args: {
|
|
15
|
+
sign: string;
|
|
16
|
+
}): RewardAdGlobalRecorder;
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @returns {RewardAdGlobalRecorder}
|
|
20
|
+
*/
|
|
21
|
+
static getInstance(): RewardAdGlobalRecorder;
|
|
22
|
+
/**
|
|
23
|
+
* @param {object} args
|
|
24
|
+
* @param {string} args.sign 初始化标识
|
|
25
|
+
*/
|
|
26
|
+
constructor(args: {
|
|
27
|
+
sign: string;
|
|
28
|
+
});
|
|
29
|
+
_initSign: string;
|
|
30
|
+
/** @type {import('../typings/ad.js').SceneTextMap} */
|
|
31
|
+
_halfway: import("../typings/ad.js").SceneTextMap;
|
|
32
|
+
_finished: {
|
|
33
|
+
scene: number;
|
|
34
|
+
count: number;
|
|
35
|
+
}[];
|
|
36
|
+
/**
|
|
37
|
+
* @param {object} args
|
|
38
|
+
* @param {string} args.sign 初始化标识
|
|
39
|
+
*/
|
|
40
|
+
initialize(args: {
|
|
41
|
+
sign: string;
|
|
42
|
+
}): void;
|
|
43
|
+
/**
|
|
44
|
+
* 找到相同的场景值,如果没有则新增
|
|
45
|
+
* @param {object} args
|
|
46
|
+
* @param {RecordType} args.type
|
|
47
|
+
* @param {number} args.scene
|
|
48
|
+
*/
|
|
49
|
+
_halfwayUpdate(args: {
|
|
50
|
+
type: RecordType;
|
|
51
|
+
scene: number;
|
|
52
|
+
}): void;
|
|
53
|
+
/**
|
|
54
|
+
* @param {object} args
|
|
55
|
+
* @param {number[]} args.scenes
|
|
56
|
+
* @returns
|
|
57
|
+
*/
|
|
58
|
+
_halfwayGet(args: {
|
|
59
|
+
scenes: number[];
|
|
60
|
+
}): any;
|
|
61
|
+
_halfwayReset(): void;
|
|
62
|
+
/**
|
|
63
|
+
* 找到相同的场景值,如果没有则新增
|
|
64
|
+
* @param {object} args
|
|
65
|
+
* @param {RecordType} args.type
|
|
66
|
+
* @param {number} args.scene
|
|
67
|
+
*/
|
|
68
|
+
_finishedUpdate(args: {
|
|
69
|
+
type: RecordType;
|
|
70
|
+
scene: number;
|
|
71
|
+
}): void;
|
|
72
|
+
/**
|
|
73
|
+
* @param {object} args
|
|
74
|
+
* @param {number[]} args.scenes
|
|
75
|
+
* @returns
|
|
76
|
+
*/
|
|
77
|
+
_finishedGet(args: {
|
|
78
|
+
scenes: number[];
|
|
79
|
+
}): number;
|
|
80
|
+
_finishedReset(): void;
|
|
81
|
+
/**
|
|
82
|
+
* @param {object} args
|
|
83
|
+
* @param {RecordType} args.type
|
|
84
|
+
* @param {number} args.scene
|
|
85
|
+
*/
|
|
86
|
+
record(args: {
|
|
87
|
+
type: RecordType;
|
|
88
|
+
scene: number;
|
|
89
|
+
}): void;
|
|
90
|
+
/**
|
|
91
|
+
*
|
|
92
|
+
* @param {RecordType} type
|
|
93
|
+
*/
|
|
94
|
+
rest(type: RecordType): void;
|
|
95
|
+
/**
|
|
96
|
+
* @param {object} args
|
|
97
|
+
* @param {number[]} [args.scenes]
|
|
98
|
+
* @param {RecordType} args.type
|
|
99
|
+
*/
|
|
100
|
+
get(args: {
|
|
101
|
+
scenes?: number[];
|
|
102
|
+
type: RecordType;
|
|
103
|
+
}): any;
|
|
104
|
+
/**
|
|
105
|
+
* 站位方法,没有任何左右
|
|
106
|
+
* @returns
|
|
107
|
+
*/
|
|
108
|
+
placeholder(): any;
|
|
109
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export default RewardAdSceneTriggerManager;
|
|
2
|
+
/**
|
|
3
|
+
* 场景值枚举 可持续添加
|
|
4
|
+
*/
|
|
5
|
+
export type RewardAdTriggerScene = import("../typings/ad.js").RewardAdTriggerScene;
|
|
6
|
+
/**
|
|
7
|
+
* 场景值枚举 可持续添加
|
|
8
|
+
* @typedef {import('../typings/ad.js').RewardAdTriggerScene} RewardAdTriggerScene
|
|
9
|
+
*/
|
|
10
|
+
declare class RewardAdSceneTriggerManager {
|
|
11
|
+
static instance: any;
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param {object} args
|
|
15
|
+
* @param {string} args.sign 初始化标识
|
|
16
|
+
* @param {import('../typings/ad.js').SceneTypeMap} args.sceneTypeObj 当前场景sceneTypeMap 场景值类型映射表
|
|
17
|
+
* @returns {RewardAdSceneTriggerManager}
|
|
18
|
+
*/
|
|
19
|
+
static build(args: {
|
|
20
|
+
sign: string;
|
|
21
|
+
sceneTypeObj: import("../typings/ad.js").SceneTypeMap;
|
|
22
|
+
}): RewardAdSceneTriggerManager;
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @returns {RewardAdSceneTriggerManager}
|
|
26
|
+
*/
|
|
27
|
+
static getInstance(): RewardAdSceneTriggerManager;
|
|
28
|
+
/**
|
|
29
|
+
* @param {object} args
|
|
30
|
+
* @param {string} args.sign 初始化标识
|
|
31
|
+
* @param {import('../typings/ad.js').SceneTypeMap} args.sceneTypeObj 当前场景sceneTypeMap 场景值类型映射表
|
|
32
|
+
*/
|
|
33
|
+
constructor(args: {
|
|
34
|
+
sign: string;
|
|
35
|
+
sceneTypeObj: import("../typings/ad.js").SceneTypeMap;
|
|
36
|
+
});
|
|
37
|
+
_initSign: string;
|
|
38
|
+
/** @type {RewardAdTriggerScene} */
|
|
39
|
+
_currScene: RewardAdTriggerScene;
|
|
40
|
+
/** @type {import('../typings/ad.js').SceneTypeMap} */
|
|
41
|
+
_sceneTypeObj: import("../typings/ad.js").SceneTypeMap;
|
|
42
|
+
/**
|
|
43
|
+
* @param {object} args
|
|
44
|
+
* @param {string} args.sign 初始化标识
|
|
45
|
+
*/
|
|
46
|
+
initialize(args: {
|
|
47
|
+
sign: string;
|
|
48
|
+
}): void;
|
|
49
|
+
/**
|
|
50
|
+
* 获取场景值
|
|
51
|
+
* @param {RewardAdTriggerScene} value 场景值
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
addScene(value: RewardAdTriggerScene): this;
|
|
55
|
+
/**
|
|
56
|
+
* 获取场景值
|
|
57
|
+
* @param {import('../typings/ad.js').RewardAdTriggerSceneType} value 场景值类型
|
|
58
|
+
* @returns
|
|
59
|
+
*/
|
|
60
|
+
addSceneType(value?: import("../typings/ad.js").RewardAdTriggerSceneType): this;
|
|
61
|
+
/**
|
|
62
|
+
* 获取当前场景值
|
|
63
|
+
* @returns
|
|
64
|
+
*/
|
|
65
|
+
getCurrentScene(): string;
|
|
66
|
+
/**
|
|
67
|
+
* 站位方法,没有任何左右
|
|
68
|
+
* @returns
|
|
69
|
+
*/
|
|
70
|
+
placeholder(): any;
|
|
71
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
export default Storage;
|
|
2
|
+
export type StorageOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* 存储key的前缀
|
|
5
|
+
*/
|
|
6
|
+
prefix?: string;
|
|
7
|
+
/**
|
|
8
|
+
* 默认过期时间(毫秒),null表示永不过期
|
|
9
|
+
*/
|
|
10
|
+
expire?: number | null;
|
|
11
|
+
/**
|
|
12
|
+
* 用户ID
|
|
13
|
+
*/
|
|
14
|
+
userId?: string | number;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* @example
|
|
18
|
+
const storage = new Storage({
|
|
19
|
+
prefix: 'myapp_',
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// 设置当天有效的数据
|
|
23
|
+
*storage.setItem('dailyTask', { completed: false }, 'today');
|
|
24
|
+
|
|
25
|
+
// 设置普通带过期时间的数据(2小时)
|
|
26
|
+
storage.setItem('tempData', { value: 123 }, 2 * 60 * 60 * 1000);
|
|
27
|
+
|
|
28
|
+
// 设置永久有效的数据
|
|
29
|
+
storage.setItem('userSettings', { theme: 'dark' });
|
|
30
|
+
|
|
31
|
+
// 获取数据
|
|
32
|
+
const dailyTask = storage.getStorageSync('dailyTask');
|
|
33
|
+
const tempData = storage.getStorageSync('tempData');
|
|
34
|
+
const userSettings = storage.getStorageSync('userSettings');
|
|
35
|
+
|
|
36
|
+
console.log('Daily Task:', dailyTask);
|
|
37
|
+
console.log('Temp Data:', tempData);
|
|
38
|
+
console.log('User Settings:', userSettings);
|
|
39
|
+
*/
|
|
40
|
+
declare class Storage {
|
|
41
|
+
/**
|
|
42
|
+
* @param {StorageOptions=} args
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
static "new"(args?: StorageOptions | undefined): Storage;
|
|
46
|
+
/**
|
|
47
|
+
* @param {StorageOptions} [options]
|
|
48
|
+
*/
|
|
49
|
+
constructor(options?: StorageOptions);
|
|
50
|
+
config: {
|
|
51
|
+
/**
|
|
52
|
+
* 存储key的前缀
|
|
53
|
+
*/
|
|
54
|
+
prefix: string;
|
|
55
|
+
/**
|
|
56
|
+
* 默认过期时间(毫秒),null表示永不过期
|
|
57
|
+
*/
|
|
58
|
+
expire: number | null;
|
|
59
|
+
/**
|
|
60
|
+
* 用户ID
|
|
61
|
+
*/
|
|
62
|
+
userId?: string | number;
|
|
63
|
+
};
|
|
64
|
+
logger: Logger;
|
|
65
|
+
/**
|
|
66
|
+
* 获取当天结束时间的时间戳
|
|
67
|
+
* @returns {number} 当天23:59:59的时间戳
|
|
68
|
+
*/
|
|
69
|
+
getTodayEndTimestamp(): number;
|
|
70
|
+
/**
|
|
71
|
+
* 设置存储项 - 内部使用
|
|
72
|
+
* @param {string} key 存储键
|
|
73
|
+
* @param {any} value 存储值
|
|
74
|
+
* @param {number|'today'} expire 过期时间(毫秒)或'today'表示当天有效,可选
|
|
75
|
+
*/
|
|
76
|
+
_setItem(storageKey: any, value: any, expire: number | "today"): void;
|
|
77
|
+
/**
|
|
78
|
+
* 获取存储项 - 内部使用
|
|
79
|
+
* @param {string} key 存储键
|
|
80
|
+
* @returns {any} 存储的值,如果过期或不存在则返回null
|
|
81
|
+
*/
|
|
82
|
+
_getItem(storageKey: any): any;
|
|
83
|
+
/**
|
|
84
|
+
* 设置存储项
|
|
85
|
+
* @param {string} key 存储键
|
|
86
|
+
* @param {any} value 存储值
|
|
87
|
+
* @param {number|'today'} expire 过期时间(毫秒)或'today'表示当天有效,可选
|
|
88
|
+
*/
|
|
89
|
+
setItem(key: string, value: any, expire: number | "today"): void;
|
|
90
|
+
/**
|
|
91
|
+
* 获取存储项
|
|
92
|
+
* @param {string} key 存储键
|
|
93
|
+
* @returns {any} 存储的值,如果过期或不存在则返回null
|
|
94
|
+
*/
|
|
95
|
+
getItem(key: string): any;
|
|
96
|
+
/**
|
|
97
|
+
* 获取存储项 - 用户维度
|
|
98
|
+
* @param {string} key 存储键
|
|
99
|
+
* @returns {any} 存储的值,如果过期或不存在则返回null
|
|
100
|
+
*/
|
|
101
|
+
getUserItem(key: string): any;
|
|
102
|
+
/**
|
|
103
|
+
* 设置存储项 - 用户维度
|
|
104
|
+
* @param {string} key 存储键
|
|
105
|
+
* @param {any} value 存储值
|
|
106
|
+
* @param {number|'today'} expire 过期时间(毫秒)或'today'表示当天有效,可选
|
|
107
|
+
*/
|
|
108
|
+
setUserItem(key: string, value: any, expire: number | "today"): void;
|
|
109
|
+
/**
|
|
110
|
+
* 删除存储项
|
|
111
|
+
* @param {string} key 存储键
|
|
112
|
+
*/
|
|
113
|
+
removeItem(key: string): void;
|
|
114
|
+
/**
|
|
115
|
+
* 清空所有存储项
|
|
116
|
+
*/
|
|
117
|
+
clear(): void;
|
|
118
|
+
/**
|
|
119
|
+
* 获取所有未过期的存储键
|
|
120
|
+
* @returns {string[]} 键数组
|
|
121
|
+
*/
|
|
122
|
+
keys(): string[];
|
|
123
|
+
}
|
|
124
|
+
import { Logger } from './Logger';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { CountRecorder } from "./CountRecorder.js";
|
|
2
|
+
export { Logger } from "./Logger.js";
|
|
3
|
+
export { SerializableError } from "./SerializableError.js";
|
|
4
|
+
export { default as Storage } from "./Storage.js";
|
|
5
|
+
export { default as PubSub } from "./PubSub.js";
|
|
6
|
+
export { EventEmitter } from "./EventEmitter.js";
|
|
7
|
+
export { default as AdAnalyticsJS } from "./AdAnalyticsJS.js";
|
|
8
|
+
export { default as LovelUnlockManager } from "./LovelUnlockManager.js";
|
|
9
|
+
export { default as RewardAdGlobalRecorder } from "./RewardAdGlobalRecorder.js";
|
|
10
|
+
export { default as RewardAdSceneTriggerManager } from "./RewardAdSceneTriggerManager.js";
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export default AdExecuteManager;
|
|
2
|
+
import AdExecuteManager from './core/AdExecuteManager';
|
|
3
|
+
import RewardAdFather from './ad/RewardAdFather';
|
|
4
|
+
import { SerializableError } from './helper/SerializableError';
|
|
5
|
+
import { Logger } from './helper/Logger';
|
|
6
|
+
import Storage from './helper/Storage';
|
|
7
|
+
import { CountRecorder } from './helper/CountRecorder';
|
|
8
|
+
import RewardAdGlobalRecorder from './helper/RewardAdGlobalRecorder';
|
|
9
|
+
import RewardAdSceneTriggerManager from './helper/RewardAdSceneTriggerManager';
|
|
10
|
+
import AdAnalyticsJS from './helper/AdAnalyticsJS';
|
|
11
|
+
import RewardAdNovel from './ad/RewardAdNovel';
|
|
12
|
+
import InterstitialAdFather from './ad/InterstitialAdFather';
|
|
13
|
+
import InterstitialAdNovel from './ad/InterstitialAdNovel';
|
|
14
|
+
import PubSub from './helper/PubSub';
|
|
15
|
+
export { AdExecuteManager, RewardAdFather, SerializableError, Logger, Storage, CountRecorder, RewardAdGlobalRecorder, RewardAdSceneTriggerManager, AdAnalyticsJS, RewardAdNovel, InterstitialAdFather, InterstitialAdNovel, PubSub };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class e{constructor(e={}){let{prefix:t="Logger",level:s="log",enabled:n=!0}=e;this.prefix=t,this.enabled=n,this.levels={error:0,warn:1,info:2,log:3,debug:4},this.currentLevel=this.levels[s]||this.levels.log}enable(){this.enabled=!0}disable(){this.enabled=!1}isEnabled(){return this.enabled}setLevel(e){Object.prototype.hasOwnProperty.call(this.levels,e)&&(this.currentLevel=this.levels[e])}formatMessage(e,t){let s=new Date,n=`${s.getFullYear()}/${s.getMonth()+1}/${s.getDate()} ${s.getHours()}:${s.getMinutes()}:${s.getSeconds()}`;return`[${n}] [${e.toUpperCase()}] [${this.prefix}] ${t}`}_log(e,t,...s){if(!this.enabled)return;let n=this.levels[e];if(void 0!==n&&this.currentLevel>=n){let n=this.formatMessage(e,t);switch(e){case"error":console.error(n,...s);break;case"warn":console.warn(n,...s);break;case"info":console.info(n,...s);break;case"log":default:console.log(n,...s);break;case"debug":console.debug(n,...s)}}}error(e,...t){this._log("error",e,...t)}warn(e,...t){this._log("warn",e,...t)}info(e,...t){this._log("info",e,...t)}log(e,...t){this._log("log",e,...t)}debug(e,...t){this._log("debug",e,...t)}}class t{constructor(t={}){this.config={prefix:"storage_",expire:null,...t},this.logger=new e({prefix:"Storage"})}getTodayEndTimestamp(){let e=new Date;return new Date(e.getFullYear(),e.getMonth(),e.getDate(),23,59,59,999).getTime()}_setItem(e,t,s){let n=void 0!==s?s:this.config.expire;"today"===n&&(n=this.getTodayEndTimestamp()-Date.now());let i={value:t,expire:n,timestamp:Date.now()};try{tt.setStorageSync(e,JSON.stringify(i))}catch(e){console.error("Storage setItem error:",e)}}_getItem(e){try{let t=tt.getStorageSync(e);if(!t)return null;let s=JSON.parse(t);if(s.expire&&Date.now()-s.timestamp>s.expire)return this.removeItem(e),null;return s.value}catch(e){return console.error("Storage getItem error:",e),null}}setItem(e,t,s){let n=this.config.prefix+e;return this._setItem(n,t,s)}getItem(e){let t=this.config.prefix+e;return this._getItem(t)}getUserItem(e){let t=this.config.userId??"null";if("null"===t)return this.logger.error("userId is required"),null;let s=`${this.config.prefix}_${t}_${e}`;return this._getItem(s)}setUserItem(e,t,s){let n=this.config.userId??"null";if("null"===n)return void this.logger.error("userId is required");let i=`${this.config.prefix}_${n}_${e}`;return this._setItem(i,t,s)}removeItem(e){try{tt.removeStorageSync(e)}catch(e){console.error("Storage removeItem error:",e)}}clear(){try{tt.clearStorageSync()}catch(e){console.error("Storage clear error:",e)}}keys(){try{let e=[];return(tt.getStorageInfoSync().keys??[]).forEach(t=>{if(t.startsWith(this.config.prefix)){let s=JSON.parse(tt.getStorageSync(t));(!s.expire||Date.now()-s.timestamp<=s.expire)&&e.push(t.replace(this.config.prefix,""))}}),e}catch(e){return console.error("Storage keys error:",e),[]}}static new(e){return new t(e)}}let s=t;class n{_total=0;_local_sign="";_expire="today";constructor(e){if(this.storage=s.new({userId:e.userId}),!e.local_sign)throw Error("local_sign is required");this._local_sign=e.local_sign,this._total=e.total??0,this._expire=e.expire??"today",this._init()}_init(){this._initLocalTimes()}_adTimes(){return this._total}_safeLocalValue(e){return"object"!=typeof e||null===e?{}:e}_initLocalTimes(){let e=this._adTimes(),t=this.storage.getUserItem(this._local_sign),s=this._safeLocalValue(t);s&&s?.total==e||this.storage.setUserItem(this._local_sign,{total:e,today:s?.today??0},this._expire)}updateToday(){let e=this._adTimes(),t=this.storage.getUserItem(this._local_sign),s=this._safeLocalValue(t),n=s?.today??0;this.storage.setUserItem(this._local_sign,{total:e,today:n+1},this._expire)}remain(){let e=this.storage.getUserItem(this._local_sign),t=this._safeLocalValue(e),s=t?.today??0;return Number(t?.total??0)-Number(s)}static new(e){return new n(e)}}class i extends Error{constructor(e){super(e),this.name=this.constructor.name,this.stack=Error(e).stack,Object.defineProperty(this,"message",{enumerable:!0}),Object.defineProperty(this,"name",{enumerable:!0}),Object.defineProperty(this,"stack",{enumerable:!0})}toJSON(){return{name:this.name,message:this.message,stack:this.stack}}}class r{constructor(){this.events={}}on(e,t){return this.events[e]||(this.events[e]=[]),this.events[e].push(t),()=>{this.off(e,t)}}off(e,t){if(this.events[e]){if(!t){this.events[e]=[];return}this.events[e]=this.events[e].filter(e=>e!==t)}}emit(e,...t){this.events[e]&&this.events[e].forEach(s=>{try{s(...t)}catch(t){console.error(`Error in event listener for ${e}:`,t)}})}once(e,t){let s=(...n)=>{t(...n),this.off(e,s)};this.on(e,s)}listenerCount(e){return this.events[e]?this.events[e].length:0}removeAllListeners(){this.events={}}}class a{constructor(e={}){this.events={},this.queues={},this.onceEvents={},this.maxListeners=e.maxListeners||5,this.maxQueueSize=e.maxQueueSize||1,this.maxOnceEvents=e.maxOnceEvents||5}on(e,t){(this.events[e]||(this.events[e]=[]),this.events[e].length>=this.maxListeners)?console.warn(`EventEmitter: Maximum listeners (${this.maxListeners}) reached for event "${e}". Listener not added.`):(this.events[e].push(t),this.queues[e]&&this.queues[e].length>0&&(this.queues[e].forEach(e=>{t(...e)}),this.queues[e]=[]))}once(e,t){let s=(...n)=>{t(...n),this.off(e,s)};(this.onceEvents[e]||(this.onceEvents[e]=new Set),this.onceEvents[e].size>=this.maxOnceEvents)?console.warn(`EventEmitter: Maximum once events (${this.maxOnceEvents}) reached for event "${e}". Once listener not added.`):(this.onceEvents[e].add(s),this.on(e,s))}emit(e,...t){this.events[e]&&this.events[e].length>0?[...this.events[e]].forEach(e=>{e(...t)}):(this.queues[e]||(this.queues[e]=[]),this.queues[e].length>=this.maxQueueSize&&(console.warn(`EventEmitter: Maximum queue size (${this.maxQueueSize}) reached for event "${e}". Oldest event removed.`),this.queues[e].shift()),this.queues[e].push(t))}off(e,t){if(!t){this.events[e]=[],this.onceEvents[e]=new Set;return}this.events[e]=this.events[e].filter(e=>e!==t),this.onceEvents[e]&&this.onceEvents[e].delete(t)}removeAllListeners(e){e?(delete this.events[e],delete this.queues[e],delete this.onceEvents[e]):(this.events={},this.queues={},this.onceEvents={})}static geInstance(e){return this._instance||(this._instance=new a(e)),this._instance}}class o{static instance=null;_initSign="";_needReport=!1;constructor(e){if(o.instance)return o.instance;this._initSign=e?.sign??"",this._needReport=e?.needReport??!1,this._commonConfig=e?.commonConfig??null,o.instance=this}initialize(e){return this._needReport?e:void console.warn("AdAnalyticsJS needReport is false, do not report")}track(e,t,s){if(!this._needReport)return;if(!e)throw Error("eventName is required");let n=Object.assign({},this.getTrackCommonInfo(),t),i=s?.sign??"track";console.log(`-------------${i}-----------------------:`,e,n),tt.reportAnalytics(e,n)}getCommonInfo(){return this._commonConfig??{}}getTrackCommonInfo(){return this._commonConfig??{}}identify(e,t){if(!e&&0!==e)throw Error("identify user_id is required");return this._commonConfig=Object.assign({},this._commonConfig,{__user_id:e},t),this}alias(){return null}pages(){return null}page(e,t){this.track(e,t,{sign:"page"})}cpage(e){return this.page("cpage",e)}placeholder(){return null}static build(e){return o.instance||(o.instance=new o(e)),o.instance}static getInstance(){if(!o.instance)throw Error("AdAnalyticsJS instance is not init");return o.instance}static new(e){return new o(e)}}let h=o;class l{static instance=null;_initSign="";_dramaDetailData=[];_unlockChapterThreshold=2e3;_unlockChapterNum=30;_unlockChapterWaterLevel=15;_isReachThreshold=!1;_unlockedIdArr=[];constructor(e){this._initSign=e?.sign??"",this._unlockChapterThreshold=e?.unlockChapterThreshold??2e3,this._unlockChapterNum=e?.unlockChapterNum??30,this._unlockChapterWaterLevel=e?.unlockChapterWaterLevel??15}get drama(){return this._dramaDetailData}set drama(e=[]){this._dramaDetailData=e,this._checkReachThreshold(e)}_checkReachThreshold(e=[]){let t=e.filter(e=>1===e.flagTag);this._isReachThreshold=t.length>=this._unlockChapterThreshold}_isUnlockThreshold(){return this._isReachThreshold}_unlockChapterIds(e,t=this._unlockChapterNum){let s=this.drama,n=s.findIndex(t=>t.episodeId===e);if(-1===n)return;let i=n-t,r=Math.max(i,0),a=Math.min(i>=0?n+t:n+t-i,s.length);return s.slice(r,a).map(e=>e.episodeId)}_unlockChapterIdsWithWater(e,t=this._unlockChapterNum){let s=this._unlockChapterIds(e,t),n=s.filter(e=>!this._unlockedIdArr.includes(e));if(n&&n.length>=this._unlockChapterWaterLevel)return this._unlockedIdArr=Array.from(new Set(this._unlockedIdArr.concat(s))),s}ready(e,t,s){if(this._isUnlockThreshold()){let e=this._unlockChapterIdsWithWater(s);e&&e.length>0&&"function"==typeof t&&t(e)}else"function"==typeof e&&e()}onProcessUpdate(e,t){if(this._isUnlockThreshold()){let s=e.chapterId,n=this._unlockChapterIdsWithWater(s);n&&n.length>0&&"function"==typeof t&&t(n)}}onChapterChange(e,t){if(this._isUnlockThreshold()){let s=e.nextChapterId,n=this._unlockChapterIdsWithWater(s);n&&n.length>0&&"function"==typeof t&&t(n)}}unlockAll(){let e=this.drama.map(e=>({...e,flagTag:1}));this.drama=e}static build(e){return l.instance||(l.instance=new l(e)),l.instance}static getInstance(){if(!l.instance)throw Error("LovelUnlockManager instance is not init");return l.instance}static new(e){return new l(e)}}let c=l,u=Object.entries({9999:"inner_default_other"}).reduce((e,[t,s])=>(e[s]=Number(t),e),{});Object.entries({AD_TYPE_REWARD:1,AD_TYPE_INTERSTITIAL:2}).reduce((e,[t,s])=>(e[s]=t,e),{});class d{static instance=null;_initSign="";_halfway=[{scene:u.inner_default_other,count:0}];_finished=[{scene:u.inner_default_other,count:0}];constructor(e){if(d.instance)return d.instance;this._initSign=e?.sign??"",this._halfway=[{scene:u.inner_default_other,count:0}],this._finished=[{scene:u.inner_default_other,count:0}],d.instance=this}initialize(e){}_halfwayUpdate(e){let t=this._halfway.find(t=>t.scene===e.scene);t?t.count+=1:this._halfway.push({scene:e.scene,count:1})}_halfwayGet(e){let t=e?.scenes??[];return(t.length>0?this._halfway.filter(e=>t.includes(e.scene)):this._halfway).reduce((e,t)=>e+t.count,0)}_halfwayReset(){this._halfway=[{scene:u.inner_default_other,count:0}]}_finishedUpdate(e){let t=this._finished.find(t=>t.scene===e.scene);t?t.count+=1:this._finished.push({scene:e.scene,count:1})}_finishedGet(e){let t=e?.scenes??[];return(t.length>0?this._finished.filter(e=>t.includes(e.scene)):this._finished).reduce((e,t)=>e+t.count,0)}_finishedReset(){this._finished=[{scene:u.inner_default_other,count:0}]}record(e){switch(e.type){case"halfway":this._halfwayUpdate(e);break;case"finished":this._finishedUpdate(e)}}rest(e){switch(e){case"halfway":this._halfwayReset();break;case"finished":this._finishedReset()}}get(e){switch(e.type){case"halfway":return this._halfwayGet(e);case"finished":return this._finishedGet(e);default:return null}}placeholder(){return null}static build(e){return d.instance||(d.instance=new d(e)),d.instance}static getInstance(){if(!d.instance)throw Error("RewardAdGlobalRecorder instance is not init");return d.instance}}let g=d;class _{static instance=null;_initSign="";_currScene=null;_sceneTypeObj={};constructor(e){if(_.instance)return _.instance;this._initSign=e?.sign??"",this._sceneTypeObj=e?.sceneTypeObj??{},_.instance=this}initialize(e){}addScene(e){return console.log("----------------------AD触发场景:--------------------",e),this._currScene=e,this}addSceneType(e=1){return this.addScene(this._sceneTypeObj[e]),this}getCurrentScene(){return this._currScene}placeholder(){return null}static build(e){return _.instance||(_.instance=new _(e)),_.instance}static getInstance(){if(!_.instance)throw Error("RewardAdSceneTriggerManager instance is not init");return _.instance}}let f=_;export{h as AdAnalyticsJS,n as CountRecorder,a as EventEmitter,e as Logger,c as LovelUnlockManager,r as PubSub,g as RewardAdGlobalRecorder,f as RewardAdSceneTriggerManager,i as SerializableError,s as Storage};
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
export type IRewordAdConfig = {
|
|
2
|
+
/**
|
|
3
|
+
* 激励视频广告id - 必填
|
|
4
|
+
*/
|
|
5
|
+
adUnitId: string;
|
|
6
|
+
/**
|
|
7
|
+
* 是否开启进度提醒。开启时广告文案为「再看 n 个xxx」,关闭时为「再看 1 个xxx」。其中 n 表示用户当前还需额外观看广告的次数
|
|
8
|
+
* 再得广告的奖励文案,用户每看完一个广告都会展示,multiton 为 true 时必填。
|
|
9
|
+
* 文案完整内容为「再看 1 个xxx」,其中 xxx 是 multitonRewardMsg 配置的文案内容,最大长度为 7,
|
|
10
|
+
* 文案内容根据 multitonRewardMsg 的配置按顺序展示。若 multitonRewardMsg 长度小于 multitonRewardTimes ,
|
|
11
|
+
* 则后续的激励再得广告文案取 multitonRewardMsg 数组最后一个。
|
|
12
|
+
*/
|
|
13
|
+
progressTip?: boolean | undefined;
|
|
14
|
+
multitonRewardMsg?: Array<string> | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* 是否开启激励再得广告
|
|
17
|
+
*/
|
|
18
|
+
multiton?: boolean | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* 额外观看广告的次数,合法的数据范围为 1~4,multiton 为 true 时必填
|
|
21
|
+
*/
|
|
22
|
+
multitonRewardTimes?: number | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* 场景值 - 自用参数,非tt API要求的参数
|
|
25
|
+
*/
|
|
26
|
+
scene?: number | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* 广告超时时间 单位ms - 自用参数,非tt API要求的参数
|
|
29
|
+
*/
|
|
30
|
+
timeout?: number | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* 奖励金额 - 自用参数 ,非tt API要求的参数
|
|
33
|
+
*/
|
|
34
|
+
log?: boolean | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* 重试次数 - 自用参数 ,非tt API要求的参数
|
|
37
|
+
*/
|
|
38
|
+
retry: number;
|
|
39
|
+
};
|
|
40
|
+
export type InterstitialAdConfig = {
|
|
41
|
+
/**
|
|
42
|
+
* 单个广告单元的 id。可从「开放平台控制台-进入对应小程序-运营-商业化变现-广告管理」中获取 - 必填
|
|
43
|
+
*/
|
|
44
|
+
adUnitId: string;
|
|
45
|
+
/**
|
|
46
|
+
* 场景值 - 自用参数
|
|
47
|
+
*/
|
|
48
|
+
scene?: number | undefined;
|
|
49
|
+
};
|
|
50
|
+
export type IExeCallbackArgs = {
|
|
51
|
+
/**
|
|
52
|
+
* 广告执行场景
|
|
53
|
+
*/
|
|
54
|
+
scene: number;
|
|
55
|
+
/**
|
|
56
|
+
* 是否看完
|
|
57
|
+
*/
|
|
58
|
+
isEnded: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* 完整观看次数
|
|
61
|
+
*/
|
|
62
|
+
count: number;
|
|
63
|
+
/**
|
|
64
|
+
* 剩余观看次数
|
|
65
|
+
*/
|
|
66
|
+
remain?: number;
|
|
67
|
+
};
|
|
68
|
+
export type CallbackCollection = {
|
|
69
|
+
/**
|
|
70
|
+
* 每次外部回调
|
|
71
|
+
*/
|
|
72
|
+
always?: (ctx?: IExeCallbackArgs) => void;
|
|
73
|
+
/**
|
|
74
|
+
* 完整看完广告外部回调 不管一个还是几个
|
|
75
|
+
*/
|
|
76
|
+
finished?: (ctx?: IExeCallbackArgs) => void;
|
|
77
|
+
/**
|
|
78
|
+
* 半途退出广告外部回调
|
|
79
|
+
*/
|
|
80
|
+
halfway?: (ctx?: IExeCallbackArgs) => void;
|
|
81
|
+
/**
|
|
82
|
+
* 完成广告外部回调 不管看不看完
|
|
83
|
+
*/
|
|
84
|
+
complete?: (ctx?: IExeCallbackArgs) => void;
|
|
85
|
+
/**
|
|
86
|
+
* 取消广告外部回调
|
|
87
|
+
*/
|
|
88
|
+
onCancel?: (ctx?: IExeCallbackArgs) => void;
|
|
89
|
+
/**
|
|
90
|
+
* 展示广告外部回调
|
|
91
|
+
*/
|
|
92
|
+
before?: (ctx?: IExeCallbackArgs) => void;
|
|
93
|
+
/**
|
|
94
|
+
* 展示广告成功外部回调
|
|
95
|
+
*/
|
|
96
|
+
success?: (ctx?: IExeCallbackArgs) => void;
|
|
97
|
+
/**
|
|
98
|
+
* 计时回调
|
|
99
|
+
*/
|
|
100
|
+
prelude?: (ctx?: unknown) => void;
|
|
101
|
+
};
|
|
102
|
+
export type ICallbackArgs = {
|
|
103
|
+
/**
|
|
104
|
+
* 广告执行场景
|
|
105
|
+
*/
|
|
106
|
+
scene: number;
|
|
107
|
+
/**
|
|
108
|
+
* 是否看完
|
|
109
|
+
*/
|
|
110
|
+
isEnded: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* 完整观看次数
|
|
113
|
+
*/
|
|
114
|
+
count: number;
|
|
115
|
+
/**
|
|
116
|
+
* 剩余观看次数
|
|
117
|
+
*/
|
|
118
|
+
remain?: number;
|
|
119
|
+
/**
|
|
120
|
+
* 执行下一个任务的回调函数,手动调用以继续执行流程[end]
|
|
121
|
+
*/
|
|
122
|
+
end?: () => void;
|
|
123
|
+
/**
|
|
124
|
+
* 执行下一个任务的回调函数, 手动调用以继续执行流程[circle]
|
|
125
|
+
*/
|
|
126
|
+
circle?: (args: {
|
|
127
|
+
ignoreRemain: boolean;
|
|
128
|
+
scene: number;
|
|
129
|
+
}) => void;
|
|
130
|
+
};
|
|
131
|
+
export type IConnection = {
|
|
132
|
+
/**
|
|
133
|
+
* 广告中途退出回调
|
|
134
|
+
*/
|
|
135
|
+
onHalfway?: (args: ICallbackArgs) => void;
|
|
136
|
+
/**
|
|
137
|
+
* 广告展示回调
|
|
138
|
+
*/
|
|
139
|
+
onShow?: (args: ICallbackArgs) => void;
|
|
140
|
+
/**
|
|
141
|
+
* 广告执行成功回调
|
|
142
|
+
*/
|
|
143
|
+
onFinish?: (args: ICallbackArgs) => void;
|
|
144
|
+
/**
|
|
145
|
+
* 广告执行失败回调
|
|
146
|
+
*/
|
|
147
|
+
onError?: (e: unknown) => void;
|
|
148
|
+
};
|
|
149
|
+
export type IConstructArgs = {
|
|
150
|
+
/**
|
|
151
|
+
* 初始化标识
|
|
152
|
+
*/
|
|
153
|
+
sign: string;
|
|
154
|
+
/**
|
|
155
|
+
* 重试次数
|
|
156
|
+
*/
|
|
157
|
+
retry: number;
|
|
158
|
+
/**
|
|
159
|
+
* 是否保留tt激励视频广告实例
|
|
160
|
+
*/
|
|
161
|
+
preserveOnEnd: boolean;
|
|
162
|
+
/**
|
|
163
|
+
* 激励视频参数 (可选)
|
|
164
|
+
*/
|
|
165
|
+
adConfig?: IRewordAdConfig | undefined;
|
|
166
|
+
/**
|
|
167
|
+
* 回调集合
|
|
168
|
+
*/
|
|
169
|
+
collection?: IConnection | undefined;
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* 广告场景类型映射对象
|
|
173
|
+
*/
|
|
174
|
+
export type SceneTypeMap = {
|
|
175
|
+
readonly [x: number]: string;
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* 广告场景类型文本映射对象(反向映射)
|
|
179
|
+
*/
|
|
180
|
+
export type SceneTextMap = { readonly [K in SceneTypeMap[keyof SceneTypeMap]]: { [P in keyof SceneTypeMap]: SceneTypeMap[P] extends K ? P : never; }[keyof SceneTypeMap]; };
|
|
181
|
+
/**
|
|
182
|
+
* 场景值枚举 可持续添加
|
|
183
|
+
*/
|
|
184
|
+
export type RewardAdTriggerScene = keyof SceneTextMap;
|
|
185
|
+
/**
|
|
186
|
+
* 场景值枚举 可持续添加
|
|
187
|
+
*/
|
|
188
|
+
export type RewardAdTriggerSceneType = keyof SceneTypeMap;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type IAdType = {
|
|
2
|
+
/**
|
|
3
|
+
* 激励视频
|
|
4
|
+
*/
|
|
5
|
+
AD_TYPE_REWARD: 1;
|
|
6
|
+
/**
|
|
7
|
+
* 插屏广告
|
|
8
|
+
*/
|
|
9
|
+
AD_TYPE_INTERSTITIAL: 2;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* 广告场景类型文本映射对象(反向映射)
|
|
13
|
+
*/
|
|
14
|
+
export type IAdTypeReverse = { readonly [K in IAdType[keyof IAdType]]: { [P in keyof IAdType]: IAdType[P] extends K ? P : never; }[keyof IAdType]; };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {string[]} ttErrorMsgs
|
|
4
|
+
* @param {string[]} keyword
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export function matchErrorWithKeywords(ttErrorMsgs: string[], keyword: string[]): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* 广告场景类型映射对象
|
|
10
|
+
* @param {import('../typings/ad.js').SceneTypeMap} scentTypeObj
|
|
11
|
+
* @returns {import('../typings/ad.js').SceneTextMap}
|
|
12
|
+
*/
|
|
13
|
+
export function getAdSceneTextObj(scentTypeObj: import("../typings/ad.js").SceneTypeMap): import("../typings/ad.js").SceneTextMap;
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ad-execute-manager/helper",
|
|
3
|
+
"version": "2.0.0-alpha.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.cjs",
|
|
15
|
+
"types": "./dist/index.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"author": "singcl",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"homepage": "https://npmjs.com/package/@ad-execute-manager/helper",
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"@singcl/ad-execute-manager": ">=2.0.0"
|
|
23
|
+
}
|
|
24
|
+
}
|