pairit 0.3.11 → 0.3.13

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.
Files changed (2) hide show
  1. package/dist/index.js +107 -11
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -9535,6 +9535,9 @@ function parseDuration(value) {
9535
9535
  return Number(match[1]) * UNIT_MS[match[2]];
9536
9536
  }
9537
9537
  function isLive(entry) {
9538
+ return entry.activeNow.total > 0;
9539
+ }
9540
+ function isLiveGroup(entry) {
9538
9541
  return entry.isGroupStudy && entry.activeNow.total > 0;
9539
9542
  }
9540
9543
  function owner(entry) {
@@ -9556,18 +9559,24 @@ function flags(entry) {
9556
9559
  }
9557
9560
  function describeLiveStudy(entry) {
9558
9561
  const { total, inGroup, solo } = entry.activeNow;
9559
- return `${entry.configId} (${owner(entry)}): ${total} active (${inGroup} in a group, ${solo} solo), ${entry.waitingInMatchmaking} waiting in matchmaking`;
9562
+ if (entry.isGroupStudy) {
9563
+ return `${entry.configId} (${owner(entry)}): ${total} active (${inGroup} in a group, ${solo} solo), ${entry.waitingInMatchmaking} waiting in matchmaking`;
9564
+ }
9565
+ return `${entry.configId} (${owner(entry)}): ${total} active (solo)`;
9560
9566
  }
9561
9567
  function formatActivity(report, options = {}) {
9562
9568
  const paint = (code, text) => options.color ? `\x1B[${code}m${text}\x1B[0m` : text;
9563
9569
  const lines = [];
9564
- const live = report.configs.filter(isLive);
9570
+ const live = [
9571
+ ...report.configs.filter(isLiveGroup),
9572
+ ...report.configs.filter((entry) => isLive(entry) && !isLiveGroup(entry))
9573
+ ];
9565
9574
  if (live.length > 0) {
9566
- lines.push(paint("1;31", `${live.length} group ${live.length === 1 ? "study is" : "studies are"} live. Don't deploy production.`));
9575
+ lines.push(paint("1;31", `${live.length} ${live.length === 1 ? "study is" : "studies are"} live. Don't deploy production.`));
9567
9576
  for (const entry of live)
9568
9577
  lines.push(` ${describeLiveStudy(entry)}`);
9569
9578
  } else {
9570
- lines.push("No group study is live.");
9579
+ lines.push("No study is live.");
9571
9580
  }
9572
9581
  lines.push("");
9573
9582
  if (report.configs.length === 0) {
@@ -10047,6 +10056,39 @@ async function loadKeyringEntry() {
10047
10056
  }
10048
10057
  }
10049
10058
 
10059
+ // src/chat-lint.ts
10060
+ function lintChats(config) {
10061
+ const errors = [];
10062
+ config.pages?.forEach((page, pageIndex) => {
10063
+ const pageName = page.id ?? `pages[${pageIndex}]`;
10064
+ const seenRooms = new Map;
10065
+ page.components?.forEach((component, componentIndex) => {
10066
+ const c = component;
10067
+ if (c?.type !== "chat")
10068
+ return;
10069
+ const where = `${pageName}.components[${componentIndex}]`;
10070
+ const scope = c.props?.scope;
10071
+ const scopeValid = scope === undefined || scope === "participant" || scope === "group";
10072
+ if (!scopeValid) {
10073
+ errors.push(`${where}: chat scope must be "participant" or "group"`);
10074
+ return;
10075
+ }
10076
+ if (c.when !== undefined)
10077
+ return;
10078
+ const resolvedScope = scope === "participant" ? "participant" : "group";
10079
+ const explicitGroupId = typeof c.props?.groupId === "string" && c.props.groupId ? c.props.groupId : pageName;
10080
+ const roomKey = `${resolvedScope}:${explicitGroupId}`;
10081
+ const prev = seenRooms.get(roomKey);
10082
+ if (prev) {
10083
+ errors.push(`${where}: duplicate chat room on page "${pageName}" (same as ${prev}); set distinct groupId props (and scope: "participant" for private chats)`);
10084
+ } else {
10085
+ seenRooms.set(roomKey, where);
10086
+ }
10087
+ });
10088
+ });
10089
+ return errors;
10090
+ }
10091
+
10050
10092
  // src/csv.ts
10051
10093
  var FORMULA_PREFIX = /^[=+\-@\t\r]/;
10052
10094
  var PLAIN_NUMBER = /^[+-]?(\d+\.?\d*|\.\d+)(e[+-]?\d+)?$/i;
@@ -10488,9 +10530,56 @@ function lintEndRedirectUrls(config) {
10488
10530
  return errors;
10489
10531
  }
10490
10532
 
10533
+ // src/timer-lint.ts
10534
+ var VALID_TIMER_KEY = /^[A-Za-z0-9_-]+$/;
10535
+ function lintTimers(config) {
10536
+ const errors = [];
10537
+ const keyedTimers = new Map;
10538
+ config.pages?.forEach((page, pageIndex) => {
10539
+ const pageName = page.id ?? `pages[${pageIndex}]`;
10540
+ page.components?.forEach((component, componentIndex) => {
10541
+ const c = component;
10542
+ if (c?.type !== "timer" || !c.props)
10543
+ return;
10544
+ const where = `${pageName}.components[${componentIndex}]`;
10545
+ const { scope, key, duration } = c.props;
10546
+ const scopeValid = scope === undefined || scope === "session" || scope === "group";
10547
+ if (!scopeValid) {
10548
+ errors.push(`${where}: timer scope must be "session" or "group"`);
10549
+ }
10550
+ if (key !== undefined) {
10551
+ if (typeof key !== "string" || !VALID_TIMER_KEY.test(key)) {
10552
+ errors.push(`${where}: timer key must be a non-empty string of letters, numbers, hyphens, or underscores`);
10553
+ return;
10554
+ }
10555
+ if (!scopeValid)
10556
+ return;
10557
+ const resolvedScope = scope === "group" ? "group" : "session";
10558
+ const resolvedDuration = typeof duration === "number" && Number.isFinite(duration) ? Math.floor(duration) : undefined;
10559
+ const prev = keyedTimers.get(key);
10560
+ if (prev) {
10561
+ if (prev.scope !== resolvedScope) {
10562
+ errors.push(`${where}: timer key "${key}" uses scope "${resolvedScope}", which conflicts with ${prev.where} ("${prev.scope}")`);
10563
+ }
10564
+ if (prev.duration !== undefined && resolvedDuration !== undefined && prev.duration !== resolvedDuration) {
10565
+ errors.push(`${where}: timer key "${key}" has duration ${resolvedDuration}, which conflicts with ${prev.where} (${prev.duration})`);
10566
+ }
10567
+ } else {
10568
+ keyedTimers.set(key, {
10569
+ where,
10570
+ scope: resolvedScope,
10571
+ duration: resolvedDuration
10572
+ });
10573
+ }
10574
+ }
10575
+ });
10576
+ });
10577
+ return errors;
10578
+ }
10579
+
10491
10580
  // src/index.ts
10492
10581
  var program2 = new Command;
10493
- program2.name("pairit").description("CLI for Pairit experiment configs").version("0.3.11").option("--env <name>", "Target environment: staging or production", (value) => {
10582
+ program2.name("pairit").description("CLI for Pairit experiment configs").version("0.3.13").option("--env <name>", "Target environment: staging or production", (value) => {
10494
10583
  try {
10495
10584
  return parseEnvName(value);
10496
10585
  } catch (error) {
@@ -10766,13 +10855,13 @@ adminCommand.command("list-users").description("List users on the manager allowl
10766
10855
  reportCliError("List users failed", error);
10767
10856
  }
10768
10857
  });
10769
- adminCommand.command("activity").description("Show studies with recent sessions, live group studies first (check before deploying production)").option("--since <duration>", "How far back to look, e.g. 2h, 7d", (value) => {
10858
+ adminCommand.command("activity").description("Show studies with recent sessions, live studies first (check before deploying production)").option("--since <duration>", "How far back to look, e.g. 2h, 7d", (value) => {
10770
10859
  try {
10771
10860
  return parseDuration(value);
10772
10861
  } catch (error) {
10773
10862
  throw new InvalidArgumentError(error.message);
10774
10863
  }
10775
- }).option("--json", "Print the raw report as JSON").option("--fail-if-live", "Exit with code 2 if any group study has active participants").action(async (options) => {
10864
+ }).option("--json", "Print the raw report as JSON").option("--fail-if-live", "Exit with code 2 if any study has active participants").action(async (options) => {
10776
10865
  try {
10777
10866
  const query = options.since ? `?since=${encodeURIComponent(new Date(Date.now() - options.since).toISOString())}` : "";
10778
10867
  const report = await callFunctions(`/admin/activity${query}`, {
@@ -10785,7 +10874,8 @@ adminCommand.command("activity").description("Show studies with recent sessions,
10785
10874
  color: Boolean(process11.stdout.isTTY) && !process11.env.NO_COLOR
10786
10875
  }));
10787
10876
  }
10788
- if (options.failIfLive && report.liveGroupStudies.length > 0) {
10877
+ const liveStudies = report.liveStudies ?? report.configs.filter((entry) => entry.activeNow.total > 0);
10878
+ if (options.failIfLive && liveStudies.length > 0) {
10789
10879
  process11.exitCode = 2;
10790
10880
  }
10791
10881
  } catch (error) {
@@ -10845,6 +10935,8 @@ async function lintConfig(configPath) {
10845
10935
  errors.push(...lintRandomization(config));
10846
10936
  errors.push(...lintGroupView(config));
10847
10937
  errors.push(...lintEndRedirectUrls(config));
10938
+ errors.push(...lintTimers(config));
10939
+ errors.push(...lintChats(config));
10848
10940
  if (errors.length) {
10849
10941
  throw new Error(errors.join(", "));
10850
10942
  }
@@ -10911,9 +11003,13 @@ async function compileConfig(configPath) {
10911
11003
  }
10912
11004
  async function buildUploadPayload(configPath, options) {
10913
11005
  const sourceConfig = await loadConfig(configPath);
10914
- const randomizationErrors = lintRandomization(sourceConfig);
10915
- if (randomizationErrors.length) {
10916
- throw new Error(randomizationErrors.join(", "));
11006
+ const validationErrors = [
11007
+ ...lintRandomization(sourceConfig),
11008
+ ...lintTimers(sourceConfig),
11009
+ ...lintChats(sourceConfig)
11010
+ ];
11011
+ if (validationErrors.length) {
11012
+ throw new Error(validationErrors.join(", "));
10917
11013
  }
10918
11014
  const allowRetake = sourceConfig.allowRetake === true;
10919
11015
  const requireAuth = sourceConfig.requireAuth;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pairit",
3
- "version": "0.3.11",
3
+ "version": "0.3.13",
4
4
  "description": "CLI for the Pairit behavioral science experiment platform",
5
5
  "type": "module",
6
6
  "bin": {