querysub 0.728.0 → 0.729.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "querysub",
3
- "version": "0.728.0",
3
+ "version": "0.729.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "note1": "note on node-forge fork, see https://github.com/digitalbazaar/forge/issues/744 for details",
@@ -40,6 +40,7 @@
40
40
  "watch-service": "yarn typenode ./src/diagnostics/network/watchServiceMain.ts",
41
41
  "remote-flushlogs": "yarn typenode ./src/diagnostics/network/remoteFlushLogsMain.ts",
42
42
  "publish-querysub": "yarn typenode ./src/deployManager/publishQuerysubMain.ts",
43
+ "web-otp-claude": "yarn typenode ./src/deployManager/webOtpMain.ts",
43
44
  "parameters-timeline": "yarn typenode ./src/deployManager/parametersTimelineMain.ts",
44
45
  "setup-machine": "yarn typenode ./src/deployManager/setupMachineMain.ts",
45
46
  "stop-machine": "yarn typenode ./src/deployManager/stopMachineMain.ts",
@@ -95,8 +96,8 @@
95
96
  "node-forge": "https://github.com/sliftist/forge#e618181b469b07bdc70b968b0391beb8ef5fecd6",
96
97
  "pako": "^2.1.0",
97
98
  "peggy": "^5.0.6",
98
- "sliftutils": "^1.9.21",
99
- "socket-function": "^1.3.1",
99
+ "sliftutils": "1.9.22",
100
+ "socket-function": "1.3.13",
100
101
  "terser": "^5.31.0",
101
102
  "typenode": "^6.6.3",
102
103
  "typesafecss": "^0.32.0",
@@ -462,6 +462,7 @@ class PathValueCommitter {
462
462
  }
463
463
 
464
464
  export const pathValueCommitter = new PathValueCommitter();
465
+ (globalThis as any).pathValueCommitter = pathValueCommitter;
465
466
 
466
467
  registerShutdownHandler(async () => {
467
468
  await pathValueCommitter.waitForValuesToCommit();
@@ -44,7 +44,7 @@ export async function publishQuerysubAsync(config: { querysubFolder: string }):
44
44
  throw new Error(`yarn publish of querysub ${version} as ${user} failed, and didn't ask for a one-time code:\n${output}`);
45
45
  }
46
46
 
47
- let otp = await getWebOtpAsync();
47
+ let otp = await getWebOtpAsync("querysub");
48
48
  output = await runPromise(`${publishCommand} --otp ${otp}`, { cwd: querysubFolder, nothrow: true, includeStderrInOutput: true });
49
49
  if (!output.includes(PUBLISH_SUCCESS_TEXT)) {
50
50
  throw new Error(`yarn publish of querysub ${version} as ${user} with the one-time code from the browser failed:\n${output}`);
@@ -56,21 +56,21 @@ function readVersion(querysubFolder: string): string {
56
56
  return String(JSON.parse(fs.readFileSync(path.join(querysubFolder, "package.json"), "utf8")).version);
57
57
  }
58
58
 
59
- async function getWebOtpAsync(): Promise<string> {
59
+ export async function getWebOtpAsync(packageName: string): Promise<string> {
60
60
  let npmrcPath = path.join(os.homedir(), ".npmrc");
61
61
  let token = NPMRC_TOKEN_PATTERN.exec(await fs.promises.readFile(npmrcPath, "utf8"))?.[1]?.trim();
62
62
  if (!token) {
63
63
  throw new Error(`Expected an auth token for ${PUBLISH_REGISTRY} in ${npmrcPath} after logging in, but there wasn't one`);
64
64
  }
65
- let latest = (await runPromise(`npm view querysub dist-tags.latest`, { quiet: true })).trim();
65
+ let latest = (await runPromise(`npm view ${packageName} dist-tags.latest`, { quiet: true })).trim();
66
66
  if (!latest) {
67
- throw new Error(`Expected npm view querysub dist-tags.latest to give a version, was empty`);
67
+ throw new Error(`Expected npm view ${packageName} dist-tags.latest to give a version, was empty`);
68
68
  }
69
69
 
70
70
  let npmVersion = (await runPromise(`npm --version`, { quiet: true })).trim();
71
71
  let userAgent = `npm/${npmVersion} node/${process.version} ${process.platform} ${process.arch} workspaces/false`;
72
72
 
73
- let probeUrl = `${PUBLISH_REGISTRY}/-/package/querysub/dist-tags/latest`;
73
+ let probeUrl = `${PUBLISH_REGISTRY}/-/package/${packageName}/dist-tags/latest`;
74
74
  let probe = await registryRequestAsync({ url: probeUrl, method: "PUT", token, userAgent, payload: JSON.stringify(latest) });
75
75
  if (probe.statusCode !== 401) {
76
76
  throw new Error(`Expected setting dist-tag latest to its current ${latest} to require two-factor (401), was ${probe.statusCode}: ${probe.body.slice(0, ERROR_BODY_LIMIT)}`);
@@ -0,0 +1,25 @@
1
+ module.hotreload = false;
2
+
3
+ import fs from "fs";
4
+ import yargs from "yargs";
5
+ import { getWebOtpAsync } from "./publishQuerysub";
6
+
7
+ let args = yargs(process.argv.slice(2))
8
+ .option("package", { type: "string", demandOption: true, describe: "npm package to get a publish one-time code for" })
9
+ .option("out", { type: "string", demandOption: true, describe: "file to write the one-time code to" })
10
+ .strict()
11
+ .argv;
12
+
13
+ async function main() {
14
+ let otp = await getWebOtpAsync(args.package);
15
+ await fs.promises.writeFile(args.out, otp);
16
+ console.log(`Wrote the one-time code for ${args.package} to ${args.out}`);
17
+ }
18
+
19
+ main().then(
20
+ () => process.exit(),
21
+ e => {
22
+ console.error((e as Error).stack || e);
23
+ process.exit(1);
24
+ },
25
+ );
@@ -1172,5 +1172,38 @@ export async function nodeJSLoginToUser(userId: string) {
1172
1172
  });
1173
1173
  }
1174
1174
 
1175
+ export const TEST_USER_ID_PREFIX = "test-";
1176
+ export async function scriptAddTrust(config: { userId: string; machineId: string; }) {
1177
+ const { userId, machineId } = config;
1178
+ if (!userId.startsWith(TEST_USER_ID_PREFIX)) {
1179
+ throw new Error(`Trust can only be added to test accounts, whose user ids start with "${TEST_USER_ID_PREFIX}", was ${userId}`);
1180
+ }
1181
+ const ips = [await getExternalIP(), "127.0.0.1"];
1182
+ let now = Date.now();
1183
+ await Querysub.commitSynced(() => {
1184
+ if (!(userId in data().users)) {
1185
+ data().users[userId] = {
1186
+ userId,
1187
+ email: `${userId} is a test account without email login`,
1188
+ settings: { displayName: userId },
1189
+ userType: "user",
1190
+ createTime: now,
1191
+ machineIds: {},
1192
+ allowedIPs: {},
1193
+ loginTokens: {},
1194
+ lastPageLoadsIPs: {},
1195
+ invitedUsers2: {},
1196
+ invitesRemaining: 0,
1197
+ };
1198
+ }
1199
+ let userObj = data().users[userId];
1200
+ for (let ip of ips) {
1201
+ userObj.allowedIPs[ip] = atomicObjectWrite({ time: now, machineId });
1202
+ }
1203
+ userObj.machineIds[machineId] = atomicObjectWrite({ time: now, ip: ips[0] });
1204
+ data().machineSecure[machineId].userId = userId;
1205
+ });
1206
+ }
1207
+
1175
1208
  export const user_data = data;
1176
1209
  export const user_functions = functions;