adsbooster-js-sdk 0.0.0-stage → 1.2.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.
- package/LICENSE +21 -0
- package/README.md +269 -3
- package/dist/adsbooster.js +630 -0
- package/dist/adsbooster.mjs +612 -0
- package/examples/browser-ugc.html +54 -0
- package/examples/express-webhooks.js +45 -0
- package/examples/node-create-campaign.js +52 -0
- package/examples/node-smoke-test.js +55 -0
- package/package.json +82 -4
- package/src/adsbooster.js +630 -0
- package/types/index.d.ts +260 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Adsbooster.net Engineering Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,269 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# Adsbooster JavaScript SDK
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/adsbooster-js-sdk)
|
|
4
|
+
[](https://www.npmjs.com/package/adsbooster-js-sdk)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
Official JavaScript / TypeScript client for the **Adsbooster.net REST API v1** — built for SaaS teams that want AI ad creatives, multi-network campaign management, social publishing and server-side conversion tracking inside their own product.
|
|
8
|
+
|
|
9
|
+
- **Zero dependencies** — one small file, works in Node.js (≥18) and modern browsers
|
|
10
|
+
- **Typed** — ships complete TypeScript definitions
|
|
11
|
+
- **Resilient** — automatic retries on `429`/`5xx`, timeout via `AbortController`, rate-limit telemetry on every response
|
|
12
|
+
- **Universal** — UMD (`dist/adsbooster.js`), ESM (`dist/adsbooster.mjs`)
|
|
13
|
+
- **Optional integrations** — Flutterwave, Google Gemini and Groq ship alongside the SDK and load lazily
|
|
14
|
+
|
|
15
|
+
> **Published:** [`adsbooster-js-sdk` on npm](https://www.npmjs.com/package/adsbooster-js-sdk) — `npm install adsbooster-js-sdk`
|
|
16
|
+
> SDK repo: https://github.com/FushionHub/adsbooster-js-sdk
|
|
17
|
+
> Platform repo: https://github.com/FushionHub/adbooster_net
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
**npm / yarn / pnpm**
|
|
24
|
+
```bash
|
|
25
|
+
npm install adsbooster-js-sdk
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**Browser (CDN or self-hosted from your Adsbooster deployment)**
|
|
29
|
+
```html
|
|
30
|
+
<!-- Self-hosted — served straight from your platform, always in sync -->
|
|
31
|
+
<script src="https://adsbooster.net/api/v1/sdk/adsbooster.js"></script>
|
|
32
|
+
|
|
33
|
+
<!-- or jsDelivr (npm CDN) -->
|
|
34
|
+
<script src="https://cdn.jsdelivr.net/npm/adsbooster-js-sdk/dist/adsbooster.js"></script>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Quick start
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
const { Adsbooster } = require('adsbooster-js-sdk'); // Node
|
|
41
|
+
// import { Adsbooster } from 'adsbooster-js-sdk'; // ESM / TS
|
|
42
|
+
// const Adsbooster = window.Adsbooster.Adsbooster; // Browser <script>
|
|
43
|
+
|
|
44
|
+
const client = new Adsbooster({
|
|
45
|
+
apiKey: process.env.ADSBOOSTER_API_KEY, // from Developer Console → api-settings
|
|
46
|
+
// baseUrl: 'https://adsbooster.net', // default; change for self-hosted
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// 1) Check wallet balance
|
|
50
|
+
const balance = await client.credits.balance();
|
|
51
|
+
console.log(balance.ad_credits, balance.ai_credits);
|
|
52
|
+
|
|
53
|
+
// 2) Generate an AI UGC creative (Nano Banana 2 image stack)
|
|
54
|
+
const creative = await client.ugc.generateImage({
|
|
55
|
+
product_name: 'Cloud-Knit Running Shoes',
|
|
56
|
+
ugc_style: 'selfie_hold',
|
|
57
|
+
creator_persona: 'gen_z',
|
|
58
|
+
aspect_ratio: '1:1',
|
|
59
|
+
});
|
|
60
|
+
console.log(creative.creative.image_url);
|
|
61
|
+
|
|
62
|
+
// 3) Launch a campaign across connected networks
|
|
63
|
+
const campaign = await client.campaigns.create({
|
|
64
|
+
name: 'Q4 Sneaker Drop',
|
|
65
|
+
platform: 'meta',
|
|
66
|
+
objective: 'conversions',
|
|
67
|
+
budget_amount: 25,
|
|
68
|
+
budget_type: 'daily',
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// 4) Publish a post live to social
|
|
72
|
+
await client.posts.create({
|
|
73
|
+
platform: 'tiktok',
|
|
74
|
+
caption: 'New drop 🚀 link in bio #ad',
|
|
75
|
+
media_url: creative.creative.image_url,
|
|
76
|
+
media_type: 'image',
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## API surface
|
|
81
|
+
|
|
82
|
+
| Namespace | Methods | Endpoint |
|
|
83
|
+
|---|---|---|
|
|
84
|
+
| `client.campaigns` | `list({page,limit,status})` · `get(id)` · `create(payload)` · `update(id,payload)` · `pause(id)` · `resume(id)` | `/api/v1/campaigns.php` |
|
|
85
|
+
| `client.posts` | `list({page,limit,status})` · `get(id)` · `create(payload)` · `remove(id)` | `/api/v1/posts.php` |
|
|
86
|
+
| `client.ugc` | `generateImage(payload)` · `listRecent({limit})` | `/api/v1/ugc.php` |
|
|
87
|
+
| `client.credits` | `balance()` | `/api/v1/credits.php` |
|
|
88
|
+
| `client.directory` | `list({category,q,limit})` · `createListing(payload)` | `/api/v1/directory.php` |
|
|
89
|
+
| `client.reviews` | `list({limit})` · `submit({rating,review_text,…})` | `/api/v1/reviews.php` |
|
|
90
|
+
| `client.capi` | `scriptUrl()` · `track({pixel_token,event_name,…})` | `/api/v1/capi-bridge.php` |
|
|
91
|
+
| `client.webhooks` | `list()` · `test(url)` — signed ping to YOUR registered https endpoint | `/api/v1/webhooks.php` |
|
|
92
|
+
| `client.publicAnalytics` | `feed(view?)` · `totals()` — public aggregate, no auth (30 req/min/IP) | `/api/v1/public-analytics.php` |
|
|
93
|
+
|
|
94
|
+
Every response is the raw API payload (`{ success: true, … }`). Non-2xx responses throw an [`AdsboosterError`](#error-handling).
|
|
95
|
+
|
|
96
|
+
## Optional integrations (Flutterwave · Gemini · Groq)
|
|
97
|
+
|
|
98
|
+
The SDK ships with the integration packages the platform itself uses, declared in
|
|
99
|
+
`package.json` as **optional dependencies + optional peers**:
|
|
100
|
+
|
|
101
|
+
| Package | Version | Used for |
|
|
102
|
+
|---|---|---|
|
|
103
|
+
| [`flutterwave`](https://www.npmjs.com/package/flutterwave) | `^2.2.8` | server-side payment tooling next to the Adsbooster checkout |
|
|
104
|
+
| [`@google/genai`](https://www.npmjs.com/package/@google/genai) | `^3.2.0` | Google Gemini (text + image generation) |
|
|
105
|
+
| [`groq-sdk`](https://www.npmjs.com/package/groq-sdk) | `^1.6.0` | Groq chat completions |
|
|
106
|
+
|
|
107
|
+
They are **never imported by the core client** — the browser/UMD build stays
|
|
108
|
+
dependency-free and nothing loads until you call an integration. They are
|
|
109
|
+
installed automatically with `npm install adsbooster-js-sdk`; skip them with
|
|
110
|
+
`npm install adsbooster-js-sdk --omit=optional`.
|
|
111
|
+
|
|
112
|
+
```js
|
|
113
|
+
const { Adsbooster } = require('adsbooster-js-sdk');
|
|
114
|
+
|
|
115
|
+
const client = new Adsbooster({ apiKey: process.env.ADSBOOSTER_API_KEY });
|
|
116
|
+
|
|
117
|
+
// Which optional packages are present right now?
|
|
118
|
+
client.integrations.detect();
|
|
119
|
+
// { gemini: true, flutterwave: true, groq: true }
|
|
120
|
+
|
|
121
|
+
// Google Gemini (Node.js)
|
|
122
|
+
const { text } = await client.integrations.geminiGenerateText({
|
|
123
|
+
prompt: 'Write 3 ad headlines for running shoes',
|
|
124
|
+
apiKey: process.env.GEMINI_API_KEY,
|
|
125
|
+
model: 'gemini-2.5-flash',
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// Groq chat completions
|
|
129
|
+
const completion = await client.integrations.groqChat({
|
|
130
|
+
messages: [{ role: 'user', content: 'Summarise this campaign report' }],
|
|
131
|
+
apiKey: process.env.GROQ_API_KEY,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// Flutterwave client (server-side only)
|
|
135
|
+
const flw = await client.integrations.flutterwaveClient({
|
|
136
|
+
publicKey: process.env.FLW_PUBLIC_KEY,
|
|
137
|
+
secretKey: process.env.FLW_SECRET_KEY,
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
> Payments for Adsbooster checkouts are still verified **on the platform** —
|
|
142
|
+
> `client.integrations.flutterwaveClient()` is for building your own Flutterwave
|
|
143
|
+
> tooling alongside the SDK, not for replacing checkout verification.
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Error handling
|
|
148
|
+
|
|
149
|
+
```js
|
|
150
|
+
const { Adsbooster, AdsboosterError } = require('adsbooster-js-sdk');
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
await client.ugc.generateImage({ product_name: '…' });
|
|
154
|
+
} catch (err) {
|
|
155
|
+
if (err instanceof AdsboosterError) {
|
|
156
|
+
console.error(err.status); // 401, 429, 500… (0 = network/timeout)
|
|
157
|
+
console.error(err.code); // 'Unauthorized', 'RateLimitExceeded'…
|
|
158
|
+
console.error(err.rateLimit); // { limit: 60, remaining: 0, reset: 1768… }
|
|
159
|
+
if (err.isRateLimit) {
|
|
160
|
+
await new Promise(r => setTimeout(r, 60_000)); // or rely on auto-retry
|
|
161
|
+
}
|
|
162
|
+
} else {
|
|
163
|
+
throw err;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Rate limits
|
|
169
|
+
The platform enforces **60 requests / minute / key** (sliding window). The SDK:
|
|
170
|
+
- reads `X-RateLimit-*` headers on **every** response into `client.lastRateLimit`
|
|
171
|
+
- **auto-retries** `429` honoring `Retry-After` / `X-RateLimit-Reset`, and `5xx` with exponential backoff (default `maxRetries: 2`)
|
|
172
|
+
|
|
173
|
+
```js
|
|
174
|
+
const client = new Adsbooster({ apiKey, maxRetries: 4, timeout: 60000 });
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Webhooks (server-side)
|
|
178
|
+
|
|
179
|
+
Outbound webhooks (`campaign.status_changed`, `post.published`, `payment.completed`) are signed with `X-Adsbooster-Signature: sha256=<hmac>` — verify with the raw body:
|
|
180
|
+
|
|
181
|
+
```js
|
|
182
|
+
const express = require('express');
|
|
183
|
+
const { webhooks } = require('adsbooster-js-sdk');
|
|
184
|
+
|
|
185
|
+
app.post('/adsbooster/webhook', express.raw({ type: '*/*' }), (req, res) => {
|
|
186
|
+
const ok = webhooks.verify(
|
|
187
|
+
req.body, // RAW body (Buffer/string)
|
|
188
|
+
req.get('X-Adsbooster-Signature') || '',
|
|
189
|
+
process.env.WEBHOOK_SECRET // per-endpoint secret from api-settings
|
|
190
|
+
);
|
|
191
|
+
if (!ok) return res.status(401).send('bad signature');
|
|
192
|
+
const event = JSON.parse(req.body.toString('utf8'));
|
|
193
|
+
console.log(event.event, event.data);
|
|
194
|
+
res.sendStatus(200);
|
|
195
|
+
});
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## Server-side conversion tracking (Meta CAPI / TikTok Events)
|
|
199
|
+
|
|
200
|
+
```js
|
|
201
|
+
// Browser: drop-in script (no SDK needed)
|
|
202
|
+
// <script src="https://adsbooster.net/api/v1/capi-bridge.php?js=1"></script>
|
|
203
|
+
// <script>window._adsbooster_token='px_live_…'; AdsboosterTrack('Purchase',{value:49.99,currency:'USD'});</script>
|
|
204
|
+
|
|
205
|
+
// Server-side from your SaaS:
|
|
206
|
+
await client.capi.track({
|
|
207
|
+
pixel_token: 'px_live_…',
|
|
208
|
+
event_name: 'Purchase',
|
|
209
|
+
event_id: 'order_8841',
|
|
210
|
+
custom_data: { value: 49.99, currency: 'USD' },
|
|
211
|
+
user_data: { email_hash: sha256(email) },
|
|
212
|
+
});
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## Examples
|
|
216
|
+
|
|
217
|
+
runnable scripts live in [`examples/`](examples/):
|
|
218
|
+
|
|
219
|
+
- `examples/node-smoke-test.js` — end-to-end smoke test against a live deployment
|
|
220
|
+
- `examples/node-create-campaign.js` — campaign lifecycle (create → pause → resume)
|
|
221
|
+
- `examples/browser-ugc.html` — generate an AI creative from a web page
|
|
222
|
+
- `examples/express-webhooks.js` — verify signed webhooks in Express
|
|
223
|
+
|
|
224
|
+
## TypeScript
|
|
225
|
+
|
|
226
|
+
Full definitions ship in `types/index.d.ts`:
|
|
227
|
+
|
|
228
|
+
```ts
|
|
229
|
+
import { Adsbooster, AdsboosterError } from 'adsbooster-js-sdk';
|
|
230
|
+
const client = new Adsbooster({ apiKey: process.env.ADSBOOSTER_API_KEY! });
|
|
231
|
+
const res = await client.campaigns.list({ status: 'active', limit: 50 });
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Getting an API key
|
|
235
|
+
|
|
236
|
+
1. Sign up / log in on your Adsbooster deployment
|
|
237
|
+
2. Open **Developer Console** (`/api-settings`)
|
|
238
|
+
3. Generate a key (`adsb_live_…`) — optionally restrict it to your server IPs
|
|
239
|
+
4. Fund ad/AI credits from **Billing & Wallet** (top-ups from $2.50)
|
|
240
|
+
|
|
241
|
+
## Releasing a new version
|
|
242
|
+
|
|
243
|
+
Publishing is automated with **npm Trusted Publishing (OIDC)** — no long-lived
|
|
244
|
+
token is stored in GitHub.
|
|
245
|
+
|
|
246
|
+
1. Bump the version and rebuild:
|
|
247
|
+
```bash
|
|
248
|
+
npm version 1.2.0 # updates package.json + creates a git tag
|
|
249
|
+
npm run build:esm # regenerate dist/adsbooster.mjs
|
|
250
|
+
npm test
|
|
251
|
+
git push --follow-tags
|
|
252
|
+
```
|
|
253
|
+
2. Create a GitHub release for the tag — the `Publish` workflow publishes to npm
|
|
254
|
+
with provenance automatically.
|
|
255
|
+
|
|
256
|
+
One-time setup on npmjs.com: **Package → Settings → Trusted Publisher → GitHub
|
|
257
|
+
Actions** → owner `FushionHub`, repository `adsbooster-js-sdk`, workflow
|
|
258
|
+
`publish.yml`.
|
|
259
|
+
|
|
260
|
+
Local publishing (no CI):
|
|
261
|
+
|
|
262
|
+
```bash
|
|
263
|
+
npm login
|
|
264
|
+
npm publish --access public
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
## License
|
|
268
|
+
|
|
269
|
+
[MIT](LICENSE) © Adsbooster.net Engineering Team
|