@singcl/ad-execute-manager 2.0.12 → 2.1.0

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.
@@ -4,6 +4,8 @@ export type CallbackCollection = import("./typings/ad.js").CallbackCollection;
4
4
  export type RecoveredInfo = import("./typings/ad.js").RecoveredInfo;
5
5
  export type IConstructArgs = import("./typings/ad.js").IConstructArgs;
6
6
  export type RewardedVideoAd = import("./typings/create-rewarded-video-ad.js").RewardedVideoAd;
7
+ export type ITaskResult = import("./typings/ad.js").ITaskResult;
8
+ export type ITaskResultGeneric<T extends unknown> = ITaskResult & T;
7
9
  export type IRewardedVideoAd = {
8
10
  /**
9
11
  * 显示激励视频广告
@@ -22,18 +24,18 @@ declare class RewardAdFather {
22
24
  */
23
25
  static buildArgs(args: IRewordAdConfig): void;
24
26
  /**
27
+ * @template {object} T
25
28
  * 使用管理器执行广告
26
29
  * @param {Object} adInstance 广告实例
27
30
  * @param {Object} ctx 上下文对象,用于传递数据和状态
28
31
  * @param {import('./typings/ad.js').IAdOptions} ctx.options 广告执行选项
29
32
  * @param {CallbackCollection} ctx.collection 回调集合
33
+ * @returns {Promise<ITaskResultGeneric<T> | undefined>} 广告执行结果的Promise
30
34
  */
31
- static executeWithManager(adInstance: any, ctx: {
35
+ static executeWithManager<T extends unknown>(adInstance: any, ctx: {
32
36
  options: import("./typings/ad.js").IAdOptions;
33
37
  collection: CallbackCollection;
34
- }): Promise<import("@ad-execute-manager/core/dist/AdExecuteManager.js").ITaskResult & {
35
- [key: string]: any;
36
- }>;
38
+ }): Promise<ITaskResultGeneric<T> | undefined>;
37
39
  /**
38
40
  * @param {IConstructArgs} args
39
41
  */
@@ -100,18 +102,22 @@ declare class RewardAdFather {
100
102
  recovered?: RecoveredInfo;
101
103
  }, next?: Function): Promise<unknown>;
102
104
  /**
105
+ * @template {object} T
103
106
  * 确保广告按顺序执行
104
107
  * @param {Object} [ctx] 上下文对象,用于传递数据和状态
105
108
  * @param {import('./typings/ad.js').IAdOptions} [ctx.options] 广告执行选项
106
109
  * @param {CallbackCollection} [ctx.collection] 回调集合
110
+ * @returns {Promise<ITaskResultGeneric<T> | undefined>} 广告执行结果的Promise
107
111
  */
108
- addExecuteManager(ctx?: {
112
+ addExecuteManager<T extends unknown>(ctx?: {
109
113
  options?: import("./typings/ad.js").IAdOptions;
110
114
  collection?: CallbackCollection;
111
- }): Promise<import("@ad-execute-manager/core/dist/AdExecuteManager.js").ITaskResult & {
112
- [key: string]: any;
113
- }>;
114
- destroy(): void;
115
+ }): Promise<ITaskResultGeneric<T> | undefined>;
116
+ /**
117
+ * 销毁广告实例
118
+ * @param {boolean} preserved 是否保留广告实例
119
+ */
120
+ destroy(preserved?: boolean): void;
115
121
  /**
116
122
  * 清理广告实例
117
123
  * @abstract 清理广告实例,子类必须实现此方法
@@ -50,11 +50,36 @@ declare class RewardAdNovel extends RewardAdFather {
50
50
  * @returns {RewardAdNovel}
51
51
  */
52
52
  static "new"(args: IConstructArgs): RewardAdNovel;
53
- _onHalfway: any;
54
- _onShow: any;
55
- _onFinish: any;
56
- _onAlways: any;
57
- _onError: any;
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;
58
83
  _alwaysCallback: any;
59
84
  _halfwayCallback: any;
60
85
  _finishedCallback: any;
@@ -72,12 +97,38 @@ declare class RewardAdNovel extends RewardAdFather {
72
97
  _lookUpRemainOnError: boolean;
73
98
  /** @deprecated TODO 移除 */
74
99
  _needSpeedEndOnTimeout: boolean;
75
- bindAdCloseLister: any;
76
- bindAdErrorLister: any;
77
- bindAdLoadLister: any;
78
- bindApiAdErrorLister: any;
79
- _bindShiftCloseLister: any;
80
- _bindShiftErrorLister: any;
100
+ /**
101
+ * @private
102
+ */
103
+ private bindAdCloseLister;
104
+ /**
105
+ * @private 内部方法请勿使用
106
+ */
107
+ private bindAdErrorLister;
108
+ /**
109
+ * @private 内部方法请勿使用
110
+ */
111
+ private bindAdLoadLister;
112
+ /**
113
+ * @private 内部方法请勿使用
114
+ */
115
+ private bindApiAdErrorLister;
116
+ /**
117
+ * @private 内部方法请勿使用
118
+ */
119
+ private _bindShiftCloseLister;
120
+ /**
121
+ * @private 内部方法请勿使用
122
+ */
123
+ private _bindShiftErrorLister;
124
+ /**
125
+ * @private 内部方法请勿使用
126
+ */
127
+ private bindAdTimeoutCloseLister;
128
+ /**
129
+ * @private 内部方法请勿使用
130
+ */
131
+ private bindAdTimeoutErrorLister;
81
132
  /**
82
133
  * 初始化
83
134
  * 子类可以选择覆盖此方法,或使用默认实现
@@ -293,9 +344,88 @@ declare class RewardAdNovel extends RewardAdFather {
293
344
  * @returns
294
345
  */
295
346
  adShow(): Promise<void>;
296
- _outerCloseCallback(args: any): void;
297
- _outerHalfwayCallback(args: any): void;
298
- _outerFinishedCallback(args: any): void;
347
+ /**
348
+ * @deprecated - 已废弃,使用onExeAlways代替
349
+ * - 关闭广告时候调用的回调,不管是否看完视频都会调用
350
+ * - 调用adExecuteManager时collection.always回调
351
+ * @param {Array.<unknown>} args
352
+ */
353
+ _outerCloseCallback(...args: Array<unknown>): any;
354
+ /**
355
+ * - 关闭广告时候调用的回调 不管是否看完视频都会调用
356
+ * - 调用adExecuteManager时collection.always回调
357
+ * @param {Array.<unknown>} args
358
+ */
359
+ onExeAlways(...args: Array<unknown>): any;
360
+ /**
361
+ * @deprecated 已废弃,使用onExeHalfway代替
362
+ * - 广告未看完时候调用的回调
363
+ * - 调用adExecuteManager时collection.halfway回调
364
+ * @param {Array.<unknown>} args
365
+ */
366
+ _outerHalfwayCallback(...args: Array<unknown>): any;
367
+ /**
368
+ * - 广告未看完时候调用的回调
369
+ * - 调用adExecuteManager时collection.halfway回调
370
+ * @param {Array.<unknown>} args
371
+ */
372
+ onExeHalfway(...args: Array<unknown>): any;
373
+ /**
374
+ * @deprecated 已废弃,使用onExeFinished代替
375
+ * - 广告看完时候调用的回调
376
+ * - 调用adExecuteManager时collection.finished回调
377
+ * @param {Array.<unknown>} args
378
+ */
379
+ _outerFinishedCallback(...args: Array<unknown>): any;
380
+ /**
381
+ * - 广告看完时候调用的回调
382
+ * - 调用adExecuteManager时collection.finished回调
383
+ * @param {Array.<unknown>} args
384
+ */
385
+ onExeFinished(...args: Array<unknown>): any;
386
+ /**
387
+ * @description 广告中途退出回调
388
+ * 初始化广告实例.new()中传入的参数args.collection.onHalfway回调
389
+ * @param {Array.<unknown>} args
390
+ */
391
+ onFinish(...args: Array<unknown>): any;
392
+ /**
393
+ *
394
+ * @description 广告展示回调
395
+ * 初始化广告实例.new()中传入的参数args.collection.onShow回调
396
+ * @param {Array.<unknown>} args
397
+ */
398
+ onHalfway(...args: Array<unknown>): any;
399
+ /**
400
+ * @description 广告展示回调
401
+ * 初始化广告实例.new()中传入的参数args.collection.onAlways回调
402
+ * @param {Array.<unknown>} args
403
+ */
404
+ onAlways(...args: Array<unknown>): any;
405
+ /**
406
+ * 内部关闭激励视频
407
+ * @private
408
+ * @param {ICloseArgs} args
409
+ */
410
+ private __adTimeoutCloseLister__;
411
+ /**
412
+ * 子类可以选择覆盖此方法
413
+ * @param {*} args
414
+ * @returns
415
+ */
416
+ adTimeoutCloseLister(args: any): any;
417
+ /**
418
+ * 内部关闭激励视频
419
+ * @private
420
+ * @param {*} e
421
+ */
422
+ private __adTimeoutErrorLister__;
423
+ /**
424
+ * 子类可以选择覆盖此方法
425
+ * @param {*} e
426
+ * @returns
427
+ */
428
+ adTimeoutErrorLister(e: any): any;
299
429
  /**
300
430
  * 内部关闭激励视频
301
431
  * @private
@@ -361,7 +491,12 @@ declare class RewardAdNovel extends RewardAdFather {
361
491
  * @param {unknown} e
362
492
  */
363
493
  protected adLoadLister(e: unknown): unknown;
364
- adDestroy(): void;
494
+ /**
495
+ * 销毁广告实例
496
+ * @protected
497
+ * @param {boolean} preserved 是否保留广告实例
498
+ */
499
+ protected adDestroy(preserved?: boolean): void;
365
500
  _shiftCloseLister(args: any): void;
366
501
  _shiftErrorLister(args: any): void;
367
502
  /**
@@ -152,6 +152,40 @@ export type IApiError = {
152
152
  */
153
153
  message?: string;
154
154
  };
155
+ export type ITaskResult = {
156
+ /**
157
+ * 广告任务的唯一标识符
158
+ */
159
+ id: string;
160
+ /**
161
+ * 广告错误信息
162
+ */
163
+ apiError?: IApiError;
164
+ /**
165
+ * 广告任务后台恢复前台时预估重试次数的原因
166
+ */
167
+ recovered?: RecoveredInfo;
168
+ /**
169
+ * 广告场景
170
+ */
171
+ scene?: string;
172
+ /**
173
+ * 广告类型 1:激励视频 2:插屏
174
+ */
175
+ adTypeR?: 1 | 2;
176
+ /**
177
+ * 广告结束类型
178
+ */
179
+ end_type?: "finished" | "halfway";
180
+ /**
181
+ * 是否看完广告
182
+ */
183
+ isEnded?: boolean;
184
+ /**
185
+ * 完整观看广告次数
186
+ */
187
+ count?: number;
188
+ };
155
189
  export type ICallbackArgs = IExeCallbackArgs;
156
190
  export type IConnection = {
157
191
  /**
package/package.json CHANGED
@@ -1,97 +1,97 @@
1
- {
2
- "name": "@singcl/ad-execute-manager",
3
- "version": "2.0.12",
4
- "description": "A powerful and flexible ad execution management library for handling reward-based ads, interstitial ads, and other advertising formats in JavaScript applications.",
5
- "type": "module",
6
- "exports": {
7
- ".": {
8
- "import": "./dist/index.js",
9
- "require": "./dist/index.cjs",
10
- "types": "./dist/index.d.ts"
11
- }
12
- },
13
- "main": "./dist/index.cjs",
14
- "types": "./dist/index.d.ts",
15
- "files": [
16
- "dist"
17
- ],
18
- "author": {
19
- "name": "singcl",
20
- "email": "iambabyer@gmail.com",
21
- "url": "https://github.com/singcl"
22
- },
23
- "license": "MIT",
24
- "homepage": "https://npmx.dev/package/@singcl/ad-execute-manager",
25
- "repository": {
26
- "type": "git",
27
- "url": "git+https://github.com/singcl/ad-execute-manager.git"
28
- },
29
- "bugs": {
30
- "url": "https://github.com/singcl/ad-execute-manager/issues"
31
- },
32
- "engines": {
33
- "node": ">=8.0.0",
34
- "npm": ">=6.0.0",
35
- "yarn": ">=1.0.0",
36
- "pnpm": ">=8.0.0"
37
- },
38
- "publishConfig": {
39
- "access": "public"
40
- },
41
- "keywords": [
42
- "ad",
43
- "advertisement",
44
- "reward-ad",
45
- "interstitial-ad",
46
- "ad-manager",
47
- "ad-execution",
48
- "javascript",
49
- "nodejs"
50
- ],
51
- "scripts": {
52
- "build": "rslib build && tsc",
53
- "dev": "rslib build --watch",
54
- "format": "prettier --write .",
55
- "lint": "eslint .",
56
- "test": "rstest",
57
- "prepublishOnly": "npm i && npm run build",
58
- "packages:install": "node build-packages.js install",
59
- "packages:build": "node build-packages.js build",
60
- "packages:publish": "node build-packages.js publish",
61
- "packages:publish:patch": "node build-packages.js publish patch",
62
- "packages:publish:minor": "node build-packages.js publish minor",
63
- "packages:publish:major": "node build-packages.js publish major",
64
- "packages:lint": "node build-packages.js lint",
65
- "packages:format": "node build-packages.js format",
66
- "packages:clean": "node build-packages.js clean",
67
- "packages:all": "node build-packages.js all",
68
- "packages:all:patch": "node build-packages.js all patch",
69
- "packages:all:minor": "node build-packages.js all minor",
70
- "packages:all:major": "node build-packages.js all major"
71
- },
72
- "devDependencies": {
73
- "@babel/eslint-parser": "^7.28.5",
74
- "@babel/preset-env": "^7.28.5",
75
- "@douyin-microapp/typings": "^1.3.1",
76
- "@eslint/js": "^9.39.1",
77
- "@rslib/core": "^0.18.5",
78
- "@rstest/core": "^0.7.2",
79
- "@singcl/ad-execute-manager": "^1.11.12",
80
- "eslint": "^9.39.2",
81
- "eslint-plugin-import": "^2.32.0",
82
- "globals": "^16.5.0",
83
- "prettier": "^3.7.3",
84
- "typescript": "^5.9.3"
85
- },
86
- "dependencies": {
87
- "@ad-execute-manager/core": "^2.0.5",
88
- "@ad-execute-manager/logger": "^2.0.5",
89
- "@ad-execute-manager/ad-reward": "^2.0.5",
90
- "@ad-execute-manager/ad-interstitial": "^2.0.5",
91
- "@ad-execute-manager/count-recorder": "^2.0.5",
92
- "@ad-execute-manager/serializable-error": "^2.0.5",
93
- "@ad-execute-manager/storage": "^2.0.5",
94
- "@ad-execute-manager/event": "^2.0.5",
95
- "@ad-execute-manager/analytics": "^2.0.5"
96
- }
97
- }
1
+ {
2
+ "name": "@singcl/ad-execute-manager",
3
+ "version": "2.1.0",
4
+ "description": "A powerful and flexible ad execution management library for handling reward-based ads, interstitial ads, and other advertising formats in JavaScript applications.",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./dist/index.js",
9
+ "require": "./dist/index.cjs",
10
+ "types": "./dist/index.d.ts"
11
+ }
12
+ },
13
+ "main": "./dist/index.cjs",
14
+ "types": "./dist/index.d.ts",
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "author": {
19
+ "name": "singcl",
20
+ "email": "iambabyer@gmail.com",
21
+ "url": "https://github.com/singcl"
22
+ },
23
+ "license": "MIT",
24
+ "homepage": "https://npmx.dev/package/@singcl/ad-execute-manager",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/singcl/ad-execute-manager.git"
28
+ },
29
+ "bugs": {
30
+ "url": "https://github.com/singcl/ad-execute-manager/issues"
31
+ },
32
+ "engines": {
33
+ "node": ">=8.0.0",
34
+ "npm": ">=6.0.0",
35
+ "yarn": ">=1.0.0",
36
+ "pnpm": ">=8.0.0"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "keywords": [
42
+ "ad",
43
+ "advertisement",
44
+ "reward-ad",
45
+ "interstitial-ad",
46
+ "ad-manager",
47
+ "ad-execution",
48
+ "javascript",
49
+ "nodejs"
50
+ ],
51
+ "scripts": {
52
+ "build": "rslib build && tsc",
53
+ "dev": "rslib build --watch",
54
+ "format": "prettier --write .",
55
+ "lint": "eslint .",
56
+ "test": "rstest",
57
+ "prepublishOnly": "npm i && npm run build",
58
+ "packages:install": "node build-packages.js install",
59
+ "packages:build": "node build-packages.js build",
60
+ "packages:publish": "node build-packages.js publish",
61
+ "packages:publish:patch": "node build-packages.js publish patch",
62
+ "packages:publish:minor": "node build-packages.js publish minor",
63
+ "packages:publish:major": "node build-packages.js publish major",
64
+ "packages:lint": "node build-packages.js lint",
65
+ "packages:format": "node build-packages.js format",
66
+ "packages:clean": "node build-packages.js clean",
67
+ "packages:all": "node build-packages.js all",
68
+ "packages:all:patch": "node build-packages.js all patch",
69
+ "packages:all:minor": "node build-packages.js all minor",
70
+ "packages:all:major": "node build-packages.js all major"
71
+ },
72
+ "devDependencies": {
73
+ "@babel/eslint-parser": "^7.28.5",
74
+ "@babel/preset-env": "^7.28.5",
75
+ "@douyin-microapp/typings": "^1.3.1",
76
+ "@eslint/js": "^9.39.1",
77
+ "@rslib/core": "^0.18.5",
78
+ "@rstest/core": "^0.7.2",
79
+ "@singcl/ad-execute-manager": "^1.11.12",
80
+ "eslint": "^9.39.2",
81
+ "eslint-plugin-import": "^2.32.0",
82
+ "globals": "^16.5.0",
83
+ "prettier": "^3.7.3",
84
+ "typescript": "^5.9.3"
85
+ },
86
+ "dependencies": {
87
+ "@ad-execute-manager/core": "^2.0.6",
88
+ "@ad-execute-manager/logger": "^2.0.5",
89
+ "@ad-execute-manager/ad-reward": "^2.1.0",
90
+ "@ad-execute-manager/ad-interstitial": "^2.0.6",
91
+ "@ad-execute-manager/count-recorder": "^2.0.5",
92
+ "@ad-execute-manager/serializable-error": "^2.0.5",
93
+ "@ad-execute-manager/storage": "^2.0.5",
94
+ "@ad-execute-manager/event": "^2.0.5",
95
+ "@ad-execute-manager/analytics": "^2.0.5"
96
+ }
97
+ }