pairit 0.1.6 → 0.1.8
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 +28 -48
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9528,9 +9528,9 @@ async function login() {
|
|
|
9528
9528
|
});
|
|
9529
9529
|
const redirectUri = `http://127.0.0.1:${port}`;
|
|
9530
9530
|
const targetUrl = `${loginUrl}?cli_redirect_uri=${encodeURIComponent(redirectUri)}`;
|
|
9531
|
-
console.log(
|
|
9531
|
+
console.log(`Opening ${loginUrl} in your browser...`);
|
|
9532
9532
|
await open2(targetUrl);
|
|
9533
|
-
console.log(
|
|
9533
|
+
console.log("Waiting for sign-in to complete...");
|
|
9534
9534
|
const authCode = await new Promise((resolve, reject) => {
|
|
9535
9535
|
const timeout = setTimeout(() => {
|
|
9536
9536
|
server.close();
|
|
@@ -9666,7 +9666,7 @@ async function loadKeytar() {
|
|
|
9666
9666
|
|
|
9667
9667
|
// src/index.ts
|
|
9668
9668
|
var program2 = new Command;
|
|
9669
|
-
program2.name("pairit").description("CLI for Pairit experiment configs").version("0.1.
|
|
9669
|
+
program2.name("pairit").description("CLI for Pairit experiment configs").version("0.1.8");
|
|
9670
9670
|
program2.command("login").description("Login to Pairit Manager").action(async () => {
|
|
9671
9671
|
try {
|
|
9672
9672
|
await login();
|
|
@@ -10018,6 +10018,19 @@ async function resolvePath(configPath) {
|
|
|
10018
10018
|
await stat(absolute);
|
|
10019
10019
|
return absolute;
|
|
10020
10020
|
}
|
|
10021
|
+
async function fetchAllPages(pathname, extract) {
|
|
10022
|
+
const all = [];
|
|
10023
|
+
let since = null;
|
|
10024
|
+
do {
|
|
10025
|
+
const url = since ? `${pathname}?since=${encodeURIComponent(since)}` : pathname;
|
|
10026
|
+
const response = await callFunctions(url, { method: "GET" });
|
|
10027
|
+
if (!response)
|
|
10028
|
+
break;
|
|
10029
|
+
all.push(...extract(response));
|
|
10030
|
+
since = response.nextCursor ?? null;
|
|
10031
|
+
} while (since);
|
|
10032
|
+
return all;
|
|
10033
|
+
}
|
|
10021
10034
|
async function callFunctions(pathname, init = {}) {
|
|
10022
10035
|
const baseUrl = getFunctionsBaseUrl();
|
|
10023
10036
|
const url = new URL(pathname, baseUrl).toString();
|
|
@@ -10083,54 +10096,21 @@ async function exportData(configId, options) {
|
|
|
10083
10096
|
const outDir = path2.resolve(process9.cwd(), options.out);
|
|
10084
10097
|
await mkdir2(outDir, { recursive: true });
|
|
10085
10098
|
console.log(`Exporting data for ${configId} in ${format} format...`);
|
|
10086
|
-
const
|
|
10087
|
-
|
|
10088
|
-
|
|
10089
|
-
|
|
10090
|
-
|
|
10091
|
-
|
|
10092
|
-
|
|
10093
|
-
] = await Promise.all([
|
|
10094
|
-
callFunctions(`/data/${encodeURIComponent(configId)}/sessions`, {
|
|
10095
|
-
method: "GET"
|
|
10096
|
-
}),
|
|
10097
|
-
callFunctions(`/data/${encodeURIComponent(configId)}/events`, {
|
|
10098
|
-
method: "GET"
|
|
10099
|
-
}),
|
|
10100
|
-
callFunctions(`/data/${encodeURIComponent(configId)}/chat-messages`, {
|
|
10101
|
-
method: "GET"
|
|
10102
|
-
}),
|
|
10103
|
-
callFunctions(`/data/${encodeURIComponent(configId)}/groups`, {
|
|
10104
|
-
method: "GET"
|
|
10105
|
-
}),
|
|
10106
|
-
callFunctions(`/data/${encodeURIComponent(configId)}/survey-responses`, {
|
|
10107
|
-
method: "GET"
|
|
10108
|
-
}),
|
|
10109
|
-
callFunctions(`/data/${encodeURIComponent(configId)}/workspace-documents`, {
|
|
10110
|
-
method: "GET"
|
|
10111
|
-
})
|
|
10112
|
-
]);
|
|
10113
|
-
const sessions = sessionsRes.sessions ?? [];
|
|
10114
|
-
const events = eventsRes.events ?? [];
|
|
10115
|
-
const messages = messagesRes.messages ?? [];
|
|
10116
|
-
const groups = groupsRes.groups ?? [];
|
|
10117
|
-
const surveyResponses = surveyRes.surveyResponses ?? [];
|
|
10118
|
-
const workspaceDocuments = workspaceRes.workspaceDocuments ?? [];
|
|
10119
|
-
await writeExportFile(path2.join(outDir, `${configId}-sessions`), sessions, format, flattenSession);
|
|
10120
|
-
console.log(`✓ Exported ${sessions.length} sessions`);
|
|
10121
|
-
await writeExportFile(path2.join(outDir, `${configId}-events`), events, format, flattenEvent);
|
|
10122
|
-
console.log(`✓ Exported ${events.length} events`);
|
|
10123
|
-
await writeExportFile(path2.join(outDir, `${configId}-chat-messages`), messages, format, (msg) => msg);
|
|
10124
|
-
console.log(`✓ Exported ${messages.length} chat messages`);
|
|
10125
|
-
await writeExportFile(path2.join(outDir, `${configId}-groups`), groups, format, (group) => group);
|
|
10126
|
-
console.log(`✓ Exported ${groups.length} groups`);
|
|
10127
|
-
await writeExportFile(path2.join(outDir, `${configId}-survey-responses`), surveyResponses, format, flattenSurveyResponse);
|
|
10128
|
-
console.log(`✓ Exported ${surveyResponses.length} survey responses`);
|
|
10129
|
-
await writeExportFile(path2.join(outDir, `${configId}-workspace-documents`), workspaceDocuments, format, flattenWorkspaceDocument);
|
|
10130
|
-
console.log(`✓ Exported ${workspaceDocuments.length} workspace documents`);
|
|
10099
|
+
const cfg = encodeURIComponent(configId);
|
|
10100
|
+
await fetchAndWriteExport(`/data/${cfg}/sessions`, path2.join(outDir, `${configId}-sessions`), (r) => r.sessions ?? [], format, flattenSession, "sessions");
|
|
10101
|
+
await fetchAndWriteExport(`/data/${cfg}/events`, path2.join(outDir, `${configId}-events`), (r) => r.events ?? [], format, flattenEvent, "events");
|
|
10102
|
+
await fetchAndWriteExport(`/data/${cfg}/chat-messages`, path2.join(outDir, `${configId}-chat-messages`), (r) => r.messages ?? [], format, (msg) => msg, "chat messages");
|
|
10103
|
+
await fetchAndWriteExport(`/data/${cfg}/groups`, path2.join(outDir, `${configId}-groups`), (r) => r.groups ?? [], format, (group) => group, "groups");
|
|
10104
|
+
await fetchAndWriteExport(`/data/${cfg}/survey-responses`, path2.join(outDir, `${configId}-survey-responses`), (r) => r.surveyResponses ?? [], format, flattenSurveyResponse, "survey responses");
|
|
10105
|
+
await fetchAndWriteExport(`/data/${cfg}/workspace-documents`, path2.join(outDir, `${configId}-workspace-documents`), (r) => r.workspaceDocuments ?? [], format, flattenWorkspaceDocument, "workspace documents");
|
|
10131
10106
|
console.log(`
|
|
10132
10107
|
Files written to: ${outDir}`);
|
|
10133
10108
|
}
|
|
10109
|
+
async function fetchAndWriteExport(pathname, outBase, extract, format, flatten, label) {
|
|
10110
|
+
const data = await fetchAllPages(pathname, extract);
|
|
10111
|
+
await writeExportFile(outBase, data, format, flatten);
|
|
10112
|
+
console.log(`✓ Exported ${data.length} ${label}`);
|
|
10113
|
+
}
|
|
10134
10114
|
function flattenSession(session) {
|
|
10135
10115
|
const { session_state, prolific, ...rest } = session;
|
|
10136
10116
|
const flattened = { ...rest };
|