pairit 0.3.12 → 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 +54 -9
  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;
@@ -10537,7 +10579,7 @@ function lintTimers(config) {
10537
10579
 
10538
10580
  // src/index.ts
10539
10581
  var program2 = new Command;
10540
- program2.name("pairit").description("CLI for Pairit experiment configs").version("0.3.12").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) => {
10541
10583
  try {
10542
10584
  return parseEnvName(value);
10543
10585
  } catch (error) {
@@ -10813,13 +10855,13 @@ adminCommand.command("list-users").description("List users on the manager allowl
10813
10855
  reportCliError("List users failed", error);
10814
10856
  }
10815
10857
  });
10816
- 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) => {
10817
10859
  try {
10818
10860
  return parseDuration(value);
10819
10861
  } catch (error) {
10820
10862
  throw new InvalidArgumentError(error.message);
10821
10863
  }
10822
- }).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) => {
10823
10865
  try {
10824
10866
  const query = options.since ? `?since=${encodeURIComponent(new Date(Date.now() - options.since).toISOString())}` : "";
10825
10867
  const report = await callFunctions(`/admin/activity${query}`, {
@@ -10832,7 +10874,8 @@ adminCommand.command("activity").description("Show studies with recent sessions,
10832
10874
  color: Boolean(process11.stdout.isTTY) && !process11.env.NO_COLOR
10833
10875
  }));
10834
10876
  }
10835
- 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) {
10836
10879
  process11.exitCode = 2;
10837
10880
  }
10838
10881
  } catch (error) {
@@ -10893,6 +10936,7 @@ async function lintConfig(configPath) {
10893
10936
  errors.push(...lintGroupView(config));
10894
10937
  errors.push(...lintEndRedirectUrls(config));
10895
10938
  errors.push(...lintTimers(config));
10939
+ errors.push(...lintChats(config));
10896
10940
  if (errors.length) {
10897
10941
  throw new Error(errors.join(", "));
10898
10942
  }
@@ -10961,7 +11005,8 @@ async function buildUploadPayload(configPath, options) {
10961
11005
  const sourceConfig = await loadConfig(configPath);
10962
11006
  const validationErrors = [
10963
11007
  ...lintRandomization(sourceConfig),
10964
- ...lintTimers(sourceConfig)
11008
+ ...lintTimers(sourceConfig),
11009
+ ...lintChats(sourceConfig)
10965
11010
  ];
10966
11011
  if (validationErrors.length) {
10967
11012
  throw new Error(validationErrors.join(", "));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pairit",
3
- "version": "0.3.12",
3
+ "version": "0.3.13",
4
4
  "description": "CLI for the Pairit behavioral science experiment platform",
5
5
  "type": "module",
6
6
  "bin": {