botasaurus-desktop-api 4.1.85 → 4.1.87

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/dist/bundle.js CHANGED
@@ -2864,11 +2864,11 @@ function cleanBasePath(apiBasePath) {
2864
2864
  }
2865
2865
  class Api {
2866
2866
  _writeJson(filename, data) {
2867
- /**
2868
- * Writes data to a JSON file specified by the filename. This method only runs if the createResponseFiles flag is True.
2869
- *
2870
- * @param filename The filename for the JSON file to be created.
2871
- * @param data The data to be written to the file.
2867
+ /**
2868
+ * Writes data to a JSON file specified by the filename. This method only runs if the createResponseFiles flag is True.
2869
+ *
2870
+ * @param filename The filename for the JSON file to be created.
2871
+ * @param data The data to be written to the file.
2872
2872
  */ if (this._createResponseFiles) {
2873
2873
  const path = _createFilename(filename);
2874
2874
  (0,_utils__WEBPACK_IMPORTED_MODULE_0__.writeJsonResponse)(path, data);
@@ -2878,11 +2878,16 @@ class Api {
2878
2878
  _makeApiUrl(path) {
2879
2879
  return `${this._apiUrl}${this._apiBasePath}${path === '' && this._apiBasePath ? "" : "/"}${path}`;
2880
2880
  }
2881
+ _getCacheParams() {
2882
+ return typeof this._enableCache === 'boolean' ? {
2883
+ enable_cache: this._enableCache
2884
+ } : {};
2885
+ }
2881
2886
  async isApiRunning() {
2882
- /**
2883
- * Checks if the API is running by performing a health check on the "/api" endpoint.
2884
- *
2885
- * @return True if the health check is successful, otherwise False.
2887
+ /**
2888
+ * Checks if the API is running by performing a health check on the "/api" endpoint.
2889
+ *
2890
+ * @return True if the health check is successful, otherwise False.
2886
2891
  */ try {
2887
2892
  const response = await axios__WEBPACK_IMPORTED_MODULE_1__["default"].get(this._makeApiUrl(""));
2888
2893
  return response.status === 200;
@@ -2897,16 +2902,17 @@ const api = new Api({ apiUrl: 'https://example.com' })`);
2897
2902
  }
2898
2903
  async createAsyncTask(param) {
2899
2904
  let { data, scraperName } = param;
2900
- /**
2901
- * Submits an asynchronous task to the server.
2902
- *
2903
- * @param data The data to be received by the scraper.
2904
- * @param scraperName The name of the scraper to use for the task. If not provided, the server will use the default scraper.
2905
- * @return The created task object.
2905
+ /**
2906
+ * Submits an asynchronous task to the server.
2907
+ *
2908
+ * @param data The data to be received by the scraper.
2909
+ * @param scraperName The name of the scraper to use for the task. If not provided, the server will use the default scraper.
2910
+ * @return The created task object.
2906
2911
  */ const url = this._makeApiUrl("tasks/create-task-async");
2907
2912
  const payload = {
2908
2913
  data,
2909
- scraper_name: scraperName
2914
+ scraper_name: scraperName,
2915
+ ...this._getCacheParams()
2910
2916
  };
2911
2917
  try {
2912
2918
  const response = await axios__WEBPACK_IMPORTED_MODULE_1__["default"].post(url, payload);
@@ -2921,16 +2927,17 @@ const api = new Api({ apiUrl: 'https://example.com' })`);
2921
2927
  }
2922
2928
  async createSyncTask(param) {
2923
2929
  let { data, scraperName } = param;
2924
- /**
2925
- * Submits a synchronous task to the server.
2926
- *
2927
- * @param data The data to be received by the scraper.
2928
- * @param scraperName The name of the scraper to use for the task. If not provided, the server will use the default scraper.
2929
- * @return The created task object.
2930
+ /**
2931
+ * Submits a synchronous task to the server.
2932
+ *
2933
+ * @param data The data to be received by the scraper.
2934
+ * @param scraperName The name of the scraper to use for the task. If not provided, the server will use the default scraper.
2935
+ * @return The created task object.
2930
2936
  */ const url = this._makeApiUrl("tasks/create-task-sync");
2931
2937
  const payload = {
2932
2938
  data,
2933
- scraper_name: scraperName
2939
+ scraper_name: scraperName,
2940
+ ...this._getCacheParams()
2934
2941
  };
2935
2942
  try {
2936
2943
  const response = await axios__WEBPACK_IMPORTED_MODULE_1__["default"].post(url, payload);
@@ -2945,16 +2952,17 @@ const api = new Api({ apiUrl: 'https://example.com' })`);
2945
2952
  }
2946
2953
  async createAsyncTasks(param) {
2947
2954
  let { dataItems, scraperName } = param;
2948
- /**
2949
- * Submits multiple asynchronous tasks to the server in a batch.
2950
- *
2951
- * @param dataItems A list of data items to be processed by the scraper.
2952
- * @param scraperName The name of the scraper to use for the tasks. If not provided, the server will use the default scraper.
2953
- * @return A list of created task objects.
2955
+ /**
2956
+ * Submits multiple asynchronous tasks to the server in a batch.
2957
+ *
2958
+ * @param dataItems A list of data items to be processed by the scraper.
2959
+ * @param scraperName The name of the scraper to use for the tasks. If not provided, the server will use the default scraper.
2960
+ * @return A list of created task objects.
2954
2961
  */ const url = this._makeApiUrl("tasks/create-task-async");
2955
2962
  const payload = dataItems.map((data)=>({
2956
2963
  data,
2957
- scraper_name: scraperName
2964
+ scraper_name: scraperName,
2965
+ ...this._getCacheParams()
2958
2966
  }));
2959
2967
  try {
2960
2968
  const response = await axios__WEBPACK_IMPORTED_MODULE_1__["default"].post(url, payload);
@@ -2969,16 +2977,17 @@ const api = new Api({ apiUrl: 'https://example.com' })`);
2969
2977
  }
2970
2978
  async createSyncTasks(param) {
2971
2979
  let { dataItems, scraperName } = param;
2972
- /**
2973
- * Submits multiple synchronous tasks to the server in a batch and waits for the results.
2974
- *
2975
- * @param dataItems A list of data items to be processed by the scraper.
2976
- * @param scraperName The name of the scraper to use for the tasks. If not provided, the server will use the default scraper.
2977
- * @return A list of created task objects, each with its processing result.
2980
+ /**
2981
+ * Submits multiple synchronous tasks to the server in a batch and waits for the results.
2982
+ *
2983
+ * @param dataItems A list of data items to be processed by the scraper.
2984
+ * @param scraperName The name of the scraper to use for the tasks. If not provided, the server will use the default scraper.
2985
+ * @return A list of created task objects, each with its processing result.
2978
2986
  */ const url = this._makeApiUrl("tasks/create-task-sync");
2979
2987
  const payload = dataItems.map((data)=>({
2980
2988
  data,
2981
- scraper_name: scraperName
2989
+ scraper_name: scraperName,
2990
+ ...this._getCacheParams()
2982
2991
  }));
2983
2992
  try {
2984
2993
  const response = await axios__WEBPACK_IMPORTED_MODULE_1__["default"].post(url, payload);
@@ -2996,13 +3005,13 @@ const api = new Api({ apiUrl: 'https://example.com' })`);
2996
3005
  page: 1,
2997
3006
  withResults: true
2998
3007
  };
2999
- /**
3000
- * Fetches tasks from the server, with optional result inclusion, pagination, and filtering.
3001
- *
3002
- * @param page The page number for pagination.
3003
- * @param perPage The number of tasks to return per page.
3004
- * @param withResults Whether to include the task results in the response.
3005
- * @return A dictionary containing the task results and pagination information.
3008
+ /**
3009
+ * Fetches tasks from the server, with optional result inclusion, pagination, and filtering.
3010
+ *
3011
+ * @param page The page number for pagination.
3012
+ * @param perPage The number of tasks to return per page.
3013
+ * @param withResults Whether to include the task results in the response.
3014
+ * @return A dictionary containing the task results and pagination information.
3006
3015
  */ const url = this._makeApiUrl("tasks");
3007
3016
  const params = {
3008
3017
  with_results: withResults
@@ -3030,11 +3039,11 @@ const api = new Api({ apiUrl: 'https://example.com' })`);
3030
3039
  }
3031
3040
  }
3032
3041
  async getTask(taskId) {
3033
- /**
3034
- * Retrieves a specific task by ID.
3035
- *
3036
- * @param taskId The ID of the task to retrieve.
3037
- * @return The task object.
3042
+ /**
3043
+ * Retrieves a specific task by ID.
3044
+ *
3045
+ * @param taskId The ID of the task to retrieve.
3046
+ * @return The task object.
3038
3047
  */ const url = this._makeApiUrl(`tasks/${taskId}`);
3039
3048
  try {
3040
3049
  const response = await axios__WEBPACK_IMPORTED_MODULE_1__["default"].get(url);
@@ -3049,16 +3058,16 @@ const api = new Api({ apiUrl: 'https://example.com' })`);
3049
3058
  }
3050
3059
  async getTaskResults(param) {
3051
3060
  let { taskId, filters, sort, view, page = 1, perPage } = param;
3052
- /**
3053
- * Retrieves the results of a specific task.
3054
- *
3055
- * @param taskId The ID of the task.
3056
- * @param filters A dictionary of filters to apply to the task results, optional.
3057
- * @param sort The sort to apply to the task results, optional.
3058
- * @param view The view to apply to the task results, optional.
3059
- * @param page The page number to retrieve, default is 1.
3060
- * @param perPage The number of results to return per page. If perPage is not provided, all results are returned, optional.
3061
- * @return A dictionary containing the task results and pagination information if page and perPage are provided.
3061
+ /**
3062
+ * Retrieves the results of a specific task.
3063
+ *
3064
+ * @param taskId The ID of the task.
3065
+ * @param filters A dictionary of filters to apply to the task results, optional.
3066
+ * @param sort The sort to apply to the task results, optional.
3067
+ * @param view The view to apply to the task results, optional.
3068
+ * @param page The page number to retrieve, default is 1.
3069
+ * @param perPage The number of results to return per page. If perPage is not provided, all results are returned, optional.
3070
+ * @return A dictionary containing the task results and pagination information if page and perPage are provided.
3062
3071
  */ const url = this._makeApiUrl(`tasks/${taskId}/results`);
3063
3072
  const payload = {
3064
3073
  page
@@ -3086,19 +3095,23 @@ const api = new Api({ apiUrl: 'https://example.com' })`);
3086
3095
  }
3087
3096
  }
3088
3097
  async get(scraperName, data) {
3089
- /**
3090
- * Makes a direct GET request to the scraper endpoint, bypassing the task creating and scheduling system.
3091
- *
3092
- * @param scraperName The name of the scraper, which corresponds to the route path (e.g., "scrape-heading-task").
3093
- * @param data The data to be received by the scraper.
3094
- * @return The result from the scraper.
3098
+ /**
3099
+ * Makes a direct GET request to the scraper endpoint, bypassing the task creating and scheduling system.
3100
+ *
3101
+ * @param scraperName The name of the scraper, which corresponds to the route path (e.g., "scrape-heading-task").
3102
+ * @param data The data to be received by the scraper.
3103
+ * @return The result from the scraper.
3095
3104
  */ if (scraperName.startsWith('/')) {
3096
3105
  scraperName = scraperName.slice(1);
3097
3106
  }
3098
3107
  const url = this._makeApiUrl(scraperName);
3108
+ const params = {
3109
+ ...data,
3110
+ ...this._getCacheParams()
3111
+ };
3099
3112
  try {
3100
3113
  const response = await axios__WEBPACK_IMPORTED_MODULE_1__["default"].get(url, {
3101
- params: data
3114
+ params
3102
3115
  });
3103
3116
  const fileScraperName = scraperName.replaceAll('/', '-');
3104
3117
  this._writeJson(`${fileScraperName}-result`, response.data);
@@ -3112,16 +3125,16 @@ const api = new Api({ apiUrl: 'https://example.com' })`);
3112
3125
  }
3113
3126
  async downloadTaskResults(param) {
3114
3127
  let { taskId, format, filters, sort, view, convertToEnglish = true } = param;
3115
- /**
3116
- * Downloads the results of a specific task in the specified format.
3117
- *
3118
- * @param taskId The ID of the task.
3119
- * @param format The format to download the task results in. Available formats are "json", "csv", "excel". The default format is "json".
3120
- * @param filters A dictionary of filters to apply to the task results, optional.
3121
- * @param sort The sort to apply to the task results, optional.
3122
- * @param view The view to apply to the task results, optional.
3123
- * @param convertToEnglish Whether to convert the task results to English, default is True, optional.
3124
- * @return A tuple containing the downloaded content as a buffer and the filename.
3128
+ /**
3129
+ * Downloads the results of a specific task in the specified format.
3130
+ *
3131
+ * @param taskId The ID of the task.
3132
+ * @param format The format to download the task results in. Available formats are "json", "csv", "excel". The default format is "json".
3133
+ * @param filters A dictionary of filters to apply to the task results, optional.
3134
+ * @param sort The sort to apply to the task results, optional.
3135
+ * @param view The view to apply to the task results, optional.
3136
+ * @param convertToEnglish Whether to convert the task results to English, default is True, optional.
3137
+ * @return A tuple containing the downloaded content as a buffer and the filename.
3125
3138
  */ const url = this._makeApiUrl(`tasks/${taskId}/download`);
3126
3139
  const payload = {
3127
3140
  convert_to_english: convertToEnglish
@@ -3158,11 +3171,11 @@ const api = new Api({ apiUrl: 'https://example.com' })`);
3158
3171
  }
3159
3172
  }
3160
3173
  async abortTask(taskId) {
3161
- /**
3162
- * Aborts a specific task.
3163
- *
3164
- * @param taskId The ID of the task to abort.
3165
- * @return A success message.
3174
+ /**
3175
+ * Aborts a specific task.
3176
+ *
3177
+ * @param taskId The ID of the task to abort.
3178
+ * @return A success message.
3166
3179
  */ const url = this._makeApiUrl(`tasks/${taskId}/abort`);
3167
3180
  try {
3168
3181
  const response = await axios__WEBPACK_IMPORTED_MODULE_1__["default"].patch(url, {}, {
@@ -3180,11 +3193,11 @@ const api = new Api({ apiUrl: 'https://example.com' })`);
3180
3193
  }
3181
3194
  }
3182
3195
  async deleteTask(taskId) {
3183
- /**
3184
- * Deletes a specific task.
3185
- *
3186
- * @param taskId The ID of the task to delete.
3187
- * @return A success message.
3196
+ /**
3197
+ * Deletes a specific task.
3198
+ *
3199
+ * @param taskId The ID of the task to delete.
3200
+ * @return A success message.
3188
3201
  */ const url = this._makeApiUrl(`tasks/${taskId}`);
3189
3202
  try {
3190
3203
  const response = await axios__WEBPACK_IMPORTED_MODULE_1__["default"]["delete"](url);
@@ -3199,11 +3212,11 @@ const api = new Api({ apiUrl: 'https://example.com' })`);
3199
3212
  }
3200
3213
  async deleteTasks(param) {
3201
3214
  let { taskIds } = param;
3202
- /**
3203
- * Bulk deletes tasks.
3204
- *
3205
- * @param taskIds A list of task IDs to be deleted.
3206
- * @return A success message.
3215
+ /**
3216
+ * Bulk deletes tasks.
3217
+ *
3218
+ * @param taskIds A list of task IDs to be deleted.
3219
+ * @return A success message.
3207
3220
  */ const url = this._makeApiUrl("tasks/bulk-delete");
3208
3221
  const payload = {
3209
3222
  task_ids: taskIds
@@ -3221,11 +3234,11 @@ const api = new Api({ apiUrl: 'https://example.com' })`);
3221
3234
  }
3222
3235
  async abortTasks(param) {
3223
3236
  let { taskIds } = param;
3224
- /**
3225
- * Bulk aborts tasks.
3226
- *
3227
- * @param taskIds A list of task IDs to be aborted.
3228
- * @return A success message.
3237
+ /**
3238
+ * Bulk aborts tasks.
3239
+ *
3240
+ * @param taskIds A list of task IDs to be aborted.
3241
+ * @return A success message.
3229
3242
  */ const url = this._makeApiUrl("tasks/bulk-abort");
3230
3243
  const payload = {
3231
3244
  task_ids: taskIds
@@ -3241,22 +3254,25 @@ const api = new Api({ apiUrl: 'https://example.com' })`);
3241
3254
  throw error;
3242
3255
  }
3243
3256
  }
3244
- constructor({ apiUrl, createResponseFiles = false, apiBasePath = "" } = {
3257
+ constructor({ apiUrl, createResponseFiles = false, apiBasePath = "", enableCache } = {
3245
3258
  createResponseFiles: true
3246
3259
  }){
3247
3260
  (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_2__._)(this, "_apiUrl", void 0);
3248
3261
  (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_2__._)(this, "_apiBasePath", void 0);
3249
3262
  (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_2__._)(this, "_createResponseFiles", void 0);
3263
+ (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_2__._)(this, "_enableCache", void 0);
3250
3264
  (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_2__._)(this, "DEFAULT_API_URL", "http://localhost:8000");
3251
- /**
3252
- * Initializes the API client with a specified server URL, base path, and an option to create response files.
3253
- *
3254
- * @param apiUrl The base URL for the API server. If not specified, defaults to "http://localhost:8000".
3255
- * @param createResponseFiles Indicates if the client should create response files for each API call. This is useful for debugging or development purposes. Defaults to True.
3256
- * @param apiBasePath Base path to prefix API endpoints (e.g., "/v1").
3265
+ /**
3266
+ * Initializes the API client with a specified server URL, base path, caching options, and an option to create response files.
3267
+ *
3268
+ * @param apiUrl The base URL for the API server. If not specified, defaults to "http://localhost:8000".
3269
+ * @param createResponseFiles Indicates if the client should create response files for each API call. This is useful for debugging or development purposes. Defaults to true.
3270
+ * @param apiBasePath Base path to prefix API endpoints (e.g., "/v1").
3271
+ * @param enableCache Enable or disable caching for all API requests. Overrides the server's cache setting.
3257
3272
  */ this._apiUrl = apiUrl ? (0,_utils__WEBPACK_IMPORTED_MODULE_0__.removeAfterFirstSlash)(apiUrl) : this.DEFAULT_API_URL;
3258
3273
  this._createResponseFiles = createResponseFiles;
3259
3274
  this._apiBasePath = cleanBasePath(apiBasePath);
3275
+ this._enableCache = enableCache;
3260
3276
  // Check if API is running (note: this is synchronous in the original, but should be async in TS)
3261
3277
  this.isApiRunning().then((isRunning)=>{
3262
3278
  if (!isRunning) {
@@ -7988,7 +8004,7 @@ __webpack_require__.hu = (chunkId) => ('' + chunkId + '.' + __webpack_require__.
7988
8004
  })();
7989
8005
  // webpack/runtime/get_full_hash
7990
8006
  (() => {
7991
- __webpack_require__.h = () => ("e206d326d2bfeb52")
8007
+ __webpack_require__.h = () => ("94e1e84fee824fd4")
7992
8008
  })();
7993
8009
  // webpack/runtime/get_main_filename/update manifest
7994
8010
  (() => {