Spaces:
Runtime error
Runtime error
zankdthi commited on
Commit ·
6e196a9
1
Parent(s): 31d6eae
Deploy Zone.ID Domain API 2025-12-07
Browse files- Dockerfile +2 -0
- lib/account-creator.js +11 -4
- lib/autz-account.js +39 -0
- prisma/schema.prisma +14 -13
- src/routes/domains.js +4 -1
Dockerfile
CHANGED
|
@@ -40,7 +40,9 @@ COPY --chown=node package*.json ./
|
|
| 40 |
RUN npm ci --only=production
|
| 41 |
|
| 42 |
COPY --chown=node prisma ./prisma/
|
|
|
|
| 43 |
RUN npx prisma generate
|
|
|
|
| 44 |
COPY --chown=node . .
|
| 45 |
|
| 46 |
ENV PORT=7860
|
|
|
|
| 40 |
RUN npm ci --only=production
|
| 41 |
|
| 42 |
COPY --chown=node prisma ./prisma/
|
| 43 |
+
|
| 44 |
RUN npx prisma generate
|
| 45 |
+
|
| 46 |
COPY --chown=node . .
|
| 47 |
|
| 48 |
ENV PORT=7860
|
lib/account-creator.js
CHANGED
|
@@ -313,8 +313,8 @@ async function createAndActivateAccount() {
|
|
| 313 |
throw new Error('Failed to create Autz.org account');
|
| 314 |
}
|
| 315 |
|
| 316 |
-
console.log('Waiting for verification email...');
|
| 317 |
-
const verificationEmail = await waitForEmail(email,
|
| 318 |
|
| 319 |
const otp = await extractOtpFromEmail(verificationEmail.html || verificationEmail.text);
|
| 320 |
if (!otp) {
|
|
@@ -363,20 +363,27 @@ async function createAndActivateAccount() {
|
|
| 363 |
}
|
| 364 |
|
| 365 |
async function getOrCreateAvailableAccount() {
|
|
|
|
|
|
|
| 366 |
let account = await prisma.account.findFirst({
|
| 367 |
where: {
|
| 368 |
status: 'active',
|
| 369 |
domainCount: { lt: 10 },
|
| 370 |
-
refreshToken: { not: null }
|
|
|
|
|
|
|
|
|
|
|
|
|
| 371 |
},
|
| 372 |
orderBy: { domainCount: 'asc' }
|
| 373 |
});
|
| 374 |
|
| 375 |
if (account) {
|
|
|
|
| 376 |
return account;
|
| 377 |
}
|
| 378 |
|
| 379 |
-
console.log('No available account
|
| 380 |
return await createAndActivateAccount();
|
| 381 |
}
|
| 382 |
|
|
|
|
| 313 |
throw new Error('Failed to create Autz.org account');
|
| 314 |
}
|
| 315 |
|
| 316 |
+
console.log('Waiting for verification email (5 min timeout)...');
|
| 317 |
+
const verificationEmail = await waitForEmail(email, 300000, 5000);
|
| 318 |
|
| 319 |
const otp = await extractOtpFromEmail(verificationEmail.html || verificationEmail.text);
|
| 320 |
if (!otp) {
|
|
|
|
| 363 |
}
|
| 364 |
|
| 365 |
async function getOrCreateAvailableAccount() {
|
| 366 |
+
const thirtyMinutesAgo = new Date(Date.now() - 30 * 60 * 1000);
|
| 367 |
+
|
| 368 |
let account = await prisma.account.findFirst({
|
| 369 |
where: {
|
| 370 |
status: 'active',
|
| 371 |
domainCount: { lt: 10 },
|
| 372 |
+
refreshToken: { not: null },
|
| 373 |
+
OR: [
|
| 374 |
+
{ lastDomainRegistration: null },
|
| 375 |
+
{ lastDomainRegistration: { lt: thirtyMinutesAgo } }
|
| 376 |
+
]
|
| 377 |
},
|
| 378 |
orderBy: { domainCount: 'asc' }
|
| 379 |
});
|
| 380 |
|
| 381 |
if (account) {
|
| 382 |
+
console.log(`Using existing account ${account.email} (last registration: ${account.lastDomainRegistration || 'never'})`);
|
| 383 |
return account;
|
| 384 |
}
|
| 385 |
|
| 386 |
+
console.log('No available account (all are rate-limited or full). Creating new account...');
|
| 387 |
return await createAndActivateAccount();
|
| 388 |
}
|
| 389 |
|
lib/autz-account.js
CHANGED
|
@@ -88,6 +88,45 @@ async function createAutzAccount(email, password, name, phone) {
|
|
| 88 |
await new Promise(r => setTimeout(r, 5000));
|
| 89 |
}
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
return {
|
| 92 |
success: !!userTokenId,
|
| 93 |
email,
|
|
|
|
| 88 |
await new Promise(r => setTimeout(r, 5000));
|
| 89 |
}
|
| 90 |
|
| 91 |
+
console.log('[Autz] Registration completed, clicking Activate Now...');
|
| 92 |
+
|
| 93 |
+
await Promise.all([
|
| 94 |
+
page.waitForNavigation({ waitUntil: 'networkidle2', timeout: 30000 }).catch(() => {}),
|
| 95 |
+
page.evaluate(() => {
|
| 96 |
+
document.querySelectorAll('a, span, button').forEach(el => {
|
| 97 |
+
if (el.textContent?.toLowerCase().includes('activate')) el.click();
|
| 98 |
+
});
|
| 99 |
+
})
|
| 100 |
+
]);
|
| 101 |
+
|
| 102 |
+
await new Promise(r => setTimeout(r, 2000));
|
| 103 |
+
|
| 104 |
+
let pages = await browser.pages();
|
| 105 |
+
let activePage = page;
|
| 106 |
+
if (pages.length > 1) {
|
| 107 |
+
activePage = pages[pages.length - 1];
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
let pageText = await activePage.evaluate(() => document.body.innerText);
|
| 111 |
+
console.log('[Autz] Current page:', pageText.substring(0, 120).replace(/\n/g, ' '));
|
| 112 |
+
|
| 113 |
+
if (pageText.toLowerCase().includes('send otp')) {
|
| 114 |
+
console.log('[Autz] Found Send OTP page - clicking Send OTP button...');
|
| 115 |
+
|
| 116 |
+
await activePage.evaluate(() => {
|
| 117 |
+
document.querySelectorAll('button').forEach(btn => {
|
| 118 |
+
if (btn.textContent?.toLowerCase().includes('send otp')) {
|
| 119 |
+
btn.click();
|
| 120 |
+
}
|
| 121 |
+
});
|
| 122 |
+
});
|
| 123 |
+
|
| 124 |
+
await new Promise(r => setTimeout(r, 3000));
|
| 125 |
+
console.log('[Autz] Send OTP clicked - email should be sent now');
|
| 126 |
+
} else {
|
| 127 |
+
console.log('[Autz] Send OTP page not found, checking for other activation methods...');
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
return {
|
| 131 |
success: !!userTokenId,
|
| 132 |
email,
|
prisma/schema.prisma
CHANGED
|
@@ -8,20 +8,21 @@ datasource db {
|
|
| 8 |
}
|
| 9 |
|
| 10 |
model Account {
|
| 11 |
-
id
|
| 12 |
-
email
|
| 13 |
-
passwordHash
|
| 14 |
-
refreshToken
|
| 15 |
-
name
|
| 16 |
-
phone
|
| 17 |
-
autzorgId
|
| 18 |
-
zoneIdUserId
|
| 19 |
-
status
|
| 20 |
-
domainCount
|
| 21 |
-
|
| 22 |
-
|
|
|
|
| 23 |
|
| 24 |
-
domains
|
| 25 |
}
|
| 26 |
|
| 27 |
model Domain {
|
|
|
|
| 8 |
}
|
| 9 |
|
| 10 |
model Account {
|
| 11 |
+
id String @id @default(cuid())
|
| 12 |
+
email String @unique
|
| 13 |
+
passwordHash String
|
| 14 |
+
refreshToken String?
|
| 15 |
+
name String?
|
| 16 |
+
phone String?
|
| 17 |
+
autzorgId String?
|
| 18 |
+
zoneIdUserId String?
|
| 19 |
+
status String @default("active")
|
| 20 |
+
domainCount Int @default(0)
|
| 21 |
+
lastDomainRegistration DateTime?
|
| 22 |
+
createdAt DateTime @default(now())
|
| 23 |
+
updatedAt DateTime @updatedAt
|
| 24 |
|
| 25 |
+
domains Domain[]
|
| 26 |
}
|
| 27 |
|
| 28 |
model Domain {
|
src/routes/domains.js
CHANGED
|
@@ -180,7 +180,10 @@ async function domainRoutes(fastify, options) {
|
|
| 180 |
|
| 181 |
await prisma.account.update({
|
| 182 |
where: { id: account.id },
|
| 183 |
-
data: {
|
|
|
|
|
|
|
|
|
|
| 184 |
});
|
| 185 |
|
| 186 |
reply.code(201);
|
|
|
|
| 180 |
|
| 181 |
await prisma.account.update({
|
| 182 |
where: { id: account.id },
|
| 183 |
+
data: {
|
| 184 |
+
domainCount: { increment: 1 },
|
| 185 |
+
lastDomainRegistration: new Date()
|
| 186 |
+
}
|
| 187 |
});
|
| 188 |
|
| 189 |
reply.code(201);
|