@thetypefounders/continue-with-google 1.1.0 → 1.2.1
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.ts +3 -1
- package/dist/index.js +3 -3
- package/package.json +1 -1
- package/src/index.ts +6 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { type ElementHandle, Page } from 'puppeteer';
|
|
1
|
+
import { type ElementHandle, Page, WaitForSelectorOptions } from 'puppeteer';
|
|
2
2
|
export interface Logger {
|
|
3
3
|
info(message: string): void;
|
|
4
|
+
warn(message: string): void;
|
|
4
5
|
}
|
|
5
6
|
export type Options = {
|
|
6
7
|
challengeCount?: number;
|
|
7
8
|
challengeTimeoutSeconds?: number;
|
|
8
9
|
trialCount?: number;
|
|
9
10
|
trialTimeoutSeconds?: number;
|
|
11
|
+
waitForSelector?: WaitForSelectorOptions;
|
|
10
12
|
};
|
|
11
13
|
export declare function authenticate(page: Page, email: string, password: string, secret: string, selector: string, options?: Options, logger?: Logger): Promise<ElementHandle | null>;
|
package/dist/index.js
CHANGED
|
@@ -19,7 +19,7 @@ export async function authenticate(page, email, password, secret, selector, opti
|
|
|
19
19
|
await page.keyboard.press('Enter');
|
|
20
20
|
for (let attempt = 0, found = false; attempt < (options.challengeCount || DEFAULTS.challengeCount) && !found; attempt++) {
|
|
21
21
|
if (attempt > 0) {
|
|
22
|
-
logger.
|
|
22
|
+
logger.warn(`Challenged on attempt ${attempt}. Entering the code...`);
|
|
23
23
|
if (attempt > 1) {
|
|
24
24
|
await setTimeout(1000 *
|
|
25
25
|
(options.challengeTimeoutSeconds ||
|
|
@@ -35,7 +35,7 @@ export async function authenticate(page, email, password, secret, selector, opti
|
|
|
35
35
|
await waitForTrial(page, options.trialCount || DEFAULTS.trialCount, options.trialTimeoutSeconds || DEFAULTS.trialTimeoutSeconds, logger);
|
|
36
36
|
}
|
|
37
37
|
found = await Promise.any([
|
|
38
|
-
page.waitForSelector(selector).then(() => true),
|
|
38
|
+
page.waitForSelector(selector, options.waitForSelector).then(() => true),
|
|
39
39
|
page
|
|
40
40
|
.waitForSelector('input[type=tel]', { visible: true })
|
|
41
41
|
.then(() => false),
|
|
@@ -46,7 +46,7 @@ export async function authenticate(page, email, password, secret, selector, opti
|
|
|
46
46
|
async function waitForTrial(page, attemptCount, attemptTimeoutSeconds, logger) {
|
|
47
47
|
for (let attempt = -1, previous = undefined, current = undefined; attempt < attemptCount && (current === undefined || previous !== current); attempt++) {
|
|
48
48
|
if (attempt > 0) {
|
|
49
|
-
logger.
|
|
49
|
+
logger.warn(`Tried on attempt ${attempt}. Waiting to finish...`);
|
|
50
50
|
}
|
|
51
51
|
if (attempt > -1) {
|
|
52
52
|
await setTimeout(1000 * attemptTimeoutSeconds);
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { generateToken } from 'authenticator';
|
|
2
2
|
import { setTimeout } from 'node:timers/promises';
|
|
3
|
-
import { type ElementHandle, Page } from 'puppeteer';
|
|
3
|
+
import { type ElementHandle, Page, WaitForSelectorOptions } from 'puppeteer';
|
|
4
4
|
|
|
5
5
|
export interface Logger {
|
|
6
6
|
info(message: string): void;
|
|
7
|
+
warn(message: string): void;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
export type Options = {
|
|
@@ -11,6 +12,7 @@ export type Options = {
|
|
|
11
12
|
challengeTimeoutSeconds?: number;
|
|
12
13
|
trialCount?: number;
|
|
13
14
|
trialTimeoutSeconds?: number;
|
|
15
|
+
waitForSelector?: WaitForSelectorOptions;
|
|
14
16
|
};
|
|
15
17
|
|
|
16
18
|
const DEFAULTS: Options = {
|
|
@@ -47,7 +49,7 @@ export async function authenticate(
|
|
|
47
49
|
attempt++
|
|
48
50
|
) {
|
|
49
51
|
if (attempt > 0) {
|
|
50
|
-
logger.
|
|
52
|
+
logger.warn(`Challenged on attempt ${attempt}. Entering the code...`);
|
|
51
53
|
if (attempt > 1) {
|
|
52
54
|
await setTimeout(
|
|
53
55
|
1000 *
|
|
@@ -70,7 +72,7 @@ export async function authenticate(
|
|
|
70
72
|
);
|
|
71
73
|
}
|
|
72
74
|
found = await Promise.any([
|
|
73
|
-
page.waitForSelector(selector).then(() => true),
|
|
75
|
+
page.waitForSelector(selector, options.waitForSelector).then(() => true),
|
|
74
76
|
page
|
|
75
77
|
.waitForSelector('input[type=tel]', { visible: true })
|
|
76
78
|
.then(() => false),
|
|
@@ -92,7 +94,7 @@ async function waitForTrial(
|
|
|
92
94
|
attempt++
|
|
93
95
|
) {
|
|
94
96
|
if (attempt > 0) {
|
|
95
|
-
logger.
|
|
97
|
+
logger.warn(`Tried on attempt ${attempt}. Waiting to finish...`);
|
|
96
98
|
}
|
|
97
99
|
if (attempt > -1) {
|
|
98
100
|
await setTimeout(1000 * attemptTimeoutSeconds);
|