@singcl/ad-execute-manager 1.5.2 → 1.5.3

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.
Files changed (2) hide show
  1. package/README.md +200 -1
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1 +1,200 @@
1
- # AD Execute Manager
1
+ # AD Execute Manager
2
+
3
+ A powerful and flexible ad execution management library for handling reward-based ads, interstitial ads, and other advertising formats in JavaScript applications.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Features](#features)
8
+ - [Installation](#installation)
9
+ - [Usage](#usage)
10
+ - [API Reference](#api-reference)
11
+ - [Examples](#examples)
12
+ - [Contributing](#contributing)
13
+ - [License](#license)
14
+
15
+ ## Features
16
+
17
+ - **Unified Ad Execution**: Single interface for managing different types of ads
18
+ - **Task Queue Management**: Handles multiple ad execution tasks in a queue
19
+ - **Flexible Control**: Manual control over ad execution flow with `next` function
20
+ - **Error Handling**: Comprehensive error handling and logging
21
+ - **State Persistence**: Built-in storage for ad state management
22
+ - **Analytics Integration**: Built-in analytics support
23
+ - **Middleware Pattern**: Uses middleware pattern for ad execution flow
24
+ - **Cancellation Support**: Ability to clear and cancel pending tasks
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ npm install @singcl/ad-execute-manager
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ ### Basic Usage
35
+
36
+ ```javascript
37
+ import { AdExecuteManager, RewardAdFather } from '@singcl/ad-execute-manager';
38
+
39
+ // Get the singleton instance
40
+ const adManager = AdExecuteManager.getInstance();
41
+
42
+ // Create an ad instance (extend RewardAdFather)
43
+ class MyRewardAd extends RewardAdFather {
44
+ async ad(ctx, next) {
45
+ // Your ad logic here
46
+ console.log('Executing reward ad');
47
+
48
+ // Call next when ready to proceed
49
+ await next();
50
+
51
+ return { success: true, message: 'Ad executed successfully' };
52
+ }
53
+ }
54
+
55
+ // Create ad instance
56
+ const myAd = new MyRewardAd();
57
+
58
+ // Add task to execution queue
59
+ const result = await adManager.addTask(myAd, {
60
+ options: { /* ad options */ },
61
+ collection: { /* callback collection */ }
62
+ });
63
+ ```
64
+
65
+ ### Advanced Usage
66
+
67
+ ```javascript
68
+ import { AdExecuteManager, RewardAdSceneTriggerManager } from '@singcl/ad-execute-manager';
69
+
70
+ // Initialize with logging enabled
71
+ const adManager = AdExecuteManager.getInstance({ log: true });
72
+
73
+ // Check if manager is running
74
+ if (adManager.isRunning()) {
75
+ console.log('Ad manager is currently executing tasks');
76
+ }
77
+
78
+ // Get current task ID
79
+ const currentTaskId = adManager.getCurrentTaskId();
80
+
81
+ // Get total number of pending tasks
82
+ const taskCount = adManager.getTaskCount();
83
+
84
+ // Wait for all tasks to complete
85
+ await adManager.whenAllTasksComplete();
86
+
87
+ // Clear all pending tasks
88
+ adManager.clearTasks();
89
+ ```
90
+
91
+ ## API Reference
92
+
93
+ ### AdExecuteManager
94
+
95
+ The main class for managing ad execution flow.
96
+
97
+ #### Methods
98
+
99
+ - `getInstance(args)`: Get the singleton instance of AdExecuteManager
100
+ - `getSafeInstance()`: Get the instance, returns null if not initialized
101
+ - `addTask(adInstance, ctx)`: Add an ad task to the execution queue
102
+ - `clearTasks()`: Cancel all pending tasks
103
+ - `getTaskCount()`: Get the number of pending tasks
104
+ - `isRunning()`: Check if tasks are currently running
105
+ - `getCurrentTaskId()`: Get the ID of the current executing task
106
+ - `whenAllTasksComplete()`: Returns a Promise that resolves when all tasks are complete
107
+
108
+ ### RewardAdFather
109
+
110
+ Base class for reward ad implementations.
111
+
112
+ ### InterstitialAdFather
113
+
114
+ Base class for interstitial ad implementations.
115
+
116
+ ### Other Exports
117
+
118
+ - `SerializableError`: Error class that can be serialized
119
+ - `Logger`: Logging utility
120
+ - `Storage`: Storage management
121
+ - `CountRecorder`: Ad execution counter
122
+ - `RewardAdGlobalRecorder`: Global ad recorder
123
+ - `RewardAdSceneTriggerManager`: Scene-based ad trigger manager
124
+ - `AdAnalyticsJS`: Analytics integration
125
+ - `RewardAdNovel`: Novel-specific reward ad implementation
126
+ - `InterstitialAdNovel`: Novel-specific interstitial ad implementation
127
+ - `PubSub`: Publish-subscribe pattern implementation
128
+
129
+ ## Examples
130
+
131
+ ### Reward Ad Unlock
132
+
133
+ ```javascript
134
+ import { AdExecuteManager, RewardAdFather } from '@singcl/ad-execute-manager';
135
+
136
+ class UnlockAd extends RewardAdFather {
137
+ async ad(ctx, next) {
138
+ const { options, collection } = ctx;
139
+
140
+ try {
141
+ // Show reward ad
142
+ const result = await this.showAd();
143
+
144
+ if (result.isRewarded) {
145
+ // Execute success callback
146
+ collection.onSuccess && collection.onSuccess(result);
147
+
148
+ // Proceed to next task
149
+ await next();
150
+
151
+ return { success: true, data: result };
152
+ } else {
153
+ // Ad not completed
154
+ collection.onCancel && collection.onCancel();
155
+ return { success: false, message: 'Ad not completed' };
156
+ }
157
+ } catch (error) {
158
+ collection.onError && collection.onError(error);
159
+ throw error;
160
+ }
161
+ }
162
+ }
163
+
164
+ const adManager = AdExecuteManager.getInstance();
165
+ const unlockAd = new UnlockAd();
166
+
167
+ await adManager.addTask(unlockAd, {
168
+ options: { /* ad options */ },
169
+ collection: {
170
+ onSuccess: () => console.log('Reward received!'),
171
+ onCancel: () => console.log('Ad cancelled'),
172
+ onError: (error) => console.error('Ad error:', error)
173
+ }
174
+ });
175
+ ```
176
+
177
+ More examples can be found in the [examples](./example/) directory.
178
+
179
+ ## Contributing
180
+
181
+ We welcome contributions to this project! Please follow these steps:
182
+
183
+ 1. Fork the repository
184
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
185
+ 3. Make your changes
186
+ 4. Commit your changes (`git commit -m 'Add some amazing feature'`)
187
+ 5. Push to the branch (`git push origin feature/amazing-feature`)
188
+ 6. Open a Pull Request
189
+
190
+ ### Development Scripts
191
+
192
+ - `npm run build`: Build the library for production
193
+ - `npm run dev`: Turn on watch mode
194
+ - `npm run lint`: Lint your code
195
+ - `npm run format`: Format your code
196
+ - `npm run test`: Run tests
197
+
198
+ ## License
199
+
200
+ This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@singcl/ad-execute-manager",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {