@bragduck/cli 2.38.2 → 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
@@ -76,6 +76,14 @@ var init_constants = __esm({
76
76
  ORGANISATIONS: {
77
77
  LIST: "/v1/users/{userId}/organisations"
78
78
  },
79
+ STORIES: {
80
+ LIST: "/v1/users/{userId}/stories",
81
+ CREATE: "/v1/users/{userId}/stories",
82
+ DELETE: "/v1/users/{userId}/stories/{storyId}"
83
+ },
84
+ INTEGRATIONS: {
85
+ ACCESS_TOKEN: "/v1/integrations/{provider}/access-token"
86
+ },
79
87
  VERSION: "/v1/cli/version",
80
88
  /**
81
89
  * @deprecated Use BRAGS.REFINE instead
@@ -1222,7 +1230,7 @@ function getPlatformInfo() {
1222
1230
  const arch = process.arch;
1223
1231
  return `${platform}-${arch}`;
1224
1232
  }
1225
- var __filename4, __dirname4, ApiService, apiService;
1233
+ var __filename4, __dirname4, REFINE_BATCH_SIZE, CREATE_BATCH_SIZE, inBatches, ApiService, apiService;
1226
1234
  var init_api_service = __esm({
1227
1235
  "src/services/api.service.ts"() {
1228
1236
  "use strict";
@@ -1233,6 +1241,15 @@ var init_api_service = __esm({
1233
1241
  init_logger();
1234
1242
  __filename4 = fileURLToPath4(import.meta.url);
1235
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
+ };
1236
1253
  ApiService = class {
1237
1254
  baseURL;
1238
1255
  client;
@@ -1348,10 +1365,23 @@ var init_api_service = __esm({
1348
1365
  };
1349
1366
  logger.debug(`Refining ${trimmedRequest.brags.length} brags`);
1350
1367
  try {
1351
- const response = await this.makeRequest(API_ENDPOINTS.BRAGS.REFINE, {
1352
- method: "POST",
1353
- body: trimmedRequest
1354
- });
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
+ }
1355
1385
  logger.debug(`Successfully refined ${response.refined_brags.length} brags`);
1356
1386
  return response;
1357
1387
  } catch (_error) {
@@ -1385,10 +1415,18 @@ var init_api_service = __esm({
1385
1415
  logger.debug(`Creating ${request.brags.length} brags`);
1386
1416
  logger.debug(`Request body: ${JSON.stringify(request, null, 2)}`);
1387
1417
  try {
1388
- const response = await this.makeRequest(API_ENDPOINTS.BRAGS.CREATE, {
1389
- method: "POST",
1390
- body: request
1391
- });
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
+ }
1392
1430
  logger.debug(`Response: ${JSON.stringify(response, null, 2)}`);
1393
1431
  logger.debug(`Successfully created ${response.created} brags`);
1394
1432
  return response;
@@ -1427,6 +1465,70 @@ var init_api_service = __esm({
1427
1465
  throw _error;
1428
1466
  }
1429
1467
  }
1468
+ /**
1469
+ * List user's stories
1470
+ */
1471
+ async listStories(userId, params = {}) {
1472
+ const { page = 1, perPage = 20, search, competency, orgId } = params;
1473
+ logger.debug(`Listing stories: page=${page}, perPage=${perPage}`);
1474
+ try {
1475
+ const queryParams = new URLSearchParams2({
1476
+ page: page.toString(),
1477
+ perPage: perPage.toString()
1478
+ });
1479
+ if (search) queryParams.append("search", search);
1480
+ if (competency) queryParams.append("competency", competency);
1481
+ if (orgId) queryParams.append("orgId", orgId);
1482
+ const url = `${API_ENDPOINTS.STORIES.LIST.replace("{userId}", userId)}?${queryParams.toString()}`;
1483
+ const response = await this.makeRequest(url, {
1484
+ method: "GET"
1485
+ });
1486
+ logger.debug(
1487
+ `Successfully fetched ${response.items.length} stories (total: ${response.total})`
1488
+ );
1489
+ return response;
1490
+ } catch (_error) {
1491
+ logger.debug("Failed to list stories");
1492
+ throw _error;
1493
+ }
1494
+ }
1495
+ /**
1496
+ * Create a story
1497
+ */
1498
+ async createStory(userId, body) {
1499
+ logger.debug(`Creating story: ${body.title}`);
1500
+ try {
1501
+ const url = API_ENDPOINTS.STORIES.CREATE.replace("{userId}", userId);
1502
+ const response = await this.makeRequest(url, {
1503
+ method: "POST",
1504
+ body
1505
+ });
1506
+ logger.debug(`Successfully created story: ${response.id}`);
1507
+ return response;
1508
+ } catch (_error) {
1509
+ logger.debug("Failed to create story");
1510
+ throw _error;
1511
+ }
1512
+ }
1513
+ /**
1514
+ * Delete a story (soft delete)
1515
+ */
1516
+ async deleteStory(userId, storyId) {
1517
+ logger.debug(`Deleting story: ${storyId}`);
1518
+ try {
1519
+ const url = API_ENDPOINTS.STORIES.DELETE.replace("{userId}", userId).replace(
1520
+ "{storyId}",
1521
+ storyId
1522
+ );
1523
+ await this.makeRequest(url, {
1524
+ method: "DELETE"
1525
+ });
1526
+ logger.debug(`Successfully deleted story: ${storyId}`);
1527
+ } catch (_error) {
1528
+ logger.debug("Failed to delete story");
1529
+ throw _error;
1530
+ }
1531
+ }
1430
1532
  /**
1431
1533
  * List user's organisations
1432
1534
  */
@@ -1465,6 +1567,18 @@ var init_api_service = __esm({
1465
1567
  throw error;
1466
1568
  }
1467
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
+ }
1468
1582
  /**
1469
1583
  * Check for CLI updates
1470
1584
  */