@abapify/adt-puppeteer 0.0.0 → 0.3.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/README.md +350 -1
- package/package.json +35 -3
package/README.md
CHANGED
|
@@ -1,3 +1,352 @@
|
|
|
1
1
|
# @abapify/adt-puppeteer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/abapify/adt-cli/pkgs/npm/%40abapify%2Fadt-puppeteer)
|
|
4
|
+
|
|
5
|
+
Puppeteer-based SSO authentication plugin for SAP ADT systems. Alternative to Playwright for environments where Puppeteer is preferred.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- 🔐 **SSO/IDP Support** - Works with Okta, Azure AD, and other identity providers
|
|
10
|
+
- 💾 **Session Persistence** - Reuse Okta tokens across runs
|
|
11
|
+
- 🎭 **Puppeteer-powered** - Mature, well-tested browser automation
|
|
12
|
+
- ⚡ **Fast** - Skip login when session is still valid
|
|
13
|
+
- 🔄 **AuthManager Integration** - Works seamlessly with ADT CLI
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @abapify/adt-puppeteer puppeteer
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
// adt.config.ts
|
|
25
|
+
import { defineConfig } from '@abapify/adt-config';
|
|
26
|
+
import { withPuppeteer } from '@abapify/adt-puppeteer';
|
|
27
|
+
|
|
28
|
+
export default withPuppeteer(
|
|
29
|
+
defineConfig({
|
|
30
|
+
destinations: {
|
|
31
|
+
DEV: 'https://sap-dev.example.com',
|
|
32
|
+
PROD: 'https://sap-prod.example.com',
|
|
33
|
+
},
|
|
34
|
+
}),
|
|
35
|
+
{
|
|
36
|
+
userDataDir: true, // Enable session persistence
|
|
37
|
+
headless: false, // Show browser window for SSO
|
|
38
|
+
requiredCookies: ['SAP_SESSIONID_*', 'sap-usercontext'],
|
|
39
|
+
},
|
|
40
|
+
);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Direct API Usage
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { puppeteerAuth, toCookieHeader } from '@abapify/adt-puppeteer';
|
|
47
|
+
|
|
48
|
+
// Authenticate - opens browser for SSO login
|
|
49
|
+
const credentials = await puppeteerAuth.authenticate({
|
|
50
|
+
url: 'https://sap-system.example.com',
|
|
51
|
+
userDataDir: true,
|
|
52
|
+
headless: false,
|
|
53
|
+
requiredCookies: ['SAP_SESSIONID_*', 'sap-usercontext'],
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// Convert to Cookie header for HTTP requests
|
|
57
|
+
const cookieHeader = toCookieHeader(credentials);
|
|
58
|
+
|
|
59
|
+
// Test if session is still valid
|
|
60
|
+
const result = await puppeteerAuth.test(credentials);
|
|
61
|
+
console.log(result.valid); // true/false
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## How It Works
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
68
|
+
│ Authentication Flow │
|
|
69
|
+
├─────────────────────────────────────────────────────────────────┤
|
|
70
|
+
│ │
|
|
71
|
+
│ 1. Launch Browser ──► 2. Navigate to SAP ──► 3. SSO Redirect │
|
|
72
|
+
│ │ │ │
|
|
73
|
+
│ ▼ ▼ │
|
|
74
|
+
│ [Persistent Profile] [User completes login] │
|
|
75
|
+
│ │ │ │
|
|
76
|
+
│ ▼ ▼ │
|
|
77
|
+
│ 4. Check Session ◄─────────────────────── 5. Capture Cookies │
|
|
78
|
+
│ │ │ │
|
|
79
|
+
│ ▼ ▼ │
|
|
80
|
+
│ [Valid? Skip login] [Return credentials] │
|
|
81
|
+
│ │
|
|
82
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
1. **Launch Browser** - Opens Chrome with optional persistent profile
|
|
86
|
+
2. **Navigate to SAP** - Goes to ADT discovery endpoint
|
|
87
|
+
3. **SSO Redirect** - Browser redirects to Okta/IDP
|
|
88
|
+
4. **User Login** - User completes 2FA/SSO in browser
|
|
89
|
+
5. **Capture Cookies** - Waits for required cookies, extracts session
|
|
90
|
+
|
|
91
|
+
## Options
|
|
92
|
+
|
|
93
|
+
````typescript
|
|
94
|
+
interface PuppeteerAuthOptions {
|
|
95
|
+
/** SAP system URL (required) */
|
|
96
|
+
url: string;
|
|
97
|
+
|
|
98
|
+
/** Hide browser window (default: false) */
|
|
99
|
+
headless?: boolean;
|
|
100
|
+
|
|
101
|
+
/** Login timeout in ms (default: 300000 = 5 minutes) */
|
|
102
|
+
timeout?: number;
|
|
103
|
+
|
|
104
|
+
/** Custom user agent */
|
|
105
|
+
userAgent?: string;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Cookie patterns to wait for before completing auth.
|
|
109
|
+
* Supports wildcards: 'SAP_SESSIONID_*'
|
|
110
|
+
* @example ['SAP_SESSIONID_*', 'sap-usercontext']
|
|
111
|
+
*/
|
|
112
|
+
requiredCookies?: string[];
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Session persistence directory.
|
|
116
|
+
* - true: Use default (~/.adt/browser-profile)
|
|
117
|
+
* - string: Custom path
|
|
118
|
+
* - false/undefined: No persistence
|
|
119
|
+
*/
|
|
120
|
+
userDataDir?: string | boolean;
|
|
121
|
+
|
|
122
|
+
/** Ignore HTTPS errors (default: true) */
|
|
123
|
+
ignoreHTTPSErrors?: boolean;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
## Session Persistence
|
|
127
|
+
|
|
128
|
+
By default, Puppeteer starts a fresh browser session each time. Enable `userDataDir` to persist browser state (cookies, localStorage, cache) across runs - perfect for long-lived Okta/IDP tokens!
|
|
129
|
+
|
|
130
|
+
### Benefits
|
|
131
|
+
- **Skip repeated logins**: Okta tokens persist across runs
|
|
132
|
+
- **Faster authentication**: Only refresh SAP cookies when needed
|
|
133
|
+
- **Better UX**: Same experience as using a regular browser
|
|
134
|
+
|
|
135
|
+
### Plugin-Level Configuration (Recommended)
|
|
136
|
+
|
|
137
|
+
Configure once, applies to all destinations:
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
import { withPuppeteer } from '@abapify/adt-puppeteer';
|
|
141
|
+
|
|
142
|
+
export default withPuppeteer(
|
|
143
|
+
defineConfig({
|
|
144
|
+
destinations: {
|
|
145
|
+
DEV: 'https://sap-dev.example.com',
|
|
146
|
+
PROD: 'https://sap-prod.example.com',
|
|
147
|
+
},
|
|
148
|
+
}),
|
|
149
|
+
{
|
|
150
|
+
userDataDir: true, // ALL destinations share the same profile
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
````
|
|
154
|
+
|
|
155
|
+
### Per-Destination Configuration
|
|
156
|
+
|
|
157
|
+
Only use if you need different profiles per destination:
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
import { puppeteer } from '@abapify/adt-puppeteer';
|
|
161
|
+
|
|
162
|
+
export default defineConfig({
|
|
163
|
+
destinations: {
|
|
164
|
+
DEV: puppeteer({
|
|
165
|
+
url: 'https://sap-dev.example.com',
|
|
166
|
+
userDataDir: '/path/to/dev-profile', // Custom profile for DEV
|
|
167
|
+
}),
|
|
168
|
+
PROD: puppeteer({
|
|
169
|
+
url: 'https://sap-prod.example.com',
|
|
170
|
+
// No userDataDir = fresh session every time
|
|
171
|
+
}),
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Options
|
|
177
|
+
|
|
178
|
+
- `userDataDir: true` - Use default directory (~/.adt/puppeteer-profile)
|
|
179
|
+
- `userDataDir: '/custom/path'` - Custom directory path
|
|
180
|
+
- `userDataDir: false` or omitted - No persistence (default)
|
|
181
|
+
|
|
182
|
+
### How It Works
|
|
183
|
+
|
|
184
|
+
1. **First run**: Opens browser, user logs in via Okta → profile saved
|
|
185
|
+
2. **Subsequent runs**: Loads existing profile → checks if session valid
|
|
186
|
+
- ✅ **Valid**: Skips login, extracts cookies
|
|
187
|
+
- ❌ **Expired**: Prompts for re-login (only SAP cookies need refresh)
|
|
188
|
+
|
|
189
|
+
### Silent Session Refresh
|
|
190
|
+
|
|
191
|
+
When SAP cookies expire but Okta session is still valid, use `adt auth refresh`:
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
# Refresh expired SAP session using stored Okta cookies
|
|
195
|
+
npx adt auth refresh
|
|
196
|
+
|
|
197
|
+
# Or specify a system
|
|
198
|
+
npx adt auth refresh --sid S0D
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
**How it works:**
|
|
202
|
+
|
|
203
|
+
1. Launches **headless browser** with persistent profile (no window popup!)
|
|
204
|
+
2. Navigates to SAP system
|
|
205
|
+
3. Okta **auto-authenticates** from stored session
|
|
206
|
+
4. Extracts fresh SAP cookies
|
|
207
|
+
5. Updates `~/.adt/auth.json`
|
|
208
|
+
|
|
209
|
+
**Benefits:**
|
|
210
|
+
|
|
211
|
+
- ⚡ **Fast** - No manual login, typically <30 seconds
|
|
212
|
+
- 🤫 **Silent** - Runs in background, no browser window
|
|
213
|
+
- 🔄 **Automatic** - ADT CLI can auto-refresh when detecting expired sessions
|
|
214
|
+
|
|
215
|
+
**Note:** Refresh only works when `userDataDir` is enabled. Without it, you'll need to run `adt auth login` again.
|
|
216
|
+
|
|
217
|
+
### Clearing Sessions
|
|
218
|
+
|
|
219
|
+
If authentication fails or you need a fresh start:
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
# Remove default profile
|
|
223
|
+
rm -rf ~/.adt/browser-profile
|
|
224
|
+
|
|
225
|
+
# Or remove custom profile
|
|
226
|
+
rm -rf /path/to/custom/profile
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Configuration Patterns
|
|
230
|
+
|
|
231
|
+
### Pattern 1: All destinations use Puppeteer (Recommended)
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
// adt.config.ts
|
|
235
|
+
import { defineConfig } from '@abapify/adt-config';
|
|
236
|
+
import { withPuppeteer } from '@abapify/adt-puppeteer';
|
|
237
|
+
|
|
238
|
+
export default withPuppeteer(
|
|
239
|
+
defineConfig({
|
|
240
|
+
destinations: {
|
|
241
|
+
DEV: 'https://sap-dev.example.com',
|
|
242
|
+
QAS: 'https://sap-qas.example.com',
|
|
243
|
+
PROD: 'https://sap-prod.example.com',
|
|
244
|
+
},
|
|
245
|
+
}),
|
|
246
|
+
{
|
|
247
|
+
// Plugin options applied to ALL destinations
|
|
248
|
+
userDataDir: true, // Session persistence
|
|
249
|
+
headless: false, // Show browser
|
|
250
|
+
timeout: 120000, // 2 min timeout
|
|
251
|
+
requiredCookies: ['MYSAPSSO2', 'SAP_SESSIONID_*'],
|
|
252
|
+
},
|
|
253
|
+
);
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### Pattern 2: Mixed auth types
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
import { defineConfig } from '@abapify/adt-config';
|
|
260
|
+
import { basic } from '@abapify/adt-client';
|
|
261
|
+
import { puppeteer } from '@abapify/adt-puppeteer';
|
|
262
|
+
|
|
263
|
+
export default defineConfig({
|
|
264
|
+
destinations: {
|
|
265
|
+
// Basic auth for dev
|
|
266
|
+
DEV: basic({ url: 'https://dev.example.com', client: '100' }),
|
|
267
|
+
|
|
268
|
+
// Puppeteer for production (SSO)
|
|
269
|
+
PROD: puppeteer({ url: 'https://prod.example.com' }),
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### Pattern 3: Per-destination Puppeteer options
|
|
275
|
+
|
|
276
|
+
```typescript
|
|
277
|
+
import { puppeteer } from '@abapify/adt-puppeteer';
|
|
278
|
+
|
|
279
|
+
export default defineConfig({
|
|
280
|
+
destinations: {
|
|
281
|
+
DEV: puppeteer({
|
|
282
|
+
url: 'https://sap-dev.example.com',
|
|
283
|
+
timeout: 60000, // Custom timeout for DEV
|
|
284
|
+
}),
|
|
285
|
+
|
|
286
|
+
PROD: puppeteer({
|
|
287
|
+
url: 'https://sap-prod.example.com',
|
|
288
|
+
requiredCookies: ['MYSAPSSO2', 'SAP_SESSIONID_*'],
|
|
289
|
+
}),
|
|
290
|
+
},
|
|
291
|
+
});
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
## Architecture
|
|
295
|
+
|
|
296
|
+
This package is a thin wrapper around `@abapify/browser-auth`:
|
|
297
|
+
|
|
298
|
+
```
|
|
299
|
+
@abapify/browser-auth (core logic)
|
|
300
|
+
├── Event-driven auth flow
|
|
301
|
+
├── Cookie utilities
|
|
302
|
+
└── Pattern matching
|
|
303
|
+
↑
|
|
304
|
+
@abapify/adt-puppeteer (this package)
|
|
305
|
+
├── adapter.ts - Puppeteer BrowserAdapter implementation
|
|
306
|
+
├── puppeteer-auth.ts - Wrapper around browser-auth
|
|
307
|
+
├── auth-plugin.ts - AuthManager compatibility
|
|
308
|
+
└── index.ts - Public exports
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
## Exports
|
|
312
|
+
|
|
313
|
+
```typescript
|
|
314
|
+
// Main auth object
|
|
315
|
+
export { puppeteerAuth, puppeteer } from '@abapify/adt-puppeteer';
|
|
316
|
+
|
|
317
|
+
// Config helper
|
|
318
|
+
export { withPuppeteer } from '@abapify/adt-puppeteer';
|
|
319
|
+
|
|
320
|
+
// Utilities
|
|
321
|
+
export { toCookieHeader, toHeaders } from '@abapify/adt-puppeteer';
|
|
322
|
+
|
|
323
|
+
// AuthManager plugin (default export)
|
|
324
|
+
import authPlugin from '@abapify/adt-puppeteer';
|
|
325
|
+
|
|
326
|
+
// Types
|
|
327
|
+
export type {
|
|
328
|
+
PuppeteerCredentials,
|
|
329
|
+
PuppeteerAuthOptions,
|
|
330
|
+
PuppeteerPluginOptions,
|
|
331
|
+
CookieData,
|
|
332
|
+
} from '@abapify/adt-puppeteer';
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
## Playwright vs Puppeteer
|
|
336
|
+
|
|
337
|
+
| Feature | Playwright | Puppeteer |
|
|
338
|
+
| ------------------- | -------------------------- | ------------------------ |
|
|
339
|
+
| **Browser Support** | Chromium, Firefox, WebKit | Chrome/Chromium |
|
|
340
|
+
| **Maintenance** | Microsoft-backed | Google-backed |
|
|
341
|
+
| **API Style** | Modern, auto-waiting | Classic, manual waits |
|
|
342
|
+
| **Bundle Size** | Larger | Smaller |
|
|
343
|
+
| **Recommendation** | Preferred for new projects | Legacy/existing projects |
|
|
344
|
+
|
|
345
|
+
Both packages share the same core logic via `@abapify/browser-auth`.
|
|
346
|
+
|
|
347
|
+
## Related Packages
|
|
348
|
+
|
|
349
|
+
- [`@abapify/browser-auth`](../browser-auth) - Core authentication logic
|
|
350
|
+
- [`@abapify/adt-playwright`](../adt-playwright) - Playwright alternative (recommended)
|
|
351
|
+
- [`@abapify/adt-auth`](../adt-auth) - Authentication manager
|
|
352
|
+
- [`@abapify/adt-config`](../adt-config) - Configuration utilities
|
package/package.json
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abapify/adt-puppeteer",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
5
|
-
|
|
3
|
+
"version": "0.3.5",
|
|
4
|
+
"description": "Puppeteer-based authentication for SAP ADT (SSO/IDP)",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"types": "./dist/index.d.mts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./dist/index.mjs",
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@abapify/adt-auth": "0.3.5",
|
|
21
|
+
"@abapify/adt-config": "0.3.5",
|
|
22
|
+
"@abapify/browser-auth": "0.3.5",
|
|
23
|
+
"puppeteer": "^24.0.0"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"puppeteer": ">=22.0.0"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/abapify/adt-cli.git",
|
|
31
|
+
"directory": "packages/adt-puppeteer"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/abapify/adt-cli/tree/main/packages/adt-puppeteer#readme",
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/abapify/adt-cli/issues"
|
|
36
|
+
}
|
|
37
|
+
}
|