@abapify/adt-playwright 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.
Files changed (2) hide show
  1. package/README.md +346 -1
  2. package/package.json +35 -3
package/README.md CHANGED
@@ -1,3 +1,348 @@
1
1
  # @abapify/adt-playwright
2
2
 
3
- Placeholder. The real release is published via CI/CD.
3
+ [![version](https://img.shields.io/github/package-json/v/abapify/adt-cli?filename=packages/adt-playwright/package.json)](https://github.com/abapify/adt-cli/pkgs/npm/%40abapify%2Fadt-playwright)
4
+
5
+ Playwright-based SSO authentication plugin for SAP ADT systems. Modern alternative to Puppeteer with better API and maintenance.
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
+ - 🎭 **Playwright-powered** - Modern, reliable 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-playwright playwright
19
+ ```
20
+
21
+ ## Quick Start
22
+
23
+ ```typescript
24
+ // adt.config.ts
25
+ import { defineConfig } from '@abapify/adt-config';
26
+ import { withPlaywright } from '@abapify/adt-playwright';
27
+
28
+ export default withPlaywright(
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
+ ignoreHTTPSErrors: true, // Ignore self-signed certificates
39
+ requiredCookies: ['SAP_SESSIONID_*', 'sap-usercontext'],
40
+ },
41
+ );
42
+ ```
43
+
44
+ ## Direct API Usage
45
+
46
+ ```typescript
47
+ import { playwrightAuth, toCookieHeader } from '@abapify/adt-playwright';
48
+
49
+ // Authenticate - opens browser for SSO login
50
+ const credentials = await playwrightAuth.authenticate({
51
+ url: 'https://sap-system.example.com',
52
+ userDataDir: true,
53
+ headless: false,
54
+ requiredCookies: ['SAP_SESSIONID_*', 'sap-usercontext'],
55
+ });
56
+
57
+ // Convert to Cookie header for HTTP requests
58
+ const cookieHeader = toCookieHeader(credentials);
59
+
60
+ // Test if session is still valid
61
+ const result = await playwrightAuth.test(credentials);
62
+ console.log(result.valid); // true/false
63
+ ```
64
+
65
+ ## How It Works
66
+
67
+ ```
68
+ ┌─────────────────────────────────────────────────────────────────┐
69
+ │ Authentication Flow │
70
+ ├─────────────────────────────────────────────────────────────────┤
71
+ │ │
72
+ │ 1. Launch Browser ──► 2. Navigate to SAP ──► 3. SSO Redirect │
73
+ │ │ │ │
74
+ │ ▼ ▼ │
75
+ │ [Persistent Profile] [User completes login] │
76
+ │ │ │ │
77
+ │ ▼ ▼ │
78
+ │ 4. Check Session ◄─────────────────────── 5. Capture Cookies │
79
+ │ │ │ │
80
+ │ ▼ ▼ │
81
+ │ [Valid? Skip login] [Return credentials] │
82
+ │ │
83
+ └─────────────────────────────────────────────────────────────────┘
84
+ ```
85
+
86
+ 1. **Launch Browser** - Opens Chromium with optional persistent profile
87
+ 2. **Navigate to SAP** - Goes to ADT discovery endpoint
88
+ 3. **SSO Redirect** - Browser redirects to Okta/IDP
89
+ 4. **User Login** - User completes 2FA/SSO in browser
90
+ 5. **Capture Cookies** - Waits for required cookies, extracts session
91
+
92
+ ## Options
93
+
94
+ ```typescript
95
+ interface PlaywrightAuthOptions {
96
+ /** SAP system URL (required) */
97
+ url: string;
98
+
99
+ /** Hide browser window (default: false) */
100
+ headless?: boolean;
101
+
102
+ /** Login timeout in ms (default: 300000 = 5 minutes) */
103
+ timeout?: number;
104
+
105
+ /** Custom user agent */
106
+ userAgent?: string;
107
+
108
+ /**
109
+ * Cookie patterns to wait for before completing auth.
110
+ * Supports wildcards: 'SAP_SESSIONID_*'
111
+ * @example ['SAP_SESSIONID_*', 'sap-usercontext']
112
+ */
113
+ requiredCookies?: string[];
114
+
115
+ /**
116
+ * Session persistence directory.
117
+ * - true: Use default (~/.adt/browser-profile)
118
+ * - string: Custom path
119
+ * - false/undefined: No persistence
120
+ */
121
+ userDataDir?: string | boolean;
122
+
123
+ /** Ignore HTTPS errors (default: true) */
124
+ ignoreHTTPSErrors?: boolean;
125
+ }
126
+ ```
127
+
128
+ ## Session Persistence
129
+
130
+ Enable `userDataDir` to persist browser state across runs:
131
+
132
+ ```typescript
133
+ // Use default profile directory (~/.adt/browser-profile)
134
+ {
135
+ userDataDir: true;
136
+ }
137
+
138
+ // Use custom directory
139
+ {
140
+ userDataDir: '/path/to/profile';
141
+ }
142
+
143
+ // No persistence (fresh session each time)
144
+ {
145
+ userDataDir: false;
146
+ }
147
+ ```
148
+
149
+ ### Benefits
150
+
151
+ - **Skip repeated logins** - Okta tokens persist across runs
152
+ - **Faster authentication** - Only refresh SAP cookies when needed
153
+ - **Better UX** - Same experience as using a regular browser
154
+
155
+ ### How It Works
156
+
157
+ 1. **First run**: User completes full SSO login → profile saved
158
+ 2. **Subsequent runs**:
159
+ - ✅ **Okta valid**: Auto-authenticates, extracts SAP cookies
160
+ - ❌ **Okta expired**: Prompts for re-login
161
+
162
+ ### Clearing Sessions
163
+
164
+ ```bash
165
+ # Remove default profile
166
+ rm -rf ~/.adt/browser-profile
167
+
168
+ # Or remove custom profile
169
+ rm -rf /path/to/custom/profile
170
+ ```
171
+
172
+ ## Configuration Patterns
173
+
174
+ ### Pattern 1: All Destinations with Playwright
175
+
176
+ ```typescript
177
+ import { defineConfig } from '@abapify/adt-config';
178
+ import { withPlaywright } from '@abapify/adt-playwright';
179
+
180
+ export default withPlaywright(
181
+ defineConfig({
182
+ destinations: {
183
+ DEV: 'https://sap-dev.example.com',
184
+ QAS: 'https://sap-qas.example.com',
185
+ PROD: 'https://sap-prod.example.com',
186
+ },
187
+ }),
188
+ {
189
+ userDataDir: true,
190
+ headless: false,
191
+ requiredCookies: ['SAP_SESSIONID_*', 'sap-usercontext'],
192
+ },
193
+ );
194
+ ```
195
+
196
+ ### Pattern 2: Per-Destination Options
197
+
198
+ ```typescript
199
+ import { defineConfig } from '@abapify/adt-config';
200
+ import { playwright } from '@abapify/adt-playwright';
201
+
202
+ export default defineConfig({
203
+ destinations: {
204
+ DEV: playwright({
205
+ url: 'https://sap-dev.example.com',
206
+ timeout: 60000,
207
+ }),
208
+ PROD: playwright({
209
+ url: 'https://sap-prod.example.com',
210
+ requiredCookies: ['SAP_SESSIONID_*', 'MYSAPSSO2'],
211
+ }),
212
+ },
213
+ });
214
+ ```
215
+
216
+ ### Pattern 3: Mixed Auth Types
217
+
218
+ ```typescript
219
+ import { defineConfig } from '@abapify/adt-config';
220
+ import { basic } from '@abapify/adt-auth/plugins/basic';
221
+ import { playwright } from '@abapify/adt-playwright';
222
+
223
+ export default defineConfig({
224
+ destinations: {
225
+ // Basic auth for dev
226
+ DEV: basic({
227
+ url: 'https://dev.example.com',
228
+ username: 'developer',
229
+ password: process.env.SAP_PASSWORD,
230
+ }),
231
+ // Playwright for production (SSO)
232
+ PROD: playwright({
233
+ url: 'https://prod.example.com',
234
+ userDataDir: true,
235
+ }),
236
+ },
237
+ });
238
+ ```
239
+
240
+ ## CLI Usage
241
+
242
+ ```bash
243
+ # Login to a system
244
+ npx adt auth login --sid DEV
245
+
246
+ # Login with specific destination
247
+ npx adt auth login --sid PROD
248
+
249
+ # Check session status
250
+ npx adt auth status
251
+
252
+ # Logout
253
+ npx adt auth logout --sid DEV
254
+ ```
255
+
256
+ ## Architecture
257
+
258
+ This package is a thin wrapper around `@abapify/browser-auth`:
259
+
260
+ ```
261
+ @abapify/browser-auth (core logic)
262
+ ├── Event-driven auth flow
263
+ ├── Cookie utilities
264
+ └── Pattern matching
265
+ ↑
266
+ @abapify/adt-playwright (this package)
267
+ ├── adapter.ts - Playwright BrowserAdapter implementation
268
+ ├── playwright-auth.ts - Wrapper around browser-auth
269
+ ├── auth-plugin.ts - AuthManager compatibility
270
+ └── index.ts - Public exports
271
+ ```
272
+
273
+ ## Exports
274
+
275
+ ```typescript
276
+ // Main auth object
277
+ export { playwrightAuth, playwright } from '@abapify/adt-playwright';
278
+
279
+ // Config helper
280
+ export { withPlaywright } from '@abapify/adt-playwright';
281
+
282
+ // Utilities
283
+ export { toCookieHeader, toHeaders } from '@abapify/adt-playwright';
284
+
285
+ // AuthManager plugin (default export)
286
+ import authPlugin from '@abapify/adt-playwright';
287
+
288
+ // Types
289
+ export type {
290
+ PlaywrightCredentials,
291
+ PlaywrightAuthOptions,
292
+ PlaywrightPluginOptions,
293
+ CookieData,
294
+ } from '@abapify/adt-playwright';
295
+ ```
296
+
297
+ ## Troubleshooting
298
+
299
+ ### Browser doesn't open
300
+
301
+ Ensure `headless: false` is set:
302
+
303
+ ```typescript
304
+ {
305
+ headless: false;
306
+ }
307
+ ```
308
+
309
+ ### Cookies not captured
310
+
311
+ Specify the required cookies explicitly:
312
+
313
+ ```typescript
314
+ {
315
+ requiredCookies: ['SAP_SESSIONID_*', 'sap-usercontext'];
316
+ }
317
+ ```
318
+
319
+ ### SSL Certificate errors
320
+
321
+ Enable `ignoreHTTPSErrors` (default is true):
322
+
323
+ ```typescript
324
+ {
325
+ ignoreHTTPSErrors: true;
326
+ }
327
+ ```
328
+
329
+ ### Session not persisting
330
+
331
+ Check that `userDataDir` is enabled and the directory is writable:
332
+
333
+ ```typescript
334
+ {
335
+ userDataDir: true;
336
+ }
337
+ // or
338
+ {
339
+ userDataDir: '/writable/path';
340
+ }
341
+ ```
342
+
343
+ ## Related Packages
344
+
345
+ - [`@abapify/browser-auth`](../browser-auth) - Core authentication logic
346
+ - [`@abapify/adt-puppeteer`](../adt-puppeteer) - Puppeteer alternative
347
+ - [`@abapify/adt-auth`](../adt-auth) - Authentication manager
348
+ - [`@abapify/adt-config`](../adt-config) - Configuration utilities
package/package.json CHANGED
@@ -1,5 +1,37 @@
1
1
  {
2
2
  "name": "@abapify/adt-playwright",
3
- "version": "0.0.0",
4
- "description": "Placeholder — real package is published via CI/CD (trusted publishing)."
5
- }
3
+ "version": "0.3.5",
4
+ "description": "Playwright-based SSO authentication plugin for ADT client",
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
+ "playwright": "^1.57.0"
24
+ },
25
+ "devDependencies": {
26
+ "@types/node": "^22.10.2"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/abapify/adt-cli.git",
31
+ "directory": "packages/adt-playwright"
32
+ },
33
+ "homepage": "https://github.com/abapify/adt-cli/tree/main/packages/adt-playwright#readme",
34
+ "bugs": {
35
+ "url": "https://github.com/abapify/adt-cli/issues"
36
+ }
37
+ }