@singcl/ad-execute-manager 1.0.15 → 1.1.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/RewardAdFather.d.ts +10 -0
- package/dist/ad/RewardAdGlobalRecorder.d.ts +5 -7
- package/dist/ad/RewardAdNovel.d.ts +4 -4
- package/dist/ad/RewardAdSceneTriggerManager.d.ts +7 -1
- package/dist/ad/const.d.ts +5 -5
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/typings/ad.d.ts +5 -14
- package/dist/utils/functional.d.ts +6 -0
- package/package.json +1 -1
|
@@ -79,7 +79,17 @@ declare class RewardAdFather {
|
|
|
79
79
|
collection?: CallbackCollection;
|
|
80
80
|
}): Promise<unknown>;
|
|
81
81
|
destroy(): void;
|
|
82
|
+
/**
|
|
83
|
+
* 清理广告实例
|
|
84
|
+
* @abstract 清理广告实例,子类必须实现此方法
|
|
85
|
+
*/
|
|
82
86
|
clear(): void;
|
|
87
|
+
/**
|
|
88
|
+
* 任务执行完成后始终执行的一个方法
|
|
89
|
+
* @abstract 任务执行完成后始终执行的一个方法,子类需要用到时实现此方法
|
|
90
|
+
* @param {object} [_args] 执行结果信息
|
|
91
|
+
*/
|
|
92
|
+
record(_args?: object): this;
|
|
83
93
|
/**
|
|
84
94
|
*
|
|
85
95
|
* @param {({isEnded: boolean, count: number}) => void} callback
|
|
@@ -27,12 +27,10 @@ declare class RewardAdGlobalRecorder {
|
|
|
27
27
|
sign: string;
|
|
28
28
|
});
|
|
29
29
|
_initSign: string;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
count: number;
|
|
33
|
-
}[];
|
|
30
|
+
/** @type {import('../typings/ad.js').SceneTextMap} */
|
|
31
|
+
_halfway: import("../typings/ad.js").SceneTextMap;
|
|
34
32
|
_finished: {
|
|
35
|
-
scene:
|
|
33
|
+
scene: number;
|
|
36
34
|
count: number;
|
|
37
35
|
}[];
|
|
38
36
|
/**
|
|
@@ -59,7 +57,7 @@ declare class RewardAdGlobalRecorder {
|
|
|
59
57
|
*/
|
|
60
58
|
_halfwayGet(args: {
|
|
61
59
|
scenes: number[];
|
|
62
|
-
}):
|
|
60
|
+
}): any;
|
|
63
61
|
_halfwayReset(): void;
|
|
64
62
|
/**
|
|
65
63
|
* 找到相同的场景值,如果没有则新增
|
|
@@ -102,7 +100,7 @@ declare class RewardAdGlobalRecorder {
|
|
|
102
100
|
get(args: {
|
|
103
101
|
scenes?: number[];
|
|
104
102
|
type: RecordType;
|
|
105
|
-
}):
|
|
103
|
+
}): any;
|
|
106
104
|
/**
|
|
107
105
|
* 站位方法,没有任何左右
|
|
108
106
|
* @returns
|
|
@@ -241,25 +241,25 @@ declare class RewardAdNovel extends RewardAdFather {
|
|
|
241
241
|
get rewardAd(): any;
|
|
242
242
|
/**
|
|
243
243
|
* 确保广告按顺序执行
|
|
244
|
+
* @override
|
|
244
245
|
* @param {Object} [ctx] 上下文对象,用于传递数据和状态
|
|
245
246
|
* @param {IRewordAdConfig} [ctx.options] 广告执行选项
|
|
246
247
|
* @param {import('../typings/ad.js').CallbackCollection} [ctx.collection] 回调集合
|
|
247
|
-
*
|
|
248
248
|
* @returns {Promise.<IEndArgs & ICloseArgs | Undefined>}
|
|
249
249
|
*/
|
|
250
|
-
addExecuteManager(ctx?: {
|
|
250
|
+
override addExecuteManager(ctx?: {
|
|
251
251
|
options?: IRewordAdConfig;
|
|
252
252
|
collection?: import("../typings/ad.js").CallbackCollection;
|
|
253
253
|
}): Promise<(IEndArgs & ICloseArgs) | undefined>;
|
|
254
254
|
/**
|
|
255
|
+
* @override
|
|
255
256
|
* @param {object} [ctx] 广告执行上下文
|
|
256
257
|
* @param {import('../typings/ad.js').IRewordAdConfig} [ctx.options] 广告执行选项
|
|
257
258
|
* @param {import('../typings/ad.js').CallbackCollection} [ctx.collection] 回调集合
|
|
258
259
|
* @param {Function} next 执行下一个任务的回调函数,手动调用以继续执行流程
|
|
259
|
-
*
|
|
260
260
|
* @returns {Promise.<IEndArgs & ICloseArgs | Undefined>}
|
|
261
261
|
*/
|
|
262
|
-
ad(ctx?: {
|
|
262
|
+
override ad(ctx?: {
|
|
263
263
|
options?: import("../typings/ad.js").IRewordAdConfig;
|
|
264
264
|
collection?: import("../typings/ad.js").CallbackCollection;
|
|
265
265
|
}, next?: Function): Promise<(IEndArgs & ICloseArgs) | undefined>;
|
|
@@ -13,10 +13,12 @@ declare class RewardAdSceneTriggerManager {
|
|
|
13
13
|
*
|
|
14
14
|
* @param {object} args
|
|
15
15
|
* @param {string} args.sign 初始化标识
|
|
16
|
+
* @param {import('../typings/ad.js').SceneTypeMap} args.sceneTypeObj 当前场景sceneTypeMap 场景值类型映射表
|
|
16
17
|
* @returns {RewardAdSceneTriggerManager}
|
|
17
18
|
*/
|
|
18
19
|
static build(args: {
|
|
19
20
|
sign: string;
|
|
21
|
+
sceneTypeObj: import("../typings/ad.js").SceneTypeMap;
|
|
20
22
|
}): RewardAdSceneTriggerManager;
|
|
21
23
|
/**
|
|
22
24
|
*
|
|
@@ -26,13 +28,17 @@ declare class RewardAdSceneTriggerManager {
|
|
|
26
28
|
/**
|
|
27
29
|
* @param {object} args
|
|
28
30
|
* @param {string} args.sign 初始化标识
|
|
31
|
+
* @param {import('../typings/ad.js').SceneTypeMap} args.sceneTypeObj 当前场景sceneTypeMap 场景值类型映射表
|
|
29
32
|
*/
|
|
30
33
|
constructor(args: {
|
|
31
34
|
sign: string;
|
|
35
|
+
sceneTypeObj: import("../typings/ad.js").SceneTypeMap;
|
|
32
36
|
});
|
|
33
37
|
_initSign: string;
|
|
34
38
|
/** @type {RewardAdTriggerScene} */
|
|
35
39
|
_currScene: RewardAdTriggerScene;
|
|
40
|
+
/** @type {import('../typings/ad.js').SceneTypeMap} */
|
|
41
|
+
_sceneTypeObj: import("../typings/ad.js").SceneTypeMap;
|
|
36
42
|
/**
|
|
37
43
|
* @param {object} args
|
|
38
44
|
* @param {string} args.sign 初始化标识
|
|
@@ -56,7 +62,7 @@ declare class RewardAdSceneTriggerManager {
|
|
|
56
62
|
* 获取当前场景值
|
|
57
63
|
* @returns
|
|
58
64
|
*/
|
|
59
|
-
getCurrentScene():
|
|
65
|
+
getCurrentScene(): string;
|
|
60
66
|
/**
|
|
61
67
|
* 站位方法,没有任何左右
|
|
62
68
|
* @returns
|
package/dist/ad/const.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 广告场景类型映射对象
|
|
3
|
-
* @type {import('../typings/ad.js').
|
|
3
|
+
* @type {import('../typings/ad.js').SceneTypeMap}
|
|
4
4
|
*/
|
|
5
|
-
export const
|
|
5
|
+
export const DEFAULT_SCENT_TYPE_OBJ: import("../typings/ad.js").SceneTypeMap;
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
* @type {import('../typings/ad.js').
|
|
7
|
+
* 广告场景文本映射对象
|
|
8
|
+
* @type {import('../typings/ad.js').SceneTextMap}
|
|
9
9
|
*/
|
|
10
|
-
export const
|
|
10
|
+
export const DEFAULT_SCENT_TEXT_OBJ: import("../typings/ad.js").SceneTextMap;
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const __rslib_import_meta_url__="u"<typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_require__={};__webpack_require__.d=(e,t)=>{for(var r in t)__webpack_require__.o(t,r)&&!__webpack_require__.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__webpack_require__.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{default:()=>src,Storage:()=>ad_Storage,RewardAdGlobalRecorder:()=>ad_RewardAdGlobalRecorder,CountRecorder:()=>CountRecorder,RewardAdNovel:()=>ad_RewardAdNovel,RewardAdFather:()=>ad_RewardAdFather,Logger:()=>Logger,ExbAnalyticsJS:()=>ad_ExbAnalyticsJS,AdExecuteManager:()=>ad_AdExecuteManager,RewardAdSceneTriggerManager:()=>ad_RewardAdSceneTriggerManager,SerializableError:()=>SerializableError});const compose=e=>e.map(e=>(t,r)=>async s=>await e(Object.assign({},t,s),r)).reduce((e,t)=>(r,s)=>e(r,t(r,s))),ad_compose=compose;class Logger{constructor(e={}){const{prefix:t="Logger",level:r="info",enabled:s=!0}=e;this.prefix=t,this.enabled=s,this.levels={error:0,warn:1,info:2,debug:3},this.currentLevel=this.levels[r]||this.levels.info}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 r=new Date,s=`${r.getFullYear()}/${r.getMonth()+1}/${r.getDate()} ${r.getHours()}:${r.getMinutes()}:${r.getSeconds()}`;return`[${s}] [${e.toUpperCase()}] [${this.prefix}] ${t}`}_log(e,t,...r){if(!this.enabled)return;let s=this.levels[e];if(void 0!==s&&this.currentLevel>=s){let s=this.formatMessage(e,t);switch(e){case"error":console.error(s,...r);break;case"warn":console.warn(s,...r);break;case"info":console.info(s,...r);break;case"debug":console.debug(s,...r);break;default:console.log(s,...r)}}}error(e,...t){this._log("error",e,...t)}warn(e,...t){this._log("warn",e,...t)}info(e,...t){this._log("info",e,...t)}debug(e,...t){this._log("debug",e,...t)}log(e,t,...r){this._log(e,t,...r)}}class AdExecuteManager{static _instance=null;_taskStack=[];_currentBatchTasks=[];_isRunning=!1;_currentTask=null;constructor(e){if(this.logger=new Logger({prefix:"AdExecuteManager",enabled:!!e?.log}),AdExecuteManager._instance)return AdExecuteManager._instance;AdExecuteManager._instance=this}static getInstance(e){return AdExecuteManager._instance||(AdExecuteManager._instance=new AdExecuteManager(e)),AdExecuteManager._instance}addTask(e,t){return e&&"function"==typeof e.ad?new Promise((r,s)=>{let i={adInstance:e,options:t.options??{},callbackCollection:t.collection??{},resolve:r,reject:s,id:`ad_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,_isResolved:!1,_isRejected:!1};this._taskStack.push(i),this._isRunning||this._compose()}):(this.logger.error("无效的广告实例 请正确实现.ad方法"),Promise.reject(Error("无效的广告实例")))}_compose(){if(0===this._taskStack.length){this._isRunning=!1,this._currentTask=null;return}this._isRunning=!0;let e=[...this._taskStack];this._taskStack=[],this._currentBatchTasks=e;let t=e.map(e=>async(t,r)=>{let{adInstance:s,options:i,callbackCollection:n,resolve:a,id:o}=e;if(e._isResolved||e._isRejected)return void await r(t);this._currentTask=e;try{let l=async e=>{await r(Object.assign({},t,e))},c=await s.initialize(i).ad({options:i,collection:n},l),d=Object.assign({id:o},c);this.logger.info(`任务执行成功,成功信息:${JSON.stringify(d)}`),e._isResolved=!0,a(d)}catch(n){let i=Object.assign({id:o,apiError:n});this.logger.error(`任务执行失败, 继续下一个任务,错误信息:${JSON.stringify(i)}`),e._isRejected=!0;try{s?.clear()}catch(e){this.logger.error("clear error: ",JSON.stringify(Object.assign({id:o,apiError:e})))}a(i),await r(t)}}),r={roundTasks:t.length};compose(t)(r,async e=>{this.logger.info("本轮活动队列已经清空",e),this._taskStack.length>0?Promise.resolve().then(()=>{this._compose()}):(this._isRunning=!1,this._currentTask=null,this._currentBatchTasks=[])})()}clearTasks(){if(this._currentTask){if(this._currentTask._isResolved||this._currentTask._isRejected){this._currentTask=null;return}try{this._currentTask.callbackCollection&&this._currentTask.callbackCollection.onCancel&&this._currentTask.callbackCollection.onCancel(),this._currentTask._isResolved=!0,this._currentTask.resolve()}catch(e){this.logger.error("clear current task error: ",e)}this._currentTask=null}this._currentBatchTasks.length>0&&(this._currentBatchTasks.forEach(e=>{if(e!==this._currentTask&&!e._isResolved&&!e._isRejected)try{e.callbackCollection&&e.callbackCollection.onCancel&&e.callbackCollection.onCancel(),e._isResolved=!0,e.resolve()}catch(e){this.logger.error("clear current batch task error: ",e)}}),this._currentBatchTasks=[]),this._taskStack.forEach(e=>{if(!e._isResolved&&!e._isRejected&&(e._isResolved=!0,e.resolve(),e.callbackCollection&&e.callbackCollection.onCancel))try{e.callbackCollection.onCancel()}catch(e){this.logger.error("clear task error: ",e)}}),this._taskStack=[],this._isRunning=!1}getTaskCount(){return this._taskStack.filter(e=>!e._isResolved&&!e._isRejected).length+this._currentBatchTasks.filter(e=>e!==this._currentTask&&!e._isResolved&&!e._isRejected).length+(!this._currentTask||this._currentTask._isResolved||this._currentTask._isRejected?0:1)}isRunning(){return this._isRunning}getCurrentTaskId(){return this._currentTask?.id||null}}const ad_AdExecuteManager=AdExecuteManager;class SerializableError 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 RewardAdFather{static args=null;_initSign="";_preserveOnEnd=!1;_rewardAd=null;_ttErrorMsgs=["The adUnitId is closed","The adUnitId is prohibit","The adUnitId is invalid","The adUnitId is empty","feature is not supported in app"];_ttErrorCodes=[139902,123302];constructor(e){this._initSign=e?.sign??"",this._adConfig=e?.adConfig??{},this._preserveOnEnd=e?.preserveOnEnd??!1}initialize(e,t){if(this._rewardAd)return console.warn("RewardAdFather: rewardAd has been initialized"),t?.(this._rewardAd),this;let r=Object.assign({},RewardAdFather.args,this._adConfig,e);if(!r.adUnitId)throw console.error("[RewardAdFather] reward args adUnitId is required",r),new SerializableError("[RewardAdFather] reward args adUnitId is required");return this._rewardAd=tt.createRewardedVideoAd(r),t?.(this._rewardAd),this}initialized(){return!!this._rewardAd}async ad(e,t=null){throw Error("子类必须实现ad方法")}async addExecuteManager(e){let t=Object.assign({},this._adConfig,e?.options??{});return RewardAdFather.executeWithManager(this,Object.assign({},e,{options:t}))}destroy(){this._rewardAd&&!this._preserveOnEnd&&(this._rewardAd.destroy(),this._rewardAd=null)}clear(){throw Error("子类必须实现clear方法")}onClose(e){this._rewardAd&&this._rewardAd.onClose(e)}offClose(e){this._rewardAd&&this._rewardAd.offClose(e)}show(){return this._rewardAd?this._rewardAd.show():Promise.reject({errMsg:"rewardAd is null"})}load(){if(this._rewardAd)return this._rewardAd.load()}onError(e){this._rewardAd&&this._rewardAd.onError(e)}offError(e){this._rewardAd&&this._rewardAd.offError(e)}onLoad(e){this._rewardAd&&this._rewardAd.onLoad(e)}offLoad(e){this._rewardAd&&this._rewardAd.offLoad(e)}placeholder(){return null}static buildArgs(e){e?.adUnitId||console.error("[RewardAdFather] RewardParams.adUnitId is required"),RewardAdFather.args=e}static async executeWithManager(e,t){return e&&e instanceof RewardAdFather?ad_AdExecuteManager.getInstance({log:t?.options?.log??!0}).addTask(e,t):(console.error("RewardAdFather: executeWithManager - 无效的广告实例"),Promise.reject(Error("无效的广告实例")))}}const ad_RewardAdFather=RewardAdFather;class Storage{constructor(e={}){this.config={prefix:"storage_",expire:null,...e},this.logger=new Logger({prefix:"Storage"})}getTodayEndTimestamp(){let e=new Date;return new Date(e.getFullYear(),e.getMonth(),e.getDate(),23,59,59,999).getTime()}_setItem(e,t,r){let s=void 0!==r?r:this.config.expire;"today"===s&&(s=this.getTodayEndTimestamp()-Date.now());let i={value:t,expire:s,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 r=JSON.parse(t);if(r.expire&&Date.now()-r.timestamp>r.expire)return this.removeItem(e),null;return r.value}catch(e){return console.error("Storage getItem error:",e),null}}setItem(e,t,r){let s=this.config.prefix+e;return this._setItem(s,t,r)}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 r=`${this.config.prefix}_${t}_${e}`;return this._getItem(r)}setUserItem(e,t,r){let s=this.config.userId??"null";if("null"===s)return void this.logger.error("userId is required");let i=`${this.config.prefix}_${s}_${e}`;return this._setItem(i,t,r)}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 r=JSON.parse(tt.getStorageSync(t));(!r.expire||Date.now()-r.timestamp<=r.expire)&&e.push(t.replace(this.config.prefix,""))}}),e}catch(e){return console.error("Storage keys error:",e),[]}}static new(e){return new Storage(e)}}const ad_Storage=Storage;class CountRecorder{_total=0;_local_sign="";_expire="today";constructor(e){if(this.storage=ad_Storage.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),r=this._safeLocalValue(t);r&&r?.total==e||this.storage.setUserItem(this._local_sign,{total:e,today:r?.today??0},this._expire)}updateToday(){let e=this._adTimes(),t=this.storage.getUserItem(this._local_sign),r=this._safeLocalValue(t),s=r?.today??0;this.storage.setUserItem(this._local_sign,{total:e,today:s+1},this._expire)}remain(){let e=this.storage.getUserItem(this._local_sign),t=this._safeLocalValue(e),r=t?.today??0;return Number(t?.total??0)-Number(r)}static new(e){return new CountRecorder(e)}}const SCENT_TYPE_OBJ={0:"launch_ad",1:"novel_plugin_strong_ad",2:"novel_plugin_unlock_btn",3:"novel_plugin_free_benefit_btn",4:"home_free_welfare_btn",5:"home_free_popup",6:"other",7:"home_back_show",8:"novel_plugin_free_time_btn",9:"launch_ad_alone"},SCENT_TEXT_OBJ=Object.entries(SCENT_TYPE_OBJ).reduce((e,[t,r])=>(e[r]=Number(t),e),{});class RewardAdGlobalRecorder{static instance=null;_initSign="";_halfway=[{scene:SCENT_TEXT_OBJ.other,count:0}];_finished=[{scene:SCENT_TEXT_OBJ.other,count:0}];constructor(e){if(RewardAdGlobalRecorder.instance)return RewardAdGlobalRecorder.instance;this._initSign=e?.sign??"",RewardAdGlobalRecorder.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:SCENT_TEXT_OBJ.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:SCENT_TEXT_OBJ.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 RewardAdGlobalRecorder.instance||(RewardAdGlobalRecorder.instance=new RewardAdGlobalRecorder(e)),RewardAdGlobalRecorder.instance}static getInstance(){if(!RewardAdGlobalRecorder.instance)throw Error("RewardAdGlobalRecorder instance is not init");return RewardAdGlobalRecorder.instance}}const ad_RewardAdGlobalRecorder=RewardAdGlobalRecorder;class RewardAdSceneTriggerManager{static instance=null;_initSign="";_currScene=null;constructor(e){if(RewardAdSceneTriggerManager.instance)return RewardAdSceneTriggerManager.instance;this._initSign=e?.sign??"",RewardAdSceneTriggerManager.instance=this}initialize(e){}addScene(e){return console.log("----------------------AD触发场景:--------------------",e),this._currScene=e,this}addSceneType(e=1){return this.addScene(SCENT_TYPE_OBJ[e]),this}getCurrentScene(){return this._currScene}placeholder(){return null}static build(e){return RewardAdSceneTriggerManager.instance||(RewardAdSceneTriggerManager.instance=new RewardAdSceneTriggerManager(e)),RewardAdSceneTriggerManager.instance}static getInstance(){if(!RewardAdSceneTriggerManager.instance)throw Error("RewardAdSceneTriggerManager instance is not init");return RewardAdSceneTriggerManager.instance}}const ad_RewardAdSceneTriggerManager=RewardAdSceneTriggerManager;class ExbAnalyticsJS{static instance=null;_initSign="";_needReport=!1;constructor(e){if(ExbAnalyticsJS.instance)return ExbAnalyticsJS.instance;this._initSign=e?.sign??"",this._needReport=e?.needReport??!1,this._userConfig=e?.userConfig??null,ExbAnalyticsJS.instance=this}initialize(e){return this._needReport?e:void console.warn("ExbAnalyticsJS needReport is false, do not report")}track(e,t,r){if(!this._needReport)return;if(!e)throw Error("eventName is required");let s=Object.assign({},this._getCommonUserInfo(),t),i=r?.sign??"track";console.log(`-------------${i}-----------------------:`,e,s),tt.reportAnalytics(e,s)}_getCommonUserInfo(){let{user_id:e,user_type:t,user_group:r}=this._userConfig??{};return{user_id:e,user_type:t,user_group:r}}identify(e){if(!e)throw Error("userInfo is required");if(!e.user_id)throw Error("user_id is required");return this._userConfig={user_id:e.user_id,user_type:e.user_type??0,user_group:e.user_group??0},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 ExbAnalyticsJS.instance||(ExbAnalyticsJS.instance=new ExbAnalyticsJS(e)),ExbAnalyticsJS.instance}static getInstance(){if(!ExbAnalyticsJS.instance)throw Error("ExbAnalyticsJS instance is not init");return ExbAnalyticsJS.instance}static new(e){return new ExbAnalyticsJS(e)}}const ad_ExbAnalyticsJS=ExbAnalyticsJS;function matchErrorWithKeywords(e,t){return!!t&&e.some(e=>RegExp(e,"i").test(t))}function findAdTypeBySceneFlag(e,t,r="showTimes"){if(!Array.isArray(e))return console.error("第一个参数必须是数组"),null;let s=e.find(e=>e&&e.adSceneFlag===t);return s?s[r]:null}class RewardAdNovel extends ad_RewardAdFather{_onHalfway=null;_onShow=null;_onFinish=null;_onAlways=null;_onError=null;_initSign="";_alwaysCallback=null;_halfwayCallback=null;_finishedCallback=null;_resolve=null;_next=null;_scene=SCENT_TEXT_OBJ.other;_adTimeout=null;_adTimeoutTime=8e3;_adBeforeShowTimer=null;_adBeforeShowTime=300;_adSpeedCloseTimer=null;_adSpeedCloseTime=5e3;_needEndOnTimeout=!0;_needSpeedEndOnTimeout=!1;bindAdCloseLister=this.adCloseLister.bind(this);bindAdErrorLister=this.adErrorLister.bind(this);bindAdLoadLister=this.adLoadLister.bind(this);bindApiAdErrorLister=this.apiAdErrorLister.bind(this);_bindShiftCloseLister=this._shiftCloseLister.bind(this);_bindShiftErrorLister=this._shiftErrorLister.bind(this);constructor(e){super(e),this._initSign=e?.sign??"",this._adConfig=e?.adConfig??{},this._needEndOnTimeout=e?.needEndOnTimeout??!0,this._onHalfway=e?.collection?.onHalfway??null,this._onShow=e?.collection?.onShow??null,this._onFinish=e?.collection?.onFinish??null,this._onAlways=e?.collection?.onAlways??null,this._onError=e?.collection?.onError??null}initialize(e,t){return super.initialize(e,t),this._initAdLister(),this._initNovelConfig(e),this}_initAdLister(){this.onClose(this.bindAdCloseLister),this.onError(this.bindAdErrorLister),this.onLoad(this.bindAdLoadLister),tt.onError(this.bindApiAdErrorLister)}_initNovelConfig(e){this.novelConfig=RewardAdNovelConfig.new({retry:e?.retry})}_onInnerExecuteBefore(){return null}_onInnerAdShowSuccess(){return null}_setAdTimeout(e){this._needSpeedEndOnTimeout&&(this._adSpeedCloseTimer=setTimeout(()=>{if("ios"==tt.getSystemInfoSync().platform){let t=()=>{tt.offAppShow(t),console.warn("[RewardAdNovel] ad_show_timeout: ios platform close ad onAppShow, handling fallback ad case, scene:",e?.scene);let r="ad_show_timeout: ios platform close ad onAppShow";ad_ExbAnalyticsJS.getInstance().track("incentive_ad_show",{scene:e?.scene,result:0,msg:r}),this._adTimeout&&clearTimeout(this._adTimeout),e?.end({resolvedValue:{apiError:{errMsg:r}},nextValue:null})};tt.onAppShow(t)}clearTimeout(this._adSpeedCloseTimer)},this._adSpeedCloseTime)),this._needEndOnTimeout&&(this._adTimeout=setTimeout(()=>{console.warn("[RewardAdNovel] Ad show timeout, handling fallback ad case, scene:",e?.scene),ad_ExbAnalyticsJS.getInstance().track("incentive_ad_show",{scene:e?.scene,result:0,msg:"ad_show_timeout: normal"}),e?.end({resolvedValue:{apiError:{errMsg:"ad_show_timeout: normal"}},nextValue:null})},this._adTimeoutTime))}_adPreludeInterval(e){e.prelude?.({scene:e?.scene,frequency:this._adBeforeShowTime,time:new Date().getTime()}),this._adBeforeShowTimer=setInterval(()=>{e.prelude?.({scene:e?.scene,frequency:this._adBeforeShowTime,time:new Date().getTime()})},this._adBeforeShowTime)}_clearAdTimeout(){this._adTimeout&&(clearTimeout(this._adTimeout),this._adTimeout=null),this._adBeforeShowTimer&&(clearTimeout(this._adBeforeShowTimer),this._adBeforeShowTimer=null),this._adSpeedCloseTimer&&(clearTimeout(this._adSpeedCloseTimer),this._adSpeedCloseTimer=null)}get rewardAd(){return this._rewardAd}addExecuteManager(e){return super.addExecuteManager(e)}ad(e,t=null){return this._alwaysCallback=e?.collection?.always,this._halfwayCallback=e?.collection?.halfway,this._finishedCallback=e?.collection?.finished,this._onInnerExecuteBefore(),new Promise(r=>{this._adInner({options:{scene:e?.options?.scene},collection:{resolve:r,before:e.collection?.before,success:e.collection?.success,prelude:e.collection?.prelude}},t)})}_adInner(e,t=null){let r=e?.collection?.resolve,s=e?.options?.scene??this._scene??SCENT_TEXT_OBJ.other,i=e?.collection?.before,n=e?.collection?.success,a=e?.collection?.prelude,o=e=>{this._clearAdTimeout(),this.adDestroy(),r?.(Object.assign({scene:s},e?.resolvedValue)),t?.(Object.assign({scene:s},e?.nextValue))},l=()=>{this._scene=s,i?.({scene:s}),this._before=i,this._onShow?.({scene:s}),ad_RewardAdSceneTriggerManager.getInstance().addSceneType(s),this._resolve=r,this._next=t,this._setAdTimeout({scene:s,end:o}),this._adPreludeInterval({scene:s,prelude:a}),this.adShow().then(()=>{this._clearAdTimeout(),n?.({scene:s}),this._success=n,ad_ExbAnalyticsJS.getInstance().track("incentive_ad_show",{scene:s,result:1}),this._onInnerAdShowSuccess()}).catch(e=>{(this._clearAdTimeout(),ad_ExbAnalyticsJS.getInstance().track("incentive_ad_show",{scene:s,result:0,msg:e?.errMsg}),matchErrorWithKeywords(this._ttErrorMsgs,e?.errMsg)||this._ttErrorCodes.includes(e?.errorCode))?o({scene:s,resolvedValue:{apiError:e},nextValue:null}):0>=this.novelConfig.remain()?o({scene:s,resolvedValue:null,nextValue:null}):(this.novelConfig.updateRetry(),this.adLoad().then(()=>{ad_ExbAnalyticsJS.getInstance().track("incentive_ad_load",{scene:s,result:1}),l()}).catch(e=>{ad_ExbAnalyticsJS.getInstance().track("incentive_ad_load",{scene:s,result:0}),o({scene:s,resolvedValue:{apiError:e},nextValue:null})}))})};l()}adLoad(){return this.load()}adShow(){return this.show()}_outerCloseCallback(e){this._alwaysCallback?.(e)}_outerHalfwayCallback(e){this._halfwayCallback?.(e)}_outerFinishedCallback(e){this._finishedCallback?.(e)}adCloseLister(e){this._clearAdTimeout(),ad_RewardAdGlobalRecorder.getInstance().record({type:e.isEnded?"finished":"halfway",scene:this._scene}),ad_ExbAnalyticsJS.getInstance().track("incentive_ad_close",{scene:this._scene,ad_is_completed:+!!e.isEnded,ad_count:e.count});let t={...e,scene:this._scene},r=t=>{this.adDestroy(),this._resolve?.(Object.assign({},e,{scene:this._scene},t)),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null};e?.isEnded?(this._outerFinishedCallback(t),this._onFinish?.(t)):(this._outerHalfwayCallback(t),this._onHalfway?.(t)),this._outerCloseCallback(t),this._onAlways?.(t),r({end_type:e.isEnded?"finished":"halfway"})}adErrorLister(e){this._clearAdTimeout(),console.error("[RewardAdNovel] adErrorLister",JSON.stringify(e)),this.adDestroy(),this._onError?.(e),this._resolve?.({apiError:e}),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null}apiAdErrorLister(e){this._clearAdTimeout(),console.error("[API RewardAdNovel] apiAdErrorLister:",JSON.stringify(e)),this.adDestroy(),this._onError?.(e),this._resolve?.({apiError:e}),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null}adLoadLister(e){ad_ExbAnalyticsJS.getInstance().track("incentive_ad_load",{scene:this._scene,result:1}),console.info("[RewardAdNovel] adLoadLister:",JSON.stringify({scene:this._scene,info:e}))}adDestroy(){this.offClose(this.bindAdCloseLister),this.offError(this.bindAdErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this.destroy()}clear(){this._clearAdTimeout(),this.offClose(this.bindAdCloseLister),this.offClose(this._bindShiftCloseLister),this.offError(this.bindAdErrorLister),this.offError(this._bindShiftErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this.destroy(),this._resolve=null,this._next=null,this._success=null,this._before=null}_shiftCloseLister(e){this._clearAdTimeout(),this.offError(this._bindShiftErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this.offClose(this._bindShiftCloseLister),this.destroy(),this._resolve?.(Object.assign({},e,{scene:this._scene})),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null}_shiftErrorLister(e){this._clearAdTimeout(),this.offClose(this._bindShiftCloseLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this.offError(this._bindShiftErrorLister),this.destroy(),this._resolve?.(Object.assign({},e,{scene:this._scene})),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null}shift(){this.offClose(this.bindAdCloseLister),this.onClose(this._bindShiftCloseLister),this.offError(this.bindAdErrorLister),this.onError(this._bindShiftErrorLister)}static build(e){return RewardAdNovel.instance||(RewardAdNovel.instance=new RewardAdNovel(e)),RewardAdNovel.instance}static getInstance(){if(!RewardAdNovel.instance)throw Error("RewardAdNovel instance is not init");return RewardAdNovel.instance}static new(e){return new RewardAdNovel(e)}}class RewardAdNovelConfig{frequency={total:0,current:0};constructor(e){this._init(e)}_init(e){this._adTimes(e)}_adTimes(e){this.frequency.total=e?.retry??4}reset(){this.frequency.current=0}updateRetry(){this.frequency.current=this.frequency.current+1}remain(){return this.frequency.total-this.frequency.current}static new(e){return new RewardAdNovelConfig(e)}}const ad_RewardAdNovel=RewardAdNovel,src=ad_AdExecuteManager;for(var __rspack_i in exports.AdExecuteManager=__webpack_exports__.AdExecuteManager,exports.CountRecorder=__webpack_exports__.CountRecorder,exports.ExbAnalyticsJS=__webpack_exports__.ExbAnalyticsJS,exports.Logger=__webpack_exports__.Logger,exports.RewardAdFather=__webpack_exports__.RewardAdFather,exports.RewardAdGlobalRecorder=__webpack_exports__.RewardAdGlobalRecorder,exports.RewardAdNovel=__webpack_exports__.RewardAdNovel,exports.RewardAdSceneTriggerManager=__webpack_exports__.RewardAdSceneTriggerManager,exports.SerializableError=__webpack_exports__.SerializableError,exports.Storage=__webpack_exports__.Storage,exports.default=__webpack_exports__.default,__webpack_exports__)-1===["AdExecuteManager","CountRecorder","ExbAnalyticsJS","Logger","RewardAdFather","RewardAdGlobalRecorder","RewardAdNovel","RewardAdSceneTriggerManager","SerializableError","Storage","default"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
|
|
1
|
+
"use strict";const __rslib_import_meta_url__="u"<typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_require__={};__webpack_require__.d=(e,t)=>{for(var r in t)__webpack_require__.o(t,r)&&!__webpack_require__.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__webpack_require__.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{default:()=>src,Storage:()=>ad_Storage,RewardAdGlobalRecorder:()=>ad_RewardAdGlobalRecorder,CountRecorder:()=>CountRecorder,RewardAdNovel:()=>ad_RewardAdNovel,RewardAdFather:()=>ad_RewardAdFather,Logger:()=>Logger,ExbAnalyticsJS:()=>ad_ExbAnalyticsJS,AdExecuteManager:()=>ad_AdExecuteManager,RewardAdSceneTriggerManager:()=>ad_RewardAdSceneTriggerManager,SerializableError:()=>SerializableError});const compose=e=>e.map(e=>(t,r)=>async s=>await e(Object.assign({},t,s),r)).reduce((e,t)=>(r,s)=>e(r,t(r,s))),ad_compose=compose;class Logger{constructor(e={}){const{prefix:t="Logger",level:r="info",enabled:s=!0}=e;this.prefix=t,this.enabled=s,this.levels={error:0,warn:1,info:2,debug:3},this.currentLevel=this.levels[r]||this.levels.info}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 r=new Date,s=`${r.getFullYear()}/${r.getMonth()+1}/${r.getDate()} ${r.getHours()}:${r.getMinutes()}:${r.getSeconds()}`;return`[${s}] [${e.toUpperCase()}] [${this.prefix}] ${t}`}_log(e,t,...r){if(!this.enabled)return;let s=this.levels[e];if(void 0!==s&&this.currentLevel>=s){let s=this.formatMessage(e,t);switch(e){case"error":console.error(s,...r);break;case"warn":console.warn(s,...r);break;case"info":console.info(s,...r);break;case"debug":console.debug(s,...r);break;default:console.log(s,...r)}}}error(e,...t){this._log("error",e,...t)}warn(e,...t){this._log("warn",e,...t)}info(e,...t){this._log("info",e,...t)}debug(e,...t){this._log("debug",e,...t)}log(e,t,...r){this._log(e,t,...r)}}class AdExecuteManager{static _instance=null;_taskStack=[];_currentBatchTasks=[];_isRunning=!1;_currentTask=null;constructor(e){if(this.logger=new Logger({prefix:"AdExecuteManager",enabled:!!e?.log}),AdExecuteManager._instance)return AdExecuteManager._instance;AdExecuteManager._instance=this}static getInstance(e){return AdExecuteManager._instance||(AdExecuteManager._instance=new AdExecuteManager(e)),AdExecuteManager._instance}addTask(e,t){return e&&"function"==typeof e.ad?new Promise((r,s)=>{let i={adInstance:e,options:t.options??{},callbackCollection:t.collection??{},resolve:r,reject:s,id:`ad_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,_isResolved:!1,_isRejected:!1};this._taskStack.push(i),this._isRunning||this._compose()}):(this.logger.error("无效的广告实例 请正确实现.ad方法"),Promise.reject(Error("无效的广告实例")))}_compose(){if(0===this._taskStack.length){this._isRunning=!1,this._currentTask=null;return}this._isRunning=!0;let e=[...this._taskStack];this._taskStack=[],this._currentBatchTasks=e;let t=e.map(e=>async(t,r)=>{let{adInstance:s,options:i,callbackCollection:n,resolve:a,id:o}=e;if(e._isResolved||e._isRejected)return void await r(t);this._currentTask=e;try{let l=async e=>{await r(Object.assign({},t,e))},c=await s.initialize(i).ad({options:i,collection:n},l),d=Object.assign({id:o},c);this.logger.info(`任务执行成功,成功信息:${JSON.stringify(d)}`),e._isResolved=!0,a(d),s?.record(d)}catch(n){let i=Object.assign({id:o,apiError:n});this.logger.error(`任务执行失败, 继续下一个任务,错误信息:${JSON.stringify(i)}`),e._isRejected=!0;try{s?.clear()}catch(e){this.logger.error("clear error: ",JSON.stringify(Object.assign({id:o,apiError:e})))}a(i),s?.record(i),await r(t)}}),r={roundTasks:t.length};compose(t)(r,async e=>{this.logger.info("本轮活动队列已经清空",e),this._taskStack.length>0?Promise.resolve().then(()=>{this._compose()}):(this._isRunning=!1,this._currentTask=null,this._currentBatchTasks=[])})()}clearTasks(){if(this._currentTask){if(this._currentTask._isResolved||this._currentTask._isRejected){this._currentTask=null;return}try{this._currentTask.callbackCollection&&this._currentTask.callbackCollection.onCancel&&this._currentTask.callbackCollection.onCancel(),this._currentTask._isResolved=!0,this._currentTask.resolve()}catch(e){this.logger.error("clear current task error: ",e)}this._currentTask=null}this._currentBatchTasks.length>0&&(this._currentBatchTasks.forEach(e=>{if(e!==this._currentTask&&!e._isResolved&&!e._isRejected)try{e.callbackCollection&&e.callbackCollection.onCancel&&e.callbackCollection.onCancel(),e._isResolved=!0,e.resolve()}catch(e){this.logger.error("clear current batch task error: ",e)}}),this._currentBatchTasks=[]),this._taskStack.forEach(e=>{if(!e._isResolved&&!e._isRejected&&(e._isResolved=!0,e.resolve(),e.callbackCollection&&e.callbackCollection.onCancel))try{e.callbackCollection.onCancel()}catch(e){this.logger.error("clear task error: ",e)}}),this._taskStack=[],this._isRunning=!1}getTaskCount(){return this._taskStack.filter(e=>!e._isResolved&&!e._isRejected).length+this._currentBatchTasks.filter(e=>e!==this._currentTask&&!e._isResolved&&!e._isRejected).length+(!this._currentTask||this._currentTask._isResolved||this._currentTask._isRejected?0:1)}isRunning(){return this._isRunning}getCurrentTaskId(){return this._currentTask?.id||null}}const ad_AdExecuteManager=AdExecuteManager;class SerializableError 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 RewardAdFather{static args=null;_initSign="";_preserveOnEnd=!1;_rewardAd=null;_ttErrorMsgs=["The adUnitId is closed","The adUnitId is prohibit","The adUnitId is invalid","The adUnitId is empty","feature is not supported in app"];_ttErrorCodes=[139902,123302];constructor(e){this._initSign=e?.sign??"",this._adConfig=e?.adConfig??{},this._preserveOnEnd=e?.preserveOnEnd??!1}initialize(e,t){if(this._rewardAd)return console.warn("RewardAdFather: rewardAd has been initialized"),t?.(this._rewardAd),this;let r=Object.assign({},RewardAdFather.args,this._adConfig,e);if(!r.adUnitId)throw console.error("[RewardAdFather] reward args adUnitId is required",r),new SerializableError("[RewardAdFather] reward args adUnitId is required");return this._rewardAd=tt.createRewardedVideoAd(r),t?.(this._rewardAd),this}initialized(){return!!this._rewardAd}async ad(e,t=null){throw Error("子类必须实现ad方法")}async addExecuteManager(e){let t=Object.assign({},this._adConfig,e?.options??{});return RewardAdFather.executeWithManager(this,Object.assign({},e,{options:t}))}destroy(){this._rewardAd&&!this._preserveOnEnd&&(this._rewardAd.destroy(),this._rewardAd=null)}clear(){throw Error("子类必须实现clear方法")}record(e){return this}onClose(e){this._rewardAd&&this._rewardAd.onClose(e)}offClose(e){this._rewardAd&&this._rewardAd.offClose(e)}show(){return this._rewardAd?this._rewardAd.show():Promise.reject({errMsg:"rewardAd is null"})}load(){if(this._rewardAd)return this._rewardAd.load()}onError(e){this._rewardAd&&this._rewardAd.onError(e)}offError(e){this._rewardAd&&this._rewardAd.offError(e)}onLoad(e){this._rewardAd&&this._rewardAd.onLoad(e)}offLoad(e){this._rewardAd&&this._rewardAd.offLoad(e)}placeholder(){return null}static buildArgs(e){e?.adUnitId||console.error("[RewardAdFather] RewardParams.adUnitId is required"),RewardAdFather.args=e}static async executeWithManager(e,t){return e&&e instanceof RewardAdFather?ad_AdExecuteManager.getInstance({log:t?.options?.log??!0}).addTask(e,t):(console.error("RewardAdFather: executeWithManager - 无效的广告实例"),Promise.reject(Error("无效的广告实例")))}}const ad_RewardAdFather=RewardAdFather;class Storage{constructor(e={}){this.config={prefix:"storage_",expire:null,...e},this.logger=new Logger({prefix:"Storage"})}getTodayEndTimestamp(){let e=new Date;return new Date(e.getFullYear(),e.getMonth(),e.getDate(),23,59,59,999).getTime()}_setItem(e,t,r){let s=void 0!==r?r:this.config.expire;"today"===s&&(s=this.getTodayEndTimestamp()-Date.now());let i={value:t,expire:s,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 r=JSON.parse(t);if(r.expire&&Date.now()-r.timestamp>r.expire)return this.removeItem(e),null;return r.value}catch(e){return console.error("Storage getItem error:",e),null}}setItem(e,t,r){let s=this.config.prefix+e;return this._setItem(s,t,r)}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 r=`${this.config.prefix}_${t}_${e}`;return this._getItem(r)}setUserItem(e,t,r){let s=this.config.userId??"null";if("null"===s)return void this.logger.error("userId is required");let i=`${this.config.prefix}_${s}_${e}`;return this._setItem(i,t,r)}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 r=JSON.parse(tt.getStorageSync(t));(!r.expire||Date.now()-r.timestamp<=r.expire)&&e.push(t.replace(this.config.prefix,""))}}),e}catch(e){return console.error("Storage keys error:",e),[]}}static new(e){return new Storage(e)}}const ad_Storage=Storage;class CountRecorder{_total=0;_local_sign="";_expire="today";constructor(e){if(this.storage=ad_Storage.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),r=this._safeLocalValue(t);r&&r?.total==e||this.storage.setUserItem(this._local_sign,{total:e,today:r?.today??0},this._expire)}updateToday(){let e=this._adTimes(),t=this.storage.getUserItem(this._local_sign),r=this._safeLocalValue(t),s=r?.today??0;this.storage.setUserItem(this._local_sign,{total:e,today:s+1},this._expire)}remain(){let e=this.storage.getUserItem(this._local_sign),t=this._safeLocalValue(e),r=t?.today??0;return Number(t?.total??0)-Number(r)}static new(e){return new CountRecorder(e)}}function matchErrorWithKeywords(e,t){return!!t&&e.some(e=>RegExp(e,"i").test(t))}function findAdTypeBySceneFlag(e,t,r="showTimes"){if(!Array.isArray(e))return console.error("第一个参数必须是数组"),null;let s=e.find(e=>e&&e.adSceneFlag===t);return s?s[r]:null}function getAdSceneTextObj(e){return Object.entries(e).reduce((e,[t,r])=>(e[r]=Number(t),e),{})}const DEFAULT_SCENT_TYPE_OBJ={9999:"inner_default_other"},DEFAULT_SCENT_TEXT_OBJ=getAdSceneTextObj(DEFAULT_SCENT_TYPE_OBJ);class RewardAdGlobalRecorder{static instance=null;_initSign="";_halfway=[{scene:DEFAULT_SCENT_TEXT_OBJ.inner_default_other,count:0}];_finished=[{scene:DEFAULT_SCENT_TEXT_OBJ.inner_default_other,count:0}];constructor(e){if(RewardAdGlobalRecorder.instance)return RewardAdGlobalRecorder.instance;this._initSign=e?.sign??"",this._halfway=[{scene:DEFAULT_SCENT_TEXT_OBJ.inner_default_other,count:0}],this._finished=[{scene:DEFAULT_SCENT_TEXT_OBJ.inner_default_other,count:0}],RewardAdGlobalRecorder.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:DEFAULT_SCENT_TEXT_OBJ.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:DEFAULT_SCENT_TEXT_OBJ.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 RewardAdGlobalRecorder.instance||(RewardAdGlobalRecorder.instance=new RewardAdGlobalRecorder(e)),RewardAdGlobalRecorder.instance}static getInstance(){if(!RewardAdGlobalRecorder.instance)throw Error("RewardAdGlobalRecorder instance is not init");return RewardAdGlobalRecorder.instance}}const ad_RewardAdGlobalRecorder=RewardAdGlobalRecorder;class RewardAdSceneTriggerManager{static instance=null;_initSign="";_currScene=null;_sceneTypeObj={};constructor(e){if(RewardAdSceneTriggerManager.instance)return RewardAdSceneTriggerManager.instance;this._initSign=e?.sign??"",this._sceneTypeObj=e?.sceneTypeObj??{},RewardAdSceneTriggerManager.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 RewardAdSceneTriggerManager.instance||(RewardAdSceneTriggerManager.instance=new RewardAdSceneTriggerManager(e)),RewardAdSceneTriggerManager.instance}static getInstance(){if(!RewardAdSceneTriggerManager.instance)throw Error("RewardAdSceneTriggerManager instance is not init");return RewardAdSceneTriggerManager.instance}}const ad_RewardAdSceneTriggerManager=RewardAdSceneTriggerManager;class ExbAnalyticsJS{static instance=null;_initSign="";_needReport=!1;constructor(e){if(ExbAnalyticsJS.instance)return ExbAnalyticsJS.instance;this._initSign=e?.sign??"",this._needReport=e?.needReport??!1,this._userConfig=e?.userConfig??null,ExbAnalyticsJS.instance=this}initialize(e){return this._needReport?e:void console.warn("ExbAnalyticsJS needReport is false, do not report")}track(e,t,r){if(!this._needReport)return;if(!e)throw Error("eventName is required");let s=Object.assign({},this._getCommonUserInfo(),t),i=r?.sign??"track";console.log(`-------------${i}-----------------------:`,e,s),tt.reportAnalytics(e,s)}_getCommonUserInfo(){let{user_id:e,user_type:t,user_group:r}=this._userConfig??{};return{user_id:e,user_type:t,user_group:r}}identify(e){if(!e)throw Error("userInfo is required");if(!e.user_id)throw Error("user_id is required");return this._userConfig={user_id:e.user_id,user_type:e.user_type??0,user_group:e.user_group??0},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 ExbAnalyticsJS.instance||(ExbAnalyticsJS.instance=new ExbAnalyticsJS(e)),ExbAnalyticsJS.instance}static getInstance(){if(!ExbAnalyticsJS.instance)throw Error("ExbAnalyticsJS instance is not init");return ExbAnalyticsJS.instance}static new(e){return new ExbAnalyticsJS(e)}}const ad_ExbAnalyticsJS=ExbAnalyticsJS;class RewardAdNovel extends ad_RewardAdFather{_onHalfway=null;_onShow=null;_onFinish=null;_onAlways=null;_onError=null;_initSign="";_alwaysCallback=null;_halfwayCallback=null;_finishedCallback=null;_resolve=null;_next=null;_scene=DEFAULT_SCENT_TEXT_OBJ.inner_default_other;_adTimeout=null;_adTimeoutTime=8e3;_adBeforeShowTimer=null;_adBeforeShowTime=300;_adSpeedCloseTimer=null;_adSpeedCloseTime=5e3;_needEndOnTimeout=!0;_needSpeedEndOnTimeout=!1;bindAdCloseLister=this.adCloseLister.bind(this);bindAdErrorLister=this.adErrorLister.bind(this);bindAdLoadLister=this.adLoadLister.bind(this);bindApiAdErrorLister=this.apiAdErrorLister.bind(this);_bindShiftCloseLister=this._shiftCloseLister.bind(this);_bindShiftErrorLister=this._shiftErrorLister.bind(this);constructor(e){super(e),this._initSign=e?.sign??"",this._adConfig=e?.adConfig??{},this._needEndOnTimeout=e?.needEndOnTimeout??!0,this._onHalfway=e?.collection?.onHalfway??null,this._onShow=e?.collection?.onShow??null,this._onFinish=e?.collection?.onFinish??null,this._onAlways=e?.collection?.onAlways??null,this._onError=e?.collection?.onError??null}initialize(e,t){return super.initialize(e,t),this._initAdLister(),this._initNovelConfig(e),this}_initAdLister(){this.onClose(this.bindAdCloseLister),this.onError(this.bindAdErrorLister),this.onLoad(this.bindAdLoadLister),tt.onError(this.bindApiAdErrorLister)}_initNovelConfig(e){this.novelConfig=RewardAdNovelConfig.new({retry:e?.retry})}_onInnerExecuteBefore(){return null}_onInnerAdShowSuccess(){return null}_setAdTimeout(e){this._needSpeedEndOnTimeout&&(this._adSpeedCloseTimer=setTimeout(()=>{if("ios"==tt.getSystemInfoSync().platform){let t=()=>{tt.offAppShow(t),console.warn("[RewardAdNovel] ad_show_timeout: ios platform close ad onAppShow, handling fallback ad case, scene:",e?.scene);let r="ad_show_timeout: ios platform close ad onAppShow";ad_ExbAnalyticsJS.getInstance().track("incentive_ad_show",{scene:e?.scene,result:0,msg:r}),this._adTimeout&&clearTimeout(this._adTimeout),e?.end({resolvedValue:{apiError:{errMsg:r}},nextValue:null})};tt.onAppShow(t)}clearTimeout(this._adSpeedCloseTimer)},this._adSpeedCloseTime)),this._needEndOnTimeout&&(this._adTimeout=setTimeout(()=>{console.warn("[RewardAdNovel] Ad show timeout, handling fallback ad case, scene:",e?.scene),ad_ExbAnalyticsJS.getInstance().track("incentive_ad_show",{scene:e?.scene,result:0,msg:"ad_show_timeout: normal"}),e?.end({resolvedValue:{apiError:{errMsg:"ad_show_timeout: normal"}},nextValue:null})},this._adTimeoutTime))}_adPreludeInterval(e){e.prelude?.({scene:e?.scene,frequency:this._adBeforeShowTime,time:new Date().getTime()}),this._adBeforeShowTimer=setInterval(()=>{e.prelude?.({scene:e?.scene,frequency:this._adBeforeShowTime,time:new Date().getTime()})},this._adBeforeShowTime)}_clearAdTimeout(){this._adTimeout&&(clearTimeout(this._adTimeout),this._adTimeout=null),this._adBeforeShowTimer&&(clearTimeout(this._adBeforeShowTimer),this._adBeforeShowTimer=null),this._adSpeedCloseTimer&&(clearTimeout(this._adSpeedCloseTimer),this._adSpeedCloseTimer=null)}get rewardAd(){return this._rewardAd}addExecuteManager(e){return super.addExecuteManager(e)}ad(e,t=null){return this._alwaysCallback=e?.collection?.always,this._halfwayCallback=e?.collection?.halfway,this._finishedCallback=e?.collection?.finished,this._onInnerExecuteBefore(),new Promise(r=>{this._adInner({options:{scene:e?.options?.scene},collection:{resolve:r,before:e.collection?.before,success:e.collection?.success,prelude:e.collection?.prelude}},t)})}_adInner(e,t=null){let r=e?.collection?.resolve,s=e?.options?.scene??this._scene??DEFAULT_SCENT_TEXT_OBJ.inner_default_other,i=e?.collection?.before,n=e?.collection?.success,a=e?.collection?.prelude,o=e=>{this._clearAdTimeout(),this.adDestroy(),r?.(Object.assign({scene:s},e?.resolvedValue)),t?.(Object.assign({scene:s},e?.nextValue))},l=()=>{this._scene=s,i?.({scene:s}),this._before=i,this._onShow?.({scene:s}),ad_RewardAdSceneTriggerManager.getInstance().addSceneType(s),this._resolve=r,this._next=t,this._setAdTimeout({scene:s,end:o}),this._adPreludeInterval({scene:s,prelude:a}),this.adShow().then(()=>{this._clearAdTimeout(),n?.({scene:s}),this._success=n,ad_ExbAnalyticsJS.getInstance().track("incentive_ad_show",{scene:s,result:1}),this._onInnerAdShowSuccess()}).catch(e=>{(this._clearAdTimeout(),ad_ExbAnalyticsJS.getInstance().track("incentive_ad_show",{scene:s,result:0,msg:e?.errMsg}),matchErrorWithKeywords(this._ttErrorMsgs,e?.errMsg)||this._ttErrorCodes.includes(e?.errorCode))?o({scene:s,resolvedValue:{apiError:e},nextValue:null}):0>=this.novelConfig.remain()?o({scene:s,resolvedValue:null,nextValue:null}):(this.novelConfig.updateRetry(),this.adLoad().then(()=>{ad_ExbAnalyticsJS.getInstance().track("incentive_ad_load",{scene:s,result:1}),l()}).catch(e=>{ad_ExbAnalyticsJS.getInstance().track("incentive_ad_load",{scene:s,result:0}),o({scene:s,resolvedValue:{apiError:e},nextValue:null})}))})};l()}adLoad(){return this.load()}adShow(){return this.show()}_outerCloseCallback(e){this._alwaysCallback?.(e)}_outerHalfwayCallback(e){this._halfwayCallback?.(e)}_outerFinishedCallback(e){this._finishedCallback?.(e)}adCloseLister(e){this._clearAdTimeout(),ad_RewardAdGlobalRecorder.getInstance().record({type:e.isEnded?"finished":"halfway",scene:this._scene}),ad_ExbAnalyticsJS.getInstance().track("incentive_ad_close",{scene:this._scene,ad_is_completed:+!!e.isEnded,ad_count:e.count});let t={...e,scene:this._scene},r=t=>{this.adDestroy(),this._resolve?.(Object.assign({},e,{scene:this._scene},t)),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null};e?.isEnded?(this._outerFinishedCallback(t),this._onFinish?.(t)):(this._outerHalfwayCallback(t),this._onHalfway?.(t)),this._outerCloseCallback(t),this._onAlways?.(t),r({end_type:e.isEnded?"finished":"halfway"})}adErrorLister(e){this._clearAdTimeout(),console.error("[RewardAdNovel] adErrorLister",JSON.stringify(e)),this.adDestroy(),this._onError?.(e),this._resolve?.({apiError:e}),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null}apiAdErrorLister(e){this._clearAdTimeout(),console.error("[API RewardAdNovel] apiAdErrorLister:",JSON.stringify(e)),this.adDestroy(),this._onError?.(e),this._resolve?.({apiError:e}),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null}adLoadLister(e){ad_ExbAnalyticsJS.getInstance().track("incentive_ad_load",{scene:this._scene,result:1}),console.info("[RewardAdNovel] adLoadLister:",JSON.stringify({scene:this._scene,info:e}))}adDestroy(){this.offClose(this.bindAdCloseLister),this.offError(this.bindAdErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this.destroy()}clear(){this._clearAdTimeout(),this.offClose(this.bindAdCloseLister),this.offClose(this._bindShiftCloseLister),this.offError(this.bindAdErrorLister),this.offError(this._bindShiftErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this.destroy(),this._resolve=null,this._next=null,this._success=null,this._before=null}_shiftCloseLister(e){this._clearAdTimeout(),this.offError(this._bindShiftErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this.offClose(this._bindShiftCloseLister),this.destroy(),this._resolve?.(Object.assign({},e,{scene:this._scene})),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null}_shiftErrorLister(e){this._clearAdTimeout(),this.offClose(this._bindShiftCloseLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this.offError(this._bindShiftErrorLister),this.destroy(),this._resolve?.(Object.assign({},e,{scene:this._scene})),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null}shift(){this.offClose(this.bindAdCloseLister),this.onClose(this._bindShiftCloseLister),this.offError(this.bindAdErrorLister),this.onError(this._bindShiftErrorLister)}static build(e){return RewardAdNovel.instance||(RewardAdNovel.instance=new RewardAdNovel(e)),RewardAdNovel.instance}static getInstance(){if(!RewardAdNovel.instance)throw Error("RewardAdNovel instance is not init");return RewardAdNovel.instance}static new(e){return new RewardAdNovel(e)}}class RewardAdNovelConfig{frequency={total:0,current:0};constructor(e){this._init(e)}_init(e){this._adTimes(e)}_adTimes(e){this.frequency.total=e?.retry??4}reset(){this.frequency.current=0}updateRetry(){this.frequency.current=this.frequency.current+1}remain(){return this.frequency.total-this.frequency.current}static new(e){return new RewardAdNovelConfig(e)}}const ad_RewardAdNovel=RewardAdNovel,src=ad_AdExecuteManager;for(var __rspack_i in exports.AdExecuteManager=__webpack_exports__.AdExecuteManager,exports.CountRecorder=__webpack_exports__.CountRecorder,exports.ExbAnalyticsJS=__webpack_exports__.ExbAnalyticsJS,exports.Logger=__webpack_exports__.Logger,exports.RewardAdFather=__webpack_exports__.RewardAdFather,exports.RewardAdGlobalRecorder=__webpack_exports__.RewardAdGlobalRecorder,exports.RewardAdNovel=__webpack_exports__.RewardAdNovel,exports.RewardAdSceneTriggerManager=__webpack_exports__.RewardAdSceneTriggerManager,exports.SerializableError=__webpack_exports__.SerializableError,exports.Storage=__webpack_exports__.Storage,exports.default=__webpack_exports__.default,__webpack_exports__)-1===["AdExecuteManager","CountRecorder","ExbAnalyticsJS","Logger","RewardAdFather","RewardAdGlobalRecorder","RewardAdNovel","RewardAdSceneTriggerManager","SerializableError","Storage","default"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class e{constructor(e={}){let{prefix:t="Logger",level:s="info",enabled:r=!0}=e;this.prefix=t,this.enabled=r,this.levels={error:0,warn:1,info:2,debug:3},this.currentLevel=this.levels[s]||this.levels.info}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,r=`${s.getFullYear()}/${s.getMonth()+1}/${s.getDate()} ${s.getHours()}:${s.getMinutes()}:${s.getSeconds()}`;return`[${r}] [${e.toUpperCase()}] [${this.prefix}] ${t}`}_log(e,t,...s){if(!this.enabled)return;let r=this.levels[e];if(void 0!==r&&this.currentLevel>=r){let r=this.formatMessage(e,t);switch(e){case"error":console.error(r,...s);break;case"warn":console.warn(r,...s);break;case"info":console.info(r,...s);break;case"debug":console.debug(r,...s);break;default:console.log(r,...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)}debug(e,...t){this._log("debug",e,...t)}log(e,t,...s){this._log(e,t,...s)}}class t{static _instance=null;_taskStack=[];_currentBatchTasks=[];_isRunning=!1;_currentTask=null;constructor(s){if(this.logger=new e({prefix:"AdExecuteManager",enabled:!!s?.log}),t._instance)return t._instance;t._instance=this}static getInstance(e){return t._instance||(t._instance=new t(e)),t._instance}addTask(e,t){return e&&"function"==typeof e.ad?new Promise((s,r)=>{let i={adInstance:e,options:t.options??{},callbackCollection:t.collection??{},resolve:s,reject:r,id:`ad_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,_isResolved:!1,_isRejected:!1};this._taskStack.push(i),this._isRunning||this._compose()}):(this.logger.error("无效的广告实例 请正确实现.ad方法"),Promise.reject(Error("无效的广告实例")))}_compose(){if(0===this._taskStack.length){this._isRunning=!1,this._currentTask=null;return}this._isRunning=!0;let e=[...this._taskStack];this._taskStack=[],this._currentBatchTasks=e;let t=e.map(e=>async(t,s)=>{let{adInstance:r,options:i,callbackCollection:n,resolve:a,id:o}=e;if(e._isResolved||e._isRejected)return void await s(t);this._currentTask=e;try{let l=async e=>{await s(Object.assign({},t,e))},h=await r.initialize(i).ad({options:i,collection:n},l),c=Object.assign({id:o},h);this.logger.info(`任务执行成功,成功信息:${JSON.stringify(c)}`),e._isResolved=!0,a(c)}catch(n){let i=Object.assign({id:o,apiError:n});this.logger.error(`任务执行失败, 继续下一个任务,错误信息:${JSON.stringify(i)}`),e._isRejected=!0;try{r?.clear()}catch(e){this.logger.error("clear error: ",JSON.stringify(Object.assign({id:o,apiError:e})))}a(i),await s(t)}}),s={roundTasks:t.length};t.map(e=>(t,s)=>async r=>await e(Object.assign({},t,r),s)).reduce((e,t)=>(s,r)=>e(s,t(s,r)))(s,async e=>{this.logger.info("本轮活动队列已经清空",e),this._taskStack.length>0?Promise.resolve().then(()=>{this._compose()}):(this._isRunning=!1,this._currentTask=null,this._currentBatchTasks=[])})()}clearTasks(){if(this._currentTask){if(this._currentTask._isResolved||this._currentTask._isRejected){this._currentTask=null;return}try{this._currentTask.callbackCollection&&this._currentTask.callbackCollection.onCancel&&this._currentTask.callbackCollection.onCancel(),this._currentTask._isResolved=!0,this._currentTask.resolve()}catch(e){this.logger.error("clear current task error: ",e)}this._currentTask=null}this._currentBatchTasks.length>0&&(this._currentBatchTasks.forEach(e=>{if(e!==this._currentTask&&!e._isResolved&&!e._isRejected)try{e.callbackCollection&&e.callbackCollection.onCancel&&e.callbackCollection.onCancel(),e._isResolved=!0,e.resolve()}catch(e){this.logger.error("clear current batch task error: ",e)}}),this._currentBatchTasks=[]),this._taskStack.forEach(e=>{if(!e._isResolved&&!e._isRejected&&(e._isResolved=!0,e.resolve(),e.callbackCollection&&e.callbackCollection.onCancel))try{e.callbackCollection.onCancel()}catch(e){this.logger.error("clear task error: ",e)}}),this._taskStack=[],this._isRunning=!1}getTaskCount(){return this._taskStack.filter(e=>!e._isResolved&&!e._isRejected).length+this._currentBatchTasks.filter(e=>e!==this._currentTask&&!e._isResolved&&!e._isRejected).length+(!this._currentTask||this._currentTask._isResolved||this._currentTask._isRejected?0:1)}isRunning(){return this._isRunning}getCurrentTaskId(){return this._currentTask?.id||null}}let s=t;class r 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 i{static args=null;_initSign="";_preserveOnEnd=!1;_rewardAd=null;_ttErrorMsgs=["The adUnitId is closed","The adUnitId is prohibit","The adUnitId is invalid","The adUnitId is empty","feature is not supported in app"];_ttErrorCodes=[139902,123302];constructor(e){this._initSign=e?.sign??"",this._adConfig=e?.adConfig??{},this._preserveOnEnd=e?.preserveOnEnd??!1}initialize(e,t){if(this._rewardAd)return console.warn("RewardAdFather: rewardAd has been initialized"),t?.(this._rewardAd),this;let s=Object.assign({},i.args,this._adConfig,e);if(!s.adUnitId)throw console.error("[RewardAdFather] reward args adUnitId is required",s),new r("[RewardAdFather] reward args adUnitId is required");return this._rewardAd=tt.createRewardedVideoAd(s),t?.(this._rewardAd),this}initialized(){return!!this._rewardAd}async ad(e,t=null){throw Error("子类必须实现ad方法")}async addExecuteManager(e){let t=Object.assign({},this._adConfig,e?.options??{});return i.executeWithManager(this,Object.assign({},e,{options:t}))}destroy(){this._rewardAd&&!this._preserveOnEnd&&(this._rewardAd.destroy(),this._rewardAd=null)}clear(){throw Error("子类必须实现clear方法")}onClose(e){this._rewardAd&&this._rewardAd.onClose(e)}offClose(e){this._rewardAd&&this._rewardAd.offClose(e)}show(){return this._rewardAd?this._rewardAd.show():Promise.reject({errMsg:"rewardAd is null"})}load(){if(this._rewardAd)return this._rewardAd.load()}onError(e){this._rewardAd&&this._rewardAd.onError(e)}offError(e){this._rewardAd&&this._rewardAd.offError(e)}onLoad(e){this._rewardAd&&this._rewardAd.onLoad(e)}offLoad(e){this._rewardAd&&this._rewardAd.offLoad(e)}placeholder(){return null}static buildArgs(e){e?.adUnitId||console.error("[RewardAdFather] RewardParams.adUnitId is required"),i.args=e}static async executeWithManager(e,t){return e&&e instanceof i?s.getInstance({log:t?.options?.log??!0}).addTask(e,t):(console.error("RewardAdFather: executeWithManager - 无效的广告实例"),Promise.reject(Error("无效的广告实例")))}}let n=i;class a{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 r=void 0!==s?s:this.config.expire;"today"===r&&(r=this.getTodayEndTimestamp()-Date.now());let i={value:t,expire:r,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 r=this.config.prefix+e;return this._setItem(r,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 r=this.config.userId??"null";if("null"===r)return void this.logger.error("userId is required");let i=`${this.config.prefix}_${r}_${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 a(e)}}let o=a;class l{_total=0;_local_sign="";_expire="today";constructor(e){if(this.storage=o.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),r=s?.today??0;this.storage.setUserItem(this._local_sign,{total:e,today:r+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 l(e)}}let h={0:"launch_ad",1:"novel_plugin_strong_ad",2:"novel_plugin_unlock_btn",3:"novel_plugin_free_benefit_btn",4:"home_free_welfare_btn",5:"home_free_popup",6:"other",7:"home_back_show",8:"novel_plugin_free_time_btn",9:"launch_ad_alone"},c=Object.entries(h).reduce((e,[t,s])=>(e[s]=Number(t),e),{});class d{static instance=null;_initSign="";_halfway=[{scene:c.other,count:0}];_finished=[{scene:c.other,count:0}];constructor(e){if(d.instance)return d.instance;this._initSign=e?.sign??"",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:c.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:c.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 u=d;class _{static instance=null;_initSign="";_currScene=null;constructor(e){if(_.instance)return _.instance;this._initSign=e?.sign??"",_.instance=this}initialize(e){}addScene(e){return console.log("----------------------AD触发场景:--------------------",e),this._currScene=e,this}addSceneType(e=1){return this.addScene(h[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=_;class g{static instance=null;_initSign="";_needReport=!1;constructor(e){if(g.instance)return g.instance;this._initSign=e?.sign??"",this._needReport=e?.needReport??!1,this._userConfig=e?.userConfig??null,g.instance=this}initialize(e){return this._needReport?e:void console.warn("ExbAnalyticsJS needReport is false, do not report")}track(e,t,s){if(!this._needReport)return;if(!e)throw Error("eventName is required");let r=Object.assign({},this._getCommonUserInfo(),t),i=s?.sign??"track";console.log(`-------------${i}-----------------------:`,e,r),tt.reportAnalytics(e,r)}_getCommonUserInfo(){let{user_id:e,user_type:t,user_group:s}=this._userConfig??{};return{user_id:e,user_type:t,user_group:s}}identify(e){if(!e)throw Error("userInfo is required");if(!e.user_id)throw Error("user_id is required");return this._userConfig={user_id:e.user_id,user_type:e.user_type??0,user_group:e.user_group??0},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 g.instance||(g.instance=new g(e)),g.instance}static getInstance(){if(!g.instance)throw Error("ExbAnalyticsJS instance is not init");return g.instance}static new(e){return new g(e)}}let w=g;class p extends n{_onHalfway=null;_onShow=null;_onFinish=null;_onAlways=null;_onError=null;_initSign="";_alwaysCallback=null;_halfwayCallback=null;_finishedCallback=null;_resolve=null;_next=null;_scene=c.other;_adTimeout=null;_adTimeoutTime=8e3;_adBeforeShowTimer=null;_adBeforeShowTime=300;_adSpeedCloseTimer=null;_adSpeedCloseTime=5e3;_needEndOnTimeout=!0;_needSpeedEndOnTimeout=!1;bindAdCloseLister=this.adCloseLister.bind(this);bindAdErrorLister=this.adErrorLister.bind(this);bindAdLoadLister=this.adLoadLister.bind(this);bindApiAdErrorLister=this.apiAdErrorLister.bind(this);_bindShiftCloseLister=this._shiftCloseLister.bind(this);_bindShiftErrorLister=this._shiftErrorLister.bind(this);constructor(e){super(e),this._initSign=e?.sign??"",this._adConfig=e?.adConfig??{},this._needEndOnTimeout=e?.needEndOnTimeout??!0,this._onHalfway=e?.collection?.onHalfway??null,this._onShow=e?.collection?.onShow??null,this._onFinish=e?.collection?.onFinish??null,this._onAlways=e?.collection?.onAlways??null,this._onError=e?.collection?.onError??null}initialize(e,t){return super.initialize(e,t),this._initAdLister(),this._initNovelConfig(e),this}_initAdLister(){this.onClose(this.bindAdCloseLister),this.onError(this.bindAdErrorLister),this.onLoad(this.bindAdLoadLister),tt.onError(this.bindApiAdErrorLister)}_initNovelConfig(e){this.novelConfig=b.new({retry:e?.retry})}_onInnerExecuteBefore(){return null}_onInnerAdShowSuccess(){return null}_setAdTimeout(e){this._needSpeedEndOnTimeout&&(this._adSpeedCloseTimer=setTimeout(()=>{if("ios"==tt.getSystemInfoSync().platform){let t=()=>{tt.offAppShow(t),console.warn("[RewardAdNovel] ad_show_timeout: ios platform close ad onAppShow, handling fallback ad case, scene:",e?.scene);let s="ad_show_timeout: ios platform close ad onAppShow";w.getInstance().track("incentive_ad_show",{scene:e?.scene,result:0,msg:s}),this._adTimeout&&clearTimeout(this._adTimeout),e?.end({resolvedValue:{apiError:{errMsg:s}},nextValue:null})};tt.onAppShow(t)}clearTimeout(this._adSpeedCloseTimer)},this._adSpeedCloseTime)),this._needEndOnTimeout&&(this._adTimeout=setTimeout(()=>{console.warn("[RewardAdNovel] Ad show timeout, handling fallback ad case, scene:",e?.scene),w.getInstance().track("incentive_ad_show",{scene:e?.scene,result:0,msg:"ad_show_timeout: normal"}),e?.end({resolvedValue:{apiError:{errMsg:"ad_show_timeout: normal"}},nextValue:null})},this._adTimeoutTime))}_adPreludeInterval(e){e.prelude?.({scene:e?.scene,frequency:this._adBeforeShowTime,time:new Date().getTime()}),this._adBeforeShowTimer=setInterval(()=>{e.prelude?.({scene:e?.scene,frequency:this._adBeforeShowTime,time:new Date().getTime()})},this._adBeforeShowTime)}_clearAdTimeout(){this._adTimeout&&(clearTimeout(this._adTimeout),this._adTimeout=null),this._adBeforeShowTimer&&(clearTimeout(this._adBeforeShowTimer),this._adBeforeShowTimer=null),this._adSpeedCloseTimer&&(clearTimeout(this._adSpeedCloseTimer),this._adSpeedCloseTimer=null)}get rewardAd(){return this._rewardAd}addExecuteManager(e){return super.addExecuteManager(e)}ad(e,t=null){return this._alwaysCallback=e?.collection?.always,this._halfwayCallback=e?.collection?.halfway,this._finishedCallback=e?.collection?.finished,this._onInnerExecuteBefore(),new Promise(s=>{this._adInner({options:{scene:e?.options?.scene},collection:{resolve:s,before:e.collection?.before,success:e.collection?.success,prelude:e.collection?.prelude}},t)})}_adInner(e,t=null){let s=e?.collection?.resolve,r=e?.options?.scene??this._scene??c.other,i=e?.collection?.before,n=e?.collection?.success,a=e?.collection?.prelude,o=e=>{this._clearAdTimeout(),this.adDestroy(),s?.(Object.assign({scene:r},e?.resolvedValue)),t?.(Object.assign({scene:r},e?.nextValue))},l=()=>{this._scene=r,i?.({scene:r}),this._before=i,this._onShow?.({scene:r}),f.getInstance().addSceneType(r),this._resolve=s,this._next=t,this._setAdTimeout({scene:r,end:o}),this._adPreludeInterval({scene:r,prelude:a}),this.adShow().then(()=>{this._clearAdTimeout(),n?.({scene:r}),this._success=n,w.getInstance().track("incentive_ad_show",{scene:r,result:1}),this._onInnerAdShowSuccess()}).catch(e=>{var t,s;(this._clearAdTimeout(),w.getInstance().track("incentive_ad_show",{scene:r,result:0,msg:e?.errMsg}),t=this._ttErrorMsgs,(s=e?.errMsg)&&t.some(e=>RegExp(e,"i").test(s))||this._ttErrorCodes.includes(e?.errorCode))?o({scene:r,resolvedValue:{apiError:e},nextValue:null}):0>=this.novelConfig.remain()?o({scene:r,resolvedValue:null,nextValue:null}):(this.novelConfig.updateRetry(),this.adLoad().then(()=>{w.getInstance().track("incentive_ad_load",{scene:r,result:1}),l()}).catch(e=>{w.getInstance().track("incentive_ad_load",{scene:r,result:0}),o({scene:r,resolvedValue:{apiError:e},nextValue:null})}))})};l()}adLoad(){return this.load()}adShow(){return this.show()}_outerCloseCallback(e){this._alwaysCallback?.(e)}_outerHalfwayCallback(e){this._halfwayCallback?.(e)}_outerFinishedCallback(e){this._finishedCallback?.(e)}adCloseLister(e){this._clearAdTimeout(),u.getInstance().record({type:e.isEnded?"finished":"halfway",scene:this._scene}),w.getInstance().track("incentive_ad_close",{scene:this._scene,ad_is_completed:+!!e.isEnded,ad_count:e.count});let t={...e,scene:this._scene},s=t=>{this.adDestroy(),this._resolve?.(Object.assign({},e,{scene:this._scene},t)),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null};e?.isEnded?(this._outerFinishedCallback(t),this._onFinish?.(t)):(this._outerHalfwayCallback(t),this._onHalfway?.(t)),this._outerCloseCallback(t),this._onAlways?.(t),s({end_type:e.isEnded?"finished":"halfway"})}adErrorLister(e){this._clearAdTimeout(),console.error("[RewardAdNovel] adErrorLister",JSON.stringify(e)),this.adDestroy(),this._onError?.(e),this._resolve?.({apiError:e}),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null}apiAdErrorLister(e){this._clearAdTimeout(),console.error("[API RewardAdNovel] apiAdErrorLister:",JSON.stringify(e)),this.adDestroy(),this._onError?.(e),this._resolve?.({apiError:e}),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null}adLoadLister(e){w.getInstance().track("incentive_ad_load",{scene:this._scene,result:1}),console.info("[RewardAdNovel] adLoadLister:",JSON.stringify({scene:this._scene,info:e}))}adDestroy(){this.offClose(this.bindAdCloseLister),this.offError(this.bindAdErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this.destroy()}clear(){this._clearAdTimeout(),this.offClose(this.bindAdCloseLister),this.offClose(this._bindShiftCloseLister),this.offError(this.bindAdErrorLister),this.offError(this._bindShiftErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this.destroy(),this._resolve=null,this._next=null,this._success=null,this._before=null}_shiftCloseLister(e){this._clearAdTimeout(),this.offError(this._bindShiftErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this.offClose(this._bindShiftCloseLister),this.destroy(),this._resolve?.(Object.assign({},e,{scene:this._scene})),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null}_shiftErrorLister(e){this._clearAdTimeout(),this.offClose(this._bindShiftCloseLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this.offError(this._bindShiftErrorLister),this.destroy(),this._resolve?.(Object.assign({},e,{scene:this._scene})),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null}shift(){this.offClose(this.bindAdCloseLister),this.onClose(this._bindShiftCloseLister),this.offError(this.bindAdErrorLister),this.onError(this._bindShiftErrorLister)}static build(e){return p.instance||(p.instance=new p(e)),p.instance}static getInstance(){if(!p.instance)throw Error("RewardAdNovel instance is not init");return p.instance}static new(e){return new p(e)}}class b{frequency={total:0,current:0};constructor(e){this._init(e)}_init(e){this._adTimes(e)}_adTimes(e){this.frequency.total=e?.retry??4}reset(){this.frequency.current=0}updateRetry(){this.frequency.current=this.frequency.current+1}remain(){return this.frequency.total-this.frequency.current}static new(e){return new b(e)}}let m=p,y=s;export{s as AdExecuteManager,l as CountRecorder,w as ExbAnalyticsJS,e as Logger,n as RewardAdFather,u as RewardAdGlobalRecorder,m as RewardAdNovel,f as RewardAdSceneTriggerManager,r as SerializableError,o as Storage,y as default};
|
|
1
|
+
class e{constructor(e={}){let{prefix:t="Logger",level:s="info",enabled:r=!0}=e;this.prefix=t,this.enabled=r,this.levels={error:0,warn:1,info:2,debug:3},this.currentLevel=this.levels[s]||this.levels.info}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,r=`${s.getFullYear()}/${s.getMonth()+1}/${s.getDate()} ${s.getHours()}:${s.getMinutes()}:${s.getSeconds()}`;return`[${r}] [${e.toUpperCase()}] [${this.prefix}] ${t}`}_log(e,t,...s){if(!this.enabled)return;let r=this.levels[e];if(void 0!==r&&this.currentLevel>=r){let r=this.formatMessage(e,t);switch(e){case"error":console.error(r,...s);break;case"warn":console.warn(r,...s);break;case"info":console.info(r,...s);break;case"debug":console.debug(r,...s);break;default:console.log(r,...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)}debug(e,...t){this._log("debug",e,...t)}log(e,t,...s){this._log(e,t,...s)}}class t{static _instance=null;_taskStack=[];_currentBatchTasks=[];_isRunning=!1;_currentTask=null;constructor(s){if(this.logger=new e({prefix:"AdExecuteManager",enabled:!!s?.log}),t._instance)return t._instance;t._instance=this}static getInstance(e){return t._instance||(t._instance=new t(e)),t._instance}addTask(e,t){return e&&"function"==typeof e.ad?new Promise((s,r)=>{let i={adInstance:e,options:t.options??{},callbackCollection:t.collection??{},resolve:s,reject:r,id:`ad_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,_isResolved:!1,_isRejected:!1};this._taskStack.push(i),this._isRunning||this._compose()}):(this.logger.error("无效的广告实例 请正确实现.ad方法"),Promise.reject(Error("无效的广告实例")))}_compose(){if(0===this._taskStack.length){this._isRunning=!1,this._currentTask=null;return}this._isRunning=!0;let e=[...this._taskStack];this._taskStack=[],this._currentBatchTasks=e;let t=e.map(e=>async(t,s)=>{let{adInstance:r,options:i,callbackCollection:n,resolve:a,id:o}=e;if(e._isResolved||e._isRejected)return void await s(t);this._currentTask=e;try{let l=async e=>{await s(Object.assign({},t,e))},h=await r.initialize(i).ad({options:i,collection:n},l),c=Object.assign({id:o},h);this.logger.info(`任务执行成功,成功信息:${JSON.stringify(c)}`),e._isResolved=!0,a(c),r?.record(c)}catch(n){let i=Object.assign({id:o,apiError:n});this.logger.error(`任务执行失败, 继续下一个任务,错误信息:${JSON.stringify(i)}`),e._isRejected=!0;try{r?.clear()}catch(e){this.logger.error("clear error: ",JSON.stringify(Object.assign({id:o,apiError:e})))}a(i),r?.record(i),await s(t)}}),s={roundTasks:t.length};t.map(e=>(t,s)=>async r=>await e(Object.assign({},t,r),s)).reduce((e,t)=>(s,r)=>e(s,t(s,r)))(s,async e=>{this.logger.info("本轮活动队列已经清空",e),this._taskStack.length>0?Promise.resolve().then(()=>{this._compose()}):(this._isRunning=!1,this._currentTask=null,this._currentBatchTasks=[])})()}clearTasks(){if(this._currentTask){if(this._currentTask._isResolved||this._currentTask._isRejected){this._currentTask=null;return}try{this._currentTask.callbackCollection&&this._currentTask.callbackCollection.onCancel&&this._currentTask.callbackCollection.onCancel(),this._currentTask._isResolved=!0,this._currentTask.resolve()}catch(e){this.logger.error("clear current task error: ",e)}this._currentTask=null}this._currentBatchTasks.length>0&&(this._currentBatchTasks.forEach(e=>{if(e!==this._currentTask&&!e._isResolved&&!e._isRejected)try{e.callbackCollection&&e.callbackCollection.onCancel&&e.callbackCollection.onCancel(),e._isResolved=!0,e.resolve()}catch(e){this.logger.error("clear current batch task error: ",e)}}),this._currentBatchTasks=[]),this._taskStack.forEach(e=>{if(!e._isResolved&&!e._isRejected&&(e._isResolved=!0,e.resolve(),e.callbackCollection&&e.callbackCollection.onCancel))try{e.callbackCollection.onCancel()}catch(e){this.logger.error("clear task error: ",e)}}),this._taskStack=[],this._isRunning=!1}getTaskCount(){return this._taskStack.filter(e=>!e._isResolved&&!e._isRejected).length+this._currentBatchTasks.filter(e=>e!==this._currentTask&&!e._isResolved&&!e._isRejected).length+(!this._currentTask||this._currentTask._isResolved||this._currentTask._isRejected?0:1)}isRunning(){return this._isRunning}getCurrentTaskId(){return this._currentTask?.id||null}}let s=t;class r 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 i{static args=null;_initSign="";_preserveOnEnd=!1;_rewardAd=null;_ttErrorMsgs=["The adUnitId is closed","The adUnitId is prohibit","The adUnitId is invalid","The adUnitId is empty","feature is not supported in app"];_ttErrorCodes=[139902,123302];constructor(e){this._initSign=e?.sign??"",this._adConfig=e?.adConfig??{},this._preserveOnEnd=e?.preserveOnEnd??!1}initialize(e,t){if(this._rewardAd)return console.warn("RewardAdFather: rewardAd has been initialized"),t?.(this._rewardAd),this;let s=Object.assign({},i.args,this._adConfig,e);if(!s.adUnitId)throw console.error("[RewardAdFather] reward args adUnitId is required",s),new r("[RewardAdFather] reward args adUnitId is required");return this._rewardAd=tt.createRewardedVideoAd(s),t?.(this._rewardAd),this}initialized(){return!!this._rewardAd}async ad(e,t=null){throw Error("子类必须实现ad方法")}async addExecuteManager(e){let t=Object.assign({},this._adConfig,e?.options??{});return i.executeWithManager(this,Object.assign({},e,{options:t}))}destroy(){this._rewardAd&&!this._preserveOnEnd&&(this._rewardAd.destroy(),this._rewardAd=null)}clear(){throw Error("子类必须实现clear方法")}record(e){return this}onClose(e){this._rewardAd&&this._rewardAd.onClose(e)}offClose(e){this._rewardAd&&this._rewardAd.offClose(e)}show(){return this._rewardAd?this._rewardAd.show():Promise.reject({errMsg:"rewardAd is null"})}load(){if(this._rewardAd)return this._rewardAd.load()}onError(e){this._rewardAd&&this._rewardAd.onError(e)}offError(e){this._rewardAd&&this._rewardAd.offError(e)}onLoad(e){this._rewardAd&&this._rewardAd.onLoad(e)}offLoad(e){this._rewardAd&&this._rewardAd.offLoad(e)}placeholder(){return null}static buildArgs(e){e?.adUnitId||console.error("[RewardAdFather] RewardParams.adUnitId is required"),i.args=e}static async executeWithManager(e,t){return e&&e instanceof i?s.getInstance({log:t?.options?.log??!0}).addTask(e,t):(console.error("RewardAdFather: executeWithManager - 无效的广告实例"),Promise.reject(Error("无效的广告实例")))}}let n=i;class a{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 r=void 0!==s?s:this.config.expire;"today"===r&&(r=this.getTodayEndTimestamp()-Date.now());let i={value:t,expire:r,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 r=this.config.prefix+e;return this._setItem(r,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 r=this.config.userId??"null";if("null"===r)return void this.logger.error("userId is required");let i=`${this.config.prefix}_${r}_${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 a(e)}}let o=a;class l{_total=0;_local_sign="";_expire="today";constructor(e){if(this.storage=o.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),r=s?.today??0;this.storage.setUserItem(this._local_sign,{total:e,today:r+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 l(e)}}let h=Object.entries({9999:"inner_default_other"}).reduce((e,[t,s])=>(e[s]=Number(t),e),{});class c{static instance=null;_initSign="";_halfway=[{scene:h.inner_default_other,count:0}];_finished=[{scene:h.inner_default_other,count:0}];constructor(e){if(c.instance)return c.instance;this._initSign=e?.sign??"",this._halfway=[{scene:h.inner_default_other,count:0}],this._finished=[{scene:h.inner_default_other,count:0}],c.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:h.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:h.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 c.instance||(c.instance=new c(e)),c.instance}static getInstance(){if(!c.instance)throw Error("RewardAdGlobalRecorder instance is not init");return c.instance}}let d=c;class u{static instance=null;_initSign="";_currScene=null;_sceneTypeObj={};constructor(e){if(u.instance)return u.instance;this._initSign=e?.sign??"",this._sceneTypeObj=e?.sceneTypeObj??{},u.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 u.instance||(u.instance=new u(e)),u.instance}static getInstance(){if(!u.instance)throw Error("RewardAdSceneTriggerManager instance is not init");return u.instance}}let _=u;class f{static instance=null;_initSign="";_needReport=!1;constructor(e){if(f.instance)return f.instance;this._initSign=e?.sign??"",this._needReport=e?.needReport??!1,this._userConfig=e?.userConfig??null,f.instance=this}initialize(e){return this._needReport?e:void console.warn("ExbAnalyticsJS needReport is false, do not report")}track(e,t,s){if(!this._needReport)return;if(!e)throw Error("eventName is required");let r=Object.assign({},this._getCommonUserInfo(),t),i=s?.sign??"track";console.log(`-------------${i}-----------------------:`,e,r),tt.reportAnalytics(e,r)}_getCommonUserInfo(){let{user_id:e,user_type:t,user_group:s}=this._userConfig??{};return{user_id:e,user_type:t,user_group:s}}identify(e){if(!e)throw Error("userInfo is required");if(!e.user_id)throw Error("user_id is required");return this._userConfig={user_id:e.user_id,user_type:e.user_type??0,user_group:e.user_group??0},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 f.instance||(f.instance=new f(e)),f.instance}static getInstance(){if(!f.instance)throw Error("ExbAnalyticsJS instance is not init");return f.instance}static new(e){return new f(e)}}let g=f;class w extends n{_onHalfway=null;_onShow=null;_onFinish=null;_onAlways=null;_onError=null;_initSign="";_alwaysCallback=null;_halfwayCallback=null;_finishedCallback=null;_resolve=null;_next=null;_scene=h.inner_default_other;_adTimeout=null;_adTimeoutTime=8e3;_adBeforeShowTimer=null;_adBeforeShowTime=300;_adSpeedCloseTimer=null;_adSpeedCloseTime=5e3;_needEndOnTimeout=!0;_needSpeedEndOnTimeout=!1;bindAdCloseLister=this.adCloseLister.bind(this);bindAdErrorLister=this.adErrorLister.bind(this);bindAdLoadLister=this.adLoadLister.bind(this);bindApiAdErrorLister=this.apiAdErrorLister.bind(this);_bindShiftCloseLister=this._shiftCloseLister.bind(this);_bindShiftErrorLister=this._shiftErrorLister.bind(this);constructor(e){super(e),this._initSign=e?.sign??"",this._adConfig=e?.adConfig??{},this._needEndOnTimeout=e?.needEndOnTimeout??!0,this._onHalfway=e?.collection?.onHalfway??null,this._onShow=e?.collection?.onShow??null,this._onFinish=e?.collection?.onFinish??null,this._onAlways=e?.collection?.onAlways??null,this._onError=e?.collection?.onError??null}initialize(e,t){return super.initialize(e,t),this._initAdLister(),this._initNovelConfig(e),this}_initAdLister(){this.onClose(this.bindAdCloseLister),this.onError(this.bindAdErrorLister),this.onLoad(this.bindAdLoadLister),tt.onError(this.bindApiAdErrorLister)}_initNovelConfig(e){this.novelConfig=p.new({retry:e?.retry})}_onInnerExecuteBefore(){return null}_onInnerAdShowSuccess(){return null}_setAdTimeout(e){this._needSpeedEndOnTimeout&&(this._adSpeedCloseTimer=setTimeout(()=>{if("ios"==tt.getSystemInfoSync().platform){let t=()=>{tt.offAppShow(t),console.warn("[RewardAdNovel] ad_show_timeout: ios platform close ad onAppShow, handling fallback ad case, scene:",e?.scene);let s="ad_show_timeout: ios platform close ad onAppShow";g.getInstance().track("incentive_ad_show",{scene:e?.scene,result:0,msg:s}),this._adTimeout&&clearTimeout(this._adTimeout),e?.end({resolvedValue:{apiError:{errMsg:s}},nextValue:null})};tt.onAppShow(t)}clearTimeout(this._adSpeedCloseTimer)},this._adSpeedCloseTime)),this._needEndOnTimeout&&(this._adTimeout=setTimeout(()=>{console.warn("[RewardAdNovel] Ad show timeout, handling fallback ad case, scene:",e?.scene),g.getInstance().track("incentive_ad_show",{scene:e?.scene,result:0,msg:"ad_show_timeout: normal"}),e?.end({resolvedValue:{apiError:{errMsg:"ad_show_timeout: normal"}},nextValue:null})},this._adTimeoutTime))}_adPreludeInterval(e){e.prelude?.({scene:e?.scene,frequency:this._adBeforeShowTime,time:new Date().getTime()}),this._adBeforeShowTimer=setInterval(()=>{e.prelude?.({scene:e?.scene,frequency:this._adBeforeShowTime,time:new Date().getTime()})},this._adBeforeShowTime)}_clearAdTimeout(){this._adTimeout&&(clearTimeout(this._adTimeout),this._adTimeout=null),this._adBeforeShowTimer&&(clearTimeout(this._adBeforeShowTimer),this._adBeforeShowTimer=null),this._adSpeedCloseTimer&&(clearTimeout(this._adSpeedCloseTimer),this._adSpeedCloseTimer=null)}get rewardAd(){return this._rewardAd}addExecuteManager(e){return super.addExecuteManager(e)}ad(e,t=null){return this._alwaysCallback=e?.collection?.always,this._halfwayCallback=e?.collection?.halfway,this._finishedCallback=e?.collection?.finished,this._onInnerExecuteBefore(),new Promise(s=>{this._adInner({options:{scene:e?.options?.scene},collection:{resolve:s,before:e.collection?.before,success:e.collection?.success,prelude:e.collection?.prelude}},t)})}_adInner(e,t=null){let s=e?.collection?.resolve,r=e?.options?.scene??this._scene??h.inner_default_other,i=e?.collection?.before,n=e?.collection?.success,a=e?.collection?.prelude,o=e=>{this._clearAdTimeout(),this.adDestroy(),s?.(Object.assign({scene:r},e?.resolvedValue)),t?.(Object.assign({scene:r},e?.nextValue))},l=()=>{this._scene=r,i?.({scene:r}),this._before=i,this._onShow?.({scene:r}),_.getInstance().addSceneType(r),this._resolve=s,this._next=t,this._setAdTimeout({scene:r,end:o}),this._adPreludeInterval({scene:r,prelude:a}),this.adShow().then(()=>{this._clearAdTimeout(),n?.({scene:r}),this._success=n,g.getInstance().track("incentive_ad_show",{scene:r,result:1}),this._onInnerAdShowSuccess()}).catch(e=>{var t,s;(this._clearAdTimeout(),g.getInstance().track("incentive_ad_show",{scene:r,result:0,msg:e?.errMsg}),t=this._ttErrorMsgs,(s=e?.errMsg)&&t.some(e=>RegExp(e,"i").test(s))||this._ttErrorCodes.includes(e?.errorCode))?o({scene:r,resolvedValue:{apiError:e},nextValue:null}):0>=this.novelConfig.remain()?o({scene:r,resolvedValue:null,nextValue:null}):(this.novelConfig.updateRetry(),this.adLoad().then(()=>{g.getInstance().track("incentive_ad_load",{scene:r,result:1}),l()}).catch(e=>{g.getInstance().track("incentive_ad_load",{scene:r,result:0}),o({scene:r,resolvedValue:{apiError:e},nextValue:null})}))})};l()}adLoad(){return this.load()}adShow(){return this.show()}_outerCloseCallback(e){this._alwaysCallback?.(e)}_outerHalfwayCallback(e){this._halfwayCallback?.(e)}_outerFinishedCallback(e){this._finishedCallback?.(e)}adCloseLister(e){this._clearAdTimeout(),d.getInstance().record({type:e.isEnded?"finished":"halfway",scene:this._scene}),g.getInstance().track("incentive_ad_close",{scene:this._scene,ad_is_completed:+!!e.isEnded,ad_count:e.count});let t={...e,scene:this._scene},s=t=>{this.adDestroy(),this._resolve?.(Object.assign({},e,{scene:this._scene},t)),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null};e?.isEnded?(this._outerFinishedCallback(t),this._onFinish?.(t)):(this._outerHalfwayCallback(t),this._onHalfway?.(t)),this._outerCloseCallback(t),this._onAlways?.(t),s({end_type:e.isEnded?"finished":"halfway"})}adErrorLister(e){this._clearAdTimeout(),console.error("[RewardAdNovel] adErrorLister",JSON.stringify(e)),this.adDestroy(),this._onError?.(e),this._resolve?.({apiError:e}),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null}apiAdErrorLister(e){this._clearAdTimeout(),console.error("[API RewardAdNovel] apiAdErrorLister:",JSON.stringify(e)),this.adDestroy(),this._onError?.(e),this._resolve?.({apiError:e}),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null}adLoadLister(e){g.getInstance().track("incentive_ad_load",{scene:this._scene,result:1}),console.info("[RewardAdNovel] adLoadLister:",JSON.stringify({scene:this._scene,info:e}))}adDestroy(){this.offClose(this.bindAdCloseLister),this.offError(this.bindAdErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this.destroy()}clear(){this._clearAdTimeout(),this.offClose(this.bindAdCloseLister),this.offClose(this._bindShiftCloseLister),this.offError(this.bindAdErrorLister),this.offError(this._bindShiftErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this.destroy(),this._resolve=null,this._next=null,this._success=null,this._before=null}_shiftCloseLister(e){this._clearAdTimeout(),this.offError(this._bindShiftErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this.offClose(this._bindShiftCloseLister),this.destroy(),this._resolve?.(Object.assign({},e,{scene:this._scene})),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null}_shiftErrorLister(e){this._clearAdTimeout(),this.offClose(this._bindShiftCloseLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this.offError(this._bindShiftErrorLister),this.destroy(),this._resolve?.(Object.assign({},e,{scene:this._scene})),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null}shift(){this.offClose(this.bindAdCloseLister),this.onClose(this._bindShiftCloseLister),this.offError(this.bindAdErrorLister),this.onError(this._bindShiftErrorLister)}static build(e){return w.instance||(w.instance=new w(e)),w.instance}static getInstance(){if(!w.instance)throw Error("RewardAdNovel instance is not init");return w.instance}static new(e){return new w(e)}}class p{frequency={total:0,current:0};constructor(e){this._init(e)}_init(e){this._adTimes(e)}_adTimes(e){this.frequency.total=e?.retry??4}reset(){this.frequency.current=0}updateRetry(){this.frequency.current=this.frequency.current+1}remain(){return this.frequency.total-this.frequency.current}static new(e){return new p(e)}}let b=w,m=s;export{s as AdExecuteManager,l as CountRecorder,g as ExbAnalyticsJS,e as Logger,n as RewardAdFather,d as RewardAdGlobalRecorder,b as RewardAdNovel,_ as RewardAdSceneTriggerManager,r as SerializableError,o as Storage,m as default};
|
package/dist/typings/ad.d.ts
CHANGED
|
@@ -167,27 +167,18 @@ export type IConstructArgs = {
|
|
|
167
167
|
/**
|
|
168
168
|
* 广告场景类型映射对象
|
|
169
169
|
*/
|
|
170
|
-
export type
|
|
171
|
-
readonly
|
|
172
|
-
readonly 1: "novel_plugin_strong_ad";
|
|
173
|
-
readonly 2: "novel_plugin_unlock_btn";
|
|
174
|
-
readonly 3: "novel_plugin_free_benefit_btn";
|
|
175
|
-
readonly 4: "home_free_welfare_btn";
|
|
176
|
-
readonly 5: "home_free_popup";
|
|
177
|
-
readonly 6: "other";
|
|
178
|
-
readonly 7: "home_back_show";
|
|
179
|
-
readonly 8: "novel_plugin_free_time_btn";
|
|
180
|
-
readonly 9: "launch_ad_alone";
|
|
170
|
+
export type SceneTypeMap = {
|
|
171
|
+
readonly [number]: string;
|
|
181
172
|
};
|
|
182
173
|
/**
|
|
183
174
|
* 广告场景类型文本映射对象(反向映射)
|
|
184
175
|
*/
|
|
185
|
-
export type
|
|
176
|
+
export type SceneTextMap = { readonly [K in SceneTypeMap[keyof SceneTypeMap]]: { [P in keyof SceneTypeMap]: SceneTypeMap[P] extends K ? P : never; }[keyof SceneTypeMap]; };
|
|
186
177
|
/**
|
|
187
178
|
* 场景值枚举 可持续添加
|
|
188
179
|
*/
|
|
189
|
-
export type RewardAdTriggerScene = keyof
|
|
180
|
+
export type RewardAdTriggerScene = keyof SceneTextMap;
|
|
190
181
|
/**
|
|
191
182
|
* 场景值枚举 可持续添加
|
|
192
183
|
*/
|
|
193
|
-
export type RewardAdTriggerSceneType = keyof
|
|
184
|
+
export type RewardAdTriggerSceneType = keyof SceneTypeMap;
|
|
@@ -11,3 +11,9 @@ export function matchErrorWithKeywords(ttErrorMsgs: string[], keyword: any): boo
|
|
|
11
11
|
* @returns {number|null} 匹配项的值,默认showTimes
|
|
12
12
|
*/
|
|
13
13
|
export function findAdTypeBySceneFlag(strategyList: any, sceneFlag: string, type?: string): number | null;
|
|
14
|
+
/**
|
|
15
|
+
* 广告场景类型映射对象
|
|
16
|
+
* @param {import('../typings/ad.js').SceneTypeMap} scentTypeObj
|
|
17
|
+
* @returns {import('../typings/ad.js').SceneTextMap}
|
|
18
|
+
*/
|
|
19
|
+
export function getAdSceneTextObj(scentTypeObj: import("../typings/ad.js").SceneTypeMap): import("../typings/ad.js").SceneTextMap;
|