@ubaidbinwaris/linkedin 1.1.7 → 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 +110 -69
- package/package.json +1 -1
- package/LICENSE +0 -21
package/Readme.md
CHANGED
|
@@ -1,55 +1,85 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ubaidbinwaris/linkedin - Enterprise Automation Service
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
4
6
|
|
|
5
|
-
|
|
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
|
-
|
|
9
|
+
> **v1.1.7 Update**: Introduces "Smart Mobile Verification" with Visible Browser Fallback.
|
|
8
10
|
|
|
9
|
-
|
|
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
|
-
|
|
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
|
-
|
|
24
|
-
npm install @ubaidbinwaris/linkedin
|
|
25
|
-
```
|
|
24
|
+
## 🏗️ Architecture
|
|
26
25
|
|
|
27
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
##
|
|
73
|
+
## 📦 Installation
|
|
49
74
|
|
|
50
|
-
|
|
75
|
+
```bash
|
|
76
|
+
npm install @ubaidbinwaris/linkedin
|
|
77
|
+
```
|
|
51
78
|
|
|
52
|
-
|
|
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: '
|
|
63
|
-
password: '
|
|
92
|
+
username: 'alice@example.com',
|
|
93
|
+
password: 'secure_password'
|
|
64
94
|
});
|
|
65
95
|
|
|
66
|
-
console.log("Logged in
|
|
96
|
+
console.log("✅ Logged in successfully!");
|
|
67
97
|
|
|
68
|
-
//
|
|
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("
|
|
77
|
-
} else if (err.message.
|
|
78
|
-
console.error("User is
|
|
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("
|
|
108
|
+
console.error("Error:", err.message);
|
|
81
109
|
}
|
|
82
110
|
}
|
|
83
111
|
})();
|
|
84
112
|
```
|
|
85
113
|
|
|
86
|
-
### Custom
|
|
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
|
-
//
|
|
96
|
-
|
|
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.
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
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.
|