luxlabs 1.0.13 → 1.0.15

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.
@@ -465,10 +465,28 @@ function getInterfaceId(options) {
465
465
  return null;
466
466
  }
467
467
 
468
+ /**
469
+ * Get local test data by ID
470
+ */
471
+ function getLocalTest(interfaceId, testId) {
472
+ const testsPath = getABTestsPath(interfaceId);
473
+ if (!testsPath || !fs.existsSync(testsPath)) {
474
+ return null;
475
+ }
476
+
477
+ try {
478
+ const tests = JSON.parse(fs.readFileSync(testsPath, 'utf-8'));
479
+ return tests.find(t => t.id === testId) || null;
480
+ } catch (e) {
481
+ return null;
482
+ }
483
+ }
484
+
468
485
  /**
469
486
  * Call API endpoint for lifecycle operations
487
+ * Includes local test data in the request body for create/update
470
488
  */
471
- async function callLifecycleApi(endpoint, testId, interfaceId, creds) {
489
+ async function callLifecycleApi(endpoint, testId, interfaceId, creds, testData = null) {
472
490
  const url = `${creds.apiUrl}/api/interfaces/${interfaceId}/ab-tests/${testId}/${endpoint}`;
473
491
 
474
492
  const response = await fetch(url, {
@@ -478,13 +496,15 @@ async function callLifecycleApi(endpoint, testId, interfaceId, creds) {
478
496
  'X-Org-Id': creds.orgId,
479
497
  'X-Project-Id': creds.projectId,
480
498
  'Content-Type': 'application/json'
481
- }
499
+ },
500
+ body: JSON.stringify({ test: testData })
482
501
  });
483
502
 
484
503
  const data = await response.json();
485
504
 
486
505
  if (!response.ok) {
487
- throw new Error(data.error || `API returned ${response.status}`);
506
+ const errorMsg = data.details || data.error || `API returned ${response.status}`;
507
+ throw new Error(errorMsg);
488
508
  }
489
509
 
490
510
  return data;
@@ -564,13 +584,20 @@ async function createFinished(testId, options) {
564
584
  return;
565
585
  }
566
586
 
567
- // Call API to sync to PostHog and update DB
568
- const result = await callLifecycleApi('create-finished', testId, interfaceId, creds);
587
+ // Read local test data to send with request
588
+ const localTest = getLocalTest(interfaceId, testId);
589
+ if (!localTest) {
590
+ spinner.fail(`Test ${testId} not found in local ab-tests.json`);
591
+ return;
592
+ }
593
+
594
+ // Call API to sync to PostHog and update DB (send local test data)
595
+ const result = await callLifecycleApi('create-finished', testId, interfaceId, creds, localTest);
569
596
 
570
597
  // Update local file status
571
598
  updateLocalTestStatus(interfaceId, testId, 'active');
572
599
 
573
- spinner.succeed(`A/B test "${result.test?.name || testId}" synced to PostHog`);
600
+ spinner.succeed(`A/B test "${result.test?.name || localTest.name}" synced to PostHog`);
574
601
  console.log(chalk.dim(` PostHog flag ID: ${result.posthogFlagId}`));
575
602
  console.log(chalk.dim(` Status: active`));
576
603
  } catch (error) {
@@ -602,13 +629,20 @@ async function updateFinished(testId, options) {
602
629
  return;
603
630
  }
604
631
 
605
- // Call API to sync to PostHog and update DB
606
- const result = await callLifecycleApi('update-finished', testId, interfaceId, creds);
632
+ // Read local test data to send with request
633
+ const localTest = getLocalTest(interfaceId, testId);
634
+ if (!localTest) {
635
+ spinner.fail(`Test ${testId} not found in local ab-tests.json`);
636
+ return;
637
+ }
638
+
639
+ // Call API to sync to PostHog and update DB (send local test data)
640
+ const result = await callLifecycleApi('update-finished', testId, interfaceId, creds, localTest);
607
641
 
608
642
  // Update local file status
609
643
  updateLocalTestStatus(interfaceId, testId, 'active');
610
644
 
611
- spinner.succeed(`A/B test "${result.test?.name || testId}" updated and synced`);
645
+ spinner.succeed(`A/B test "${result.test?.name || localTest.name}" updated and synced`);
612
646
  console.log(chalk.dim(` Status: active`));
613
647
  } catch (error) {
614
648
  spinner.fail(`Failed to sync A/B test: ${error.message}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "luxlabs",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "CLI tool for Lux - Upload and deploy interfaces from your terminal",
5
5
  "author": "Jason Henkel <jason@uselux.ai>",
6
6
  "license": "SEE LICENSE IN LICENSE",