emusks 2.0.3 → 2.0.5

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/src/index.js CHANGED
@@ -1,19 +1,16 @@
1
1
  import { ClientTransaction, handleXMigration } from "x-client-transaction-id";
2
- import parseUser from "./parsers/user.js";
3
- import getCycleTLS from "./cycletls.js";
4
2
  import clients from "./clients.js";
3
+ import getCycleTLS from "./cycletls.js";
4
+ import flowLogin from "./flow.js";
5
5
  import graphql from "./graphql.js";
6
+ import initHelpers from "./helpers/index.js";
7
+ import parseUser from "./parsers/user.js";
6
8
  import v1_1 from "./v1.1.js";
7
9
  import v2 from "./v2.js";
8
- import flowLogin from "./flow.js";
9
- import initHelpers from "./helpers/index.js";
10
10
 
11
11
  export default class Emusks {
12
12
  auth = null;
13
13
  elevatedCookies = null;
14
- graphql = graphql;
15
- v1_1 = v1_1;
16
- v2 = v2;
17
14
 
18
15
  async elevate(password) {
19
16
  if (!this.auth) throw new Error("must be logged in before calling elevate");
@@ -54,8 +51,10 @@ export default class Emusks {
54
51
  }
55
52
 
56
53
  if (p.type === "password") {
57
- if (!p.username) throw new Error("username is required for password login");
58
- if (!p.password) throw new Error("password is required for password login");
54
+ if (!p.username)
55
+ throw new Error("username is required for password login");
56
+ if (!p.password)
57
+ throw new Error("password is required for password login");
59
58
 
60
59
  const flowResult = await flowLogin({
61
60
  username: p.username,
@@ -128,8 +127,16 @@ export default class Emusks {
128
127
  }
129
128
  this.auth.client.headers.cookie = cookieParts.join("; ");
130
129
 
130
+ const document = await handleXMigration();
131
+ const transaction = new ClientTransaction(document);
132
+ await transaction.initialize();
133
+ this.auth.generateTransactionId =
134
+ transaction.generateTransactionId.bind(transaction);
135
+
131
136
  const responseText = await res.text();
132
- const initialStateMatch = responseText.match(/window\.__INITIAL_STATE__\s*=\s*({.*?});/s);
137
+ const initialStateMatch = responseText.match(
138
+ /window\.__INITIAL_STATE__\s*=\s*({.*?});/s,
139
+ );
133
140
 
134
141
  if (!initialStateMatch) {
135
142
  console.warn("[emusks] failed to extract initial state from response");
@@ -148,14 +155,11 @@ export default class Emusks {
148
155
  this.user = parseUser(initialStateUser);
149
156
  this.settings = initialState?.settings?.remote?.settings;
150
157
 
151
- const document = await handleXMigration();
152
- const transaction = new ClientTransaction(document);
153
- await transaction.initialize();
154
- this.auth.generateTransactionId = transaction.generateTransactionId.bind(transaction);
155
-
156
- const helpers = initHelpers(this);
157
- Object.assign(this, helpers);
158
-
159
158
  return this.user;
160
159
  }
161
- }
160
+ }
161
+
162
+ Emusks.prototype.graphql = graphql;
163
+ Emusks.prototype.v1_1 = v1_1;
164
+ Emusks.prototype.v2 = v2;
165
+ initHelpers(Emusks.prototype);