@abapify/adt-puppeteer 0.4.16 → 0.4.19
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/dist/index.d.mts +0 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +4 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { BrowserAuthOptions, BrowserAuthOptions as BrowserAuthOptions$1, BrowserCredentials, BrowserCredentials as BrowserCredentials$1, CookieData, testCredentials, toCookieHeader, toHeaders } from "@abapify/browser-auth";
|
|
2
2
|
import { AdtConfig } from "@abapify/adt-config";
|
|
3
3
|
import { AuthPlugin } from "@abapify/adt-auth";
|
|
4
|
-
//#region src/puppeteer-auth.d.ts
|
|
5
4
|
type PuppeteerCredentials = BrowserCredentials$1;
|
|
6
5
|
type PuppeteerAuthOptions = BrowserAuthOptions$1;
|
|
7
6
|
/**
|
|
@@ -47,14 +46,10 @@ declare const puppeteer: {
|
|
|
47
46
|
};
|
|
48
47
|
}): Promise<PuppeteerCredentials | null>;
|
|
49
48
|
};
|
|
50
|
-
//#endregion
|
|
51
|
-
//#region src/auth-plugin.d.ts
|
|
52
49
|
/**
|
|
53
50
|
* Standard auth plugin that conforms to AuthPluginResult interface.
|
|
54
51
|
*/
|
|
55
52
|
declare const authPlugin: AuthPlugin;
|
|
56
|
-
//#endregion
|
|
57
|
-
//#region src/index.d.ts
|
|
58
53
|
/**
|
|
59
54
|
* Plugin-level options applied to all destinations
|
|
60
55
|
*/
|
|
@@ -63,6 +58,5 @@ type PuppeteerPluginOptions = BrowserAuthOptions$1;
|
|
|
63
58
|
* Wrap a standard config with puppeteer auth for all destinations.
|
|
64
59
|
*/
|
|
65
60
|
declare function withPuppeteer(config: AdtConfig, options?: Partial<BrowserAuthOptions$1>): AdtConfig;
|
|
66
|
-
//#endregion
|
|
67
61
|
export { type BrowserAuthOptions, type BrowserCredentials, type CookieData, type PuppeteerAuthOptions, type PuppeteerCredentials, PuppeteerPluginOptions, authPlugin, authPlugin as default, puppeteer, puppeteerAuth, toCookieHeader, toHeaders, withPuppeteer };
|
|
68
62
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/puppeteer-auth.ts","../src/auth-plugin.ts","../src/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":["BrowserCredentials","BrowserAuthOptions","BrowserAuthOptions"],"sources":["../src/puppeteer-auth.ts","../src/auth-plugin.ts","../src/index.ts"],"mappings":";;;KAeY,uBAAuBA;KACvB,uBAAuBC;;;;cAKtB;;;;EAKA,aAAA,SAAA,uBACR,QAAQ;;;;;;;;EAaY,QAAA;IACrB;MAAS;QAAkB,OAAO;;;MAChC,QAAQ;;cAaD;;;;EA7BA,aAAA,SAAA,uBACR,QAAQ;;;;;;;;EAaY,QAAA;IACrB;MAAS;QAAkB,OAAO;;;MAChC,QAAQ;;;;;cCVR,YAAY;;;;KCRN,yBAAyBC;;;;iBAerB,cACd,QAAQ,WACR,UAAU,QAAQA,wBACjB"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { authenticate, testCredentials, toCookieHeader, toHeaders } from "@abapify/browser-auth";
|
|
2
2
|
import puppeteer$1 from "puppeteer";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// src/adapter.ts
|
|
5
5
|
/**
|
|
6
6
|
* Puppeteer Browser Adapter
|
|
7
7
|
*
|
|
@@ -107,8 +107,7 @@ function createPuppeteerAdapter() {
|
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
|
|
111
|
-
//#region src/puppeteer-auth.ts
|
|
110
|
+
// src/puppeteer-auth.ts
|
|
112
111
|
/**
|
|
113
112
|
* Puppeteer Authentication Plugin
|
|
114
113
|
*
|
|
@@ -140,8 +139,7 @@ const puppeteerAuth = {
|
|
|
140
139
|
};
|
|
141
140
|
const puppeteer = puppeteerAuth;
|
|
142
141
|
|
|
143
|
-
|
|
144
|
-
//#region src/auth-plugin.ts
|
|
142
|
+
// src/auth-plugin.ts
|
|
145
143
|
/**
|
|
146
144
|
* Get earliest expiration from cookies, or default to 8 hours
|
|
147
145
|
*/
|
|
@@ -169,8 +167,7 @@ const authPlugin = {
|
|
|
169
167
|
}
|
|
170
168
|
};
|
|
171
169
|
|
|
172
|
-
|
|
173
|
-
//#region src/index.ts
|
|
170
|
+
// src/index.ts
|
|
174
171
|
/**
|
|
175
172
|
* Create a puppeteer destination config
|
|
176
173
|
*/
|
|
@@ -209,6 +206,5 @@ function withPuppeteer(config, options) {
|
|
|
209
206
|
};
|
|
210
207
|
}
|
|
211
208
|
|
|
212
|
-
//#endregion
|
|
213
209
|
export { authPlugin, authPlugin as default, puppeteer, puppeteerAuth, toCookieHeader, toHeaders, withPuppeteer };
|
|
214
210
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["puppeteer"],"sources":["../src/adapter.ts","../src/puppeteer-auth.ts","../src/auth-plugin.ts","../src/index.ts"],"sourcesContent":["/**\n * Puppeteer Browser Adapter\n *\n * Implements BrowserAdapter interface for Puppeteer.\n * This is a thin wrapper - all auth logic is in @abapify/browser-auth.\n */\n\nimport puppeteer from 'puppeteer';\nimport type { Browser, Page, Protocol } from 'puppeteer';\nimport type {\n BrowserAdapter,\n CookieData,\n ResponseEvent,\n} from '@abapify/browser-auth';\n\n/**\n * Convert Puppeteer cookie to CookieData\n */\nfunction convertCookie(cookie: Protocol.Network.Cookie): CookieData {\n return {\n name: cookie.name,\n value: cookie.value,\n domain: cookie.domain,\n path: cookie.path,\n expires: cookie.expires,\n httpOnly: cookie.httpOnly,\n secure: cookie.secure,\n sameSite: cookie.sameSite as CookieData['sameSite'],\n };\n}\n\n/**\n * Create a Puppeteer browser adapter\n */\nexport function createPuppeteerAdapter(): BrowserAdapter {\n let browser: Browser | null = null;\n let page: Page | null = null;\n let launchOptions: { ignoreHTTPSErrors?: boolean; userAgent?: string } = {};\n\n const responseHandlers: ((event: ResponseEvent) => void)[] = [];\n const closeHandlers: (() => void)[] = [];\n\n return {\n async launch(options: {\n headless: boolean;\n userDataDir?: string;\n ignoreHTTPSErrors?: boolean;\n userAgent?: string;\n }) {\n const { headless, userDataDir, ignoreHTTPSErrors, userAgent } = options;\n launchOptions = { ignoreHTTPSErrors, userAgent };\n\n browser = await puppeteer.launch({\n headless,\n userDataDir,\n args: userAgent ? [`--user-agent=${userAgent}`] : [],\n });\n },\n\n async newPage() {\n if (!browser) throw new Error('Browser not launched');\n page = await browser.newPage();\n\n // Set page-level options\n if (launchOptions.ignoreHTTPSErrors) {\n await page.setBypassCSP(true);\n }\n\n // Wire up event handlers\n page.on('response', (response) => {\n const event: ResponseEvent = {\n url: response.url(),\n status: response.status(),\n };\n responseHandlers.forEach((handler) => handler(event));\n });\n\n page.once('close', () => {\n closeHandlers.forEach((handler) => handler());\n });\n },\n\n async goto(url: string, options?: { timeout?: number }) {\n if (!page) throw new Error('Page not created');\n await page\n .goto(url, {\n waitUntil: 'domcontentloaded',\n timeout: options?.timeout ?? 30000,\n })\n // Navigation errors are intentionally ignored; caller handles auth via event listeners\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n .catch(() => {});\n },\n\n async getCookies(): Promise<CookieData[]> {\n if (!page) throw new Error('Page not created');\n const client = await page.createCDPSession();\n const { cookies } = await client.send('Network.getAllCookies');\n return cookies.map(convertCookie);\n },\n\n async clearCookies(domain: string): Promise<void> {\n if (!page) throw new Error('Page not created');\n const client = await page.createCDPSession();\n const { cookies } = await client.send('Network.getAllCookies');\n const toRemove = cookies.filter(\n (c) =>\n c.domain.includes(domain) ||\n domain.includes(c.domain.replace(/^\\./, '')),\n );\n for (const cookie of toRemove) {\n await client.send('Network.deleteCookies', {\n name: cookie.name,\n domain: cookie.domain,\n });\n }\n },\n\n async getUserAgent(): Promise<string> {\n if (!page) throw new Error('Page not created');\n return page.evaluate(() => navigator.userAgent);\n },\n\n async closePage() {\n if (page) {\n await page.close();\n page = null;\n }\n },\n\n async close() {\n if (browser) {\n await browser.close();\n browser = null;\n }\n },\n\n onResponse(handler: (event: ResponseEvent) => void) {\n responseHandlers.push(handler);\n },\n\n onPageClose(handler: () => void) {\n closeHandlers.push(handler);\n },\n };\n}\n","/**\n * Puppeteer Authentication Plugin\n *\n * Thin wrapper around @abapify/browser-auth core.\n * Provides Puppeteer-specific browser adapter.\n */\n\nimport { authenticate, testCredentials } from '@abapify/browser-auth';\nimport type {\n BrowserCredentials,\n BrowserAuthOptions,\n} from '@abapify/browser-auth';\nimport { createPuppeteerAdapter } from './adapter';\n\n// Re-export types with Puppeteer-specific names for backwards compatibility\nexport type PuppeteerCredentials = BrowserCredentials;\nexport type PuppeteerAuthOptions = BrowserAuthOptions;\n\n/**\n * Puppeteer authentication object\n */\nexport const puppeteerAuth = {\n /**\n * Authenticate using Puppeteer browser\n */\n async authenticate(\n options: PuppeteerAuthOptions,\n ): Promise<PuppeteerCredentials> {\n const adapter = createPuppeteerAdapter();\n return authenticate(adapter, options);\n },\n\n /**\n * Test if credentials are still valid\n */\n test: testCredentials,\n\n /**\n * Refresh is not reliable with Okta SSO - always return null to trigger full re-authentication\n */\n async refresh(session: {\n auth?: { pluginOptions?: { log?: (message: string) => void } };\n }): Promise<PuppeteerCredentials | null> {\n const log = session?.auth?.pluginOptions?.log as\n | ((message: string) => void)\n | undefined;\n (log ?? console.log)(\n '🔄 Session expired, will trigger full re-authentication...',\n );\n return null;\n },\n};\n\n// Re-export utilities\n// Legacy export\nexport const puppeteer = puppeteerAuth;\nexport { toCookieHeader, toHeaders } from '@abapify/browser-auth';\n","/**\n * Standard authPlugin export for AuthManager compatibility\n *\n * Wraps puppeteerAuth to return AuthPluginResult format expected by AuthManager.\n */\n\nimport type {\n AuthPlugin,\n AuthPluginResult,\n AuthPluginOptions,\n AuthSession,\n} from '@abapify/adt-auth';\nimport { puppeteerAuth, toCookieHeader } from './puppeteer-auth';\n\n/**\n * Get earliest expiration from cookies, or default to 8 hours\n */\nfunction getExpiresAt(cookies: { expires?: number }[]): Date {\n const expirations = cookies\n .filter((c) => c.expires && c.expires > 0)\n .map((c) => c.expires! * 1000); // Convert seconds to ms\n\n if (expirations.length > 0) {\n return new Date(Math.min(...expirations));\n }\n // Default fallback if no expiration set\n return new Date(Date.now() + 8 * 60 * 60 * 1000);\n}\n\n/**\n * Standard auth plugin that conforms to AuthPluginResult interface.\n */\nconst authPlugin: AuthPlugin = {\n async authenticate(options: AuthPluginOptions): Promise<AuthPluginResult> {\n const credentials = await puppeteerAuth.authenticate(options);\n const cookieString = toCookieHeader(credentials);\n\n return {\n method: 'cookie',\n credentials: {\n cookies: cookieString,\n expiresAt: getExpiresAt(credentials.cookies),\n },\n };\n },\n\n async refresh(_session: AuthSession): Promise<AuthPluginResult | null> {\n // Don't try to refresh - Okta SSO cookies can't be silently refreshed\n return null;\n },\n};\n\nexport default authPlugin;\n","/**\n * @abapify/adt-puppeteer\n *\n * Puppeteer-based SSO authentication plugin for ADT client.\n * Uses @abapify/browser-auth core with Puppeteer adapter.\n */\n\nimport type { AdtConfig, Destination } from '@abapify/adt-config';\nimport type { BrowserAuthOptions } from '@abapify/browser-auth';\n\n// Re-export types\nexport type {\n PuppeteerCredentials,\n PuppeteerAuthOptions,\n} from './puppeteer-auth';\nexport type {\n BrowserCredentials,\n BrowserAuthOptions,\n CookieData,\n} from '@abapify/browser-auth';\n\n/**\n * Plugin-level options applied to all destinations\n */\nexport type PuppeteerPluginOptions = BrowserAuthOptions;\n\n/**\n * Create a puppeteer destination config\n */\nfunction createPuppeteerDestination(options: BrowserAuthOptions): Destination {\n return {\n type: '@abapify/adt-puppeteer',\n options,\n };\n}\n\n/**\n * Wrap a standard config with puppeteer auth for all destinations.\n */\nexport function withPuppeteer(\n config: AdtConfig,\n options?: Partial<BrowserAuthOptions>,\n): AdtConfig {\n if (!config.destinations) {\n return config;\n }\n\n const destinations: Record<string, Destination> = {};\n\n for (const [name, dest] of Object.entries(config.destinations)) {\n if (typeof dest === 'object' && 'type' in dest) {\n if (dest.type === '@abapify/adt-puppeteer' || dest.type === 'puppeteer') {\n destinations[name] = {\n type: '@abapify/adt-puppeteer',\n options: { ...options, ...(dest.options as BrowserAuthOptions) },\n };\n } else {\n destinations[name] = dest;\n }\n } else if (typeof dest === 'string') {\n destinations[name] = createPuppeteerDestination({\n url: dest,\n ...options,\n });\n } else {\n destinations[name] = createPuppeteerDestination({\n ...(dest as BrowserAuthOptions),\n ...options,\n });\n }\n }\n\n return { ...config, destinations };\n}\n\n// Main exports\nexport {\n puppeteerAuth,\n puppeteer,\n toCookieHeader,\n toHeaders,\n} from './puppeteer-auth';\n\n// AuthManager compatibility exports\nexport { default } from './auth-plugin';\nexport { default as authPlugin } from './auth-plugin';\n"],"mappings":";;;;;;;;;;;;;AAkBA,SAAS,cAAc,QAA6C;CAClE,OAAO;EACL,MAAM,OAAO;EACb,OAAO,OAAO;EACd,QAAQ,OAAO;EACf,MAAM,OAAO;EACb,SAAS,OAAO;EAChB,UAAU,OAAO;EACjB,QAAQ,OAAO;EACf,UAAU,OAAO;CACnB;AACF;;;;AAKA,SAAgB,yBAAyC;CACvD,IAAI,UAA0B;CAC9B,IAAI,OAAoB;CACxB,IAAI,gBAAqE,CAAC;CAE1E,MAAM,mBAAuD,CAAC;CAC9D,MAAM,gBAAgC,CAAC;CAEvC,OAAO;EACL,MAAM,OAAO,SAKV;GACD,MAAM,EAAE,UAAU,aAAa,mBAAmB,cAAc;GAChE,gBAAgB;IAAE;IAAmB;GAAU;GAE/C,UAAU,MAAMA,YAAU,OAAO;IAC/B;IACA;IACA,MAAM,YAAY,CAAC,gBAAgB,WAAW,IAAI,CAAC;GACrD,CAAC;EACH;EAEA,MAAM,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;CACX,IAAI,CAAC,OAAO,cACV,OAAO;CAGT,MAAM,eAA4C,CAAC;CAEnD,KAAK,MAAM,CAAC,MAAM,SAAS,OAAO,QAAQ,OAAO,YAAY,GAC3D,IAAI,OAAO,SAAS,YAAY,UAAU,MAAM;EAC9C,IAAI,KAAK,SAAS,4BAA4B,KAAK,SAAS,aAC1D,aAAa,QAAQ;GACnB,MAAM;GACN,SAAS;IAAE,GAAG;IAAS,GAAI,KAAK;GAA+B;EACjE;OAEA,aAAa,QAAQ;CAEzB,OAAO,IAAI,OAAO,SAAS,UACzB,aAAa,QAAQ,2BAA2B;EAC9C,KAAK;EACL,GAAG;CACL,CAAC;MAED,aAAa,QAAQ,2BAA2B;EAC9C,GAAI;EACJ,GAAG;CACL,CAAC;CAIL,OAAO;EAAE,GAAG;EAAQ;CAAa;AACnC"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["puppeteer"],"sources":["../src/adapter.ts","../src/puppeteer-auth.ts","../src/auth-plugin.ts","../src/index.ts"],"sourcesContent":["/**\n * Puppeteer Browser Adapter\n *\n * Implements BrowserAdapter interface for Puppeteer.\n * This is a thin wrapper - all auth logic is in @abapify/browser-auth.\n */\n\nimport puppeteer from 'puppeteer';\nimport type { Browser, Page, Protocol } from 'puppeteer';\nimport type {\n BrowserAdapter,\n CookieData,\n ResponseEvent,\n} from '@abapify/browser-auth';\n\n/**\n * Convert Puppeteer cookie to CookieData\n */\nfunction convertCookie(cookie: Protocol.Network.Cookie): CookieData {\n return {\n name: cookie.name,\n value: cookie.value,\n domain: cookie.domain,\n path: cookie.path,\n expires: cookie.expires,\n httpOnly: cookie.httpOnly,\n secure: cookie.secure,\n sameSite: cookie.sameSite as CookieData['sameSite'],\n };\n}\n\n/**\n * Create a Puppeteer browser adapter\n */\nexport function createPuppeteerAdapter(): BrowserAdapter {\n let browser: Browser | null = null;\n let page: Page | null = null;\n let launchOptions: { ignoreHTTPSErrors?: boolean; userAgent?: string } = {};\n\n const responseHandlers: ((event: ResponseEvent) => void)[] = [];\n const closeHandlers: (() => void)[] = [];\n\n return {\n async launch(options: {\n headless: boolean;\n userDataDir?: string;\n ignoreHTTPSErrors?: boolean;\n userAgent?: string;\n }) {\n const { headless, userDataDir, ignoreHTTPSErrors, userAgent } = options;\n launchOptions = { ignoreHTTPSErrors, userAgent };\n\n browser = await puppeteer.launch({\n headless,\n userDataDir,\n args: userAgent ? [`--user-agent=${userAgent}`] : [],\n });\n },\n\n async newPage() {\n if (!browser) throw new Error('Browser not launched');\n page = await browser.newPage();\n\n // Set page-level options\n if (launchOptions.ignoreHTTPSErrors) {\n await page.setBypassCSP(true);\n }\n\n // Wire up event handlers\n page.on('response', (response) => {\n const event: ResponseEvent = {\n url: response.url(),\n status: response.status(),\n };\n responseHandlers.forEach((handler) => handler(event));\n });\n\n page.once('close', () => {\n closeHandlers.forEach((handler) => handler());\n });\n },\n\n async goto(url: string, options?: { timeout?: number }) {\n if (!page) throw new Error('Page not created');\n await page\n .goto(url, {\n waitUntil: 'domcontentloaded',\n timeout: options?.timeout ?? 30000,\n })\n // Navigation errors are intentionally ignored; caller handles auth via event listeners\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n .catch(() => {});\n },\n\n async getCookies(): Promise<CookieData[]> {\n if (!page) throw new Error('Page not created');\n const client = await page.createCDPSession();\n const { cookies } = await client.send('Network.getAllCookies');\n return cookies.map(convertCookie);\n },\n\n async clearCookies(domain: string): Promise<void> {\n if (!page) throw new Error('Page not created');\n const client = await page.createCDPSession();\n const { cookies } = await client.send('Network.getAllCookies');\n const toRemove = cookies.filter(\n (c) =>\n c.domain.includes(domain) ||\n domain.includes(c.domain.replace(/^\\./, '')),\n );\n for (const cookie of toRemove) {\n await client.send('Network.deleteCookies', {\n name: cookie.name,\n domain: cookie.domain,\n });\n }\n },\n\n async getUserAgent(): Promise<string> {\n if (!page) throw new Error('Page not created');\n return page.evaluate(() => navigator.userAgent);\n },\n\n async closePage() {\n if (page) {\n await page.close();\n page = null;\n }\n },\n\n async close() {\n if (browser) {\n await browser.close();\n browser = null;\n }\n },\n\n onResponse(handler: (event: ResponseEvent) => void) {\n responseHandlers.push(handler);\n },\n\n onPageClose(handler: () => void) {\n closeHandlers.push(handler);\n },\n };\n}\n","/**\n * Puppeteer Authentication Plugin\n *\n * Thin wrapper around @abapify/browser-auth core.\n * Provides Puppeteer-specific browser adapter.\n */\n\nimport { authenticate, testCredentials } from '@abapify/browser-auth';\nimport type {\n BrowserCredentials,\n BrowserAuthOptions,\n} from '@abapify/browser-auth';\nimport { createPuppeteerAdapter } from './adapter';\n\n// Re-export types with Puppeteer-specific names for backwards compatibility\nexport type PuppeteerCredentials = BrowserCredentials;\nexport type PuppeteerAuthOptions = BrowserAuthOptions;\n\n/**\n * Puppeteer authentication object\n */\nexport const puppeteerAuth = {\n /**\n * Authenticate using Puppeteer browser\n */\n async authenticate(\n options: PuppeteerAuthOptions,\n ): Promise<PuppeteerCredentials> {\n const adapter = createPuppeteerAdapter();\n return authenticate(adapter, options);\n },\n\n /**\n * Test if credentials are still valid\n */\n test: testCredentials,\n\n /**\n * Refresh is not reliable with Okta SSO - always return null to trigger full re-authentication\n */\n async refresh(session: {\n auth?: { pluginOptions?: { log?: (message: string) => void } };\n }): Promise<PuppeteerCredentials | null> {\n const log = session?.auth?.pluginOptions?.log as\n | ((message: string) => void)\n | undefined;\n (log ?? console.log)(\n '🔄 Session expired, will trigger full re-authentication...',\n );\n return null;\n },\n};\n\n// Re-export utilities\n// Legacy export\nexport const puppeteer = puppeteerAuth;\nexport { toCookieHeader, toHeaders } from '@abapify/browser-auth';\n","/**\n * Standard authPlugin export for AuthManager compatibility\n *\n * Wraps puppeteerAuth to return AuthPluginResult format expected by AuthManager.\n */\n\nimport type {\n AuthPlugin,\n AuthPluginResult,\n AuthPluginOptions,\n AuthSession,\n} from '@abapify/adt-auth';\nimport { puppeteerAuth, toCookieHeader } from './puppeteer-auth';\n\n/**\n * Get earliest expiration from cookies, or default to 8 hours\n */\nfunction getExpiresAt(cookies: { expires?: number }[]): Date {\n const expirations = cookies\n .filter((c) => c.expires && c.expires > 0)\n .map((c) => c.expires! * 1000); // Convert seconds to ms\n\n if (expirations.length > 0) {\n return new Date(Math.min(...expirations));\n }\n // Default fallback if no expiration set\n return new Date(Date.now() + 8 * 60 * 60 * 1000);\n}\n\n/**\n * Standard auth plugin that conforms to AuthPluginResult interface.\n */\nconst authPlugin: AuthPlugin = {\n async authenticate(options: AuthPluginOptions): Promise<AuthPluginResult> {\n const credentials = await puppeteerAuth.authenticate(options);\n const cookieString = toCookieHeader(credentials);\n\n return {\n method: 'cookie',\n credentials: {\n cookies: cookieString,\n expiresAt: getExpiresAt(credentials.cookies),\n },\n };\n },\n\n async refresh(_session: AuthSession): Promise<AuthPluginResult | null> {\n // Don't try to refresh - Okta SSO cookies can't be silently refreshed\n return null;\n },\n};\n\nexport default authPlugin;\n","/**\n * @abapify/adt-puppeteer\n *\n * Puppeteer-based SSO authentication plugin for ADT client.\n * Uses @abapify/browser-auth core with Puppeteer adapter.\n */\n\nimport type { AdtConfig, Destination } from '@abapify/adt-config';\nimport type { BrowserAuthOptions } from '@abapify/browser-auth';\n\n// Re-export types\nexport type {\n PuppeteerCredentials,\n PuppeteerAuthOptions,\n} from './puppeteer-auth';\nexport type {\n BrowserCredentials,\n BrowserAuthOptions,\n CookieData,\n} from '@abapify/browser-auth';\n\n/**\n * Plugin-level options applied to all destinations\n */\nexport type PuppeteerPluginOptions = BrowserAuthOptions;\n\n/**\n * Create a puppeteer destination config\n */\nfunction createPuppeteerDestination(options: BrowserAuthOptions): Destination {\n return {\n type: '@abapify/adt-puppeteer',\n options,\n };\n}\n\n/**\n * Wrap a standard config with puppeteer auth for all destinations.\n */\nexport function withPuppeteer(\n config: AdtConfig,\n options?: Partial<BrowserAuthOptions>,\n): AdtConfig {\n if (!config.destinations) {\n return config;\n }\n\n const destinations: Record<string, Destination> = {};\n\n for (const [name, dest] of Object.entries(config.destinations)) {\n if (typeof dest === 'object' && 'type' in dest) {\n if (dest.type === '@abapify/adt-puppeteer' || dest.type === 'puppeteer') {\n destinations[name] = {\n type: '@abapify/adt-puppeteer',\n options: { ...options, ...(dest.options as BrowserAuthOptions) },\n };\n } else {\n destinations[name] = dest;\n }\n } else if (typeof dest === 'string') {\n destinations[name] = createPuppeteerDestination({\n url: dest,\n ...options,\n });\n } else {\n destinations[name] = createPuppeteerDestination({\n ...(dest as BrowserAuthOptions),\n ...options,\n });\n }\n }\n\n return { ...config, destinations };\n}\n\n// Main exports\nexport {\n puppeteerAuth,\n puppeteer,\n toCookieHeader,\n toHeaders,\n} from './puppeteer-auth';\n\n// AuthManager compatibility exports\nexport { default } from './auth-plugin';\nexport { default as authPlugin } from './auth-plugin';\n"],"mappings":";;;;;;;;;;;;;AAkBA,SAAS,cAAc,QAA6C;CAClE,OAAO;EACL,MAAM,OAAO;EACb,OAAO,OAAO;EACd,QAAQ,OAAO;EACf,MAAM,OAAO;EACb,SAAS,OAAO;EAChB,UAAU,OAAO;EACjB,QAAQ,OAAO;EACf,UAAU,OAAO;CACnB;AACF;;;;AAKA,SAAgB,yBAAyC;CACvD,IAAI,UAA0B;CAC9B,IAAI,OAAoB;CACxB,IAAI,gBAAqE,CAAC;CAE1E,MAAM,mBAAuD,CAAC;CAC9D,MAAM,gBAAgC,CAAC;CAEvC,OAAO;EACL,MAAM,OAAO,SAKV;GACD,MAAM,EAAE,UAAU,aAAa,mBAAmB,cAAc;GAChE,gBAAgB;IAAE;IAAmB;GAAU;GAE/C,UAAU,MAAMA,YAAU,OAAO;IAC/B;IACA;IACA,MAAM,YAAY,CAAC,gBAAgB,WAAW,IAAI,CAAC;GACrD,CAAC;EACH;EAEA,MAAM,UAAU;GACd,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,sBAAsB;GACpD,OAAO,MAAM,QAAQ,QAAQ;GAG7B,IAAI,cAAc,mBAChB,MAAM,KAAK,aAAa,IAAI;GAI9B,KAAK,GAAG,aAAa,aAAa;IAChC,MAAM,QAAu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,4BAA4B,KAAK,SAAS,aAC1D,aAAa,QAAQ;GACnB,MAAM;GACN,SAAS;IAAE,GAAG;IAAS,GAAI,KAAK;GAA+B;EACjE;OAEA,aAAa,QAAQ;CAEzB,OAAO,IAAI,OAAO,SAAS,UACzB,aAAa,QAAQ,2BAA2B;EAC9C,KAAK;EACL,GAAG;CACL,CAAC;MAED,aAAa,QAAQ,2BAA2B;EAC9C,GAAI;EACJ,GAAG;CACL,CAAC;CAIL,OAAO;EAAE,GAAG;EAAQ;CAAa;AACnC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abapify/adt-puppeteer",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.19",
|
|
4
4
|
"description": "Puppeteer-based authentication for SAP ADT (SSO/IDP)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
"README.md"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@abapify/adt-auth": "0.4.
|
|
21
|
-
"@abapify/adt-config": "0.4.
|
|
22
|
-
"@abapify/browser-auth": "0.4.
|
|
23
|
-
"puppeteer": "^
|
|
20
|
+
"@abapify/adt-auth": "0.4.19",
|
|
21
|
+
"@abapify/adt-config": "0.4.19",
|
|
22
|
+
"@abapify/browser-auth": "0.4.19",
|
|
23
|
+
"puppeteer": "^25.15.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"puppeteer": ">=22.0.0"
|