@ad-execute-manager/ad-reward 2.3.1 → 2.3.2

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.
@@ -0,0 +1,659 @@
1
+ export default RewardAdNovel;
2
+ export type IRewordAdConfig = import("./typings/ad.js").IRewordAdConfig;
3
+ export type IConstructArgs = import("./typings/ad.js").IConstructArgs;
4
+ export type ICloseArgs = {
5
+ /**
6
+ * 是否看完
7
+ */
8
+ isEnded: boolean;
9
+ /**
10
+ * 完整观看次数
11
+ */
12
+ count: number;
13
+ };
14
+ export type IRewardedVideoAd = {
15
+ /**
16
+ * 显示激励视频广告
17
+ */
18
+ show: () => Promise<void>;
19
+ };
20
+ /**
21
+ * @typedef {import('./typings/ad.js').IRewordAdConfig} IRewordAdConfig
22
+ */
23
+ /**
24
+ * @typedef {import('./typings/ad.js').IConstructArgs} IConstructArgs
25
+ */
26
+ /**
27
+ * @typedef ICloseArgs
28
+ * @property {boolean} isEnded 是否看完
29
+ * @property {number} count 完整观看次数
30
+ */
31
+ /**
32
+ * @typedef IRewardedVideoAd
33
+ * @property {() => Promise.<void>} show 显示激励视频广告
34
+ */
35
+ declare class RewardAdNovel extends RewardAdFather {
36
+ /**
37
+ *
38
+ * @param {IConstructArgs} args
39
+ * @returns {RewardAdNovel}
40
+ */
41
+ static build(args: IConstructArgs): RewardAdNovel;
42
+ /**
43
+ *
44
+ * @returns {RewardAdNovel}
45
+ */
46
+ static getInstance(): RewardAdNovel;
47
+ /**
48
+ *
49
+ * @param {IConstructArgs} args
50
+ * @returns {RewardAdNovel}
51
+ */
52
+ static "new"(args: IConstructArgs): RewardAdNovel;
53
+ /**
54
+ * @private 内部方法请勿使用,如需要请使用.onHalfway()替代
55
+ * @description 广告中途退出回调
56
+ * 初始化广告实例.new()中传入的参数args.collection.onHalfway回调
57
+ */
58
+ private _onHalfway;
59
+ /**
60
+ * @private 内部方法请勿使用,如需要请使用.onShow()替代
61
+ * @description 广告展示回调
62
+ * 初始化广告实例.new()中传入的参数args.collection.onShow回调
63
+ */
64
+ private _onShow;
65
+ /**
66
+ * @private 内部方法请勿使用,如需要请使用.onFinish()替代
67
+ * @description 广告执行成功回调
68
+ * 初始化广告实例.new()中传入的参数args.collection.onFinish回调
69
+ */
70
+ private _onFinish;
71
+ /**
72
+ * @private 内部方法请勿使用,如需要请使用.onAlways()替代
73
+ * @description 广告执行成功回调
74
+ * 初始化广告实例.new()中传入的参数args.collection.onAlways回调
75
+ */
76
+ private _onAlways;
77
+ /**
78
+ * @private 内部方法请勿使用,如需要请使用.onError()替代
79
+ * @description 广告执行失败回调
80
+ * 初始化广告实例.new()中传入的参数args.collection.onError回调
81
+ */
82
+ private _onError;
83
+ /** @private */
84
+ /** @type {Logger} */
85
+ _logger: Logger;
86
+ _alwaysCallback: any;
87
+ _halfwayCallback: any;
88
+ _finishedCallback: any;
89
+ _resolve: any;
90
+ _next: any;
91
+ /** @type {{options: import('./typings/ad.js').IAdOptions, collection: import('./typings/ad.js').CallbackCollection, recovered: import('./typings/ad.js').RecoveredInfo}} */
92
+ _adExecuteArgs: {
93
+ options: import("./typings/ad.js").IAdOptions;
94
+ collection: import("./typings/ad.js").CallbackCollection;
95
+ recovered: import("./typings/ad.js").RecoveredInfo;
96
+ };
97
+ /** @type {Function} */
98
+ _adNext: Function;
99
+ /** @type {number} 广告执行场景 */
100
+ _scene: number;
101
+ /** @type {string} 当前广告执行的唯一ID */
102
+ _eId: string;
103
+ _adTypeR: 1;
104
+ _adTimeout: any;
105
+ _adBeforeShowTimer: any;
106
+ _adBeforeShowTime: number;
107
+ _adSpeedCloseTimer: any;
108
+ _adSpeedCloseTime: number;
109
+ _needEndOnTimeout: boolean;
110
+ _lookUpRemainOnError: boolean;
111
+ /** @deprecated TODO 移除 */
112
+ _needSpeedEndOnTimeout: boolean;
113
+ /**
114
+ * @private
115
+ */
116
+ private bindAdCloseLister;
117
+ /**
118
+ * @private 内部方法请勿使用
119
+ */
120
+ private bindAdErrorLister;
121
+ /**
122
+ * @private 内部方法请勿使用
123
+ */
124
+ private bindAdLoadLister;
125
+ /**
126
+ * @private 内部方法请勿使用
127
+ */
128
+ private bindApiAdErrorLister;
129
+ /**
130
+ * @private 内部方法请勿使用
131
+ */
132
+ private _bindShiftCloseLister;
133
+ /**
134
+ * @private 内部方法请勿使用
135
+ */
136
+ private _bindShiftErrorLister;
137
+ /**
138
+ * @private 内部方法请勿使用
139
+ */
140
+ private bindAdTimeoutCloseLister;
141
+ /**
142
+ * @private 内部方法请勿使用
143
+ */
144
+ private bindAdTimeoutErrorLister;
145
+ /**
146
+ * 初始化
147
+ * 子类可以选择覆盖此方法,或使用默认实现
148
+ * @param {import('./typings/ad.js').IAdOptions} args
149
+ * @param {(v: IRewardedVideoAd) => void} [callback] 初始化成功回调
150
+ * @returns {this} 当前实例
151
+ */
152
+ initialize(args: import("./typings/ad.js").IAdOptions, callback?: (v: IRewardedVideoAd) => void): this;
153
+ _initAdLister(): void;
154
+ /**
155
+ * @param {object} args
156
+ * @param {number} [args.retry] 重试次数
157
+ */
158
+ _initNovelConfig(args: {
159
+ retry?: number;
160
+ }): void;
161
+ novelConfig: RewardAdNovelConfig;
162
+ _onInnerExecuteBefore(_args: any): any;
163
+ _onAdExecuteBefore(_args: any): any;
164
+ /**
165
+ * @param {object} _args
166
+ * @param {string} _args.scene 广告执行场景 必填
167
+ * @param {string} _args.eId 广告执行唯一ID 必填
168
+ * @param {number} [_args.result] 广告执行成功结果 必填
169
+ * @param {import('./typings/ad.js').RecoveredInfo} [_args.recovered] 恢复重试信息
170
+ * @returns
171
+ */
172
+ _onInnerAdShowSuccess(_args: {
173
+ scene: string;
174
+ eId: string;
175
+ result?: number;
176
+ recovered?: import("./typings/ad.js").RecoveredInfo;
177
+ }): any;
178
+ /**
179
+ * 子类可以选择覆盖此方法,或使用默认实现
180
+ * 视频展示中时 android会销毁成功,iOS会销毁失败
181
+ * @param {object} _args
182
+ * @param {string} _args.scene 广告执行场景 必填
183
+ * @param {string} _args.eId 广告执行唯一ID 必填
184
+ * @param {string} [_args.errMsg] 广告销毁失败原因
185
+ * @param {number} [_args.errorCode] 广告销毁失败错误码
186
+ * @returns
187
+ */
188
+ _onInnerAdDestroySuccess(_args: {
189
+ scene: string;
190
+ eId: string;
191
+ errMsg?: string;
192
+ errorCode?: number;
193
+ }): any;
194
+ /**
195
+ * 子类可以选择覆盖此方法,或使用默认实现
196
+ * @param {object} _args
197
+ * @param {string} _args.scene 广告执行场景 必填
198
+ * @param {string} _args.eId 广告执行唯一ID 必填
199
+ * @param {string} [_args.errMsg] 广告销毁失败原因
200
+ * @param {number} [_args.errorCode] 广告销毁失败错误码
201
+ * @returns
202
+ */
203
+ _onInnerAdDestroyFailed(_args: {
204
+ scene: string;
205
+ eId: string;
206
+ errMsg?: string;
207
+ errorCode?: number;
208
+ }): any;
209
+ /**
210
+ * @private
211
+ * 广告展示超时设置
212
+ * @param {object} args
213
+ * @param {string} args.scene 广告执行场景 必填
214
+ * @param {number} [args.timeout] 广告超时时间 单位ms
215
+ * @param {Function} args.end 结束当前广告任务的回调函数 必填
216
+ * @param {boolean} [args.preserved] 是否在超时情况下保留广告实例 - 自用参数,非tt API要求的参数
217
+ */
218
+ private _setAdTimeout;
219
+ /**
220
+ * @protected
221
+ * 广告展示超时设置
222
+ * @param {object} _args
223
+ * @param {string} _args.scene 广告执行场景 必填
224
+ * @param {number} [_args.timeout] 广告超时时间 单位ms
225
+ * @param {string} _args.eId 广告执行唯一ID 必填
226
+ * @param {Function} _args.end 结束当前广告任务的回调函数 必填
227
+ */
228
+ protected customExecuteAfterTimeout(_args: {
229
+ scene: string;
230
+ timeout?: number;
231
+ eId: string;
232
+ end: Function;
233
+ }): void;
234
+ /**
235
+ * 子类可以选择覆盖此方法
236
+ * 添加超时情况下结束任务前的回调
237
+ * @param {object} args
238
+ * @param {string} args.scene 广告执行场景 必填
239
+ * @param {number} args.timeout 广告超时时间 单位ms 必填
240
+ * @param {string} args.eId 广告执行唯一ID 必填
241
+ */
242
+ _adTimeoutBeforeEnd(args: {
243
+ scene: string;
244
+ timeout: number;
245
+ eId: string;
246
+ }): {
247
+ scene: string;
248
+ timeout: number;
249
+ eId: string;
250
+ };
251
+ /**
252
+ * 广告展示前定时器
253
+ * @param {object} args
254
+ * @param {string} args.scene 广告执行场景 必填
255
+ * @param {string} args.eId 广告执行唯一ID 必填
256
+ * @param {Function} args.prelude 广告展示前回调函数 可选
257
+ */
258
+ _adPreludeInterval(args: {
259
+ scene: string;
260
+ eId: string;
261
+ prelude: Function;
262
+ }): void;
263
+ _clearAdTimeout(): void;
264
+ /**
265
+ * 广告展示成功前分析
266
+ * 子类需要埋点可以选择覆盖此方法
267
+ * @protected
268
+ * @param {object} _args
269
+ * @param {string} _args.scene 广告执行场景 必填
270
+ * @param {string} _args.eId 广告执行唯一ID 必填
271
+ * @returns
272
+ */
273
+ protected _adShowBeforeAnalytics(_args: {
274
+ scene: string;
275
+ eId: string;
276
+ }): any;
277
+ /**
278
+ * 广告展示成功分析
279
+ * 子类需要埋点可以选择覆盖此方法
280
+ * @protected
281
+ * @param {object} _args
282
+ * @param {string} _args.scene 广告执行场景 必填
283
+ * @param {string} _args.eId 广告执行唯一ID 必填
284
+ * @param {string} [_args.msg] 广告执行成功原因
285
+ * @param {0|1} _args.result 广告执行成功结果 必填
286
+ * @param {import('./typings/ad.js').RecoveredInfo} [_args.recovered] 恢复重试信息
287
+ * @returns
288
+ */
289
+ protected _adShowSuccessAnalytics(_args: {
290
+ scene: string;
291
+ eId: string;
292
+ msg?: string;
293
+ result: 0 | 1;
294
+ recovered?: import("./typings/ad.js").RecoveredInfo;
295
+ }): any;
296
+ /**
297
+ * 广告展示失败分析
298
+ * 子类需要埋点可以选择覆盖此方法
299
+ * ATTENTION:该方法可能会调用两次,一次是show().catch(),一次是onError(),所以需要做好去重处理
300
+ * @protected
301
+ * @param {object} _args
302
+ * @param {string} _args.scene 广告执行场景 必填
303
+ * @param {string} _args.eId 广告执行唯一ID 必填
304
+ * @param {number} _args.poz 广告执行位置 必填
305
+ * @param {string} _args.msg 广告执行失败原因 必填
306
+ * @param {number} _args.errorCode 广告执行失败错误码 必填
307
+ * @param {0|1} _args.result 广告执行失败结果
308
+ * @returns
309
+ */
310
+ protected _adShowFailureAnalytics(_args: {
311
+ scene: string;
312
+ eId: string;
313
+ poz: number;
314
+ msg: string;
315
+ errorCode: number;
316
+ result: 0 | 1;
317
+ }): any;
318
+ /**
319
+ * 广告加载成功分析
320
+ * 子类需要埋点可以选择覆盖此方法
321
+ * @protected
322
+ * @param {object} _args
323
+ * @param {string} _args.scene 广告执行场景 必填
324
+ * @param {string} _args.eId 广告执行唯一ID 必填
325
+ * @param {string} [_args.msg] 广告执行成功原因
326
+ * @param {0|1} _args.result 广告执行成功结果 必填
327
+ * @param {object} [_args.frequency] 广告执行重试参数
328
+ * @param {number} _args.frequency.total 广告执行总次数 必填
329
+ * @param {number} _args.frequency.current 广告执行当前次数 必填
330
+ * @returns
331
+ */
332
+ protected _adLoadSuccessAnalytics(_args: {
333
+ scene: string;
334
+ eId: string;
335
+ msg?: string;
336
+ result: 0 | 1;
337
+ frequency?: {
338
+ total: number;
339
+ current: number;
340
+ };
341
+ }): any;
342
+ /**
343
+ * 广告加载失败分析
344
+ * 子类需要埋点可以选择覆盖此方法
345
+ * @protected
346
+ * @param {object} _args
347
+ * @param {string} _args.scene 广告执行场景 必填
348
+ * @param {string} _args.eId 广告执行唯一ID 必填
349
+ * @param {string} _args.msg 广告执行失败原因 必填
350
+ * @param {0|1} _args.result 广告执行失败结果
351
+ * @returns
352
+ */
353
+ protected _adLoadFailureAnalytics(_args: {
354
+ scene: string;
355
+ eId: string;
356
+ msg: string;
357
+ result: 0 | 1;
358
+ }): any;
359
+ /**
360
+ * 广告关闭成功分析
361
+ * 子类需要埋点可以选择覆盖此方法
362
+ * @protected
363
+ * @param {object} _args
364
+ * @param {string} _args.scene 广告执行场景 必填
365
+ * @param {string} _args.eId 广告执行唯一ID 必填
366
+ * @param {number} _args.ad_is_completed 广告是否完成 必填
367
+ * @param {number} _args.ad_count 广告执行次数 必填
368
+ * @returns
369
+ */
370
+ protected _adCloseSuccessAnalytics(_args: {
371
+ scene: string;
372
+ eId: string;
373
+ ad_is_completed: number;
374
+ ad_count: number;
375
+ }): any;
376
+ get rewardAd(): import("./typings/create-rewarded-video-ad.js").RewardedVideoAd;
377
+ /**
378
+ * @override
379
+ * @param {object} [ctx] 广告执行上下文
380
+ * @param {import('./typings/ad.js').IAdOptions} [ctx.options] 广告执行选项
381
+ * @param {import('./typings/ad.js').CallbackCollection} [ctx.collection] 回调集合
382
+ * @param {import('./typings/ad.js').RecoveredInfo} [ctx.recovered] 恢复重试信息
383
+ * @param {Function} next 执行下一个任务的回调函数,手动调用以继续执行流程
384
+ * @returns {Promise.<object | Undefined>}
385
+ */
386
+ override ad(ctx?: {
387
+ options?: import("./typings/ad.js").IAdOptions;
388
+ collection?: import("./typings/ad.js").CallbackCollection;
389
+ recovered?: import("./typings/ad.js").RecoveredInfo;
390
+ }, next?: Function): Promise<object | undefined>;
391
+ _recovered: import("./typings/ad.js").RecoveredInfo;
392
+ _preservedOnTimeout: boolean;
393
+ /**
394
+ * ATTENTION: 广告循环执行内部函数,如果需要循环执行,请使用adCircleInner()函数, 不要直接调用此函数
395
+ * @private
396
+ * @param {object} [ctx] 广告执行上下文
397
+ * @param {object} [ctx.options] 广告执行选项
398
+ * @param {number} [ctx.options.scene] 广告执行场景 必填
399
+ * @param {number} [ctx.options.timeout] 广告超时时间 单位ms
400
+ * @param {object} ctx.collection 回调集合
401
+ * @param {(v?: unknown) => void} ctx.collection.resolve 广告执行成功的回调函数
402
+ * @param {(v?: unknown) => void} [ctx.collection.before] 广告执行前的回调函数
403
+ * @param {(v?: unknown) => void} [ctx.collection.success] 广告执行成功的回调函数
404
+ * @param {(v?: unknown) => void} [ctx.collection.prelude] 拉起广告前计时的回调函数
405
+ * @param {import('./typings/ad.js').RecoveredInfo} [ctx.recovered] 恢复重试信息
406
+ * @param {Function} next 执行下一个任务的回调函数,手动调用以继续执行流程
407
+ */
408
+ private _adInner;
409
+ _before: (v?: unknown) => void;
410
+ _success: (v?: unknown) => void;
411
+ /**
412
+ * 广告循环执行
413
+ * @public
414
+ * @param {object} [ctx] 广告执行上下文
415
+ * @param {object} [ctx.options] 广告执行选项
416
+ * @param {number} [ctx.options.scene] 广告执行场景 必填
417
+ * @param {number} [ctx.options.timeout] 广告超时时间 单位ms
418
+ * @param {object} ctx.collection 回调集合
419
+ * @param {(v?: unknown) => void} [ctx.collection.before] 广告执行前的回调函数
420
+ * @param {(v?: unknown) => void} [ctx.collection.success] 广告执行成功的回调函数
421
+ * @param {(v?: unknown) => void} [ctx.collection.prelude] 拉起广告前计时的回调函数
422
+ */
423
+ public adCircleInner(ctx?: {
424
+ options?: {
425
+ scene?: number;
426
+ timeout?: number;
427
+ };
428
+ collection: {
429
+ before?: (v?: unknown) => void;
430
+ success?: (v?: unknown) => void;
431
+ prelude?: (v?: unknown) => void;
432
+ };
433
+ }): void;
434
+ /**
435
+ * 广告加载
436
+ * @returns
437
+ */
438
+ adLoad(): Promise<void>;
439
+ /**
440
+ * 广告展示
441
+ * @returns
442
+ */
443
+ adShow(): Promise<void>;
444
+ /**
445
+ * @deprecated - 1.x版本自v1.15.2已废弃,使用onExeAlways代替
446
+ * - 关闭广告时候调用的回调,不管是否看完视频都会调用
447
+ * - 调用adExecuteManager时collection.always回调
448
+ * @param {Array.<unknown>} args
449
+ */
450
+ _outerCloseCallback(...args: Array<unknown>): any;
451
+ /**
452
+ * - 关闭广告时候调用的回调 不管是否看完视频都会调用
453
+ * - 调用adExecuteManager时collection.always回调
454
+ * @param {Array.<unknown>} args
455
+ */
456
+ onExeAlways(...args: Array<unknown>): any;
457
+ /**
458
+ * @deprecated 1.x版本自v1.15.2已废弃,使用onExeHalfway代替
459
+ * - 广告未看完时候调用的回调
460
+ * - 调用adExecuteManager时collection.halfway回调
461
+ * @param {Array.<unknown>} args
462
+ */
463
+ _outerHalfwayCallback(...args: Array<unknown>): any;
464
+ /**
465
+ * - 广告未看完时候调用的回调
466
+ * - 调用adExecuteManager时collection.halfway回调
467
+ * @param {Array.<unknown>} args
468
+ */
469
+ onExeHalfway(...args: Array<unknown>): any;
470
+ /**
471
+ * @deprecated 1.x版本自v1.15.2已废弃,使用onExeFinished代替
472
+ * - 广告看完时候调用的回调
473
+ * - 调用adExecuteManager时collection.finished回调
474
+ * @param {Array.<unknown>} args
475
+ */
476
+ _outerFinishedCallback(...args: Array<unknown>): any;
477
+ /**
478
+ * - 广告看完时候调用的回调
479
+ * - 调用adExecuteManager时collection.finished回调
480
+ * @param {Array.<unknown>} args
481
+ */
482
+ onExeFinished(...args: Array<unknown>): any;
483
+ /**
484
+ * @description 广告中途退出回调
485
+ * 初始化广告实例.new()中传入的参数args.collection.onHalfway回调
486
+ * @param {Array.<unknown>} args
487
+ */
488
+ onFinish(...args: Array<unknown>): any;
489
+ /**
490
+ *
491
+ * @description 广告展示回调
492
+ * 初始化广告实例.new()中传入的参数args.collection.onShow回调
493
+ * @param {Array.<unknown>} args
494
+ */
495
+ onHalfway(...args: Array<unknown>): any;
496
+ /**
497
+ * @description 广告展示回调
498
+ * 初始化广告实例.new()中传入的参数args.collection.onAlways回调
499
+ * @param {Array.<unknown>} args
500
+ */
501
+ onAlways(...args: Array<unknown>): any;
502
+ /**
503
+ * 内部关闭激励视频
504
+ * @private
505
+ * @param {ICloseArgs} args
506
+ */
507
+ private __adTimeoutCloseLister__;
508
+ /**
509
+ * 子类可以选择覆盖此方法
510
+ * @param {*} args
511
+ * @returns
512
+ */
513
+ adTimeoutCloseLister(args: any): any;
514
+ /**
515
+ * 内部关闭激励视频
516
+ * @private
517
+ * @param {*} e
518
+ */
519
+ private __adTimeoutErrorLister__;
520
+ /**
521
+ * 子类可以选择覆盖此方法
522
+ * @param {*} e
523
+ * @returns
524
+ */
525
+ adTimeoutErrorLister(e: any): any;
526
+ /**
527
+ * 内部关闭激励视频
528
+ * @private
529
+ * @param {ICloseArgs} args
530
+ */
531
+ private __adCloseLister__;
532
+ /**
533
+ * 关闭激励视频
534
+ * 子类可重写该方法
535
+ * @protected
536
+ * @param {object} args
537
+ * @param {boolean} args.isEnded 广告是否完成
538
+ * @param {number} args.count 广告执行次数
539
+ * @param {string} args.scene 广告执行场景
540
+ * @param {number} args.adTypeR 广告类型
541
+ * @param {string} args.end_type 广告关闭类型
542
+ * @param {object} [connection] 广告关闭回调集合
543
+ * @param {(ctx: object) => void} [connection.conn] 调用外部传入的回调
544
+ * @param {(ctx: object) => void} [connection.end] 结束任务的回调
545
+ *
546
+ */
547
+ protected adCloseLister(args: {
548
+ isEnded: boolean;
549
+ count: number;
550
+ scene: string;
551
+ adTypeR: number;
552
+ end_type: string;
553
+ }, connection?: {
554
+ conn?: (ctx: object) => void;
555
+ end?: (ctx: object) => void;
556
+ }): void;
557
+ /**
558
+ * 激励视频广告组件**失败**时会触发
559
+ * @private
560
+ */
561
+ private __adErrorLister__;
562
+ /**
563
+ * 激励视频广告组件**失败**时会触发
564
+ * @protected
565
+ */
566
+ protected adErrorLister(e: any): any;
567
+ /**
568
+ * 激励视频广告组件api**失败**时会触发
569
+ * @private
570
+ */
571
+ private __apiAdErrorLister__;
572
+ /**
573
+ * 激励视频广告组件api**失败**时会触发
574
+ * @protected
575
+ */
576
+ protected apiAdErrorLister(e: any): any;
577
+ /**
578
+ * @private
579
+ * 激励视频广告组件**成功**拉取广告素材时会触发
580
+ * 创建激励时候后会自动拉取广告素材,如果广告拉取成功,也会触发此事件,不管是否调用show方法
581
+ * @param {unknown} e
582
+ */
583
+ private __adLoadLister__;
584
+ /**
585
+ * @protected
586
+ * 激励视频广告组件**成功**拉取广告素材时会触发
587
+ * 创建激励时候后会自动拉取广告素材,如果广告拉取成功,也会触发此事件,不管是否调用show方法
588
+ * @param {unknown} e
589
+ */
590
+ protected adLoadLister(e: unknown): unknown;
591
+ /**
592
+ * 销毁广告实例
593
+ * @private
594
+ * @param {object} [args] - 参数对象
595
+ * @param {boolean} [args.preserved] - 是否保留某些状态或数据的标志
596
+ */
597
+ private __novelDestroy__;
598
+ /**
599
+ * 销毁广告实例
600
+ * @protected
601
+ * @param {object} args 广告实例销毁参数
602
+ * @param {boolean} [args.preserved] 是否保留广告实例
603
+ */
604
+ protected adDestroy(args: {
605
+ preserved?: boolean;
606
+ }): void;
607
+ _shiftCloseLister(args: any): void;
608
+ _shiftErrorLister(args: any): void;
609
+ /**
610
+ * 手动出栈
611
+ */
612
+ shift(): void;
613
+ }
614
+ import RewardAdFather from './RewardAdFather.js';
615
+ import { Logger } from '../../logger/src/index.js';
616
+ declare class RewardAdNovelConfig {
617
+ /**
618
+ *
619
+ * @param {object} args
620
+ * @param {string} args.sign 初始化标识
621
+ * @param {number} [args.retry] 重试次数
622
+ * @returns {RewardAdNovelConfig}
623
+ */
624
+ static "new"(args: {
625
+ sign: string;
626
+ retry?: number;
627
+ }): RewardAdNovelConfig;
628
+ /**
629
+ *
630
+ * @param {object} [args]
631
+ * @param {number} [args.retry]
632
+ */
633
+ constructor(args?: {
634
+ retry?: number;
635
+ });
636
+ frequency: {
637
+ total: number;
638
+ current: number;
639
+ };
640
+ /**
641
+ *
642
+ * @param {object} [args]
643
+ * @param {number} [args.retry]
644
+ */
645
+ _init(args?: {
646
+ retry?: number;
647
+ }): void;
648
+ /**
649
+ *
650
+ * @param {object} [args]
651
+ * @param {number} [args.retry]
652
+ */
653
+ _adTimes(args?: {
654
+ retry?: number;
655
+ }): void;
656
+ reset(): void;
657
+ updateRetry(): void;
658
+ remain(): number;
659
+ }
@@ -298,6 +298,7 @@ declare class RewardAdNovel extends RewardAdFather {
298
298
  * @param {object} _args
299
299
  * @param {string} _args.scene 广告执行场景 必填
300
300
  * @param {string} _args.eId 广告执行唯一ID 必填
301
+ * @param {number} _args.poz 广告执行位置 必填
301
302
  * @param {string} _args.msg 广告执行失败原因 必填
302
303
  * @param {number} _args.errorCode 广告执行失败错误码 必填
303
304
  * @param {0|1} _args.result 广告执行失败结果
@@ -306,6 +307,7 @@ declare class RewardAdNovel extends RewardAdFather {
306
307
  protected _adShowFailureAnalytics(_args: {
307
308
  scene: string;
308
309
  eId: string;
310
+ poz: number;
309
311
  msg: string;
310
312
  errorCode: number;
311
313
  result: 0 | 1;
@@ -316,6 +318,7 @@ declare class RewardAdNovel extends RewardAdFather {
316
318
  * @protected
317
319
  * @param {object} _args
318
320
  * @param {string} _args.scene 广告执行场景 必填
321
+ * @param {string} _args.eId 广告执行唯一ID 必填
319
322
  * @param {string} [_args.msg] 广告执行成功原因
320
323
  * @param {0|1} _args.result 广告执行成功结果 必填
321
324
  * @param {object} [_args.frequency] 广告执行重试参数
@@ -325,6 +328,7 @@ declare class RewardAdNovel extends RewardAdFather {
325
328
  */
326
329
  protected _adLoadSuccessAnalytics(_args: {
327
330
  scene: string;
331
+ eId: string;
328
332
  msg?: string;
329
333
  result: 0 | 1;
330
334
  frequency?: {
@@ -338,12 +342,14 @@ declare class RewardAdNovel extends RewardAdFather {
338
342
  * @protected
339
343
  * @param {object} _args
340
344
  * @param {string} _args.scene 广告执行场景 必填
345
+ * @param {string} _args.eId 广告执行唯一ID 必填
341
346
  * @param {string} _args.msg 广告执行失败原因 必填
342
347
  * @param {0|1} _args.result 广告执行失败结果
343
348
  * @returns
344
349
  */
345
350
  protected _adLoadFailureAnalytics(_args: {
346
351
  scene: string;
352
+ eId: string;
347
353
  msg: string;
348
354
  result: 0 | 1;
349
355
  }): any;
@@ -581,19 +587,20 @@ declare class RewardAdNovel extends RewardAdFather {
581
587
  protected adLoadLister(e: unknown): unknown;
582
588
  /**
583
589
  * 销毁广告实例
584
- * @protected
585
- * @param {object} [args]
586
- * @param {boolean} [args.preserved] 是否保留广告实例
590
+ * @private
591
+ * @param {object} [args] - 参数对象
592
+ * @param {boolean} [args.preserved] - 是否保留某些状态或数据的标志
587
593
  */
588
- protected __novelDestroy__(args?: {
589
- preserved?: boolean;
590
- }): void;
594
+ private __novelDestroy__;
591
595
  /**
592
596
  * 销毁广告实例
593
597
  * @protected
594
- * @param {boolean} preserved 是否保留广告实例
598
+ * @param {object} args 广告实例销毁参数
599
+ * @param {boolean} [args.preserved] 是否保留广告实例
595
600
  */
596
- protected adDestroy(preserved?: boolean): void;
601
+ protected adDestroy(args: {
602
+ preserved?: boolean;
603
+ }): void;
597
604
  _shiftCloseLister(args: any): void;
598
605
  _shiftErrorLister(args: any): void;
599
606
  /**
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
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,r)=>{for(var t in r)__webpack_require__.o(r,t)&&!__webpack_require__.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},__webpack_require__.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),__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__,{AdExecuteManager:()=>core_namespaceObject.AdExecuteManager,RewardAdFather:()=>src_RewardAdFather,RewardAdNovel:()=>src_RewardAdNovel});const core_namespaceObject=require("@ad-execute-manager/core"),logger_namespaceObject=require("@ad-execute-manager/logger"),serializable_error_namespaceObject=require("@ad-execute-manager/serializable-error");class RewardAdFather{static args=null;_logger=null;_adTimeoutTime=8e3;_initSign="";_preserveOnEnd=!1;_rewardAd=null;__ad__=null;_ttErrorMsgs=["The adUnitId is closed","The adUnitId is prohibit","The adUnitId is invalid","The adUnitId is required","The adUnitId is empty","feature is not supported in app"];_ttErrorCodes=[139902,123302];__bindAdErrorForeverHandler=this.__adErrorForeverHandler.bind(this);constructor(e){this._logger=new logger_namespaceObject.Logger({prefix:"RewardAdFather",enabled:!!((null==e?void 0:e.log)??!0)}),this._initSign=(null==e?void 0:e.sign)??"",this._adConfig=(null==e?void 0:e.adConfig)??{},this._preserveOnEnd=(null==e?void 0:e.preserveOnEnd)??!1}initialize(e,r){if(this._rewardAd)return this._logger.warn("rewardAd has been initialized"),null==r||r(this._rewardAd),this;let t=Object.assign({},RewardAdFather.args,this._adConfig,e);if(!t.adUnitId)throw this._logger.error("reward args The adUnitId is required",t),new serializable_error_namespaceObject.SerializableError("[RewardAdFather] reward args The adUnitId is required",{errMsg:"The adUnitId is required",errorCode:100002});let i=tt.createRewardedVideoAd(t);return this._logger.info("bindAdErrorForeverHandler at initialized:",null==e?void 0:e.foreverErrorBind),(null==e?void 0:e.foreverErrorBind)&&(null==i||i.offError(this.__bindAdErrorForeverHandler),null==i||i.onError(this.__bindAdErrorForeverHandler)),this._rewardAd=i,this.__ad__=i,null==r||r(this._rewardAd),this}initialized(){return!!this._rewardAd}__adErrorForeverHandler(e){this.adErrorForeverHandler(e)}adErrorForeverHandler(e){return null}async ad(e,r=null){throw Error("子类必须实现ad方法")}async addExecuteManager(e){let r=Object.assign({},this._adConfig,(null==e?void 0:e.options)??{});return RewardAdFather.executeWithManager(this,Object.assign({},e,{options:r}))}destroy(e=!1){var r,t;return!this._rewardAd||this._preserveOnEnd||e?Promise.reject({errMsg:`can not destroy,ad is: ${!!this._rewardAd}, preserved: ${e}, preservedOnEnd: ${this._preserveOnEnd}`,errorCode:110003}):null==(t=this._rewardAd.destroy().then(e=>Promise.resolve(e)))||null==(r=t.catch(e=>Promise.reject({errMsg:`rewardAd destroy failed: ${JSON.stringify(e)}`,errorCode:110004})))?void 0:r.finally(()=>{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:"[RewardAdFather] can not show,rewardAd is null",errorCode:110001})}load(){return this._rewardAd?this._rewardAd.load():Promise.reject({errMsg:"[RewardAdFather] can not load,rewardAd is null",errorCode:110002})}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){(null==e?void 0:e.adUnitId)||new logger_namespaceObject.Logger({prefix:"RewardAdFather",enable:!0}).error("RewardParams.adUnitId is required"),RewardAdFather.args=e}static async executeWithManager(e,r){return e&&e instanceof RewardAdFather?core_namespaceObject.AdExecuteManager.getInstance().addTask(e,r):(new logger_namespaceObject.Logger({prefix:"RewardAdFather",enable:!0}).error("executeWithManager - 无效的广告实例"),Promise.reject(Error("无效的广告实例")))}}const src_RewardAdFather=RewardAdFather;function matchErrorWithKeywords(e,r){return!!r&&e.some(e=>RegExp(e,"i").test(r))}function getAdSceneTextObj(e){return Object.entries(e).reduce((e,[r,t])=>(e[t]=Number(r),e),{})}const DEFAULT_SCENT_TYPE_OBJ={9999:"inner_default_other"},DEFAULT_SCENT_TEXT_OBJ=getAdSceneTextObj(DEFAULT_SCENT_TYPE_OBJ),AD_TYPE_ENUM={AD_TYPE_REWARD:1,AD_TYPE_INTERSTITIAL:2},AD_TYPE_ENUM_REVERSE=Object.entries(AD_TYPE_ENUM).reduce((e,[r,t])=>(e[t]=r,e),{});class RewardAdNovel extends src_RewardAdFather{_onHalfway=null;_onShow=null;_onFinish=null;_onAlways=null;_onError=null;_logger=null;_initSign="";_alwaysCallback=null;_halfwayCallback=null;_finishedCallback=null;_resolve=null;_next=null;_adExecuteArgs=null;_adNext=null;_scene=DEFAULT_SCENT_TEXT_OBJ.inner_default_other;_eId=null;_adTypeR=AD_TYPE_ENUM.AD_TYPE_REWARD;_adTimeout=null;_adTimeoutTime=8e3;_adBeforeShowTimer=null;_adBeforeShowTime=300;_adSpeedCloseTimer=null;_adSpeedCloseTime=5e3;_needEndOnTimeout=!0;_lookUpRemainOnError=!1;_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);bindAdTimeoutCloseLister=this.__adTimeoutCloseLister__.bind(this);bindAdTimeoutErrorLister=this.__adTimeoutErrorLister__.bind(this);constructor(e){var r,t,i,l,s;super(e),this._logger=new logger_namespaceObject.Logger({prefix:"RewardAdNovel",enabled:!!((null==e?void 0:e.log)??!0)}),this._initSign=(null==e?void 0:e.sign)??"",this._adConfig=(null==e?void 0:e.adConfig)??{},this._needEndOnTimeout=(null==e?void 0:e.needEndOnTimeout)??!0,this._lookUpRemainOnError=(null==e?void 0:e.lookUpRemainOnError)??!1,this._onHalfway=(null==e||null==(r=e.collection)?void 0:r.onHalfway)??null,this._onShow=(null==e||null==(t=e.collection)?void 0:t.onShow)??null,this._onFinish=(null==e||null==(i=e.collection)?void 0:i.onFinish)??null,this._onAlways=(null==e||null==(l=e.collection)?void 0:l.onAlways)??null,this._onError=(null==e||null==(s=e.collection)?void 0:s.onError)??null}initialize(e,r){return super.initialize(e,r),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:null==e?void 0:e.retry})}_onInnerExecuteBefore(e){return null}_onAdExecuteBefore(e){return null}_onInnerAdShowSuccess(e){return null}_onInnerAdDestroySuccess(e){return null}_onInnerAdDestroyFailed(e){return null}_setAdTimeout(e){if(this._needSpeedEndOnTimeout&&(this._adSpeedCloseTimer=setTimeout(()=>{if("ios"==tt.getSystemInfoSync().platform){let r=()=>{tt.offAppShow(r),this._logger.warn("ad_show_timeout: ios platform close ad onAppShow, handling fallback ad case, scene:",null==e?void 0:e.scene);let t="ad_show_timeout: ios platform close ad onAppShow";this._adShowFailureAnalytics({scene:null==e?void 0:e.scene,eId:this._eId,msg:t,errorCode:1e5,result:0}),this._adTimeout&&clearTimeout(this._adTimeout),null==e||e.end({resolvedValue:{apiError:{errMsg:t,errorCode:1e5}},nextValue:null})};tt.onAppShow(r)}clearTimeout(this._adSpeedCloseTimer)},this._adSpeedCloseTime)),this._needEndOnTimeout){let r=(null==e?void 0:e.timeout)??this._adTimeoutTime;this._adTimeout=setTimeout(()=>{this._logger.warn("Ad show timeout, handling fallback ad case,",`scene: ${null==e?void 0:e.scene},timeout: ${r}, eId: ${this._eId}`),this._adShowFailureAnalytics({scene:null==e?void 0:e.scene,eId:this._eId,msg:"ad_show_timeout: normal",errorCode:1e5,result:0}),this._adTimeoutBeforeEnd({scene:null==e?void 0:e.scene,timeout:r,eId:this._eId}),this.onClose(this.bindAdTimeoutCloseLister),this.onError(this.bindAdTimeoutErrorLister);let t=()=>{null==e||e.end({preserved:null==e?void 0:e.preserved,resolvedValue:{eId:this._eId,apiError:{errMsg:`ad_show_timeout: normal, reward ad, timeout: ${r}`,errorCode:1e5,timeout:r}},nextValue:null})};try{this.customExecuteAfterTimeout({scene:null==e?void 0:e.scene,timeout:r,eId:this._eId,end:t})}catch(e){this._logger.warn(`${this._eId} use default timeout end task logic:`,e),t()}},r)}}customExecuteAfterTimeout(e){throw Error("customExecuteAfterTimeout not be implemented")}_adTimeoutBeforeEnd(e){return e}_adPreludeInterval(e){var r;null==(r=e.prelude)||r.call(e,{scene:null==e?void 0:e.scene,eId:this._eId,frequency:this._adBeforeShowTime,time:new Date().getTime()}),this._adBeforeShowTimer=setInterval(()=>{var r;null==(r=e.prelude)||r.call(e,{scene:null==e?void 0:e.scene,eId:this._eId,frequency:this._adBeforeShowTime,time:new Date().getTime()})},this._adBeforeShowTime)}_clearAdTimeout(){this._adTimeout&&(clearTimeout(this._adTimeout),this._adTimeout=null),this._adBeforeShowTimer&&(clearInterval(this._adBeforeShowTimer),this._adBeforeShowTimer=null),this._adSpeedCloseTimer&&(clearTimeout(this._adSpeedCloseTimer),this._adSpeedCloseTimer=null)}_adShowBeforeAnalytics(e){return null}_adShowSuccessAnalytics(e){return null}_adShowFailureAnalytics(e){return null}_adLoadSuccessAnalytics(e){return null}_adLoadFailureAnalytics(e){return null}_adCloseSuccessAnalytics(e){return null}get rewardAd(){return this._rewardAd}ad(e,r=null){var t,i,l,s;return this._alwaysCallback=null==e||null==(t=e.collection)?void 0:t.always,this._halfwayCallback=null==e||null==(i=e.collection)?void 0:i.halfway,this._finishedCallback=null==e||null==(l=e.collection)?void 0:l.finished,this._recovered=null==e?void 0:e.recovered,this._preservedOnTimeout=null==e||null==(s=e.options)?void 0:s.preservedOnTimeout,this._adExecuteArgs=e,this._adNext=r,this._onAdExecuteBefore({eId:this._eId}),new Promise(t=>{var i,l,s,n,o;this._resolve=t,this._adInner({options:{scene:null==e||null==(i=e.options)?void 0:i.scene,timeout:null==e||null==(l=e.options)?void 0:l.timeout},collection:{resolve:t,before:null==(s=e.collection)?void 0:s.before,success:null==(n=e.collection)?void 0:n.success,prelude:null==(o=e.collection)?void 0:o.prelude},recovered:e.recovered},r)})}_adInner(e,r=null){var t,i,l,s,n;this._eId=`ead_${Date.now()}_${Math.random().toString(36).slice(2,11)}`,this._onInnerExecuteBefore({eId:this._eId});let o=null==e||null==(t=e.collection)?void 0:t.resolve,d=(null==e||null==(i=e.options)?void 0:i.scene)??this._scene??DEFAULT_SCENT_TEXT_OBJ.inner_default_other,a=null==e||null==(l=e.collection)?void 0:l.before,_=null==e||null==(s=e.collection)?void 0:s.success,h=null==e||null==(n=e.collection)?void 0:n.prelude,u=(null==e?void 0:e.recovered)??this._recovered,c=e=>{this._clearAdTimeout(),this.adDestroy(null==e?void 0:e.preserved),null==o||o(Object.assign({scene:d,adTypeR:this._adTypeR,eId:this._eId},null==e?void 0:e.resolvedValue)),this._resolve=null,null==r||r(Object.assign({scene:d},null==e?void 0:e.nextValue)),this._next=null,this._adExecuteArgs=null,this._adNext=null},v=()=>{var t,i;this._scene=d,null==a||a({scene:d,eId:this._eId}),this._before=a,null==(t=this._onShow)||t.call(this,{scene:d,eId:this._eId}),this._adShowBeforeAnalytics({scene:d,eId:this._eId}),this._resolve=o,this._next=r,this._setAdTimeout({scene:d,end:c,timeout:null==e||null==(i=e.options)?void 0:i.timeout,preserved:this._preservedOnTimeout}),this._adPreludeInterval({scene:d,prelude:h,eId:this._eId}),this.adShow().then(()=>{this._clearAdTimeout(),null==_||_({scene:d,eId:this._eId}),this._success=_,this._adShowSuccessAnalytics({scene:d,eId:this._eId,result:1,recovered:u}),this._onInnerAdShowSuccess({scene:d,eId:this._eId,result:1,recovered:u})}).catch(e=>{(this._clearAdTimeout(),this._adShowFailureAnalytics({scene:d,eId:this._eId,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),matchErrorWithKeywords(this._ttErrorMsgs,null==e?void 0:e.errMsg)||this._ttErrorCodes.includes(null==e?void 0:e.errorCode))?c({scene:d,resolvedValue:{apiError:e},nextValue:null}):0>=this.novelConfig.remain()?c({scene:d,resolvedValue:{apiError:{errMsg:`[RewardAdNovel]: no remain, remain: ${this.novelConfig.remain()}, retry: ${this.novelConfig.frequency.total},
2
- tt: {errMsg: ${null==e?void 0:e.errMsg}, errorCode: ${null==e?void 0:e.errorCode}}`,errorCode:1e5}},nextValue:null}):(this.novelConfig.updateRetry(),this.adLoad().then(()=>{this._adLoadSuccessAnalytics({scene:d,result:1,frequency:this.novelConfig.frequency}),v()}).catch(e=>{this._adLoadFailureAnalytics({scene:d,msg:null==e?void 0:e.errMsg,result:0}),c({scene:d,resolvedValue:{apiError:e},nextValue:null})}))})};v()}adCircleInner(e){var r,t,i,l,s,n,o,d,a,_,h,u,c,v,f,A;let w={scene:(null==e||null==(r=e.options)?void 0:r.scene)??(null==(i=this._adExecuteArgs)||null==(t=i.options)?void 0:t.scene),timeout:(null==e||null==(l=e.options)?void 0:l.timeout)??(null==(n=this._adExecuteArgs)||null==(s=n.options)?void 0:s.timeout)},E={resolve:this._resolve,before:(null==e||null==(o=e.collection)?void 0:o.before)??(null==(a=this._adExecuteArgs)||null==(d=a.collection)?void 0:d.before),success:(null==e||null==(_=e.collection)?void 0:_.success)??(null==(u=this._adExecuteArgs)||null==(h=u.collection)?void 0:h.success),prelude:(null==e||null==(c=e.collection)?void 0:c.prelude)??(null==(f=this._adExecuteArgs)||null==(v=f.collection)?void 0:v.prelude)};this._adInner({options:w,collection:E,recovered:null==(A=this._adExecuteArgs)?void 0:A.recovered},this._adNext)}adLoad(){return this.load()}adShow(){return this.show()}_outerCloseCallback(...e){var r;return null==(r=this._alwaysCallback)?void 0:r.call(this,...e)}onExeAlways(...e){var r;return null==(r=this._alwaysCallback)?void 0:r.call(this,...e)}_outerHalfwayCallback(...e){var r;return null==(r=this._halfwayCallback)?void 0:r.call(this,...e)}onExeHalfway(...e){var r;return null==(r=this._halfwayCallback)?void 0:r.call(this,...e)}_outerFinishedCallback(...e){var r;return null==(r=this._finishedCallback)?void 0:r.call(this,...e)}onExeFinished(...e){var r;return null==(r=this._finishedCallback)?void 0:r.call(this,...e)}onFinish(...e){var r;return null==(r=this._onFinish)?void 0:r.call(this,...e)}onHalfway(...e){var r;return null==(r=this._onHalfway)?void 0:r.call(this,...e)}onAlways(...e){var r;return null==(r=this._onAlways)?void 0:r.call(this,...e)}__adTimeoutCloseLister__(e){let r=Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR,eId:this._eId});this._logger.warn("ad close lister that after task end because timeout:",r),this._clearAdTimeout(),this.offClose(this.bindAdTimeoutCloseLister),this.adTimeoutCloseLister(r)}adTimeoutCloseLister(e){return e}__adTimeoutErrorLister__(e){let r=Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR,eId:this._eId});this._logger.error("ad error lister that after task end because timeout:",r),this._clearAdTimeout(),this.offError(this.bindAdTimeoutErrorLister),this.adTimeoutErrorLister(r)}adTimeoutErrorLister(e){return e}__adCloseLister__(e){this._clearAdTimeout(),this._adCloseSuccessAnalytics({scene:this._scene,eId:this._eId,ad_is_completed:+!!e.isEnded,ad_count:e.count});let r=Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR,eId:this._eId,end_type:e.isEnded?"finished":"halfway"}),t=e=>{var t,i;this.adDestroy(),null==(t=this._resolve)||t.call(this,Object.assign({},r,e)),this._resolve=null,null==(i=this._next)||i.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null},i=e=>{var t,i,l;let s=Object.assign({},r,e);(null==s?void 0:s.isEnded)?(this._outerFinishedCallback(s),this.onExeFinished(s),null==(i=this._onFinish)||i.call(this,s),this.onFinish(s)):(this._outerHalfwayCallback(s),this.onExeHalfway(s),null==(l=this._onHalfway)||l.call(this,s),this.onHalfway(s)),this._outerCloseCallback(s),this.onExeAlways(s),null==(t=this._onAlways)||t.call(this,s),this.onAlways(s)};this.adCloseLister(r,{conn:i,end:t})}adCloseLister(e,r){var t,i;null==r||null==(t=r.conn)||t.call(r,e),null==r||null==(i=r.end)||i.call(r,e)}__adErrorLister__(e){this._clearAdTimeout(),this._logger.error("adErrorLister",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,eId:this._eId,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),this.adErrorLister(e);let r=()=>{var r,t,i;this.adDestroy(),null==(r=this._onError)||r.call(this,e),null==(t=this._resolve)||t.call(this,{apiError:e,scene:this._scene,adTypeR:this._adTypeR,eId:this._eId}),this._resolve=null,null==(i=this._next)||i.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null};(!this._lookUpRemainOnError||0>=this.novelConfig.remain())&&r()}adErrorLister(e){return e}__apiAdErrorLister__(e){var r,t,i;this._clearAdTimeout(),this._logger.error("API apiAdErrorLister:",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,eId:this._eId,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),this.apiAdErrorLister(e),this.adDestroy(),null==(r=this._onError)||r.call(this,e),null==(t=this._resolve)||t.call(this,{apiError:e,scene:this._scene,adTypeR:this._adTypeR}),this._resolve=null,null==(i=this._next)||i.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}apiAdErrorLister(e){return e}__adLoadLister__(e){this._adLoadSuccessAnalytics({scene:this._scene,result:1,msg:null==e?void 0:e.errMsg}),this._logger.info("adLoadLister:",JSON.stringify({scene:this._scene,info:e})),this.adLoadLister(e)}adLoadLister(e){return e}__novelDestroy__(e){this.destroy(null==e?void 0:e.preserved).then(e=>{var r;null==(r=this._onInnerAdDestroySuccess)||r.call(this,{scene:this._scene,eId:this._eId,errMsg:e})}).catch(e=>{var r;this._logger.warn("ad destroy failed:",JSON.stringify(e)),null==(r=this._onInnerAdDestroyFailed)||r.call(this,{scene:this._scene,eId:this._eId,errorCode:null==e?void 0:e.errorCode,errMsg:null==e?void 0:e.errMsg})})}adDestroy(e=!1){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._recovered=null,this._preservedOnTimeout=null,this.__novelDestroy__({preserved:e})}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._recovered=null,this._preservedOnTimeout=null,this.__novelDestroy__(),this._resolve=null,this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}_shiftCloseLister(e){var r,t;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._recovered=null,this._preservedOnTimeout=null,this.offClose(this._bindShiftCloseLister),this.__novelDestroy__(),null==(r=this._resolve)||r.call(this,Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR})),this._resolve=null,null==(t=this._next)||t.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}_shiftErrorLister(e){var r,t;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._recovered=null,this._preservedOnTimeout=null,this.offError(this._bindShiftErrorLister),this.__novelDestroy__(),null==(r=this._resolve)||r.call(this,Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR})),this._resolve=null,null==(t=this._next)||t.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=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=(null==e?void 0: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 src_RewardAdNovel=RewardAdNovel;for(var __rspack_i in exports.AdExecuteManager=__webpack_exports__.AdExecuteManager,exports.RewardAdFather=__webpack_exports__.RewardAdFather,exports.RewardAdNovel=__webpack_exports__.RewardAdNovel,__webpack_exports__)-1===["AdExecuteManager","RewardAdFather","RewardAdNovel"].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,r)=>{for(var t in r)__webpack_require__.o(r,t)&&!__webpack_require__.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},__webpack_require__.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),__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__,{AdExecuteManager:()=>core_namespaceObject.AdExecuteManager,RewardAdFather:()=>src_RewardAdFather,RewardAdNovel:()=>src_RewardAdNovel});const core_namespaceObject=require("@ad-execute-manager/core"),logger_namespaceObject=require("@ad-execute-manager/logger"),serializable_error_namespaceObject=require("@ad-execute-manager/serializable-error");class RewardAdFather{static args=null;_logger=null;_adTimeoutTime=8e3;_initSign="";_preserveOnEnd=!1;_rewardAd=null;__ad__=null;_ttErrorMsgs=["The adUnitId is closed","The adUnitId is prohibit","The adUnitId is invalid","The adUnitId is required","The adUnitId is empty","feature is not supported in app"];_ttErrorCodes=[139902,123302];__bindAdErrorForeverHandler=this.__adErrorForeverHandler.bind(this);constructor(e){this._logger=new logger_namespaceObject.Logger({prefix:"RewardAdFather",enabled:!!((null==e?void 0:e.log)??!0)}),this._initSign=(null==e?void 0:e.sign)??"",this._adConfig=(null==e?void 0:e.adConfig)??{},this._preserveOnEnd=(null==e?void 0:e.preserveOnEnd)??!1}initialize(e,r){if(this._rewardAd)return this._logger.warn("rewardAd has been initialized"),null==r||r(this._rewardAd),this;let t=Object.assign({},RewardAdFather.args,this._adConfig,e);if(!t.adUnitId)throw this._logger.error("reward args The adUnitId is required",t),new serializable_error_namespaceObject.SerializableError("[RewardAdFather] reward args The adUnitId is required",{errMsg:"The adUnitId is required",errorCode:100002});let i=tt.createRewardedVideoAd(t);return this._logger.info("bindAdErrorForeverHandler at initialized:",null==e?void 0:e.foreverErrorBind),(null==e?void 0:e.foreverErrorBind)&&(null==i||i.offError(this.__bindAdErrorForeverHandler),null==i||i.onError(this.__bindAdErrorForeverHandler)),this._rewardAd=i,this.__ad__=i,null==r||r(this._rewardAd),this}initialized(){return!!this._rewardAd}__adErrorForeverHandler(e){this.adErrorForeverHandler(e)}adErrorForeverHandler(e){return null}async ad(e,r=null){throw Error("子类必须实现ad方法")}async addExecuteManager(e){let r=Object.assign({},this._adConfig,(null==e?void 0:e.options)??{});return RewardAdFather.executeWithManager(this,Object.assign({},e,{options:r}))}destroy(e=!1){var r,t;return!this._rewardAd||this._preserveOnEnd||e?Promise.reject({errMsg:`can not destroy,ad is: ${!!this._rewardAd}, preserved: ${e}, preservedOnEnd: ${this._preserveOnEnd}`,errorCode:110003}):null==(t=this._rewardAd.destroy().then(e=>Promise.resolve(e)))||null==(r=t.catch(e=>Promise.reject({errMsg:`rewardAd destroy failed: ${JSON.stringify(e)}`,errorCode:110004})))?void 0:r.finally(()=>{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:"[RewardAdFather] can not show,rewardAd is null",errorCode:110001})}load(){return this._rewardAd?this._rewardAd.load():Promise.reject({errMsg:"[RewardAdFather] can not load,rewardAd is null",errorCode:110002})}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){(null==e?void 0:e.adUnitId)||new logger_namespaceObject.Logger({prefix:"RewardAdFather",enable:!0}).error("RewardParams.adUnitId is required"),RewardAdFather.args=e}static async executeWithManager(e,r){return e&&e instanceof RewardAdFather?core_namespaceObject.AdExecuteManager.getInstance().addTask(e,r):(new logger_namespaceObject.Logger({prefix:"RewardAdFather",enable:!0}).error("executeWithManager - 无效的广告实例"),Promise.reject(Error("无效的广告实例")))}}const src_RewardAdFather=RewardAdFather;function matchErrorWithKeywords(e,r){return!!r&&e.some(e=>RegExp(e,"i").test(r))}function getAdSceneTextObj(e){return Object.entries(e).reduce((e,[r,t])=>(e[t]=Number(r),e),{})}const DEFAULT_SCENT_TYPE_OBJ={9999:"inner_default_other"},DEFAULT_SCENT_TEXT_OBJ=getAdSceneTextObj(DEFAULT_SCENT_TYPE_OBJ),AD_TYPE_ENUM={AD_TYPE_REWARD:1,AD_TYPE_INTERSTITIAL:2},AD_TYPE_ENUM_REVERSE=Object.entries(AD_TYPE_ENUM).reduce((e,[r,t])=>(e[t]=r,e),{});class RewardAdNovel extends src_RewardAdFather{_onHalfway=null;_onShow=null;_onFinish=null;_onAlways=null;_onError=null;_logger=null;_initSign="";_alwaysCallback=null;_halfwayCallback=null;_finishedCallback=null;_resolve=null;_next=null;_adExecuteArgs=null;_adNext=null;_scene=DEFAULT_SCENT_TEXT_OBJ.inner_default_other;_eId=null;_adTypeR=AD_TYPE_ENUM.AD_TYPE_REWARD;_adTimeout=null;_adTimeoutTime=8e3;_adBeforeShowTimer=null;_adBeforeShowTime=300;_adSpeedCloseTimer=null;_adSpeedCloseTime=5e3;_needEndOnTimeout=!0;_lookUpRemainOnError=!1;_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);bindAdTimeoutCloseLister=this.__adTimeoutCloseLister__.bind(this);bindAdTimeoutErrorLister=this.__adTimeoutErrorLister__.bind(this);constructor(e){var r,t,i,l,s;super(e),this._logger=new logger_namespaceObject.Logger({prefix:"RewardAdNovel",enabled:!!((null==e?void 0:e.log)??!0)}),this._initSign=(null==e?void 0:e.sign)??"",this._adConfig=(null==e?void 0:e.adConfig)??{},this._needEndOnTimeout=(null==e?void 0:e.needEndOnTimeout)??!0,this._lookUpRemainOnError=(null==e?void 0:e.lookUpRemainOnError)??!1,this._onHalfway=(null==e||null==(r=e.collection)?void 0:r.onHalfway)??null,this._onShow=(null==e||null==(t=e.collection)?void 0:t.onShow)??null,this._onFinish=(null==e||null==(i=e.collection)?void 0:i.onFinish)??null,this._onAlways=(null==e||null==(l=e.collection)?void 0:l.onAlways)??null,this._onError=(null==e||null==(s=e.collection)?void 0:s.onError)??null}initialize(e,r){return super.initialize(e,r),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:null==e?void 0:e.retry})}_onInnerExecuteBefore(e){return null}_onAdExecuteBefore(e){return null}_onInnerAdShowSuccess(e){return null}_onInnerAdDestroySuccess(e){return null}_onInnerAdDestroyFailed(e){return null}_setAdTimeout(e){if(this._needSpeedEndOnTimeout&&(this._adSpeedCloseTimer=setTimeout(()=>{if("ios"==tt.getSystemInfoSync().platform){let r=()=>{tt.offAppShow(r),this._logger.warn("ad_show_timeout: ios platform close ad onAppShow, handling fallback ad case, scene:",null==e?void 0:e.scene);let t="ad_show_timeout: ios platform close ad onAppShow";this._adShowFailureAnalytics({scene:null==e?void 0:e.scene,eId:this._eId,poz:4,msg:t,errorCode:1e5,result:0}),this._adTimeout&&clearTimeout(this._adTimeout),null==e||e.end({resolvedValue:{apiError:{errMsg:t,errorCode:1e5}},nextValue:null})};tt.onAppShow(r)}clearTimeout(this._adSpeedCloseTimer)},this._adSpeedCloseTime)),this._needEndOnTimeout){let r=(null==e?void 0:e.timeout)??this._adTimeoutTime;this._adTimeout=setTimeout(()=>{this._logger.warn("Ad show timeout, handling fallback ad case,",`scene: ${null==e?void 0:e.scene},timeout: ${r}, eId: ${this._eId}`),this._adShowFailureAnalytics({scene:null==e?void 0:e.scene,eId:this._eId,poz:5,msg:"ad_show_timeout: normal",errorCode:1e5,result:0}),this._adTimeoutBeforeEnd({scene:null==e?void 0:e.scene,timeout:r,eId:this._eId}),this.onClose(this.bindAdTimeoutCloseLister),this.onError(this.bindAdTimeoutErrorLister);let t=()=>{null==e||e.end({preserved:null==e?void 0:e.preserved,resolvedValue:{eId:this._eId,apiError:{errMsg:`ad_show_timeout: normal, reward ad, timeout: ${r}`,errorCode:1e5,timeout:r}},nextValue:null})};try{this.customExecuteAfterTimeout({scene:null==e?void 0:e.scene,timeout:r,eId:this._eId,end:t})}catch(e){this._logger.warn(`${this._eId} use default timeout end task logic:`,e),t()}},r)}}customExecuteAfterTimeout(e){throw Error("customExecuteAfterTimeout not be implemented")}_adTimeoutBeforeEnd(e){return e}_adPreludeInterval(e){var r;null==(r=e.prelude)||r.call(e,{scene:null==e?void 0:e.scene,eId:this._eId,frequency:this._adBeforeShowTime,time:new Date().getTime()}),this._adBeforeShowTimer=setInterval(()=>{var r;null==(r=e.prelude)||r.call(e,{scene:null==e?void 0:e.scene,eId:this._eId,frequency:this._adBeforeShowTime,time:new Date().getTime()})},this._adBeforeShowTime)}_clearAdTimeout(){this._adTimeout&&(clearTimeout(this._adTimeout),this._adTimeout=null),this._adBeforeShowTimer&&(clearInterval(this._adBeforeShowTimer),this._adBeforeShowTimer=null),this._adSpeedCloseTimer&&(clearTimeout(this._adSpeedCloseTimer),this._adSpeedCloseTimer=null)}_adShowBeforeAnalytics(e){return null}_adShowSuccessAnalytics(e){return null}_adShowFailureAnalytics(e){return null}_adLoadSuccessAnalytics(e){return null}_adLoadFailureAnalytics(e){return null}_adCloseSuccessAnalytics(e){return null}get rewardAd(){return this._rewardAd}ad(e,r=null){var t,i,l,s;return this._alwaysCallback=null==e||null==(t=e.collection)?void 0:t.always,this._halfwayCallback=null==e||null==(i=e.collection)?void 0:i.halfway,this._finishedCallback=null==e||null==(l=e.collection)?void 0:l.finished,this._recovered=null==e?void 0:e.recovered,this._preservedOnTimeout=null==e||null==(s=e.options)?void 0:s.preservedOnTimeout,this._adExecuteArgs=e,this._adNext=r,this._onAdExecuteBefore({eId:this._eId}),new Promise(t=>{var i,l,s,n,o;this._resolve=t,this._adInner({options:{scene:null==e||null==(i=e.options)?void 0:i.scene,timeout:null==e||null==(l=e.options)?void 0:l.timeout},collection:{resolve:t,before:null==(s=e.collection)?void 0:s.before,success:null==(n=e.collection)?void 0:n.success,prelude:null==(o=e.collection)?void 0:o.prelude},recovered:e.recovered},r)})}_adInner(e,r=null){var t,i,l,s,n;this._eId=`ead_${Date.now()}_${Math.random().toString(36).slice(2,11)}`,this._onInnerExecuteBefore({eId:this._eId});let o=null==e||null==(t=e.collection)?void 0:t.resolve,d=(null==e||null==(i=e.options)?void 0:i.scene)??this._scene??DEFAULT_SCENT_TEXT_OBJ.inner_default_other,a=null==e||null==(l=e.collection)?void 0:l.before,_=null==e||null==(s=e.collection)?void 0:s.success,h=null==e||null==(n=e.collection)?void 0:n.prelude,u=(null==e?void 0:e.recovered)??this._recovered,c=e=>{this._clearAdTimeout(),this.adDestroy({preserved:null==e?void 0:e.preserved}),null==o||o(Object.assign({scene:d,adTypeR:this._adTypeR,eId:this._eId},null==e?void 0:e.resolvedValue)),this._resolve=null,null==r||r(Object.assign({scene:d},null==e?void 0:e.nextValue)),this._next=null,this._adExecuteArgs=null,this._adNext=null},v=()=>{var t,i;this._scene=d,null==a||a({scene:d,eId:this._eId}),this._before=a,null==(t=this._onShow)||t.call(this,{scene:d,eId:this._eId}),this._adShowBeforeAnalytics({scene:d,eId:this._eId}),this._resolve=o,this._next=r,this._setAdTimeout({scene:d,end:c,timeout:null==e||null==(i=e.options)?void 0:i.timeout,preserved:this._preservedOnTimeout}),this._adPreludeInterval({scene:d,prelude:h,eId:this._eId}),this.adShow().then(()=>{this._clearAdTimeout(),null==_||_({scene:d,eId:this._eId}),this._success=_,this._adShowSuccessAnalytics({scene:d,eId:this._eId,result:1,recovered:u}),this._onInnerAdShowSuccess({scene:d,eId:this._eId,result:1,recovered:u})}).catch(e=>{(this._clearAdTimeout(),this._adShowFailureAnalytics({scene:d,eId:this._eId,poz:1,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),matchErrorWithKeywords(this._ttErrorMsgs,null==e?void 0:e.errMsg)||this._ttErrorCodes.includes(null==e?void 0:e.errorCode))?c({scene:d,resolvedValue:{apiError:e},nextValue:null}):0>=this.novelConfig.remain()?c({scene:d,resolvedValue:{apiError:{errMsg:`[RewardAdNovel]: no remain, remain: ${this.novelConfig.remain()}, retry: ${this.novelConfig.frequency.total},
2
+ tt: {errMsg: ${null==e?void 0:e.errMsg}, errorCode: ${null==e?void 0:e.errorCode}}`,errorCode:1e5}},nextValue:null}):(this.novelConfig.updateRetry(),this.adLoad().then(()=>{this._adLoadSuccessAnalytics({scene:d,eId:this._eId,result:1,frequency:this.novelConfig.frequency}),v()}).catch(e=>{this._adLoadFailureAnalytics({scene:d,eId:this._eId,msg:null==e?void 0:e.errMsg,result:0}),c({scene:d,resolvedValue:{apiError:e},nextValue:null})}))})};v()}adCircleInner(e){var r,t,i,l,s,n,o,d,a,_,h,u,c,v,f,A;let w={scene:(null==e||null==(r=e.options)?void 0:r.scene)??(null==(i=this._adExecuteArgs)||null==(t=i.options)?void 0:t.scene),timeout:(null==e||null==(l=e.options)?void 0:l.timeout)??(null==(n=this._adExecuteArgs)||null==(s=n.options)?void 0:s.timeout)},E={resolve:this._resolve,before:(null==e||null==(o=e.collection)?void 0:o.before)??(null==(a=this._adExecuteArgs)||null==(d=a.collection)?void 0:d.before),success:(null==e||null==(_=e.collection)?void 0:_.success)??(null==(u=this._adExecuteArgs)||null==(h=u.collection)?void 0:h.success),prelude:(null==e||null==(c=e.collection)?void 0:c.prelude)??(null==(f=this._adExecuteArgs)||null==(v=f.collection)?void 0:v.prelude)};this._adInner({options:w,collection:E,recovered:null==(A=this._adExecuteArgs)?void 0:A.recovered},this._adNext)}adLoad(){return this.load()}adShow(){return this.show()}_outerCloseCallback(...e){var r;return null==(r=this._alwaysCallback)?void 0:r.call(this,...e)}onExeAlways(...e){var r;return null==(r=this._alwaysCallback)?void 0:r.call(this,...e)}_outerHalfwayCallback(...e){var r;return null==(r=this._halfwayCallback)?void 0:r.call(this,...e)}onExeHalfway(...e){var r;return null==(r=this._halfwayCallback)?void 0:r.call(this,...e)}_outerFinishedCallback(...e){var r;return null==(r=this._finishedCallback)?void 0:r.call(this,...e)}onExeFinished(...e){var r;return null==(r=this._finishedCallback)?void 0:r.call(this,...e)}onFinish(...e){var r;return null==(r=this._onFinish)?void 0:r.call(this,...e)}onHalfway(...e){var r;return null==(r=this._onHalfway)?void 0:r.call(this,...e)}onAlways(...e){var r;return null==(r=this._onAlways)?void 0:r.call(this,...e)}__adTimeoutCloseLister__(e){let r=Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR,eId:this._eId});this._logger.warn("ad close lister that after ad end because timeout:",r),this._clearAdTimeout(),this.offClose(this.bindAdTimeoutCloseLister),this.adTimeoutCloseLister(r)}adTimeoutCloseLister(e){return e}__adTimeoutErrorLister__(e){let r=Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR,eId:this._eId});this._logger.error("ad error lister that after task end because timeout:",r),this._clearAdTimeout(),this.offError(this.bindAdTimeoutErrorLister),this.adTimeoutErrorLister(r)}adTimeoutErrorLister(e){return e}__adCloseLister__(e){this._clearAdTimeout(),this._adCloseSuccessAnalytics({scene:this._scene,eId:this._eId,ad_is_completed:+!!e.isEnded,ad_count:e.count});let r=Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR,eId:this._eId,end_type:e.isEnded?"finished":"halfway"}),t=e=>{var t,i;this.adDestroy(),null==(t=this._resolve)||t.call(this,Object.assign({},r,e)),this._resolve=null,null==(i=this._next)||i.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null},i=e=>{var t,i,l;let s=Object.assign({},r,e);(null==s?void 0:s.isEnded)?(this._outerFinishedCallback(s),this.onExeFinished(s),null==(i=this._onFinish)||i.call(this,s),this.onFinish(s)):(this._outerHalfwayCallback(s),this.onExeHalfway(s),null==(l=this._onHalfway)||l.call(this,s),this.onHalfway(s)),this._outerCloseCallback(s),this.onExeAlways(s),null==(t=this._onAlways)||t.call(this,s),this.onAlways(s)};this.adCloseLister(r,{conn:i,end:t})}adCloseLister(e,r){var t,i;null==r||null==(t=r.conn)||t.call(r,e),null==r||null==(i=r.end)||i.call(r,e)}__adErrorLister__(e){this._clearAdTimeout(),this._logger.error("adErrorLister",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,eId:this._eId,poz:2,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),this.adErrorLister(e);let r=()=>{var r,t,i;this.adDestroy(),null==(r=this._onError)||r.call(this,e),null==(t=this._resolve)||t.call(this,{apiError:e,scene:this._scene,adTypeR:this._adTypeR,eId:this._eId}),this._resolve=null,null==(i=this._next)||i.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null};(!this._lookUpRemainOnError||0>=this.novelConfig.remain())&&r()}adErrorLister(e){return e}__apiAdErrorLister__(e){var r,t,i;this._clearAdTimeout(),this._logger.error("API apiAdErrorLister:",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,eId:this._eId,poz:3,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),this.apiAdErrorLister(e),this.adDestroy(),null==(r=this._onError)||r.call(this,e),null==(t=this._resolve)||t.call(this,{apiError:e,scene:this._scene,adTypeR:this._adTypeR}),this._resolve=null,null==(i=this._next)||i.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}apiAdErrorLister(e){return e}__adLoadLister__(e){this._adLoadSuccessAnalytics({scene:this._scene,eId:this._eId,result:1,msg:null==e?void 0:e.errMsg}),this._logger.info("adLoadLister:",JSON.stringify({scene:this._scene,info:e})),this.adLoadLister(e)}adLoadLister(e){return e}__novelDestroy__(e){this.destroy(null==e?void 0:e.preserved).then(e=>{var r;null==(r=this._onInnerAdDestroySuccess)||r.call(this,{scene:this._scene,eId:this._eId,errMsg:e})}).catch(e=>{var r;this._logger.warn("ad destroy failed:",JSON.stringify(e)),null==(r=this._onInnerAdDestroyFailed)||r.call(this,{scene:this._scene,eId:this._eId,errorCode:null==e?void 0:e.errorCode,errMsg:null==e?void 0:e.errMsg})})}adDestroy(e){let r=(null==e?void 0:e.preserved)??!1;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._recovered=null,this._preservedOnTimeout=null,this.__novelDestroy__({preserved:r})}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._recovered=null,this._preservedOnTimeout=null,this.__novelDestroy__(),this._resolve=null,this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}_shiftCloseLister(e){var r,t;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._recovered=null,this._preservedOnTimeout=null,this.offClose(this._bindShiftCloseLister),this.__novelDestroy__(),null==(r=this._resolve)||r.call(this,Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR})),this._resolve=null,null==(t=this._next)||t.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}_shiftErrorLister(e){var r,t;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._recovered=null,this._preservedOnTimeout=null,this.offError(this._bindShiftErrorLister),this.__novelDestroy__(),null==(r=this._resolve)||r.call(this,Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR})),this._resolve=null,null==(t=this._next)||t.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=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=(null==e?void 0: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 src_RewardAdNovel=RewardAdNovel;for(var __rspack_i in exports.AdExecuteManager=__webpack_exports__.AdExecuteManager,exports.RewardAdFather=__webpack_exports__.RewardAdFather,exports.RewardAdNovel=__webpack_exports__.RewardAdNovel,__webpack_exports__)-1===["AdExecuteManager","RewardAdFather","RewardAdNovel"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{AdExecuteManager as e}from"@ad-execute-manager/core";import{Logger as r}from"@ad-execute-manager/logger";import{SerializableError as i}from"@ad-execute-manager/serializable-error";class t{static args=null;_logger=null;_adTimeoutTime=8e3;_initSign="";_preserveOnEnd=!1;_rewardAd=null;__ad__=null;_ttErrorMsgs=["The adUnitId is closed","The adUnitId is prohibit","The adUnitId is invalid","The adUnitId is required","The adUnitId is empty","feature is not supported in app"];_ttErrorCodes=[139902,123302];__bindAdErrorForeverHandler=this.__adErrorForeverHandler.bind(this);constructor(e){this._logger=new r({prefix:"RewardAdFather",enabled:!!((null==e?void 0:e.log)??!0)}),this._initSign=(null==e?void 0:e.sign)??"",this._adConfig=(null==e?void 0:e.adConfig)??{},this._preserveOnEnd=(null==e?void 0:e.preserveOnEnd)??!1}initialize(e,r){if(this._rewardAd)return this._logger.warn("rewardAd has been initialized"),null==r||r(this._rewardAd),this;let l=Object.assign({},t.args,this._adConfig,e);if(!l.adUnitId)throw this._logger.error("reward args The adUnitId is required",l),new i("[RewardAdFather] reward args The adUnitId is required",{errMsg:"The adUnitId is required",errorCode:100002});let s=tt.createRewardedVideoAd(l);return this._logger.info("bindAdErrorForeverHandler at initialized:",null==e?void 0:e.foreverErrorBind),(null==e?void 0:e.foreverErrorBind)&&(null==s||s.offError(this.__bindAdErrorForeverHandler),null==s||s.onError(this.__bindAdErrorForeverHandler)),this._rewardAd=s,this.__ad__=s,null==r||r(this._rewardAd),this}initialized(){return!!this._rewardAd}__adErrorForeverHandler(e){this.adErrorForeverHandler(e)}adErrorForeverHandler(e){return null}async ad(e,r=null){throw Error("子类必须实现ad方法")}async addExecuteManager(e){let r=Object.assign({},this._adConfig,(null==e?void 0:e.options)??{});return t.executeWithManager(this,Object.assign({},e,{options:r}))}destroy(e=!1){var r,i;return!this._rewardAd||this._preserveOnEnd||e?Promise.reject({errMsg:`can not destroy,ad is: ${!!this._rewardAd}, preserved: ${e}, preservedOnEnd: ${this._preserveOnEnd}`,errorCode:110003}):null==(i=this._rewardAd.destroy().then(e=>Promise.resolve(e)))||null==(r=i.catch(e=>Promise.reject({errMsg:`rewardAd destroy failed: ${JSON.stringify(e)}`,errorCode:110004})))?void 0:r.finally(()=>{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:"[RewardAdFather] can not show,rewardAd is null",errorCode:110001})}load(){return this._rewardAd?this._rewardAd.load():Promise.reject({errMsg:"[RewardAdFather] can not load,rewardAd is null",errorCode:110002})}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){(null==e?void 0:e.adUnitId)||new r({prefix:"RewardAdFather",enable:!0}).error("RewardParams.adUnitId is required"),t.args=e}static async executeWithManager(i,l){return i&&i instanceof t?e.getInstance().addTask(i,l):(new r({prefix:"RewardAdFather",enable:!0}).error("executeWithManager - 无效的广告实例"),Promise.reject(Error("无效的广告实例")))}}let l=t,s=Object.entries({9999:"inner_default_other"}).reduce((e,[r,i])=>(e[i]=Number(r),e),{}),n={AD_TYPE_REWARD:1,AD_TYPE_INTERSTITIAL:2};Object.entries(n).reduce((e,[r,i])=>(e[i]=r,e),{});class o extends l{_onHalfway=null;_onShow=null;_onFinish=null;_onAlways=null;_onError=null;_logger=null;_initSign="";_alwaysCallback=null;_halfwayCallback=null;_finishedCallback=null;_resolve=null;_next=null;_adExecuteArgs=null;_adNext=null;_scene=s.inner_default_other;_eId=null;_adTypeR=n.AD_TYPE_REWARD;_adTimeout=null;_adTimeoutTime=8e3;_adBeforeShowTimer=null;_adBeforeShowTime=300;_adSpeedCloseTimer=null;_adSpeedCloseTime=5e3;_needEndOnTimeout=!0;_lookUpRemainOnError=!1;_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);bindAdTimeoutCloseLister=this.__adTimeoutCloseLister__.bind(this);bindAdTimeoutErrorLister=this.__adTimeoutErrorLister__.bind(this);constructor(e){var i,t,l,s,n;super(e),this._logger=new r({prefix:"RewardAdNovel",enabled:!!((null==e?void 0:e.log)??!0)}),this._initSign=(null==e?void 0:e.sign)??"",this._adConfig=(null==e?void 0:e.adConfig)??{},this._needEndOnTimeout=(null==e?void 0:e.needEndOnTimeout)??!0,this._lookUpRemainOnError=(null==e?void 0:e.lookUpRemainOnError)??!1,this._onHalfway=(null==e||null==(i=e.collection)?void 0:i.onHalfway)??null,this._onShow=(null==e||null==(t=e.collection)?void 0:t.onShow)??null,this._onFinish=(null==e||null==(l=e.collection)?void 0:l.onFinish)??null,this._onAlways=(null==e||null==(s=e.collection)?void 0:s.onAlways)??null,this._onError=(null==e||null==(n=e.collection)?void 0:n.onError)??null}initialize(e,r){return super.initialize(e,r),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=d.new({retry:null==e?void 0:e.retry})}_onInnerExecuteBefore(e){return null}_onAdExecuteBefore(e){return null}_onInnerAdShowSuccess(e){return null}_onInnerAdDestroySuccess(e){return null}_onInnerAdDestroyFailed(e){return null}_setAdTimeout(e){if(this._needSpeedEndOnTimeout&&(this._adSpeedCloseTimer=setTimeout(()=>{if("ios"==tt.getSystemInfoSync().platform){let r=()=>{tt.offAppShow(r),this._logger.warn("ad_show_timeout: ios platform close ad onAppShow, handling fallback ad case, scene:",null==e?void 0:e.scene);let i="ad_show_timeout: ios platform close ad onAppShow";this._adShowFailureAnalytics({scene:null==e?void 0:e.scene,eId:this._eId,msg:i,errorCode:1e5,result:0}),this._adTimeout&&clearTimeout(this._adTimeout),null==e||e.end({resolvedValue:{apiError:{errMsg:i,errorCode:1e5}},nextValue:null})};tt.onAppShow(r)}clearTimeout(this._adSpeedCloseTimer)},this._adSpeedCloseTime)),this._needEndOnTimeout){let r=(null==e?void 0:e.timeout)??this._adTimeoutTime;this._adTimeout=setTimeout(()=>{this._logger.warn("Ad show timeout, handling fallback ad case,",`scene: ${null==e?void 0:e.scene},timeout: ${r}, eId: ${this._eId}`),this._adShowFailureAnalytics({scene:null==e?void 0:e.scene,eId:this._eId,msg:"ad_show_timeout: normal",errorCode:1e5,result:0}),this._adTimeoutBeforeEnd({scene:null==e?void 0:e.scene,timeout:r,eId:this._eId}),this.onClose(this.bindAdTimeoutCloseLister),this.onError(this.bindAdTimeoutErrorLister);let i=()=>{null==e||e.end({preserved:null==e?void 0:e.preserved,resolvedValue:{eId:this._eId,apiError:{errMsg:`ad_show_timeout: normal, reward ad, timeout: ${r}`,errorCode:1e5,timeout:r}},nextValue:null})};try{this.customExecuteAfterTimeout({scene:null==e?void 0:e.scene,timeout:r,eId:this._eId,end:i})}catch(e){this._logger.warn(`${this._eId} use default timeout end task logic:`,e),i()}},r)}}customExecuteAfterTimeout(e){throw Error("customExecuteAfterTimeout not be implemented")}_adTimeoutBeforeEnd(e){return e}_adPreludeInterval(e){var r;null==(r=e.prelude)||r.call(e,{scene:null==e?void 0:e.scene,eId:this._eId,frequency:this._adBeforeShowTime,time:new Date().getTime()}),this._adBeforeShowTimer=setInterval(()=>{var r;null==(r=e.prelude)||r.call(e,{scene:null==e?void 0:e.scene,eId:this._eId,frequency:this._adBeforeShowTime,time:new Date().getTime()})},this._adBeforeShowTime)}_clearAdTimeout(){this._adTimeout&&(clearTimeout(this._adTimeout),this._adTimeout=null),this._adBeforeShowTimer&&(clearInterval(this._adBeforeShowTimer),this._adBeforeShowTimer=null),this._adSpeedCloseTimer&&(clearTimeout(this._adSpeedCloseTimer),this._adSpeedCloseTimer=null)}_adShowBeforeAnalytics(e){return null}_adShowSuccessAnalytics(e){return null}_adShowFailureAnalytics(e){return null}_adLoadSuccessAnalytics(e){return null}_adLoadFailureAnalytics(e){return null}_adCloseSuccessAnalytics(e){return null}get rewardAd(){return this._rewardAd}ad(e,r=null){var i,t,l,s;return this._alwaysCallback=null==e||null==(i=e.collection)?void 0:i.always,this._halfwayCallback=null==e||null==(t=e.collection)?void 0:t.halfway,this._finishedCallback=null==e||null==(l=e.collection)?void 0:l.finished,this._recovered=null==e?void 0:e.recovered,this._preservedOnTimeout=null==e||null==(s=e.options)?void 0:s.preservedOnTimeout,this._adExecuteArgs=e,this._adNext=r,this._onAdExecuteBefore({eId:this._eId}),new Promise(i=>{var t,l,s,n,o;this._resolve=i,this._adInner({options:{scene:null==e||null==(t=e.options)?void 0:t.scene,timeout:null==e||null==(l=e.options)?void 0:l.timeout},collection:{resolve:i,before:null==(s=e.collection)?void 0:s.before,success:null==(n=e.collection)?void 0:n.success,prelude:null==(o=e.collection)?void 0:o.prelude},recovered:e.recovered},r)})}_adInner(e,r=null){var i,t,l,n,o;this._eId=`ead_${Date.now()}_${Math.random().toString(36).slice(2,11)}`,this._onInnerExecuteBefore({eId:this._eId});let d=null==e||null==(i=e.collection)?void 0:i.resolve,a=(null==e||null==(t=e.options)?void 0:t.scene)??this._scene??s.inner_default_other,h=null==e||null==(l=e.collection)?void 0:l.before,u=null==e||null==(n=e.collection)?void 0:n.success,_=null==e||null==(o=e.collection)?void 0:o.prelude,c=(null==e?void 0:e.recovered)??this._recovered,f=e=>{this._clearAdTimeout(),this.adDestroy(null==e?void 0:e.preserved),null==d||d(Object.assign({scene:a,adTypeR:this._adTypeR,eId:this._eId},null==e?void 0:e.resolvedValue)),this._resolve=null,null==r||r(Object.assign({scene:a},null==e?void 0:e.nextValue)),this._next=null,this._adExecuteArgs=null,this._adNext=null},v=()=>{var i,t;this._scene=a,null==h||h({scene:a,eId:this._eId}),this._before=h,null==(i=this._onShow)||i.call(this,{scene:a,eId:this._eId}),this._adShowBeforeAnalytics({scene:a,eId:this._eId}),this._resolve=d,this._next=r,this._setAdTimeout({scene:a,end:f,timeout:null==e||null==(t=e.options)?void 0:t.timeout,preserved:this._preservedOnTimeout}),this._adPreludeInterval({scene:a,prelude:_,eId:this._eId}),this.adShow().then(()=>{this._clearAdTimeout(),null==u||u({scene:a,eId:this._eId}),this._success=u,this._adShowSuccessAnalytics({scene:a,eId:this._eId,result:1,recovered:c}),this._onInnerAdShowSuccess({scene:a,eId:this._eId,result:1,recovered:c})}).catch(e=>{var r,i;(this._clearAdTimeout(),this._adShowFailureAnalytics({scene:a,eId:this._eId,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),r=this._ttErrorMsgs,(i=null==e?void 0:e.errMsg)&&r.some(e=>RegExp(e,"i").test(i))||this._ttErrorCodes.includes(null==e?void 0:e.errorCode))?f({scene:a,resolvedValue:{apiError:e},nextValue:null}):0>=this.novelConfig.remain()?f({scene:a,resolvedValue:{apiError:{errMsg:`[RewardAdNovel]: no remain, remain: ${this.novelConfig.remain()}, retry: ${this.novelConfig.frequency.total},
2
- tt: {errMsg: ${null==e?void 0:e.errMsg}, errorCode: ${null==e?void 0:e.errorCode}}`,errorCode:1e5}},nextValue:null}):(this.novelConfig.updateRetry(),this.adLoad().then(()=>{this._adLoadSuccessAnalytics({scene:a,result:1,frequency:this.novelConfig.frequency}),v()}).catch(e=>{this._adLoadFailureAnalytics({scene:a,msg:null==e?void 0:e.errMsg,result:0}),f({scene:a,resolvedValue:{apiError:e},nextValue:null})}))})};v()}adCircleInner(e){var r,i,t,l,s,n,o,d,a,h,u,_,c,f,v,A;let w={scene:(null==e||null==(r=e.options)?void 0:r.scene)??(null==(t=this._adExecuteArgs)||null==(i=t.options)?void 0:i.scene),timeout:(null==e||null==(l=e.options)?void 0:l.timeout)??(null==(n=this._adExecuteArgs)||null==(s=n.options)?void 0:s.timeout)},m={resolve:this._resolve,before:(null==e||null==(o=e.collection)?void 0:o.before)??(null==(a=this._adExecuteArgs)||null==(d=a.collection)?void 0:d.before),success:(null==e||null==(h=e.collection)?void 0:h.success)??(null==(_=this._adExecuteArgs)||null==(u=_.collection)?void 0:u.success),prelude:(null==e||null==(c=e.collection)?void 0:c.prelude)??(null==(v=this._adExecuteArgs)||null==(f=v.collection)?void 0:f.prelude)};this._adInner({options:w,collection:m,recovered:null==(A=this._adExecuteArgs)?void 0:A.recovered},this._adNext)}adLoad(){return this.load()}adShow(){return this.show()}_outerCloseCallback(...e){var r;return null==(r=this._alwaysCallback)?void 0:r.call(this,...e)}onExeAlways(...e){var r;return null==(r=this._alwaysCallback)?void 0:r.call(this,...e)}_outerHalfwayCallback(...e){var r;return null==(r=this._halfwayCallback)?void 0:r.call(this,...e)}onExeHalfway(...e){var r;return null==(r=this._halfwayCallback)?void 0:r.call(this,...e)}_outerFinishedCallback(...e){var r;return null==(r=this._finishedCallback)?void 0:r.call(this,...e)}onExeFinished(...e){var r;return null==(r=this._finishedCallback)?void 0:r.call(this,...e)}onFinish(...e){var r;return null==(r=this._onFinish)?void 0:r.call(this,...e)}onHalfway(...e){var r;return null==(r=this._onHalfway)?void 0:r.call(this,...e)}onAlways(...e){var r;return null==(r=this._onAlways)?void 0:r.call(this,...e)}__adTimeoutCloseLister__(e){let r=Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR,eId:this._eId});this._logger.warn("ad close lister that after task end because timeout:",r),this._clearAdTimeout(),this.offClose(this.bindAdTimeoutCloseLister),this.adTimeoutCloseLister(r)}adTimeoutCloseLister(e){return e}__adTimeoutErrorLister__(e){let r=Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR,eId:this._eId});this._logger.error("ad error lister that after task end because timeout:",r),this._clearAdTimeout(),this.offError(this.bindAdTimeoutErrorLister),this.adTimeoutErrorLister(r)}adTimeoutErrorLister(e){return e}__adCloseLister__(e){this._clearAdTimeout(),this._adCloseSuccessAnalytics({scene:this._scene,eId:this._eId,ad_is_completed:+!!e.isEnded,ad_count:e.count});let r=Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR,eId:this._eId,end_type:e.isEnded?"finished":"halfway"}),i=e=>{var i,t;this.adDestroy(),null==(i=this._resolve)||i.call(this,Object.assign({},r,e)),this._resolve=null,null==(t=this._next)||t.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null},t=e=>{var i,t,l;let s=Object.assign({},r,e);(null==s?void 0:s.isEnded)?(this._outerFinishedCallback(s),this.onExeFinished(s),null==(t=this._onFinish)||t.call(this,s),this.onFinish(s)):(this._outerHalfwayCallback(s),this.onExeHalfway(s),null==(l=this._onHalfway)||l.call(this,s),this.onHalfway(s)),this._outerCloseCallback(s),this.onExeAlways(s),null==(i=this._onAlways)||i.call(this,s),this.onAlways(s)};this.adCloseLister(r,{conn:t,end:i})}adCloseLister(e,r){var i,t;null==r||null==(i=r.conn)||i.call(r,e),null==r||null==(t=r.end)||t.call(r,e)}__adErrorLister__(e){this._clearAdTimeout(),this._logger.error("adErrorLister",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,eId:this._eId,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),this.adErrorLister(e);let r=()=>{var r,i,t;this.adDestroy(),null==(r=this._onError)||r.call(this,e),null==(i=this._resolve)||i.call(this,{apiError:e,scene:this._scene,adTypeR:this._adTypeR,eId:this._eId}),this._resolve=null,null==(t=this._next)||t.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null};(!this._lookUpRemainOnError||0>=this.novelConfig.remain())&&r()}adErrorLister(e){return e}__apiAdErrorLister__(e){var r,i,t;this._clearAdTimeout(),this._logger.error("API apiAdErrorLister:",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,eId:this._eId,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),this.apiAdErrorLister(e),this.adDestroy(),null==(r=this._onError)||r.call(this,e),null==(i=this._resolve)||i.call(this,{apiError:e,scene:this._scene,adTypeR:this._adTypeR}),this._resolve=null,null==(t=this._next)||t.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}apiAdErrorLister(e){return e}__adLoadLister__(e){this._adLoadSuccessAnalytics({scene:this._scene,result:1,msg:null==e?void 0:e.errMsg}),this._logger.info("adLoadLister:",JSON.stringify({scene:this._scene,info:e})),this.adLoadLister(e)}adLoadLister(e){return e}__novelDestroy__(e){this.destroy(null==e?void 0:e.preserved).then(e=>{var r;null==(r=this._onInnerAdDestroySuccess)||r.call(this,{scene:this._scene,eId:this._eId,errMsg:e})}).catch(e=>{var r;this._logger.warn("ad destroy failed:",JSON.stringify(e)),null==(r=this._onInnerAdDestroyFailed)||r.call(this,{scene:this._scene,eId:this._eId,errorCode:null==e?void 0:e.errorCode,errMsg:null==e?void 0:e.errMsg})})}adDestroy(e=!1){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._recovered=null,this._preservedOnTimeout=null,this.__novelDestroy__({preserved:e})}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._recovered=null,this._preservedOnTimeout=null,this.__novelDestroy__(),this._resolve=null,this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}_shiftCloseLister(e){var r,i;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._recovered=null,this._preservedOnTimeout=null,this.offClose(this._bindShiftCloseLister),this.__novelDestroy__(),null==(r=this._resolve)||r.call(this,Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR})),this._resolve=null,null==(i=this._next)||i.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}_shiftErrorLister(e){var r,i;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._recovered=null,this._preservedOnTimeout=null,this.offError(this._bindShiftErrorLister),this.__novelDestroy__(),null==(r=this._resolve)||r.call(this,Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR})),this._resolve=null,null==(i=this._next)||i.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}shift(){this.offClose(this.bindAdCloseLister),this.onClose(this._bindShiftCloseLister),this.offError(this.bindAdErrorLister),this.onError(this._bindShiftErrorLister)}static build(e){return o.instance||(o.instance=new o(e)),o.instance}static getInstance(){if(!o.instance)throw Error("RewardAdNovel instance is not init");return o.instance}static new(e){return new o(e)}}class d{frequency={total:0,current:0};constructor(e){this._init(e)}_init(e){this._adTimes(e)}_adTimes(e){this.frequency.total=(null==e?void 0: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 d(e)}}let a=o;export{e as AdExecuteManager,l as RewardAdFather,a as RewardAdNovel};
1
+ import{AdExecuteManager as e}from"@ad-execute-manager/core";import{Logger as r}from"@ad-execute-manager/logger";import{SerializableError as i}from"@ad-execute-manager/serializable-error";class t{static args=null;_logger=null;_adTimeoutTime=8e3;_initSign="";_preserveOnEnd=!1;_rewardAd=null;__ad__=null;_ttErrorMsgs=["The adUnitId is closed","The adUnitId is prohibit","The adUnitId is invalid","The adUnitId is required","The adUnitId is empty","feature is not supported in app"];_ttErrorCodes=[139902,123302];__bindAdErrorForeverHandler=this.__adErrorForeverHandler.bind(this);constructor(e){this._logger=new r({prefix:"RewardAdFather",enabled:!!((null==e?void 0:e.log)??!0)}),this._initSign=(null==e?void 0:e.sign)??"",this._adConfig=(null==e?void 0:e.adConfig)??{},this._preserveOnEnd=(null==e?void 0:e.preserveOnEnd)??!1}initialize(e,r){if(this._rewardAd)return this._logger.warn("rewardAd has been initialized"),null==r||r(this._rewardAd),this;let l=Object.assign({},t.args,this._adConfig,e);if(!l.adUnitId)throw this._logger.error("reward args The adUnitId is required",l),new i("[RewardAdFather] reward args The adUnitId is required",{errMsg:"The adUnitId is required",errorCode:100002});let s=tt.createRewardedVideoAd(l);return this._logger.info("bindAdErrorForeverHandler at initialized:",null==e?void 0:e.foreverErrorBind),(null==e?void 0:e.foreverErrorBind)&&(null==s||s.offError(this.__bindAdErrorForeverHandler),null==s||s.onError(this.__bindAdErrorForeverHandler)),this._rewardAd=s,this.__ad__=s,null==r||r(this._rewardAd),this}initialized(){return!!this._rewardAd}__adErrorForeverHandler(e){this.adErrorForeverHandler(e)}adErrorForeverHandler(e){return null}async ad(e,r=null){throw Error("子类必须实现ad方法")}async addExecuteManager(e){let r=Object.assign({},this._adConfig,(null==e?void 0:e.options)??{});return t.executeWithManager(this,Object.assign({},e,{options:r}))}destroy(e=!1){var r,i;return!this._rewardAd||this._preserveOnEnd||e?Promise.reject({errMsg:`can not destroy,ad is: ${!!this._rewardAd}, preserved: ${e}, preservedOnEnd: ${this._preserveOnEnd}`,errorCode:110003}):null==(i=this._rewardAd.destroy().then(e=>Promise.resolve(e)))||null==(r=i.catch(e=>Promise.reject({errMsg:`rewardAd destroy failed: ${JSON.stringify(e)}`,errorCode:110004})))?void 0:r.finally(()=>{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:"[RewardAdFather] can not show,rewardAd is null",errorCode:110001})}load(){return this._rewardAd?this._rewardAd.load():Promise.reject({errMsg:"[RewardAdFather] can not load,rewardAd is null",errorCode:110002})}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){(null==e?void 0:e.adUnitId)||new r({prefix:"RewardAdFather",enable:!0}).error("RewardParams.adUnitId is required"),t.args=e}static async executeWithManager(i,l){return i&&i instanceof t?e.getInstance().addTask(i,l):(new r({prefix:"RewardAdFather",enable:!0}).error("executeWithManager - 无效的广告实例"),Promise.reject(Error("无效的广告实例")))}}let l=t,s=Object.entries({9999:"inner_default_other"}).reduce((e,[r,i])=>(e[i]=Number(r),e),{}),n={AD_TYPE_REWARD:1,AD_TYPE_INTERSTITIAL:2};Object.entries(n).reduce((e,[r,i])=>(e[i]=r,e),{});class o extends l{_onHalfway=null;_onShow=null;_onFinish=null;_onAlways=null;_onError=null;_logger=null;_initSign="";_alwaysCallback=null;_halfwayCallback=null;_finishedCallback=null;_resolve=null;_next=null;_adExecuteArgs=null;_adNext=null;_scene=s.inner_default_other;_eId=null;_adTypeR=n.AD_TYPE_REWARD;_adTimeout=null;_adTimeoutTime=8e3;_adBeforeShowTimer=null;_adBeforeShowTime=300;_adSpeedCloseTimer=null;_adSpeedCloseTime=5e3;_needEndOnTimeout=!0;_lookUpRemainOnError=!1;_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);bindAdTimeoutCloseLister=this.__adTimeoutCloseLister__.bind(this);bindAdTimeoutErrorLister=this.__adTimeoutErrorLister__.bind(this);constructor(e){var i,t,l,s,n;super(e),this._logger=new r({prefix:"RewardAdNovel",enabled:!!((null==e?void 0:e.log)??!0)}),this._initSign=(null==e?void 0:e.sign)??"",this._adConfig=(null==e?void 0:e.adConfig)??{},this._needEndOnTimeout=(null==e?void 0:e.needEndOnTimeout)??!0,this._lookUpRemainOnError=(null==e?void 0:e.lookUpRemainOnError)??!1,this._onHalfway=(null==e||null==(i=e.collection)?void 0:i.onHalfway)??null,this._onShow=(null==e||null==(t=e.collection)?void 0:t.onShow)??null,this._onFinish=(null==e||null==(l=e.collection)?void 0:l.onFinish)??null,this._onAlways=(null==e||null==(s=e.collection)?void 0:s.onAlways)??null,this._onError=(null==e||null==(n=e.collection)?void 0:n.onError)??null}initialize(e,r){return super.initialize(e,r),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=d.new({retry:null==e?void 0:e.retry})}_onInnerExecuteBefore(e){return null}_onAdExecuteBefore(e){return null}_onInnerAdShowSuccess(e){return null}_onInnerAdDestroySuccess(e){return null}_onInnerAdDestroyFailed(e){return null}_setAdTimeout(e){if(this._needSpeedEndOnTimeout&&(this._adSpeedCloseTimer=setTimeout(()=>{if("ios"==tt.getSystemInfoSync().platform){let r=()=>{tt.offAppShow(r),this._logger.warn("ad_show_timeout: ios platform close ad onAppShow, handling fallback ad case, scene:",null==e?void 0:e.scene);let i="ad_show_timeout: ios platform close ad onAppShow";this._adShowFailureAnalytics({scene:null==e?void 0:e.scene,eId:this._eId,poz:4,msg:i,errorCode:1e5,result:0}),this._adTimeout&&clearTimeout(this._adTimeout),null==e||e.end({resolvedValue:{apiError:{errMsg:i,errorCode:1e5}},nextValue:null})};tt.onAppShow(r)}clearTimeout(this._adSpeedCloseTimer)},this._adSpeedCloseTime)),this._needEndOnTimeout){let r=(null==e?void 0:e.timeout)??this._adTimeoutTime;this._adTimeout=setTimeout(()=>{this._logger.warn("Ad show timeout, handling fallback ad case,",`scene: ${null==e?void 0:e.scene},timeout: ${r}, eId: ${this._eId}`),this._adShowFailureAnalytics({scene:null==e?void 0:e.scene,eId:this._eId,poz:5,msg:"ad_show_timeout: normal",errorCode:1e5,result:0}),this._adTimeoutBeforeEnd({scene:null==e?void 0:e.scene,timeout:r,eId:this._eId}),this.onClose(this.bindAdTimeoutCloseLister),this.onError(this.bindAdTimeoutErrorLister);let i=()=>{null==e||e.end({preserved:null==e?void 0:e.preserved,resolvedValue:{eId:this._eId,apiError:{errMsg:`ad_show_timeout: normal, reward ad, timeout: ${r}`,errorCode:1e5,timeout:r}},nextValue:null})};try{this.customExecuteAfterTimeout({scene:null==e?void 0:e.scene,timeout:r,eId:this._eId,end:i})}catch(e){this._logger.warn(`${this._eId} use default timeout end task logic:`,e),i()}},r)}}customExecuteAfterTimeout(e){throw Error("customExecuteAfterTimeout not be implemented")}_adTimeoutBeforeEnd(e){return e}_adPreludeInterval(e){var r;null==(r=e.prelude)||r.call(e,{scene:null==e?void 0:e.scene,eId:this._eId,frequency:this._adBeforeShowTime,time:new Date().getTime()}),this._adBeforeShowTimer=setInterval(()=>{var r;null==(r=e.prelude)||r.call(e,{scene:null==e?void 0:e.scene,eId:this._eId,frequency:this._adBeforeShowTime,time:new Date().getTime()})},this._adBeforeShowTime)}_clearAdTimeout(){this._adTimeout&&(clearTimeout(this._adTimeout),this._adTimeout=null),this._adBeforeShowTimer&&(clearInterval(this._adBeforeShowTimer),this._adBeforeShowTimer=null),this._adSpeedCloseTimer&&(clearTimeout(this._adSpeedCloseTimer),this._adSpeedCloseTimer=null)}_adShowBeforeAnalytics(e){return null}_adShowSuccessAnalytics(e){return null}_adShowFailureAnalytics(e){return null}_adLoadSuccessAnalytics(e){return null}_adLoadFailureAnalytics(e){return null}_adCloseSuccessAnalytics(e){return null}get rewardAd(){return this._rewardAd}ad(e,r=null){var i,t,l,s;return this._alwaysCallback=null==e||null==(i=e.collection)?void 0:i.always,this._halfwayCallback=null==e||null==(t=e.collection)?void 0:t.halfway,this._finishedCallback=null==e||null==(l=e.collection)?void 0:l.finished,this._recovered=null==e?void 0:e.recovered,this._preservedOnTimeout=null==e||null==(s=e.options)?void 0:s.preservedOnTimeout,this._adExecuteArgs=e,this._adNext=r,this._onAdExecuteBefore({eId:this._eId}),new Promise(i=>{var t,l,s,n,o;this._resolve=i,this._adInner({options:{scene:null==e||null==(t=e.options)?void 0:t.scene,timeout:null==e||null==(l=e.options)?void 0:l.timeout},collection:{resolve:i,before:null==(s=e.collection)?void 0:s.before,success:null==(n=e.collection)?void 0:n.success,prelude:null==(o=e.collection)?void 0:o.prelude},recovered:e.recovered},r)})}_adInner(e,r=null){var i,t,l,n,o;this._eId=`ead_${Date.now()}_${Math.random().toString(36).slice(2,11)}`,this._onInnerExecuteBefore({eId:this._eId});let d=null==e||null==(i=e.collection)?void 0:i.resolve,a=(null==e||null==(t=e.options)?void 0:t.scene)??this._scene??s.inner_default_other,h=null==e||null==(l=e.collection)?void 0:l.before,u=null==e||null==(n=e.collection)?void 0:n.success,_=null==e||null==(o=e.collection)?void 0:o.prelude,c=(null==e?void 0:e.recovered)??this._recovered,f=e=>{this._clearAdTimeout(),this.adDestroy({preserved:null==e?void 0:e.preserved}),null==d||d(Object.assign({scene:a,adTypeR:this._adTypeR,eId:this._eId},null==e?void 0:e.resolvedValue)),this._resolve=null,null==r||r(Object.assign({scene:a},null==e?void 0:e.nextValue)),this._next=null,this._adExecuteArgs=null,this._adNext=null},v=()=>{var i,t;this._scene=a,null==h||h({scene:a,eId:this._eId}),this._before=h,null==(i=this._onShow)||i.call(this,{scene:a,eId:this._eId}),this._adShowBeforeAnalytics({scene:a,eId:this._eId}),this._resolve=d,this._next=r,this._setAdTimeout({scene:a,end:f,timeout:null==e||null==(t=e.options)?void 0:t.timeout,preserved:this._preservedOnTimeout}),this._adPreludeInterval({scene:a,prelude:_,eId:this._eId}),this.adShow().then(()=>{this._clearAdTimeout(),null==u||u({scene:a,eId:this._eId}),this._success=u,this._adShowSuccessAnalytics({scene:a,eId:this._eId,result:1,recovered:c}),this._onInnerAdShowSuccess({scene:a,eId:this._eId,result:1,recovered:c})}).catch(e=>{var r,i;(this._clearAdTimeout(),this._adShowFailureAnalytics({scene:a,eId:this._eId,poz:1,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),r=this._ttErrorMsgs,(i=null==e?void 0:e.errMsg)&&r.some(e=>RegExp(e,"i").test(i))||this._ttErrorCodes.includes(null==e?void 0:e.errorCode))?f({scene:a,resolvedValue:{apiError:e},nextValue:null}):0>=this.novelConfig.remain()?f({scene:a,resolvedValue:{apiError:{errMsg:`[RewardAdNovel]: no remain, remain: ${this.novelConfig.remain()}, retry: ${this.novelConfig.frequency.total},
2
+ tt: {errMsg: ${null==e?void 0:e.errMsg}, errorCode: ${null==e?void 0:e.errorCode}}`,errorCode:1e5}},nextValue:null}):(this.novelConfig.updateRetry(),this.adLoad().then(()=>{this._adLoadSuccessAnalytics({scene:a,eId:this._eId,result:1,frequency:this.novelConfig.frequency}),v()}).catch(e=>{this._adLoadFailureAnalytics({scene:a,eId:this._eId,msg:null==e?void 0:e.errMsg,result:0}),f({scene:a,resolvedValue:{apiError:e},nextValue:null})}))})};v()}adCircleInner(e){var r,i,t,l,s,n,o,d,a,h,u,_,c,f,v,A;let w={scene:(null==e||null==(r=e.options)?void 0:r.scene)??(null==(t=this._adExecuteArgs)||null==(i=t.options)?void 0:i.scene),timeout:(null==e||null==(l=e.options)?void 0:l.timeout)??(null==(n=this._adExecuteArgs)||null==(s=n.options)?void 0:s.timeout)},m={resolve:this._resolve,before:(null==e||null==(o=e.collection)?void 0:o.before)??(null==(a=this._adExecuteArgs)||null==(d=a.collection)?void 0:d.before),success:(null==e||null==(h=e.collection)?void 0:h.success)??(null==(_=this._adExecuteArgs)||null==(u=_.collection)?void 0:u.success),prelude:(null==e||null==(c=e.collection)?void 0:c.prelude)??(null==(v=this._adExecuteArgs)||null==(f=v.collection)?void 0:f.prelude)};this._adInner({options:w,collection:m,recovered:null==(A=this._adExecuteArgs)?void 0:A.recovered},this._adNext)}adLoad(){return this.load()}adShow(){return this.show()}_outerCloseCallback(...e){var r;return null==(r=this._alwaysCallback)?void 0:r.call(this,...e)}onExeAlways(...e){var r;return null==(r=this._alwaysCallback)?void 0:r.call(this,...e)}_outerHalfwayCallback(...e){var r;return null==(r=this._halfwayCallback)?void 0:r.call(this,...e)}onExeHalfway(...e){var r;return null==(r=this._halfwayCallback)?void 0:r.call(this,...e)}_outerFinishedCallback(...e){var r;return null==(r=this._finishedCallback)?void 0:r.call(this,...e)}onExeFinished(...e){var r;return null==(r=this._finishedCallback)?void 0:r.call(this,...e)}onFinish(...e){var r;return null==(r=this._onFinish)?void 0:r.call(this,...e)}onHalfway(...e){var r;return null==(r=this._onHalfway)?void 0:r.call(this,...e)}onAlways(...e){var r;return null==(r=this._onAlways)?void 0:r.call(this,...e)}__adTimeoutCloseLister__(e){let r=Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR,eId:this._eId});this._logger.warn("ad close lister that after ad end because timeout:",r),this._clearAdTimeout(),this.offClose(this.bindAdTimeoutCloseLister),this.adTimeoutCloseLister(r)}adTimeoutCloseLister(e){return e}__adTimeoutErrorLister__(e){let r=Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR,eId:this._eId});this._logger.error("ad error lister that after task end because timeout:",r),this._clearAdTimeout(),this.offError(this.bindAdTimeoutErrorLister),this.adTimeoutErrorLister(r)}adTimeoutErrorLister(e){return e}__adCloseLister__(e){this._clearAdTimeout(),this._adCloseSuccessAnalytics({scene:this._scene,eId:this._eId,ad_is_completed:+!!e.isEnded,ad_count:e.count});let r=Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR,eId:this._eId,end_type:e.isEnded?"finished":"halfway"}),i=e=>{var i,t;this.adDestroy(),null==(i=this._resolve)||i.call(this,Object.assign({},r,e)),this._resolve=null,null==(t=this._next)||t.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null},t=e=>{var i,t,l;let s=Object.assign({},r,e);(null==s?void 0:s.isEnded)?(this._outerFinishedCallback(s),this.onExeFinished(s),null==(t=this._onFinish)||t.call(this,s),this.onFinish(s)):(this._outerHalfwayCallback(s),this.onExeHalfway(s),null==(l=this._onHalfway)||l.call(this,s),this.onHalfway(s)),this._outerCloseCallback(s),this.onExeAlways(s),null==(i=this._onAlways)||i.call(this,s),this.onAlways(s)};this.adCloseLister(r,{conn:t,end:i})}adCloseLister(e,r){var i,t;null==r||null==(i=r.conn)||i.call(r,e),null==r||null==(t=r.end)||t.call(r,e)}__adErrorLister__(e){this._clearAdTimeout(),this._logger.error("adErrorLister",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,eId:this._eId,poz:2,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),this.adErrorLister(e);let r=()=>{var r,i,t;this.adDestroy(),null==(r=this._onError)||r.call(this,e),null==(i=this._resolve)||i.call(this,{apiError:e,scene:this._scene,adTypeR:this._adTypeR,eId:this._eId}),this._resolve=null,null==(t=this._next)||t.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null};(!this._lookUpRemainOnError||0>=this.novelConfig.remain())&&r()}adErrorLister(e){return e}__apiAdErrorLister__(e){var r,i,t;this._clearAdTimeout(),this._logger.error("API apiAdErrorLister:",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,eId:this._eId,poz:3,msg:null==e?void 0:e.errMsg,errorCode:null==e?void 0:e.errorCode,result:0}),this.apiAdErrorLister(e),this.adDestroy(),null==(r=this._onError)||r.call(this,e),null==(i=this._resolve)||i.call(this,{apiError:e,scene:this._scene,adTypeR:this._adTypeR}),this._resolve=null,null==(t=this._next)||t.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}apiAdErrorLister(e){return e}__adLoadLister__(e){this._adLoadSuccessAnalytics({scene:this._scene,eId:this._eId,result:1,msg:null==e?void 0:e.errMsg}),this._logger.info("adLoadLister:",JSON.stringify({scene:this._scene,info:e})),this.adLoadLister(e)}adLoadLister(e){return e}__novelDestroy__(e){this.destroy(null==e?void 0:e.preserved).then(e=>{var r;null==(r=this._onInnerAdDestroySuccess)||r.call(this,{scene:this._scene,eId:this._eId,errMsg:e})}).catch(e=>{var r;this._logger.warn("ad destroy failed:",JSON.stringify(e)),null==(r=this._onInnerAdDestroyFailed)||r.call(this,{scene:this._scene,eId:this._eId,errorCode:null==e?void 0:e.errorCode,errMsg:null==e?void 0:e.errMsg})})}adDestroy(e){let r=(null==e?void 0:e.preserved)??!1;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._recovered=null,this._preservedOnTimeout=null,this.__novelDestroy__({preserved:r})}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._recovered=null,this._preservedOnTimeout=null,this.__novelDestroy__(),this._resolve=null,this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}_shiftCloseLister(e){var r,i;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._recovered=null,this._preservedOnTimeout=null,this.offClose(this._bindShiftCloseLister),this.__novelDestroy__(),null==(r=this._resolve)||r.call(this,Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR})),this._resolve=null,null==(i=this._next)||i.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}_shiftErrorLister(e){var r,i;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._recovered=null,this._preservedOnTimeout=null,this.offError(this._bindShiftErrorLister),this.__novelDestroy__(),null==(r=this._resolve)||r.call(this,Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR})),this._resolve=null,null==(i=this._next)||i.call(this),this._next=null,this._success=null,this._before=null,this._adExecuteArgs=null,this._adNext=null}shift(){this.offClose(this.bindAdCloseLister),this.onClose(this._bindShiftCloseLister),this.offError(this.bindAdErrorLister),this.onError(this._bindShiftErrorLister)}static build(e){return o.instance||(o.instance=new o(e)),o.instance}static getInstance(){if(!o.instance)throw Error("RewardAdNovel instance is not init");return o.instance}static new(e){return new o(e)}}class d{frequency={total:0,current:0};constructor(e){this._init(e)}_init(e){this._adTimes(e)}_adTimes(e){this.frequency.total=(null==e?void 0: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 d(e)}}let a=o;export{e as AdExecuteManager,l as RewardAdFather,a as RewardAdNovel};
@@ -0,0 +1,35 @@
1
+ export class Logger {
2
+ /**
3
+ *
4
+ * @param {object} [options]
5
+ * @param {string} [options.prefix] - 日志前缀
6
+ * @param {'error'|'warn'|'info'|'log'|'debug'} [options.level] - 日志级别
7
+ * @param {boolean} [options.enabled] - 是否启用日志
8
+ */
9
+ constructor(options?: {
10
+ prefix?: string;
11
+ level?: "error" | "warn" | "info" | "log" | "debug";
12
+ enabled?: boolean;
13
+ });
14
+ prefix: string;
15
+ enabled: boolean;
16
+ levels: {
17
+ error: number;
18
+ warn: number;
19
+ info: number;
20
+ log: number;
21
+ debug: number;
22
+ };
23
+ currentLevel: number;
24
+ enable(): void;
25
+ disable(): void;
26
+ isEnabled(): boolean;
27
+ setLevel(level: any): void;
28
+ formatMessage(level: any, message: any): string;
29
+ _log(level: any, message: any, ...args: any[]): void;
30
+ error(message: any, ...args: any[]): void;
31
+ warn(message: any, ...args: any[]): void;
32
+ info(message: any, ...args: any[]): void;
33
+ log(message: any, ...args: any[]): void;
34
+ debug(message: any, ...args: any[]): void;
35
+ }
@@ -0,0 +1 @@
1
+ export { Logger } from "./Logger.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ad-execute-manager/ad-reward",
3
- "version": "2.3.1",
3
+ "version": "2.3.2",
4
4
  "description": "Reward ad-related classes including RewardAdFather and RewardAdNovel for ad management.",
5
5
  "type": "module",
6
6
  "exports": {
File without changes
File without changes
File without changes