Skip to content

Commit f2604d6

Browse files
committed
fixes
1 parent 00d0798 commit f2604d6

File tree

5 files changed

+90
-85
lines changed

5 files changed

+90
-85
lines changed

js/botasaurus-desktop-api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "botasaurus-desktop-api",
3-
"version": "4.1.45",
3+
"version": "4.1.46",
44
"description": "The Botasaurus Desktop API Client provides programmatic access to Botasaurus Desktop scrapers with a developer-friendly API.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

js/botasaurus-js/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/botasaurus-js/package.json

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,88 @@
11
{
22
"name": "botasaurus",
3-
"version": "4.0.103",
3+
"version": "4.0.110",
44
"description": "controls adder for botasaurus.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
77
"exports": {
88
".": "./dist/index.js",
9-
"./increment": "./dist/increment.js",
10-
"./env": "./dist/env.js",
11-
"./page": "./dist/page.js",
12-
"./decorators-utils": "./dist/decorators-utils.js",
13-
"./list-utils": "./dist/list-utils.js",
14-
"./string-utils": "./dist/string-utils.js",
159
"./output": "./dist/output.js",
16-
"./decorators-common": "./dist/decorators-common.js",
17-
"./beep-utils": "./dist/beep-utils.js",
18-
"./formats": "./dist/formats.js",
19-
"./task": "./dist/task.js",
10+
"./list-utils": "./dist/list-utils.js",
2011
"./botasaurus-storage": "./dist/botasaurus-storage.js",
21-
"./utils": "./dist/utils.js",
22-
"./playwright": "./dist/playwright.js",
12+
"./decorators-common": "./dist/decorators-common.js",
2313
"./on-close": "./dist/on-close.js",
2414
"./dontcache": "./dist/dontcache.js",
15+
"./formats": "./dist/formats.js",
16+
"./utils": "./dist/utils.js",
17+
"./beep-utils": "./dist/beep-utils.js",
18+
"./decorators-utils": "./dist/decorators-utils.js",
19+
"./page": "./dist/page.js",
2520
"./cache": "./dist/cache.js",
26-
"./paths": "./dist/paths.js"
21+
"./increment": "./dist/increment.js",
22+
"./paths": "./dist/paths.js",
23+
"./env": "./dist/env.js",
24+
"./playwright": "./dist/playwright.js",
25+
"./string-utils": "./dist/string-utils.js",
26+
"./task": "./dist/task.js"
2727
},
2828
"typesVersions": {
2929
"*": {
3030
"*": [
3131
"dist/*"
3232
],
33-
"increment": [
34-
"dist/increment.d.ts"
35-
],
36-
"env": [
37-
"dist/env.d.ts"
38-
],
39-
"page": [
40-
"dist/page.d.ts"
41-
],
42-
"decorators-utils": [
43-
"dist/decorators-utils.d.ts"
33+
"output": [
34+
"dist/output.d.ts"
4435
],
4536
"list-utils": [
4637
"dist/list-utils.d.ts"
4738
],
48-
"string-utils": [
49-
"dist/string-utils.d.ts"
50-
],
51-
"output": [
52-
"dist/output.d.ts"
39+
"botasaurus-storage": [
40+
"dist/botasaurus-storage.d.ts"
5341
],
5442
"decorators-common": [
5543
"dist/decorators-common.d.ts"
5644
],
57-
"beep-utils": [
58-
"dist/beep-utils.d.ts"
45+
"on-close": [
46+
"dist/on-close.d.ts"
47+
],
48+
"dontcache": [
49+
"dist/dontcache.d.ts"
5950
],
6051
"formats": [
6152
"dist/formats.d.ts"
6253
],
63-
"task": [
64-
"dist/task.d.ts"
65-
],
66-
"botasaurus-storage": [
67-
"dist/botasaurus-storage.d.ts"
68-
],
6954
"utils": [
7055
"dist/utils.d.ts"
7156
],
72-
"playwright": [
73-
"dist/playwright.d.ts"
57+
"beep-utils": [
58+
"dist/beep-utils.d.ts"
7459
],
75-
"on-close": [
76-
"dist/on-close.d.ts"
60+
"decorators-utils": [
61+
"dist/decorators-utils.d.ts"
7762
],
78-
"dontcache": [
79-
"dist/dontcache.d.ts"
63+
"page": [
64+
"dist/page.d.ts"
8065
],
8166
"cache": [
8267
"dist/cache.d.ts"
8368
],
69+
"increment": [
70+
"dist/increment.d.ts"
71+
],
8472
"paths": [
8573
"dist/paths.d.ts"
74+
],
75+
"env": [
76+
"dist/env.d.ts"
77+
],
78+
"playwright": [
79+
"dist/playwright.d.ts"
80+
],
81+
"string-utils": [
82+
"dist/string-utils.d.ts"
83+
],
84+
"task": [
85+
"dist/task.d.ts"
8686
]
8787
}
8888
},
@@ -132,7 +132,7 @@
132132
"scripts": {
133133
"dev": "tsc -w",
134134
"build": "rimraf dist tsconfig.tsbuildinfo && tsc && rimraf tsconfig.tsbuildinfo",
135-
"build-mv": "npm run build && mv -f ~/Documents/grow/botasaurus-js/dist/* ~/Documents/google-maps-extractor-desktop/node_modules/botasaurus/dist/",
135+
"build-mv": "npm run build && mv -f ~/Documents/grow/botasaurus/js/botasaurus-js/dist/* ~/Documents/botasaurus-desktop-starter/node_modules/botasaurus/dist/",
136136
"clean": "rimraf dist tsconfig.tsbuildinfo",
137137
"clean-install": "rm -rf dist/ node_modules/ package-lock.json yarn.lock .next/* && npm install",
138138
"prepublishOnly": "npm run build",

js/botasaurus-server-js/src/api-config.ts

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ function addCorsHeaders(reply: any) {
3333
reply.header("Access-Control-Allow-Headers", "Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token");
3434
}
3535

36-
function sendJson(reply: any, result: any) {
37-
return reply.type("application/json").send(result);
38-
}
3936
function addScraperRoutes(app:FastifyInstance) {
4037
Object.values(Server.scrapers).forEach(scraper => {
4138
const routePath = `/${kebabCase(scraper.scraper_name)}`
@@ -65,7 +62,7 @@ function addScraperRoutes(app:FastifyInstance) {
6562
if (DirectCallCacheService.has(cacheKey)) {
6663
try {
6764
const cachedResult = DirectCallCacheService.get(cacheKey)
68-
return sendJson(reply, cachedResult ?? { result: null })
65+
return cachedResult ?? { result: null }
6966
} catch (error) {
7067
console.error(error)
7168
// Continue with normal execution if cache fails
@@ -115,7 +112,7 @@ function addScraperRoutes(app:FastifyInstance) {
115112
}
116113
}
117114

118-
return sendJson(reply, finalResults ?? { result: null })
115+
return finalResults ?? { result: null }
119116
} finally {
120117
executor.decrementCapacity(key)
121118
}
@@ -171,46 +168,46 @@ export function buildApp(scrapers:any[]): FastifyInstance {
171168
return reply.type('text/html').send(html);
172169
});
173170

174-
app.post("/tasks/create-task-async", async (request, reply) => {
171+
app.post("/tasks/create-task-async", async (request, _) => {
175172
const jsonData = request.body;
176173
const result = await createAsyncTask(jsonData);
177-
return sendJson(reply, result);
174+
return result;
178175
});
179176

180-
app.post("/tasks/create-task-sync", async (request, reply) => {
177+
app.post("/tasks/create-task-sync", async (request, _) => {
181178
const jsonData = request.body;
182179
const result = await createSyncTask(jsonData);
183-
return sendJson(reply, result);
180+
return result;
184181
});
185182

186-
app.get("/tasks", async (request, reply) => {
183+
app.get("/tasks", async (request, _) => {
187184
const queryParams = request.query;
188185
const result = await getTasks(queryParams);
189-
return sendJson(reply, result);
186+
return result;
190187
});
191188

192189
app.get(
193190
"/tasks/:taskId",
194191
async (
195192
request: FastifyRequest<{ Params: { taskId: number } }>,
196-
reply
193+
_
197194
) => {
198195
const taskId = request.params.taskId;
199196
const result = await getTask(taskId);
200-
return sendJson(reply, result);
197+
return result;
201198
}
202199
);
203200

204201
app.post(
205202
"/tasks/:taskId/results",
206203
async (
207204
request: FastifyRequest<{ Params: { taskId: number }; Body: any }>,
208-
reply
205+
_
209206
) => {
210207
const taskId = request.params.taskId;
211208
const jsonData = request.body;
212209
const results = await getTaskResults(taskId, jsonData);
213-
return sendJson(reply, results);
210+
return results;
214211
}
215212
);
216213

@@ -230,67 +227,64 @@ export function buildApp(scrapers:any[]): FastifyInstance {
230227
"/tasks/:taskId/abort",
231228
async (
232229
request: FastifyRequest<{ Params: { taskId: number } }>,
233-
reply
230+
_
234231
) => {
235232

236233
const taskId = request.params.taskId;
237234
const result = await abortSingleTask(taskId);
238-
return sendJson(reply, result);
235+
return result;
239236
}
240237
);
241238

242239
app.delete(
243240
"/tasks/:taskId",
244241
async (
245242
request: FastifyRequest<{ Params: { taskId: number } }>,
246-
reply
243+
_
247244
) => {
248245
const taskId = request.params.taskId;
249246
const result = await deleteSingleTask(taskId);
250-
return sendJson(reply, result);
247+
return result;
251248
}
252249
);
253250

254-
app.post("/tasks/bulk-abort", async (request, reply) => {
251+
app.post("/tasks/bulk-abort", async (request, _) => {
255252
const jsonData = request.body;
256253
const result = await bulkAbortTasks(jsonData);
257-
return sendJson(reply, result);
254+
return result;
258255
});
259256

260-
app.post("/tasks/bulk-delete", async (request, reply) => {
257+
app.post("/tasks/bulk-delete", async (request, _) => {
261258
const jsonData = request.body;
262259
const result = await bulkDeleteTasks(jsonData);
263-
return sendJson(reply, result);
260+
return result;
264261
});
265262

266-
app.get("/ui/app-props", (_, reply) => {
267-
const result = getAppProps();
268-
return sendJson(reply, result);
269-
});
263+
app.get("/ui/app-props", getAppProps);
270264

271-
app.post("/ui/tasks/is-any-task-updated", async (request, reply) => {
265+
app.post("/ui/tasks/is-any-task-updated", async (request, _) => {
272266
const jsonData = request.body;
273267
const result = await isAnyTaskUpdated(jsonData);
274-
return sendJson(reply, result);
268+
return result;
275269
});
276270

277-
app.post("/ui/tasks/is-task-updated", async (request, reply) => {
271+
app.post("/ui/tasks/is-task-updated", async (request, _) => {
278272
const jsonData = request.body;
279273
const result = await isTaskUpdated(jsonData);
280-
return sendJson(reply, result);
274+
return result;
281275
});
282276

283-
app.get("/ui/tasks", async (request, reply) => {
277+
app.get("/ui/tasks", async (request, _) => {
284278
const queryParams = request.query;
285279
const result = await getTasksForUiDisplay(queryParams);
286-
return sendJson(reply, result);
280+
return result;
287281
});
288282

289-
app.patch("/ui/tasks", async (request, reply) => {
283+
app.patch("/ui/tasks", async (request, _) => {
290284
const queryParams = request.query;
291285
const jsonData = request.body;
292286
const result = await patchTask(queryParams, jsonData);
293-
return sendJson(reply, result);
287+
return result;
294288
});
295289

296290
app.post(
@@ -301,13 +295,13 @@ export function buildApp(scrapers:any[]): FastifyInstance {
301295
Body: any;
302296
Querystring: any;
303297
}>,
304-
reply
298+
_
305299
) => {
306300
const taskId = request.params.taskId;
307301
const jsonData = request.body;
308302
const queryParams = request.query;
309303
const final = await getUiTaskResults(taskId, queryParams, jsonData);
310-
return sendJson(reply, final);
304+
return final;
311305
}
312306
);
313307

js/botasaurus-server-js/src/server.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,17 @@ class _Server {
137137
}
138138

139139
addWhatsAppSupport(options: WhatsAppSupportOptions) {
140+
if (options.number.length !== 10) {
141+
throw new Error('The WhatsApp number must be exactly 10 characters long.');
142+
}
143+
144+
if (options.countryCallingCode.length < 1) {
145+
throw new Error('The country calling code must be at least 1 character long.');
146+
}
147+
148+
if (options.countryCallingCode.includes('+')) {
149+
throw new Error('The country calling code must not contain a plus sign (+).');
150+
}
140151
this.whatsAppSupport = options;
141152
}
142153

0 commit comments

Comments
 (0)