pairit 0.3.0 → 0.3.2
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 +72 -1
- package/package.json +40 -40
package/dist/index.js
CHANGED
|
@@ -9513,9 +9513,13 @@ function getEnvName() {
|
|
|
9513
9513
|
return fromEnv ? parseEnvName(fromEnv) : "production";
|
|
9514
9514
|
}
|
|
9515
9515
|
function getApiUrl() {
|
|
9516
|
+
if (selected)
|
|
9517
|
+
return ENVIRONMENTS[selected].api;
|
|
9516
9518
|
return process2.env.PAIRIT_API_URL || ENVIRONMENTS[getEnvName()].api;
|
|
9517
9519
|
}
|
|
9518
9520
|
function getLabUrl() {
|
|
9521
|
+
if (selected)
|
|
9522
|
+
return ENVIRONMENTS[selected].lab;
|
|
9519
9523
|
return process2.env.PAIRIT_LAB_URL || ENVIRONMENTS[getEnvName()].lab;
|
|
9520
9524
|
}
|
|
9521
9525
|
function getCredentialKey() {
|
|
@@ -9803,9 +9807,65 @@ async function attachHtmlToCompiledConfig(configPath, compiled) {
|
|
|
9803
9807
|
return sources;
|
|
9804
9808
|
}
|
|
9805
9809
|
|
|
9810
|
+
// src/randomize-lint.ts
|
|
9811
|
+
function lintRandomization(config) {
|
|
9812
|
+
const errors = [];
|
|
9813
|
+
const groupSize = singleGroupSize(config);
|
|
9814
|
+
const check = (where, settings) => {
|
|
9815
|
+
if (settings.distribute !== true)
|
|
9816
|
+
return;
|
|
9817
|
+
if (settings.scope !== "group") {
|
|
9818
|
+
errors.push(`${where}: distribute: true needs scope: group`);
|
|
9819
|
+
}
|
|
9820
|
+
const conditions = settings.conditions;
|
|
9821
|
+
if (!Array.isArray(conditions) || conditions.length === 0) {
|
|
9822
|
+
errors.push(`${where}: distribute: true needs a conditions list`);
|
|
9823
|
+
return;
|
|
9824
|
+
}
|
|
9825
|
+
if (groupSize !== undefined && conditions.length !== groupSize) {
|
|
9826
|
+
errors.push(`${where}: distribute: true needs one condition per group member (${conditions.length} conditions, groups of ${groupSize})`);
|
|
9827
|
+
}
|
|
9828
|
+
};
|
|
9829
|
+
config.pages?.forEach((page, pageIndex) => {
|
|
9830
|
+
const pageName = page.id ?? `pages[${pageIndex}]`;
|
|
9831
|
+
page.onEnter?.forEach((action, actionIndex) => {
|
|
9832
|
+
const a = action;
|
|
9833
|
+
if (a?.type === "randomize") {
|
|
9834
|
+
check(`${pageName}.onEnter[${actionIndex}]`, a);
|
|
9835
|
+
}
|
|
9836
|
+
});
|
|
9837
|
+
page.components?.forEach((component, componentIndex) => {
|
|
9838
|
+
const c = component;
|
|
9839
|
+
if (c?.type === "randomization" && c.props) {
|
|
9840
|
+
check(`${pageName}.components[${componentIndex}]`, c.props);
|
|
9841
|
+
}
|
|
9842
|
+
});
|
|
9843
|
+
});
|
|
9844
|
+
return errors;
|
|
9845
|
+
}
|
|
9846
|
+
function singleGroupSize(config) {
|
|
9847
|
+
const sizes = new Set;
|
|
9848
|
+
if (Array.isArray(config.matchmaking)) {
|
|
9849
|
+
for (const pool of config.matchmaking) {
|
|
9850
|
+
const size = pool?.num_users;
|
|
9851
|
+
sizes.add(typeof size === "number" ? size : 2);
|
|
9852
|
+
}
|
|
9853
|
+
}
|
|
9854
|
+
for (const page of config.pages ?? []) {
|
|
9855
|
+
for (const component of page.components ?? []) {
|
|
9856
|
+
const c = component;
|
|
9857
|
+
if (c?.type !== "matchmaking" || c.props?.poolId !== undefined)
|
|
9858
|
+
continue;
|
|
9859
|
+
const size = c.props?.num_users;
|
|
9860
|
+
sizes.add(typeof size === "number" ? size : 2);
|
|
9861
|
+
}
|
|
9862
|
+
}
|
|
9863
|
+
return sizes.size === 1 ? [...sizes][0] : undefined;
|
|
9864
|
+
}
|
|
9865
|
+
|
|
9806
9866
|
// src/index.ts
|
|
9807
9867
|
var program2 = new Command;
|
|
9808
|
-
program2.name("pairit").description("CLI for Pairit experiment configs").version("0.3.
|
|
9868
|
+
program2.name("pairit").description("CLI for Pairit experiment configs").version("0.3.2").option("--env <name>", "Target environment: staging or production", (value) => {
|
|
9809
9869
|
try {
|
|
9810
9870
|
return parseEnvName(value);
|
|
9811
9871
|
} catch (error) {
|
|
@@ -10089,8 +10149,15 @@ async function lintConfig(configPath) {
|
|
|
10089
10149
|
if (!page.id) {
|
|
10090
10150
|
errors.push(`pages[${index}] is missing id`);
|
|
10091
10151
|
}
|
|
10152
|
+
page.components?.forEach((component, componentIndex) => {
|
|
10153
|
+
const column = component?.column;
|
|
10154
|
+
if (column !== undefined && column !== "left" && column !== "right") {
|
|
10155
|
+
errors.push(`pages[${index}].components[${componentIndex}].column must be "left" or "right"`);
|
|
10156
|
+
}
|
|
10157
|
+
});
|
|
10092
10158
|
});
|
|
10093
10159
|
}
|
|
10160
|
+
errors.push(...lintRandomization(config));
|
|
10094
10161
|
if (errors.length) {
|
|
10095
10162
|
throw new Error(errors.join(", "));
|
|
10096
10163
|
}
|
|
@@ -10152,6 +10219,10 @@ async function compileConfig(configPath) {
|
|
|
10152
10219
|
}
|
|
10153
10220
|
async function buildUploadPayload(configPath, options) {
|
|
10154
10221
|
const sourceConfig = await loadConfig(configPath);
|
|
10222
|
+
const randomizationErrors = lintRandomization(sourceConfig);
|
|
10223
|
+
if (randomizationErrors.length) {
|
|
10224
|
+
throw new Error(randomizationErrors.join(", "));
|
|
10225
|
+
}
|
|
10155
10226
|
const allowRetake = sourceConfig.allowRetake === true;
|
|
10156
10227
|
const requireAuth = sourceConfig.requireAuth;
|
|
10157
10228
|
const compiledPath = await compileConfig(configPath);
|
package/package.json
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
2
|
+
"name": "pairit",
|
|
3
|
+
"version": "0.3.2",
|
|
4
|
+
"description": "CLI for the Pairit behavioral science experiment platform",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"pairit": "dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "bun build src/index.ts --outdir dist --target node",
|
|
14
|
+
"lint": "tsc --noEmit",
|
|
15
|
+
"prepublishOnly": "bun run build"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"experiment",
|
|
19
|
+
"behavioral-science",
|
|
20
|
+
"research",
|
|
21
|
+
"cli"
|
|
22
|
+
],
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/pairium/pairit.git",
|
|
26
|
+
"directory": "apps/manager/cli"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://docs.pairium.ai/pairit/",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"optionalDependencies": {
|
|
31
|
+
"keytar": "^7.9.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/bun": "^1.1.13",
|
|
35
|
+
"@types/open": "^6.2.1",
|
|
36
|
+
"better-auth": "^1.4.7",
|
|
37
|
+
"commander": "^12.1.0",
|
|
38
|
+
"open": "^11.0.0",
|
|
39
|
+
"typescript": "^5.9.3",
|
|
40
|
+
"yaml": "^2.6.0"
|
|
41
|
+
}
|
|
42
42
|
}
|