luxlabs 1.0.13 → 1.0.14
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/commands/ab-tests.js +41 -8
- package/package.json +1 -1
package/commands/ab-tests.js
CHANGED
|
@@ -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,7 +496,8 @@ 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();
|
|
@@ -564,13 +583,20 @@ async function createFinished(testId, options) {
|
|
|
564
583
|
return;
|
|
565
584
|
}
|
|
566
585
|
|
|
567
|
-
//
|
|
568
|
-
const
|
|
586
|
+
// Read local test data to send with request
|
|
587
|
+
const localTest = getLocalTest(interfaceId, testId);
|
|
588
|
+
if (!localTest) {
|
|
589
|
+
spinner.fail(`Test ${testId} not found in local ab-tests.json`);
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// Call API to sync to PostHog and update DB (send local test data)
|
|
594
|
+
const result = await callLifecycleApi('create-finished', testId, interfaceId, creds, localTest);
|
|
569
595
|
|
|
570
596
|
// Update local file status
|
|
571
597
|
updateLocalTestStatus(interfaceId, testId, 'active');
|
|
572
598
|
|
|
573
|
-
spinner.succeed(`A/B test "${result.test?.name ||
|
|
599
|
+
spinner.succeed(`A/B test "${result.test?.name || localTest.name}" synced to PostHog`);
|
|
574
600
|
console.log(chalk.dim(` PostHog flag ID: ${result.posthogFlagId}`));
|
|
575
601
|
console.log(chalk.dim(` Status: active`));
|
|
576
602
|
} catch (error) {
|
|
@@ -602,13 +628,20 @@ async function updateFinished(testId, options) {
|
|
|
602
628
|
return;
|
|
603
629
|
}
|
|
604
630
|
|
|
605
|
-
//
|
|
606
|
-
const
|
|
631
|
+
// Read local test data to send with request
|
|
632
|
+
const localTest = getLocalTest(interfaceId, testId);
|
|
633
|
+
if (!localTest) {
|
|
634
|
+
spinner.fail(`Test ${testId} not found in local ab-tests.json`);
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
// Call API to sync to PostHog and update DB (send local test data)
|
|
639
|
+
const result = await callLifecycleApi('update-finished', testId, interfaceId, creds, localTest);
|
|
607
640
|
|
|
608
641
|
// Update local file status
|
|
609
642
|
updateLocalTestStatus(interfaceId, testId, 'active');
|
|
610
643
|
|
|
611
|
-
spinner.succeed(`A/B test "${result.test?.name ||
|
|
644
|
+
spinner.succeed(`A/B test "${result.test?.name || localTest.name}" updated and synced`);
|
|
612
645
|
console.log(chalk.dim(` Status: active`));
|
|
613
646
|
} catch (error) {
|
|
614
647
|
spinner.fail(`Failed to sync A/B test: ${error.message}`);
|
package/package.json
CHANGED