@ad-execute-manager/ad 2.0.0-alpha.1 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,42 @@
1
+ /**
2
+ * 回调函数类型
3
+ */
4
+ export type Callback = () => any;
5
+ export type RewardedVideoAd = {
6
+ /**
7
+ * 广告创建后默认是隐藏的,可以通过该方法显示广告
8
+ */
9
+ show: () => Promise<any>;
10
+ /**
11
+ * 当广告素材加载出现错误时,可以通过 load 方法手动加载
12
+ */
13
+ load: () => Promise<any>;
14
+ /**
15
+ * 销毁广告实例
16
+ */
17
+ destroy: () => void;
18
+ /**
19
+ * 绑定广告 load 事件的监听器
20
+ */
21
+ onLoad: (arg0: Callback) => void;
22
+ /**
23
+ * 解除绑定 load 事件的监听器
24
+ */
25
+ offLoad: (arg0: Callback) => void;
26
+ /**
27
+ * 绑定 error 事件的监听器
28
+ */
29
+ onError: (arg0: Callback) => void;
30
+ /**
31
+ * 解除绑定 error 事件的监听器
32
+ */
33
+ offError: (arg0: Callback) => void;
34
+ /**
35
+ * 绑定 close 事件的监听器
36
+ */
37
+ onClose: (arg0: Callback) => void;
38
+ /**
39
+ * 解除绑定 close 事件的监听器
40
+ */
41
+ offClose: (arg0: Callback) => void;
42
+ };
package/package.json CHANGED
@@ -1,13 +1,8 @@
1
1
  {
2
2
  "name": "@ad-execute-manager/ad",
3
- "version": "2.0.0-alpha.1",
3
+ "version": "2.0.1",
4
+ "description": "Ad-related classes including InterstitialAdFather, InterstitialAdNovel, RewardAdFather, and RewardAdNovel for ad management.",
4
5
  "type": "module",
5
- "main": "./dist/index.cjs",
6
- "module": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
8
- "files": [
9
- "dist"
10
- ],
11
6
  "exports": {
12
7
  ".": {
13
8
  "import": "./dist/index.js",
@@ -15,10 +10,59 @@
15
10
  "types": "./dist/index.d.ts"
16
11
  }
17
12
  },
18
- "author": "singcl",
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
+ },
19
23
  "license": "MIT",
20
24
  "homepage": "https://npmjs.com/package/@ad-execute-manager/ad",
21
- "peerDependencies": {
22
- "@singcl/ad-execute-manager": ">=2.0.0"
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": ">=14.0.0"
34
+ },
35
+ "keywords": [
36
+ "ad",
37
+ "advertisement",
38
+ "interstitial-ad",
39
+ "reward-ad",
40
+ "ad-manager",
41
+ "javascript",
42
+ "nodejs"
43
+ ],
44
+ "scripts": {
45
+ "build": "rslib build && tsc",
46
+ "dev": "rslib build --watch",
47
+ "format": "prettier --write .",
48
+ "lint": "eslint .",
49
+ "test": "rstest",
50
+ "prepublishOnly": "npm run build"
51
+ },
52
+ "dependencies": {
53
+ "@ad-execute-manager/core": "^2.0.1",
54
+ "@ad-execute-manager/helper": "^2.0.1"
55
+ },
56
+ "devDependencies": {
57
+ "@babel/eslint-parser": "^7.28.5",
58
+ "@babel/preset-env": "^7.28.5",
59
+ "@eslint/js": "^9.39.1",
60
+ "@rslib/core": "^0.18.5",
61
+ "@rstest/core": "^0.7.2",
62
+ "eslint": "^9.39.2",
63
+ "eslint-plugin-import": "^2.32.0",
64
+ "globals": "^16.5.0",
65
+ "prettier": "^3.7.3",
66
+ "typescript": "^5.9.3"
23
67
  }
24
68
  }
@@ -1,4 +0,0 @@
1
- export { default as RewardAdFather } from "./RewardAdFather.js";
2
- export { default as RewardAdNovel } from "./RewardAdNovel.js";
3
- export { default as InterstitialAdFather } from "./InterstitialAdFather.js";
4
- export { default as InterstitialAdNovel } from "./InterstitialAdNovel.js";
@@ -1,129 +0,0 @@
1
- export default AdExecuteManager;
2
- export type AdTask = {
3
- /**
4
- * RewardAdFather的子类实例
5
- */
6
- adInstance: import("../ad/RewardAdFather.js").default;
7
- /**
8
- * 广告执行选项
9
- */
10
- options: import("../typings/ad.js").IRewordAdConfig;
11
- /**
12
- * 回调集合
13
- */
14
- callbackCollection: import("../typings/ad.js").CallbackCollection;
15
- /**
16
- * 广告执行成功的回调函数
17
- */
18
- resolve: Function;
19
- /**
20
- * 广告执行失败的回调函数
21
- */
22
- reject: Function;
23
- /**
24
- * 广告任务的唯一标识符
25
- */
26
- id: string;
27
- /**
28
- * 广告任务是否已成功解决
29
- */
30
- _isResolved: boolean;
31
- /**
32
- * 广告任务是否已被拒绝
33
- */
34
- _isRejected: boolean;
35
- };
36
- export type IConstructArgs = {
37
- /**
38
- * 广告执行选项
39
- */
40
- options?: object;
41
- /**
42
- * 是否打印日志
43
- */
44
- log?: boolean;
45
- };
46
- declare class AdExecuteManager {
47
- /**
48
- * 单例实例
49
- * @type {AdExecuteManager|null}
50
- */
51
- static _instance: AdExecuteManager | null;
52
- /**
53
- * 获取单例实例
54
- * @param {IConstructArgs} [args]
55
- * @returns {AdExecuteManager}
56
- */
57
- static getInstance(args?: IConstructArgs): AdExecuteManager;
58
- /**
59
- * 获取单例实例
60
- * @returns {AdExecuteManager}
61
- */
62
- static getSafeInstance(): AdExecuteManager;
63
- /**
64
- *
65
- * @param {IConstructArgs} args
66
- * @returns
67
- */
68
- constructor(args: IConstructArgs);
69
- /**
70
- * @type {Array.<AdTask>}
71
- */
72
- _taskStack: Array<AdTask>;
73
- /**
74
- * @type {Array.<AdTask>}
75
- */
76
- _currentBatchTasks: Array<AdTask>;
77
- /**
78
- * @type {boolean}
79
- */
80
- _isRunning: boolean;
81
- /**
82
- * @type {AdTask|null}
83
- */
84
- _currentTask: AdTask | null;
85
- logger: Logger;
86
- /**
87
- * 添加广告任务
88
- * @param {import('../ad/RewardAdFather.js').default} adInstance RewardAdFather的子类实例
89
- * @param {Object} ctx 广告执行上下文
90
- * @param {import('../typings/ad.js').IRewordAdConfig} ctx.options 广告执行选项
91
- * @param {import('../typings/ad.js').CallbackCollection} ctx.collection 回调集合
92
- * @returns {Promise} 广告执行结果的Promise
93
- */
94
- addTask(adInstance: import("../ad/RewardAdFather.js").default, ctx: {
95
- options: import("../typings/ad.js").IRewordAdConfig;
96
- collection: import("../typings/ad.js").CallbackCollection;
97
- }): Promise<any>;
98
- /**
99
- * 组合所有任务
100
- * @private
101
- */
102
- private _compose;
103
- /**
104
- * 清空任务栈并取消所有任务(包括正在执行的任务和middleware链中等待执行的任务)
105
- */
106
- clearTasks(): void;
107
- /**
108
- * 获取当前未完成的任务总数
109
- * 包括任务栈中待执行的任务和中间件链中未完成的任务
110
- * @returns {number} 未完成的任务数量
111
- */
112
- getTaskCount(): number;
113
- /**
114
- * 是否有任务正在运行
115
- * @returns {boolean}
116
- */
117
- isRunning(): boolean;
118
- /**
119
- * 获取当前执行的任务ID
120
- * @returns {string|null} 当前任务ID
121
- */
122
- getCurrentTaskId(): string | null;
123
- /**
124
- * 返回一个Promise,当任务队列中的所有任务都完成时resolve
125
- * @returns {Promise<void>} 当所有任务完成时resolve的Promise
126
- */
127
- whenAllTasksComplete(): Promise<void>;
128
- }
129
- import { Logger } from '../helper/Logger';
@@ -1,12 +0,0 @@
1
- export default compose;
2
- /**
3
- * Koa中间件核心处理机制
4
- * @see https://github.com/singcl/koa/blob/master/src/compose-es7.js
5
- * @param {Array.<Function>} middlewares KOA中间件数组,每个中间件函数接收ctx和next参数
6
- * @returns {Function} 返回一个组合后的中间件函数,接收ctx参数并按顺序执行所有中间件
7
- * @version 0.0.1
8
- * @since 0.0.1
9
- * @author singcl 24661881@qq.com
10
- * @description 将多个中间件函数组合成一个单一的中间件函数,形成洋葱模型的调用链
11
- */
12
- declare function compose(middlewares: Array<Function>): Function;
@@ -1,2 +0,0 @@
1
- export { default as compose } from "./compose.js";
2
- export { default as AdExecuteManager } from "./AdExecuteManager.js";
@@ -1,132 +0,0 @@
1
- export default AdAnalyticsJS;
2
- export type EventDict = {
3
- [x: string]: any;
4
- };
5
- export type IConstructorArgs = {
6
- /**
7
- * 初始化标识
8
- */
9
- sign: string;
10
- /**
11
- * 是否需要上报
12
- */
13
- needReport?: boolean;
14
- /**
15
- * 公共用户信息
16
- */
17
- commonConfig?: ICommonInfo;
18
- };
19
- export type ICommonInfo = {
20
- [x: string]: any;
21
- };
22
- /**
23
- * @typedef {Object.<string, object>} EventDict
24
- */
25
- /**
26
- * @typedef {object} IConstructorArgs
27
- * @property {string} sign 初始化标识
28
- * @property {boolean} [needReport] 是否需要上报
29
- * @property {ICommonInfo} [commonConfig] 公共用户信息
30
- *
31
- */
32
- /**
33
- * @typedef {Object.<string, object>} ICommonInfo
34
- *
35
- */
36
- declare class AdAnalyticsJS {
37
- static instance: any;
38
- /**
39
- *
40
- * @param {IConstructorArgs} args
41
- * @returns {AdAnalyticsJS}
42
- */
43
- static build(args: IConstructorArgs): AdAnalyticsJS;
44
- /**
45
- *
46
- * @returns {AdAnalyticsJS}
47
- */
48
- static getInstance(): AdAnalyticsJS;
49
- /**
50
- *
51
- * @param {IConstructorArgs} args
52
- * @returns {AdAnalyticsJS}
53
- */
54
- static "new"(args: IConstructorArgs): AdAnalyticsJS;
55
- /**
56
- * @param {IConstructorArgs} args
57
- */
58
- constructor(args: IConstructorArgs);
59
- _initSign: string;
60
- _needReport: boolean;
61
- /** @type {ICommonInfo | null} */
62
- _commonConfig: ICommonInfo | null;
63
- /**
64
- * 初始化 比如环境配置,api地址、日志等级等
65
- * @param {IConstructorArgs} args
66
- */
67
- initialize(args: IConstructorArgs): IConstructorArgs;
68
- /**
69
- * 追踪自定义事件
70
- * 用户交互,如点击、提交
71
- *
72
- * @template {keyof EventDict} K
73
- * @param {K} eventName - The name of the event to track.
74
- * @param {EventDict[K]} properties - The properties associated with the event.
75
- * @param {object} [debugParams] - The debug parameters.
76
- * @param {string} [debugParams.sign] - Whether to enable debug mode.
77
- */
78
- track<K extends keyof EventDict>(eventName: K, properties: EventDict[K], debugParams?: {
79
- sign?: string;
80
- }): void;
81
- /**
82
- * 获取公共用户信息
83
- * @public
84
- * @returns {ICommonInfo}
85
- */
86
- public getCommonInfo(): ICommonInfo;
87
- /**
88
- * 获取埋点公共用户信息
89
- * @protected
90
- * @returns {ICommonInfo}
91
- */
92
- protected getTrackCommonInfo(): ICommonInfo;
93
- /**
94
- * 识别用户身份
95
- * 用户登录后,关联用户信息
96
- * @param {string|number} user_id - 用户id
97
- * @param {ICommonInfo} info - 用户信息
98
- * @returns {AdAnalyticsJS} 返回实例本身,支持链式调用
99
- */
100
- identify(user_id: string | number, info: ICommonInfo): AdAnalyticsJS;
101
- /**
102
- * 合并用户身份
103
- * 匿名用户转为登录用户
104
- * @returns
105
- */
106
- alias(): any;
107
- /**
108
- * 追踪页面浏览
109
- * SPA 路由切换,或手动触发页面事件
110
- * @returns
111
- */
112
- pages(): any;
113
- /**
114
- * 追踪页面浏览 进入页面
115
- *
116
- * @template {'cpage'} K
117
- * @param {K} eventName - The name of the event to track.
118
- * @param {EventDict[K]} properties - The properties associated with the event.
119
- */
120
- page<K extends "cpage">(eventName: K, properties: EventDict[K]): void;
121
- /**
122
- *
123
- * @param {EventDict['cpage']} properties
124
- * @returns
125
- */
126
- cpage(properties: EventDict["cpage"]): void;
127
- /**
128
- * 站位方法,没有任何左右
129
- * @returns
130
- */
131
- placeholder(): any;
132
- }
@@ -1,59 +0,0 @@
1
- /**
2
- * @typedef {object} IConstructorArgs
3
- * @property {string} [sign] 初始化标识
4
- * @property {string} local_sign 本地存储标识
5
- * @property {number} [total] 总次数
6
- * @property {number|'today'} [expire] 过期时间(毫秒)或'today'表示当天有效,可选
7
- * @property {string | number} [userId] 用户ID
8
- *
9
- */
10
- export class CountRecorder {
11
- /**
12
- *
13
- * @param {IConstructorArgs} args
14
- * @returns {CountRecorder}
15
- */
16
- static "new"(args: IConstructorArgs): CountRecorder;
17
- /**
18
- *
19
- * @param {IConstructorArgs} args
20
- */
21
- constructor(args: IConstructorArgs);
22
- _total: number;
23
- _local_sign: string;
24
- _expire: string;
25
- storage: Storage;
26
- _init(): void;
27
- /**
28
- * 获取次数
29
- * @returns {number} 次数
30
- */
31
- _adTimes(): number;
32
- _safeLocalValue(v: any): any;
33
- _initLocalTimes(): void;
34
- updateToday(): void;
35
- remain(): number;
36
- }
37
- export type IConstructorArgs = {
38
- /**
39
- * 初始化标识
40
- */
41
- sign?: string;
42
- /**
43
- * 本地存储标识
44
- */
45
- local_sign: string;
46
- /**
47
- * 总次数
48
- */
49
- total?: number;
50
- /**
51
- * 过期时间(毫秒)或'today'表示当天有效,可选
52
- */
53
- expire?: number | "today";
54
- /**
55
- * 用户ID
56
- */
57
- userId?: string | number;
58
- };
59
- import Storage from './Storage';
@@ -1,15 +0,0 @@
1
- export class EventEmitter {
2
- static geInstance(args: any): EventEmitter;
3
- constructor(options?: {});
4
- events: {};
5
- queues: {};
6
- onceEvents: {};
7
- maxListeners: any;
8
- maxQueueSize: any;
9
- maxOnceEvents: any;
10
- on(event: any, listener: any): void;
11
- once(event: any, listener: any): void;
12
- emit(event: any, ...args: any[]): void;
13
- off(event: any, listenerToRemove: any): void;
14
- removeAllListeners(event: any): void;
15
- }
@@ -1,35 +0,0 @@
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
- }