@bragduck/cli 2.39.0 → 2.39.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.
package/dist/index.js CHANGED
@@ -81,6 +81,9 @@ var init_constants = __esm({
81
81
  CREATE: "/v1/users/{userId}/stories",
82
82
  DELETE: "/v1/users/{userId}/stories/{storyId}"
83
83
  },
84
+ INTEGRATIONS: {
85
+ ACCESS_TOKEN: "/v1/integrations/{provider}/access-token"
86
+ },
84
87
  VERSION: "/v1/cli/version",
85
88
  /**
86
89
  * @deprecated Use BRAGS.REFINE instead
@@ -1227,7 +1230,7 @@ function getPlatformInfo() {
1227
1230
  const arch = process.arch;
1228
1231
  return `${platform}-${arch}`;
1229
1232
  }
1230
- var __filename4, __dirname4, ApiService, apiService;
1233
+ var __filename4, __dirname4, REFINE_BATCH_SIZE, CREATE_BATCH_SIZE, inBatches, ApiService, apiService;
1231
1234
  var init_api_service = __esm({
1232
1235
  "src/services/api.service.ts"() {
1233
1236
  "use strict";
@@ -1238,6 +1241,15 @@ var init_api_service = __esm({
1238
1241
  init_logger();
1239
1242
  __filename4 = fileURLToPath4(import.meta.url);
1240
1243
  __dirname4 = dirname3(__filename4);
1244
+ REFINE_BATCH_SIZE = 20;
1245
+ CREATE_BATCH_SIZE = 50;
1246
+ inBatches = (items, size) => {
1247
+ const batches = [];
1248
+ for (let start = 0; start < items.length; start += size) {
1249
+ batches.push(items.slice(start, start + size));
1250
+ }
1251
+ return batches;
1252
+ };
1241
1253
  ApiService = class {
1242
1254
  baseURL;
1243
1255
  client;
@@ -1353,10 +1365,23 @@ var init_api_service = __esm({
1353
1365
  };
1354
1366
  logger.debug(`Refining ${trimmedRequest.brags.length} brags`);
1355
1367
  try {
1356
- const response = await this.makeRequest(API_ENDPOINTS.BRAGS.REFINE, {
1357
- method: "POST",
1358
- body: trimmedRequest
1359
- });
1368
+ const response = {
1369
+ refined_brags: [],
1370
+ processing_time_ms: 0,
1371
+ tokens_used: 0
1372
+ };
1373
+ for (const batch of inBatches(trimmedRequest.brags, REFINE_BATCH_SIZE)) {
1374
+ const batchResponse = await this.makeRequest(
1375
+ API_ENDPOINTS.BRAGS.REFINE,
1376
+ {
1377
+ method: "POST",
1378
+ body: { ...trimmedRequest, brags: batch }
1379
+ }
1380
+ );
1381
+ response.refined_brags.push(...batchResponse.refined_brags);
1382
+ response.processing_time_ms += batchResponse.processing_time_ms;
1383
+ response.tokens_used += batchResponse.tokens_used;
1384
+ }
1360
1385
  logger.debug(`Successfully refined ${response.refined_brags.length} brags`);
1361
1386
  return response;
1362
1387
  } catch (_error) {
@@ -1390,10 +1415,18 @@ var init_api_service = __esm({
1390
1415
  logger.debug(`Creating ${request.brags.length} brags`);
1391
1416
  logger.debug(`Request body: ${JSON.stringify(request, null, 2)}`);
1392
1417
  try {
1393
- const response = await this.makeRequest(API_ENDPOINTS.BRAGS.CREATE, {
1394
- method: "POST",
1395
- body: request
1396
- });
1418
+ const response = { created: 0, brags: [] };
1419
+ for (const batch of inBatches(request.brags, CREATE_BATCH_SIZE)) {
1420
+ const batchResponse = await this.makeRequest(
1421
+ API_ENDPOINTS.BRAGS.CREATE,
1422
+ {
1423
+ method: "POST",
1424
+ body: { ...request, brags: batch }
1425
+ }
1426
+ );
1427
+ response.created += batchResponse.created;
1428
+ response.brags.push(...batchResponse.brags);
1429
+ }
1397
1430
  logger.debug(`Response: ${JSON.stringify(response, null, 2)}`);
1398
1431
  logger.debug(`Successfully created ${response.created} brags`);
1399
1432
  return response;
@@ -1534,6 +1567,18 @@ var init_api_service = __esm({
1534
1567
  throw error;
1535
1568
  }
1536
1569
  }
1570
+ /**
1571
+ * Get the access token of a tool connected on the BragDuck web app.
1572
+ * The server refreshes it; error statuses are not retried.
1573
+ */
1574
+ async getIntegrationAccessToken(provider) {
1575
+ logger.debug(`Fetching web-connected ${provider} access token`);
1576
+ const url = API_ENDPOINTS.INTEGRATIONS.ACCESS_TOKEN.replace("{provider}", provider);
1577
+ return this.makeRequest(url, {
1578
+ method: "GET",
1579
+ retry: 0
1580
+ });
1581
+ }
1537
1582
  /**
1538
1583
  * Check for CLI updates
1539
1584
  */