pairit 0.3.11 → 0.3.12

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 +55 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -10488,9 +10488,56 @@ function lintEndRedirectUrls(config) {
10488
10488
  return errors;
10489
10489
  }
10490
10490
 
10491
+ // src/timer-lint.ts
10492
+ var VALID_TIMER_KEY = /^[A-Za-z0-9_-]+$/;
10493
+ function lintTimers(config) {
10494
+ const errors = [];
10495
+ const keyedTimers = new Map;
10496
+ config.pages?.forEach((page, pageIndex) => {
10497
+ const pageName = page.id ?? `pages[${pageIndex}]`;
10498
+ page.components?.forEach((component, componentIndex) => {
10499
+ const c = component;
10500
+ if (c?.type !== "timer" || !c.props)
10501
+ return;
10502
+ const where = `${pageName}.components[${componentIndex}]`;
10503
+ const { scope, key, duration } = c.props;
10504
+ const scopeValid = scope === undefined || scope === "session" || scope === "group";
10505
+ if (!scopeValid) {
10506
+ errors.push(`${where}: timer scope must be "session" or "group"`);
10507
+ }
10508
+ if (key !== undefined) {
10509
+ if (typeof key !== "string" || !VALID_TIMER_KEY.test(key)) {
10510
+ errors.push(`${where}: timer key must be a non-empty string of letters, numbers, hyphens, or underscores`);
10511
+ return;
10512
+ }
10513
+ if (!scopeValid)
10514
+ return;
10515
+ const resolvedScope = scope === "group" ? "group" : "session";
10516
+ const resolvedDuration = typeof duration === "number" && Number.isFinite(duration) ? Math.floor(duration) : undefined;
10517
+ const prev = keyedTimers.get(key);
10518
+ if (prev) {
10519
+ if (prev.scope !== resolvedScope) {
10520
+ errors.push(`${where}: timer key "${key}" uses scope "${resolvedScope}", which conflicts with ${prev.where} ("${prev.scope}")`);
10521
+ }
10522
+ if (prev.duration !== undefined && resolvedDuration !== undefined && prev.duration !== resolvedDuration) {
10523
+ errors.push(`${where}: timer key "${key}" has duration ${resolvedDuration}, which conflicts with ${prev.where} (${prev.duration})`);
10524
+ }
10525
+ } else {
10526
+ keyedTimers.set(key, {
10527
+ where,
10528
+ scope: resolvedScope,
10529
+ duration: resolvedDuration
10530
+ });
10531
+ }
10532
+ }
10533
+ });
10534
+ });
10535
+ return errors;
10536
+ }
10537
+
10491
10538
  // src/index.ts
10492
10539
  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) => {
10540
+ program2.name("pairit").description("CLI for Pairit experiment configs").version("0.3.12").option("--env <name>", "Target environment: staging or production", (value) => {
10494
10541
  try {
10495
10542
  return parseEnvName(value);
10496
10543
  } catch (error) {
@@ -10845,6 +10892,7 @@ async function lintConfig(configPath) {
10845
10892
  errors.push(...lintRandomization(config));
10846
10893
  errors.push(...lintGroupView(config));
10847
10894
  errors.push(...lintEndRedirectUrls(config));
10895
+ errors.push(...lintTimers(config));
10848
10896
  if (errors.length) {
10849
10897
  throw new Error(errors.join(", "));
10850
10898
  }
@@ -10911,9 +10959,12 @@ async function compileConfig(configPath) {
10911
10959
  }
10912
10960
  async function buildUploadPayload(configPath, options) {
10913
10961
  const sourceConfig = await loadConfig(configPath);
10914
- const randomizationErrors = lintRandomization(sourceConfig);
10915
- if (randomizationErrors.length) {
10916
- throw new Error(randomizationErrors.join(", "));
10962
+ const validationErrors = [
10963
+ ...lintRandomization(sourceConfig),
10964
+ ...lintTimers(sourceConfig)
10965
+ ];
10966
+ if (validationErrors.length) {
10967
+ throw new Error(validationErrors.join(", "));
10917
10968
  }
10918
10969
  const allowRetake = sourceConfig.allowRetake === true;
10919
10970
  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.12",
4
4
  "description": "CLI for the Pairit behavioral science experiment platform",
5
5
  "type": "module",
6
6
  "bin": {