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,KAAK,GACpC,IAAe,EAAW,WAAW,gBACvC,EAAY,KAAK,EAErB,CACA,KAAK,KAAK,OAAO,QAAQ,OAAS,EAAY,KAAK,MAOnD,QAJ0B,IAAxB,KAAK,eACD,KAAK,eACoB,QAAzB,KAAK,iBAAsD,gBAAzB,KAAK,gBAEpB,CACvB,MAAM,QAAiB,mBACjB,EAAc,IAAI,kBAAkB,SACpC,EAAY,aAClB,KAAK,KAAK,sBAAwB,EAAY,sBAAsB,KAAK,EAC3E,CAEA,MACM,SADqB,EAAI,QACQ,MAAM,6CAE7C,IAAK,EAEH,YADA,QAAQ,KAAK,0DAIf,MAAM,EAAe,KAAK,MAAM,EAAkB,IAC5C,EAAgB,GAAc,UAAU,OAAO,SAC/C,EAAmB,GAAiB,OAAO,OAAO,GAAe,GAEvE,GAAK,EAQL,OAHA,KAAK,KAAO,UAAU,GACtB,KAAK,SAAW,GAAc,UAAU,QAAQ,SAEzC,KAAK,KAPV,QAAQ,KAAK,qDAQjB,EAGF,OAAO,UAAU,QAAU,QAC3B,OAAO,UAAU,KAAO,KACxB,OAAO,UAAU,GAAK,GACtB,YAAY,OAAO","file":"/npm/emusks@2.0.13/src/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/emusks@2.0.13/src/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import { ClientTransaction, handleXMigration } from \"x-client-transaction-id\";\nimport clients from \"./clients.js\";\nimport getCycleTLS from \"./cycletls.js\";\nimport flowLogin from \"./flow.js\";\nimport graphql, { GRAPHQL_ENDPOINTS } from \"./graphql.js\";\nimport initHelpers from \"./helpers/index.js\";\nimport parseUser from \"./parsers/user.js\";\nimport v1_1 from \"./v1.1.js\";\nimport v2 from \"./v2.js\";\n\nexport default class Emusks {\n  auth = null;\n  elevatedCookies = null;\n  graphqlEndpoint = \"web\";\n  transactionIds = undefined;\n\n  async elevate(password) {\n    if (!this.auth) throw new Error(\"must be logged in before calling elevate\");\n\n    const res = await this.v1_1(\"account/verify_password\", {\n      body: `password=${encodeURIComponent(password)}`,\n      headers: {\n        \"content-type\": \"application/x-www-form-urlencoded\",\n      },\n    });\n\n    const setCookies = res.headers[\"Set-Cookie\"] || [];\n\n    const json = await res.json();\n    if (json.status !== \"ok\") {\n      throw new Error(\"invalid password\");\n    }\n\n    const cookieParts = [];\n    for (const setCookie of setCookies) {\n      const cookiePair = setCookie.split(\";\")[0];\n      if (cookiePair) {\n        cookieParts.push(cookiePair);\n      }\n    }\n\n    this.elevatedCookies = cookieParts.join(\"; \");\n\n    return json;\n  }\n\n  async login(p) {\n    if (typeof p === \"string\") {\n      if (p.length > 50 || p.length < 20) {\n        throw new Error(\"invalid auth token length!\");\n      }\n      p = { auth_token: p };\n    }\n\n    if (p.type === \"password\") {\n      if (!p.username) throw new Error(\"username is required for password login\");\n      if (!p.password) throw new Error(\"password is required for password login\");\n\n      const flowResult = await flowLogin({\n        username: p.username,\n        password: p.password,\n        email: p.email,\n        phone: p.phone,\n        onRequest: p.onRequest,\n        proxy: p.proxy,\n      });\n\n      p = {\n        auth_token: flowResult.authToken,\n        client: p.client,\n        proxy: p.proxy,\n      };\n    }\n\n    if (!p.client) p.client = \"web\";\n    if (!p.auth_token) throw new Error(\"auth_token is required!\");\n    if (typeof p.client === \"string\") p.client = clients[p.client];\n    if (!p.client) throw new Error(\"invalid client!\");\n    if (p.proxy) this.proxy = p.proxy;\n\n    if (p.endpoint) {\n      if (!GRAPHQL_ENDPOINTS[p.endpoint]) {\n        throw new Error(\n          `unknown graphql endpoint \"${p.endpoint}\", expected: ${Object.keys(GRAPHQL_ENDPOINTS).join(\", \")}`,\n        );\n      }\n      this.graphqlEndpoint = p.endpoint;\n    }\n\n    if (p.transactionIds !== undefined) {\n      this.transactionIds = p.transactionIds;\n    }\n\n    if (!p.client.bearer) {\n      throw new Error(\"client is missing bearer token!\");\n    }\n    if (!p.client.userAgent || !p.client.fingerprints) {\n      p.client.userAgent =\n        p.client.userAgent ||\n        \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36\";\n\n      p.client.fingerprints = p.client.fingerprints || {\n        ja3: \"771,4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,35-5-27-16-0-10-13-23-45-65037-17613-18-65281-51-43-11,4588-29-23-24,0\",\n        ja4r: \"t13d1516h2_002f,0035,009c,009d,1301,1302,1303,c013,c014,c02b,c02c,c02f,c030,cca8,cca9_0005,000a,000b,000d,0012,0017,001b,0023,002b,002d,0033,44cd,fe0d,ff01_0403,0804,0401,0503,0805,0501,0806,0601\",\n      };\n    }\n\n    p.client.headers = {\n      \"accept-language\": \"en-US,en;q=0.9\",\n      priority: \"u=1, i\",\n      \"sec-ch-ua\": '\"Not(A:Brand\";v=\"8\", \"Chromium\";v=\"144\"',\n      \"sec-ch-ua-mobile\": \"?0\",\n      \"sec-ch-ua-platform\": '\"macOS\"',\n      \"sec-fetch-dest\": \"empty\",\n      \"sec-fetch-mode\": \"cors\",\n      \"sec-fetch-site\": \"same-site\",\n      \"sec-gpc\": \"1\",\n    };\n\n    const cycleTLS = await getCycleTLS();\n    const res = await cycleTLS(\"https://x.com/\", {\n      headers: {\n        accept:\n          \"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7\",\n        cookie: `auth_token=${p.auth_token};`,\n        ...p.client.headers,\n      },\n      userAgent: p.client.fingerprints.userAgent,\n      ja3: p.client.fingerprints.ja3,\n      ja4r: p.client.fingerprints.ja4r,\n      proxy: p.proxy || undefined,\n      referrer: \"https://x.com/\",\n    });\n\n    const setCookies = res.headers[\"Set-Cookie\"] || [];\n    const csrfToken = setCookies\n      .find((c) => c?.startsWith?.(\"ct0=\"))\n      ?.split?.(\";\")?.[0]\n      ?.split?.(\"=\")?.[1];\n\n    if (!csrfToken) {\n      throw new Error(\"[emusks] failed to log in\");\n    }\n\n    this.auth = p;\n    this.auth.csrfToken = csrfToken;\n\n    const cookieParts = [`auth_token=${p.auth_token}`];\n    for (const setCookie of setCookies) {\n      const cookiePair = setCookie.split(\";\")[0];\n      if (cookiePair && !cookiePair.startsWith(\"auth_token=\")) {\n        cookieParts.push(cookiePair);\n      }\n    }\n    this.auth.client.headers.cookie = cookieParts.join(\"; \");\n\n    const needsTransactionIds =\n      this.transactionIds !== undefined\n        ? this.transactionIds\n        : this.graphqlEndpoint === \"web\" || this.graphqlEndpoint === \"web_twitter\";\n\n    if (needsTransactionIds) {\n      const document = await handleXMigration();\n      const transaction = new ClientTransaction(document);\n      await transaction.initialize();\n      this.auth.generateTransactionId = transaction.generateTransactionId.bind(transaction);\n    }\n\n    const responseText = await res.text();\n    const initialStateMatch = responseText.match(/window\\.__INITIAL_STATE__\\s*=\\s*({.*?});/s);\n\n    if (!initialStateMatch) {\n      console.warn(\"[emusks] failed to extract initial state from response\");\n      return;\n    }\n\n    const initialState = JSON.parse(initialStateMatch[1]);\n    const usersEntities = initialState?.entities?.users?.entities;\n    const initialStateUser = usersEntities && Object.values(usersEntities)[0];\n\n    if (!initialStateUser) {\n      console.warn(\"[emusks] failed to extract user from initial state\");\n      return;\n    }\n\n    this.user = parseUser(initialStateUser);\n    this.settings = initialState?.settings?.remote?.settings;\n\n    return this.user;\n  }\n}\n\nEmusks.prototype.graphql = graphql;\nEmusks.prototype.v1_1 = v1_1;\nEmusks.prototype.v2 = v2;\ninitHelpers(Emusks.prototype);\n"]}