pairit 0.3.2 → 0.3.3

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 +79 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -9806,6 +9806,71 @@ async function attachHtmlToCompiledConfig(configPath, compiled) {
9806
9806
  }
9807
9807
  return sources;
9808
9808
  }
9809
+ function listWorkspaceComponents(config) {
9810
+ const pages = config.pages;
9811
+ const pageList = Array.isArray(pages) ? pages.filter(isRecord) : isRecord(pages) ? Object.values(pages).filter(isRecord) : [];
9812
+ const result = [];
9813
+ for (const page of pageList) {
9814
+ if (!Array.isArray(page.components))
9815
+ continue;
9816
+ for (const comp of page.components) {
9817
+ if (!isRecord(comp) || comp.type !== "live-workspace")
9818
+ continue;
9819
+ const props = isRecord(comp.props) ? comp.props : {};
9820
+ const id = typeof comp.id === "string" ? comp.id : "live-workspace";
9821
+ result.push({ id, props });
9822
+ }
9823
+ }
9824
+ return result;
9825
+ }
9826
+ async function resolveWorkspaceSchema(schema, componentId, configDir) {
9827
+ if (typeof schema !== "string" || !schema.trim().endsWith(".json")) {
9828
+ throw new Error(`live-workspace ${componentId}: schema must be a .json file`);
9829
+ }
9830
+ const absolutePath = path2.resolve(configDir, schema.trim());
9831
+ const rel = path2.relative(configDir, absolutePath);
9832
+ if (rel.startsWith("..") || path2.isAbsolute(rel)) {
9833
+ throw new Error(`live-workspace ${componentId}: schema must stay inside the config directory`);
9834
+ }
9835
+ try {
9836
+ JSON.parse(await readFile2(absolutePath, "utf8"));
9837
+ } catch (error) {
9838
+ throw new Error(`live-workspace ${componentId}: can't read schema ${schema}: ${error.message}`);
9839
+ }
9840
+ return absolutePath;
9841
+ }
9842
+ async function inspectWorkspaceFiles(configPath, config) {
9843
+ const configDir = await resolveConfigDir(configPath);
9844
+ const errors = [];
9845
+ for (const comp of listWorkspaceComponents(config)) {
9846
+ try {
9847
+ if (comp.props.renderer !== undefined) {
9848
+ await resolveHtmlSource(comp.props.renderer, comp.id, configDir);
9849
+ }
9850
+ if (comp.props.schema !== undefined) {
9851
+ await resolveWorkspaceSchema(comp.props.schema, comp.id, configDir);
9852
+ }
9853
+ } catch (error) {
9854
+ errors.push(error instanceof Error ? error.message : String(error));
9855
+ }
9856
+ }
9857
+ if (errors.length)
9858
+ throw new Error(errors.join(`
9859
+ `));
9860
+ }
9861
+ async function attachWorkspaceFilesToCompiledConfig(configPath, compiled) {
9862
+ const configDir = await resolveConfigDir(configPath);
9863
+ for (const comp of listWorkspaceComponents(compiled)) {
9864
+ if (comp.props.renderer !== undefined) {
9865
+ const resolved = await resolveHtmlSource(comp.props.renderer, comp.id, configDir);
9866
+ comp.props.rendererHtml = await readFile2(resolved.absolutePath, "utf8");
9867
+ }
9868
+ if (comp.props.schema !== undefined) {
9869
+ const schemaPath = await resolveWorkspaceSchema(comp.props.schema, comp.id, configDir);
9870
+ comp.props.schema = JSON.parse(await readFile2(schemaPath, "utf8"));
9871
+ }
9872
+ }
9873
+ }
9809
9874
 
9810
9875
  // src/randomize-lint.ts
9811
9876
  function lintRandomization(config) {
@@ -9865,7 +9930,7 @@ function singleGroupSize(config) {
9865
9930
 
9866
9931
  // src/index.ts
9867
9932
  var program2 = new Command;
9868
- program2.name("pairit").description("CLI for Pairit experiment configs").version("0.3.2").option("--env <name>", "Target environment: staging or production", (value) => {
9933
+ program2.name("pairit").description("CLI for Pairit experiment configs").version("0.3.3").option("--env <name>", "Target environment: staging or production", (value) => {
9869
9934
  try {
9870
9935
  return parseEnvName(value);
9871
9936
  } catch (error) {
@@ -10161,6 +10226,7 @@ async function lintConfig(configPath) {
10161
10226
  if (errors.length) {
10162
10227
  throw new Error(errors.join(", "));
10163
10228
  }
10229
+ await inspectWorkspaceFiles(configPath, config);
10164
10230
  return inspectHtmlSources(configPath, config);
10165
10231
  }
10166
10232
  async function compileConfig(configPath) {
@@ -10229,6 +10295,7 @@ async function buildUploadPayload(configPath, options) {
10229
10295
  const compiledContent = await readFile3(compiledPath, "utf8");
10230
10296
  const parsed = JSON.parse(compiledContent);
10231
10297
  const attachments = await attachHtmlToCompiledConfig(configPath, parsed);
10298
+ await attachWorkspaceFilesToCompiledConfig(configPath, parsed);
10232
10299
  const hashBuffer = createHash("sha256").update(JSON.stringify(parsed)).digest();
10233
10300
  const checksum = hashBuffer.toString("hex");
10234
10301
  const explicitName = options.name ?? sourceConfig.name;
@@ -10418,6 +10485,7 @@ async function exportData(configId, options) {
10418
10485
  await fetchAndWriteExport(`/data/${cfg}/groups`, path3.join(outDir, `${configId}-groups`), (r) => r.groups ?? [], format, (group) => group, "groups");
10419
10486
  await fetchAndWriteExport(`/data/${cfg}/survey-responses`, path3.join(outDir, `${configId}-survey-responses`), (r) => r.surveyResponses ?? [], format, flattenSurveyResponse, "survey responses");
10420
10487
  await fetchAndWriteExport(`/data/${cfg}/workspace-documents`, path3.join(outDir, `${configId}-workspace-documents`), (r) => r.workspaceDocuments ?? [], format, flattenWorkspaceDocument, "workspace documents");
10488
+ await fetchAndWriteExport(`/data/${cfg}/workspace-updates`, path3.join(outDir, `${configId}-workspace-updates`), (r) => r.workspaceUpdates ?? [], format, (update) => update, "workspace updates");
10421
10489
  console.log(`
10422
10490
  Files written to: ${outDir}`);
10423
10491
  }
@@ -10472,13 +10540,21 @@ function flattenSurveyResponse(response) {
10472
10540
  return flattened;
10473
10541
  }
10474
10542
  function flattenWorkspaceDocument(doc) {
10475
- const { fields, ...rest } = doc;
10476
- const flattened = { ...rest };
10543
+ const { fields, authorship, fieldAuthors, ...rest } = doc;
10544
+ const flattened = {
10545
+ ...rest,
10546
+ authorship: serializeValue(authorship)
10547
+ };
10477
10548
  if (fields && typeof fields === "object") {
10478
10549
  for (const [key, value] of Object.entries(fields)) {
10479
10550
  flattened[`fields.${key}`] = serializeValue(value);
10480
10551
  }
10481
10552
  }
10553
+ if (fieldAuthors && typeof fieldAuthors === "object") {
10554
+ for (const [key, origin] of Object.entries(fieldAuthors)) {
10555
+ flattened[`fieldAuthors.${key}`] = origin;
10556
+ }
10557
+ }
10482
10558
  return flattened;
10483
10559
  }
10484
10560
  function serializeValue(value) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pairit",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "CLI for the Pairit behavioral science experiment platform",
5
5
  "type": "module",
6
6
  "bin": {