-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdebug-static-saveDraft.ts
More file actions
81 lines (65 loc) · 2.37 KB
/
debug-static-saveDraft.ts
File metadata and controls
81 lines (65 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { connectToSuperhuman, disconnect, openCompose, setSubject, addRecipient, setBody, textToHtml } from "./src/superhuman-api";
async function debugStaticSaveDraft() {
console.log("=== Examining Static saveDraft Method ===\n");
const conn = await connectToSuperhuman(9333, true);
if (!conn) {
console.error("Failed to connect");
return;
}
const draftKey = await openCompose(conn);
console.log(`1. Opened compose: ${draftKey}`);
await addRecipient(conn, "static-test@test.com", undefined, draftKey!);
await setSubject(conn, "Static SaveDraft Test", draftKey!);
await setBody(conn, textToHtml("Static saveDraft test body"), draftKey!);
console.log("2. Populated draft");
// Get full saveDraft source
const sourceResult = await conn.Runtime.evaluate({
expression: `
(() => {
const cfc = window.ViewState?._composeFormController;
const draftKey = ${JSON.stringify(draftKey)};
const ctrl = cfc[draftKey];
const ctrlClass = ctrl.constructor;
// Get the full source
return ctrlClass.saveDraft?.toString?.();
})()
`,
returnByValue: true
});
console.log("\n3. Full saveDraft source:");
console.log(sourceResult.result.value);
// Check what props.account and related things look like
const propsCheck = await conn.Runtime.evaluate({
expression: `
(() => {
const cfc = window.ViewState?._composeFormController;
const draftKey = ${JSON.stringify(draftKey)};
const ctrl = cfc[draftKey];
const props = ctrl.props;
const state = ctrl.state;
const draft = state.draft;
// Check the condition for actual saving
const isDirty = draft?.isDirty?.();
const isSnippet = draft?.isSnippet?.();
// Check account
const account = props.account;
const hasThreads = !!account?.threads;
const hasGmail = !!account?.di?.get?.('gmail');
return {
isDirty,
isSnippet,
hasAccount: !!account,
hasThreads,
hasGmail,
accountType: account?.constructor?.name,
propsKeys: Object.keys(props || {}),
};
})()
`,
returnByValue: true
});
console.log("\n4. Props and state check:");
console.log(JSON.stringify(propsCheck.result.value, null, 2));
await disconnect(conn);
}
debugStaticSaveDraft().catch(console.error);