@ubaidbinwaris/linkedin 1.1.6 → 2.0.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/Readme.md CHANGED
@@ -1,55 +1,85 @@
1
- # LinkedIn Session Manager & Automation Service (v2.0.0)
1
+ # @ubaidbinwaris/linkedin - Enterprise Automation Service
2
2
 
3
- A robust, deterministic backend service foundation for managing multiple LinkedIn accounts with strict concurrency control and session isolation.
3
+ ![Version](https://img.shields.io/npm/v/@ubaidbinwaris/linkedin?style=flat-square)
4
+ ![License](https://img.shields.io/npm/l/@ubaidbinwaris/linkedin?style=flat-square)
5
+ ![Node](https://img.shields.io/node/v/@ubaidbinwaris/linkedin?style=flat-square)
4
6
 
5
- > **v2.0.0 Change**: This major version pivots from a CLI tool to a backend service architecture. It removes "stealth" plugins and "auto-resolution" magic in favor of stability, reliability, and "fail-fast" principles.
7
+ A professional, deterministic backend service library for managing multiple LinkedIn accounts with strict concurrency control, session isolation, and enterprise-grade security.
6
8
 
7
- ## Core Features
9
+ > **v1.1.7 Update**: Introduces "Smart Mobile Verification" with Visible Browser Fallback.
8
10
 
9
- - **Multi-User Architecture**: Designed to handle hundreds of accounts safely.
10
- - **Concurrency Control**: In-memory locking (`SessionLock`) prevents parallel login attempts for the same user.
11
- - **Session Isolation**:
12
- - Sessions stored as `SHA-256` hashes of emails (privacy).
13
- - AES-256 Encryption for session data.
14
- - **Smart Validation**:
15
- - Trusts sessions validated within the last 10 minutes (reduces feed navigation load).
16
- - Automatically refreshes older sessions.
17
- - **Deterministic Flow**:
18
- - **Launch** -> **Check Session** -> **Login** -> **Fail/Success**.
19
- - **Fail Fast**: If a checkpoint/challenge is detected, it throws `CHECKPOINT_DETECTED` immediately, allowing the upper layer (API/Worker) to handle it (e.g., notify admin).
11
+ ## 🚀 Key Features
20
12
 
21
- ## Installation
13
+ * **🛡️ Multi-User Concurrency**: Built-in `SessionLock` prevents race conditions. Impossible to double-login the same user.
14
+ * **🔒 Enterprise Security**:
15
+ * Sessions stored as `SHA-256` hashed filenames (GDPR/Privacy friendly).
16
+ * Data encrypted with `AES-256-CBC` before storage.
17
+ * **🧠 Smart Validation**:
18
+ * Caches validation checks for 10 minutes to minimize ban risk from excessive reloading.
19
+ * Automatically refreshes stale sessions.
20
+ * **📱 Mobile & Fallback Support**:
21
+ * **Phase 1**: Detects "Open LinkedIn App" prompt and waits 2 minutes for user approval.
22
+ * **Phase 2**: If mobile fails, automatically launches a **Visible Browser** for manual intervention.
22
23
 
23
- ```bash
24
- npm install @ubaidbinwaris/linkedin
25
- ```
24
+ ## 🏗️ Architecture
26
25
 
27
- ## Architecture
26
+ The library follows a strict **Fail-Fast** or **Resolution** flow. It does not use "stealth" plugins, relying instead on standard browser behavior and human intervention protocols.
28
27
 
29
28
  ```mermaid
30
- graph TD
31
- A[API/Worker Request] --> B{Acquire User Lock}
32
- B -- Busy --> C[Throw BUSY Error]
33
- B -- Acquired --> D[Launch Standard Playwright]
34
- D --> E{Load Session}
35
- E -- Valid & Recent --> F[Return Context (Skip Feed)]
36
- E -- Stale/None --> G[Navigate to Feed]
37
- G --> H{Is Logged In?}
38
- H -- Yes --> I[Update Validation Timestamp]
39
- I --> F
40
- H -- No --> J[Perform Credential Login]
41
- J --> K{Checkpoint?}
42
- K -- Yes --> L[Throw CHECKPOINT_DETECTED]
43
- K -- No --> M[Login Success]
44
- M --> I
45
- F --> N[Release Lock (on Task Completion)]
29
+ sequenceDiagram
30
+ participant API as API/Worker
31
+ participant Pkg as LinkedIn Package
32
+ participant Browser as Playwright
33
+ participant Store as Session Store
34
+
35
+ API->>Pkg: loginToLinkedIn(email, pass)
36
+ Pkg->>Pkg: Acquire Lock (SessionLock)
37
+ alt is Locked
38
+ Pkg-->>API: Throw BUSY Error
39
+ end
40
+
41
+ Pkg->>Browser: Launch (Headless)
42
+ Pkg->>Store: Load Context
43
+
44
+ alt Session Valid & Recent
45
+ Pkg-->>API: Return Page (Skip Feed)
46
+ else Session Stale/Invalid
47
+ Pkg->>Browser: Goto Feed
48
+
49
+ alt Login Required
50
+ Pkg->>Browser: Fill Credentials
51
+ Pkg->>Browser: Submit
52
+
53
+ opt Checkpoint Detected
54
+ Pkg->>Browser: Check Mobile Prompt
55
+ alt Mobile Prompt Found
56
+ Pkg->>Pkg: Wait 2 Mins for Feed URL
57
+ end
58
+
59
+ alt Mobile Failed
60
+ Pkg->>Browser: Close Headless
61
+ Pkg->>Browser: Launch VISIBLE Browser
62
+ Pkg->>Browser: Re-Fill Credentials
63
+ Pkg->>Pkg: Wait for Manual Use
64
+ end
65
+ end
66
+ end
67
+
68
+ Pkg->>Store: Save Session (Encrypted)
69
+ Pkg-->>API: Return Page
70
+ end
46
71
  ```
47
72
 
48
- ## Usage
73
+ ## 📦 Installation
49
74
 
50
- ### Basic Login
75
+ ```bash
76
+ npm install @ubaidbinwaris/linkedin
77
+ ```
51
78
 
52
- The `loginToLinkedIn` function now handles locking internally. If you try to call it twice for the same user simultaneously, the second call will fail with a `BUSY` error.
79
+ ## 💻 Usage
80
+
81
+ ### 1. Basic Implementation
82
+ The simplest way to use the package. Locks and session management are handled automatically.
53
83
 
54
84
  ```javascript
55
85
  const { loginToLinkedIn } = require('@ubaidbinwaris/linkedin');
@@ -57,59 +87,70 @@ const { loginToLinkedIn } = require('@ubaidbinwaris/linkedin');
57
87
  (async () => {
58
88
  try {
59
89
  const { browser, page } = await loginToLinkedIn({
60
- headless: true
90
+ headless: true // Will auto-switch to false if fallback needed
61
91
  }, {
62
- username: 'user@example.com',
63
- password: 'secret-password'
92
+ username: 'alice@example.com',
93
+ password: 'secure_password'
64
94
  });
65
95
 
66
- console.log("Logged in and active!");
96
+ console.log("Logged in successfully!");
67
97
 
68
- // Output session status
69
- console.log(`Needs Validation? ${page.context().needsValidation}`);
98
+ // ... Perform scraping/automation tasks ...
70
99
 
71
- // Do work...
72
-
73
100
  await browser.close();
101
+
74
102
  } catch (err) {
75
103
  if (err.message === 'CHECKPOINT_DETECTED') {
76
- console.error("Manual intervention required for this account.");
77
- } else if (err.message.startsWith('BUSY')) {
78
- console.error("User is currently busy with another task.");
104
+ console.error(" Critical: Account requires manual ID verification.");
105
+ } else if (err.message.includes('BUSY')) {
106
+ console.error("⚠️ User is already running a task.");
79
107
  } else {
80
- console.error("Login failed:", err);
108
+ console.error("Error:", err.message);
81
109
  }
82
110
  }
83
111
  })();
84
112
  ```
85
113
 
86
- ### Custom Session Storage
87
-
88
- You can link this to a database (Redis/Postgres) instead of local files.
114
+ ### 2. Custom Storage (Database Integration)
115
+ By default, sessions are saved to `./sessions`. Override this to use Redis, MongoDB, or PostgreSQL.
89
116
 
90
117
  ```javascript
91
118
  const { setSessionStorage } = require('@ubaidbinwaris/linkedin');
92
119
 
93
120
  setSessionStorage({
94
121
  read: async (email) => {
95
- // Fetch encrypted string from DB
96
- return await db.sessions.findOne({ where: { email } });
122
+ // Return encrypted JSON string from your DB
123
+ const result = await db.query('SELECT session_data FROM users WHERE email = $1', [email]);
124
+ return result.rows[0]?.session_data;
97
125
  },
98
126
  write: async (email, data) => {
99
- // Save encrypted string to DB
100
- await db.sessions.upsert({ email, data });
127
+ // Save encrypted JSON string to your DB
128
+ await db.query('UPDATE users SET session_data = $1 WHERE email = $2', [data, email]);
101
129
  }
102
130
  });
103
131
  ```
104
132
 
105
- ## Directory Structure
106
-
107
- * `src/session/`:
108
- * `SessionLock.js`: In-memory concurrency control.
109
- * `sessionManager.js`: Hashing, encryption, validation logic.
110
- * `src/login/`:
111
- * `login.js`: Deterministic login flow.
112
- * `src/browser/`:
113
- * `launcher.js`: Standard Playwright launcher (no stealth plugins).
114
- * `src/auth/`:
115
- * `checkpoint.js`: Simple detection logic.
133
+ ### 3. Custom Logger
134
+ Pipe internal logs to your own system (e.g., Winston, UI Stream).
135
+
136
+ ```javascript
137
+ const { setLogger } = require('@ubaidbinwaris/linkedin');
138
+
139
+ setLogger({
140
+ info: (msg) => console.log(`[LI-INFO] ${msg}`),
141
+ warn: (msg) => console.warn(`[LI-WARN] ${msg}`),
142
+ error: (msg) => console.error(`[LI-ERR] ${msg}`)
143
+ });
144
+ ```
145
+
146
+ ## 🚨 Error Reference
147
+
148
+ | Error Message | Meaning | Handling Action |
149
+ | :--- | :--- | :--- |
150
+ | `CHECKPOINT_DETECTED` | Security challenge (ID upload/Captcha) could not be resolved. | Notify admin. Manual Login required. |
151
+ | `CHECKPOINT_DETECTED_M` | Manual Fallback (Visible Browser) timed out. | User didn't interact in time. Retry. |
152
+ | `BUSY: ...` | A task is already running for this email. | Queue the request or reject it. |
153
+ | `LOGIN_FAILED` | Credentials accepted, but session could not be verified. | Check proxy/network. |
154
+
155
+ ## License
156
+ ISC
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ubaidbinwaris/linkedin",
3
- "version": "1.1.6",
3
+ "version": "2.0.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -72,6 +72,15 @@ async function loginToLinkedIn(options = {}, credentials = null) {
72
72
  // If it returns true, it means we are now on the feed (resolved)
73
73
  if (await handleMobileVerification(page)) {
74
74
  // success, assume logged in
75
+ // Wait a moment for page to settle
76
+ await page.waitForTimeout(3000);
77
+
78
+ // Double check if we are really on feed
79
+ if (page.url().includes("/feed") || await isLoggedIn(page)) {
80
+ logger.info(`[${email}] Mobile Verification Successful ✅`);
81
+ await saveSession(context, email, true);
82
+ return { browser, context, page };
83
+ }
75
84
  } else {
76
85
  // Failed mobile verification.
77
86
  // User Request: "otherwise after some delay using browser opens the browser and fill the form"
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 UbaidBinWaris
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.