qarpeo 0.1.16 → 0.1.18
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/chunks/auth-schema.mjs +23 -5
- package/dist/chunks/wrangler.mjs +108 -20
- package/dist/cli/index.mjs +1182 -43
- package/dist/fate/index.d.ts +76 -0
- package/dist/fate/index.mjs +53 -0
- package/dist/module.mjs +395 -25
- package/dist/runtime/ai.d.ts +2 -2
- package/dist/runtime/ai.mjs +1 -1
- package/dist/runtime/app/components/BlobImage.vue +7 -0
- package/dist/runtime/app/composables/ai.d.ts +67 -4
- package/dist/runtime/app/composables/ai.mjs +144 -7
- package/dist/runtime/app/composables/auth.d.ts +1 -0
- package/dist/runtime/app/composables/auth.mjs +1 -0
- package/dist/runtime/app/composables/chat.d.ts +26 -8
- package/dist/runtime/app/composables/chat.mjs +108 -50
- package/dist/runtime/app/composables/realtime.d.ts +5 -5
- package/dist/runtime/app/composables/resumable-upload.d.ts +23 -0
- package/dist/runtime/app/composables/resumable-upload.mjs +218 -0
- package/dist/runtime/app/composables/storage.d.ts +1 -0
- package/dist/runtime/app/composables/storage.mjs +1 -0
- package/dist/runtime/app/pages/devtools/realtime.vue +482 -0
- package/dist/runtime/app/pages/devtools/security.vue +515 -0
- package/dist/runtime/app/pages/devtools/tasks.vue +260 -0
- package/dist/runtime/app/pages/devtools.vue +21 -0
- package/dist/runtime/app/plugins/fate.d.ts +6 -0
- package/dist/runtime/app/plugins/fate.mjs +27 -0
- package/dist/runtime/app/plugins/seo.mjs +1 -4
- package/dist/runtime/browser.d.ts +2 -0
- package/dist/runtime/browser.mjs +1 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.mjs +2 -0
- package/dist/runtime/providers/qarpeo.d.ts +23 -0
- package/dist/runtime/providers/qarpeo.mjs +46 -0
- package/dist/runtime/queue.d.ts +2 -0
- package/dist/runtime/queue.mjs +1 -0
- package/dist/runtime/realtime.d.ts +2 -2
- package/dist/runtime/realtime.mjs +2 -1
- package/dist/runtime/server/durable-objects/agent.mjs +7 -0
- package/dist/runtime/server/durable-objects/room.d.ts +2 -0
- package/dist/runtime/server/durable-objects/room.mjs +17 -1
- package/dist/runtime/server/middleware/devtools.mjs +1 -1
- package/dist/runtime/server/plugins/cms.mjs +6 -5
- package/dist/runtime/server/plugins/queue.mjs +9 -2
- package/dist/runtime/server/routes/__qarpeo/auth/revoke-session.post.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/auth/sessions.get.d.ts +1 -1
- package/dist/runtime/server/routes/__qarpeo/auth/sessions.get.mjs +5 -5
- package/dist/runtime/server/routes/__qarpeo/auth/users.get.d.ts +1 -1
- package/dist/runtime/server/routes/__qarpeo/auth/users.get.mjs +2 -2
- package/dist/runtime/server/routes/__qarpeo/db/query.post.d.ts +6 -7
- package/dist/runtime/server/routes/__qarpeo/db/query.post.mjs +9 -9
- package/dist/runtime/server/routes/__qarpeo/db/tables.get.d.ts +1 -1
- package/dist/runtime/server/routes/__qarpeo/db/tables.get.mjs +6 -3
- package/dist/runtime/server/routes/__qarpeo/realtime/broadcast.post.d.ts +9 -0
- package/dist/runtime/server/routes/__qarpeo/realtime/broadcast.post.mjs +33 -0
- package/dist/runtime/server/routes/__qarpeo/realtime/clear.post.d.ts +9 -0
- package/dist/runtime/server/routes/__qarpeo/realtime/clear.post.mjs +21 -0
- package/dist/runtime/server/routes/__qarpeo/realtime/disconnect.post.d.ts +9 -0
- package/dist/runtime/server/routes/__qarpeo/realtime/disconnect.post.mjs +24 -0
- package/dist/runtime/server/routes/__qarpeo/realtime/room.get.d.ts +17 -0
- package/dist/runtime/server/routes/__qarpeo/realtime/room.get.mjs +44 -0
- package/dist/runtime/server/routes/__qarpeo/realtime/rooms.get.d.ts +16 -0
- package/dist/runtime/server/routes/__qarpeo/realtime/rooms.get.mjs +15 -0
- package/dist/runtime/server/routes/__qarpeo/security/analytics.get.d.ts +25 -0
- package/dist/runtime/server/routes/__qarpeo/security/analytics.get.mjs +22 -0
- package/dist/runtime/server/routes/__qarpeo/security/ban.post.d.ts +10 -0
- package/dist/runtime/server/routes/__qarpeo/security/ban.post.mjs +20 -0
- package/dist/runtime/server/routes/__qarpeo/security/clear.post.d.ts +9 -0
- package/dist/runtime/server/routes/__qarpeo/security/clear.post.mjs +7 -0
- package/dist/runtime/server/routes/__qarpeo/security/unban.post.d.ts +10 -0
- package/dist/runtime/server/routes/__qarpeo/security/unban.post.mjs +20 -0
- package/dist/runtime/server/routes/__qarpeo/tasks/list.get.d.ts +10 -0
- package/dist/runtime/server/routes/__qarpeo/tasks/list.get.mjs +26 -0
- package/dist/runtime/server/routes/__qarpeo/tasks/run.post.d.ts +7 -0
- package/dist/runtime/server/routes/__qarpeo/tasks/run.post.mjs +22 -0
- package/dist/runtime/server/routes/agents/[agent]/chat.post.mjs +2 -1
- package/dist/runtime/server/routes/agents/[agent]/history.get.d.ts +1 -1
- package/dist/runtime/server/routes/ai/embed.post.d.ts +12 -0
- package/dist/runtime/server/routes/ai/embed.post.mjs +26 -0
- package/dist/runtime/server/routes/ai/search.post.d.ts +12 -0
- package/dist/runtime/server/routes/ai/search.post.mjs +48 -0
- package/dist/runtime/server/routes/auth/2fa/disable.post.mjs +2 -2
- package/dist/runtime/server/routes/auth/2fa/verify.post.mjs +2 -2
- package/dist/runtime/server/routes/auth/handler.d.ts +1 -1
- package/dist/runtime/server/routes/auth/magic-link/verify.get.mjs +4 -4
- package/dist/runtime/server/routes/auth/organization/mfa.post.mjs +2 -2
- package/dist/runtime/server/routes/auth/organization/sso/[id].delete.mjs +1 -1
- package/dist/runtime/server/routes/auth/organization/sso/index.post.mjs +1 -1
- package/dist/runtime/server/routes/auth/otp/verify.post.mjs +4 -4
- package/dist/runtime/server/routes/auth/sso/login.get.mjs +1 -1
- package/dist/runtime/server/routes/auth/sso/oidc/callback.get.mjs +5 -5
- package/dist/runtime/server/routes/auth/sso/saml/acs.post.mjs +47 -9
- package/dist/runtime/server/routes/auth/webauthn/login/verify.post.mjs +2 -2
- package/dist/runtime/server/routes/browser/crawl.post.d.ts +8 -0
- package/dist/runtime/server/routes/browser/crawl.post.mjs +20 -0
- package/dist/runtime/server/routes/browser/invoice.post.d.ts +8 -0
- package/dist/runtime/server/routes/browser/invoice.post.mjs +28 -0
- package/dist/runtime/server/routes/browser/og-image.post.d.ts +8 -0
- package/dist/runtime/server/routes/browser/og-image.post.mjs +29 -0
- package/dist/runtime/server/routes/browser/pdf.post.d.ts +8 -0
- package/dist/runtime/server/routes/browser/pdf.post.mjs +29 -0
- package/dist/runtime/server/routes/browser/screenshot.post.d.ts +8 -0
- package/dist/runtime/server/routes/browser/screenshot.post.mjs +29 -0
- package/dist/runtime/server/routes/cms/webhooks/[provider].post.mjs +2 -2
- package/dist/runtime/server/routes/fate.d.ts +2 -0
- package/dist/runtime/server/routes/fate.mjs +35 -0
- package/dist/runtime/server/routes/realtime/history.delete.mjs +10 -1
- package/dist/runtime/server/routes/realtime/history.get.mjs +10 -1
- package/dist/runtime/server/routes/realtime/ws.get.mjs +8 -7
- package/dist/runtime/server/routes/storage/file/[...key].delete.mjs +2 -1
- package/dist/runtime/server/routes/storage/file/[...key].get.mjs +2 -1
- package/dist/runtime/server/routes/storage/multipart/abort.post.d.ts +9 -0
- package/dist/runtime/server/routes/storage/multipart/abort.post.mjs +32 -0
- package/dist/runtime/server/routes/storage/multipart/complete.post.d.ts +16 -0
- package/dist/runtime/server/routes/storage/multipart/complete.post.mjs +83 -0
- package/dist/runtime/server/routes/storage/multipart/create.post.d.ts +17 -0
- package/dist/runtime/server/routes/storage/multipart/create.post.mjs +78 -0
- package/dist/runtime/server/routes/storage/multipart/part.put.d.ts +11 -0
- package/dist/runtime/server/routes/storage/multipart/part.put.mjs +71 -0
- package/dist/runtime/server/routes/storage/upload.post.mjs +6 -4
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.mjs +1 -1
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.mjs +1 -1
- package/dist/runtime/server/routes/tenants/[tenant]/domains/index.post.mjs +1 -1
- package/dist/runtime/server/utils/ai.d.ts +10 -4
- package/dist/runtime/server/utils/ai.mjs +49 -13
- package/dist/runtime/server/utils/auth.d.ts +12 -59
- package/dist/runtime/server/utils/auth.mjs +223 -169
- package/dist/runtime/server/utils/bots.d.ts +2 -1
- package/dist/runtime/server/utils/browser-utils.d.ts +228 -0
- package/dist/runtime/server/utils/browser-utils.mjs +561 -0
- package/dist/runtime/server/utils/cache.d.ts +22 -7
- package/dist/runtime/server/utils/cache.mjs +81 -13
- package/dist/runtime/server/utils/cms.d.ts +39 -38
- package/dist/runtime/server/utils/cms.mjs +123 -100
- package/dist/runtime/server/utils/config.d.ts +3 -2
- package/dist/runtime/server/utils/context.d.ts +4 -3
- package/dist/runtime/server/utils/crypto.d.ts +3 -2
- package/dist/runtime/server/utils/crypto.mjs +4 -1
- package/dist/runtime/server/utils/impersonation.d.ts +8 -7
- package/dist/runtime/server/utils/impersonation.mjs +2 -2
- package/dist/runtime/server/utils/jobs.d.ts +2 -0
- package/dist/runtime/server/utils/jobs.mjs +1 -1
- package/dist/runtime/server/utils/mail-suppression.d.ts +6 -5
- package/dist/runtime/server/utils/mail.d.ts +4 -3
- package/dist/runtime/server/utils/multipart-store.d.ts +30 -0
- package/dist/runtime/server/utils/multipart-store.mjs +24 -0
- package/dist/runtime/server/utils/notifications.d.ts +9 -8
- package/dist/runtime/server/utils/organization.d.ts +8 -7
- package/dist/runtime/server/utils/organization.mjs +23 -23
- package/dist/runtime/server/utils/passwordless.d.ts +5 -4
- package/dist/runtime/server/utils/payments.d.ts +15 -14
- package/dist/runtime/server/utils/payments.mjs +36 -30
- package/dist/runtime/server/utils/queue.d.ts +96 -4
- package/dist/runtime/server/utils/queue.mjs +141 -2
- package/dist/runtime/server/utils/ratelimit.d.ts +5 -4
- package/dist/runtime/server/utils/realtime-store.d.ts +21 -0
- package/dist/runtime/server/utils/realtime-store.mjs +127 -0
- package/dist/runtime/server/utils/realtime.d.ts +18 -2
- package/dist/runtime/server/utils/realtime.mjs +18 -0
- package/dist/runtime/server/utils/scheduled-task.d.ts +29 -0
- package/dist/runtime/server/utils/scheduled-task.mjs +3 -0
- package/dist/runtime/server/utils/schema-fallback.d.ts +17 -0
- package/dist/runtime/server/utils/schema-fallback.mjs +17 -0
- package/dist/runtime/server/utils/security-store.d.ts +38 -0
- package/dist/runtime/server/utils/security-store.mjs +78 -0
- package/dist/runtime/server/utils/session.d.ts +12 -12
- package/dist/runtime/server/utils/session.mjs +12 -12
- package/dist/runtime/server/utils/sso.d.ts +11 -0
- package/dist/runtime/server/utils/sso.mjs +66 -0
- package/dist/runtime/server/utils/storage.d.ts +15 -14
- package/dist/runtime/server/utils/storage.mjs +10 -4
- package/dist/runtime/server/utils/tenant.mjs +16 -12
- package/dist/runtime/server/utils/turnstile.d.ts +3 -2
- package/dist/runtime/service.d.ts +37 -0
- package/dist/runtime/service.mjs +128 -0
- package/dist/runtime/test-utils.d.ts +190 -0
- package/dist/runtime/test-utils.mjs +490 -0
- package/dist/runtime/types/auth.d.ts +1 -1
- package/dist/runtime/types/imports.d.ts +0 -35
- package/dist/runtime/types/index.d.ts +1 -0
- package/dist/runtime/types/index.mjs +1 -0
- package/dist/runtime/types/service.d.ts +70 -0
- package/dist/runtime/types/service.mjs +0 -0
- package/dist/types.d.ts +139 -0
- package/dist/utils/auth-schema.d.ts +2 -2
- package/dist/utils/queue.d.ts +3 -2
- package/dist/utils/tasks.d.ts +13 -0
- package/package.json +35 -11
- package/dist/runtime/app/composables/void-client.d.ts +0 -3
- package/dist/runtime/app/composables/void-client.mjs +0 -4
- package/dist/runtime/server/utils/void-ai.d.ts +0 -7
- package/dist/runtime/server/utils/void-ai.mjs +0 -47
- package/dist/runtime/server/utils/void-auth.d.ts +0 -2
- package/dist/runtime/server/utils/void-auth.mjs +0 -9
- package/dist/runtime/server/utils/void-db.d.ts +0 -8
- package/dist/runtime/server/utils/void-db.mjs +0 -38
- package/dist/runtime/server/utils/void-seed.d.ts +0 -11
- package/dist/runtime/server/utils/void-seed.mjs +0 -3
package/dist/cli/index.mjs
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { defineCommand, runMain } from 'citty';
|
|
3
|
-
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { spawnSync, spawn } from 'node:child_process';
|
|
4
4
|
import { existsSync, mkdirSync, writeFileSync, readFileSync, readdirSync, statSync } from 'node:fs';
|
|
5
5
|
import { loadNuxtConfig } from '@nuxt/kit';
|
|
6
|
-
import { resolve, join } from 'pathe';
|
|
7
|
-
import {
|
|
6
|
+
import { resolve, join, extname } from 'pathe';
|
|
7
|
+
import { j as findSchemaFiles, k as resolveBinaryPath, e as ensurePackage, l as getLocalDatabaseContext, m as getJiti, b as resolveProjectName, a as checkDrizzleVersion, n as findLocalD1Database } from '../chunks/wrangler.mjs';
|
|
8
8
|
import { reset, seed } from 'drizzle-seed';
|
|
9
9
|
import { stdin, stdout } from 'node:process';
|
|
10
10
|
import readline from 'node:readline/promises';
|
|
11
11
|
import { homedir } from 'node:os';
|
|
12
|
+
import { randomBytes } from 'node:crypto';
|
|
12
13
|
import 'node:module';
|
|
13
14
|
import 'drizzle-orm/node-sqlite';
|
|
14
15
|
import 'node:url';
|
|
@@ -169,10 +170,10 @@ const cleanCommand = defineCommand({
|
|
|
169
170
|
}
|
|
170
171
|
});
|
|
171
172
|
|
|
172
|
-
function getWranglerBin$
|
|
173
|
+
function getWranglerBin$7(cwd) {
|
|
173
174
|
return resolveBinaryPath("wrangler", cwd) || resolveBinaryPath("wrangler") || (process.platform === "win32" ? "wrangler.cmd" : "wrangler");
|
|
174
175
|
}
|
|
175
|
-
function loadDotEnv$
|
|
176
|
+
function loadDotEnv$7(cwd) {
|
|
176
177
|
const envPath = join(cwd, ".env");
|
|
177
178
|
if (!existsSync(envPath)) return;
|
|
178
179
|
try {
|
|
@@ -217,7 +218,7 @@ const create = defineCommand({
|
|
|
217
218
|
},
|
|
218
219
|
async run({ args }) {
|
|
219
220
|
const cwd = resolve(process.cwd(), args.cwd);
|
|
220
|
-
loadDotEnv$
|
|
221
|
+
loadDotEnv$7(cwd);
|
|
221
222
|
let dbName = args.name;
|
|
222
223
|
if (!dbName && stdin.isTTY) {
|
|
223
224
|
const rl = readline.createInterface({ input: stdin, output: stdout });
|
|
@@ -235,7 +236,7 @@ const create = defineCommand({
|
|
|
235
236
|
cwd,
|
|
236
237
|
purpose: "creating Cloudflare D1 database"
|
|
237
238
|
});
|
|
238
|
-
const wrangler = getWranglerBin$
|
|
239
|
+
const wrangler = getWranglerBin$7(cwd);
|
|
239
240
|
console.log(`
|
|
240
241
|
\u26A1 [qarpeo] Creating D1 database "${dbName}" on Cloudflare...
|
|
241
242
|
`);
|
|
@@ -261,10 +262,10 @@ const create = defineCommand({
|
|
|
261
262
|
}
|
|
262
263
|
});
|
|
263
264
|
|
|
264
|
-
function getWranglerBin$
|
|
265
|
+
function getWranglerBin$6(cwd) {
|
|
265
266
|
return resolveBinaryPath("wrangler", cwd) || resolveBinaryPath("wrangler") || (process.platform === "win32" ? "wrangler.cmd" : "wrangler");
|
|
266
267
|
}
|
|
267
|
-
function loadDotEnv$
|
|
268
|
+
function loadDotEnv$6(cwd) {
|
|
268
269
|
const envPath = join(cwd, ".env");
|
|
269
270
|
if (!existsSync(envPath)) return;
|
|
270
271
|
try {
|
|
@@ -311,7 +312,7 @@ const deleteDb = defineCommand({
|
|
|
311
312
|
},
|
|
312
313
|
async run({ args }) {
|
|
313
314
|
const cwd = resolve(process.cwd(), args.cwd);
|
|
314
|
-
loadDotEnv$
|
|
315
|
+
loadDotEnv$6(cwd);
|
|
315
316
|
let dbName = args.name;
|
|
316
317
|
if (!dbName && stdin.isTTY) {
|
|
317
318
|
const rl = readline.createInterface({ input: stdin, output: stdout });
|
|
@@ -341,7 +342,7 @@ const deleteDb = defineCommand({
|
|
|
341
342
|
cwd,
|
|
342
343
|
purpose: "deleting Cloudflare D1 database"
|
|
343
344
|
});
|
|
344
|
-
const wrangler = getWranglerBin$
|
|
345
|
+
const wrangler = getWranglerBin$6(cwd);
|
|
345
346
|
console.log(`
|
|
346
347
|
\u{1F5D1}\uFE0F [qarpeo] Deleting D1 database "${dbName}" on Cloudflare...
|
|
347
348
|
`);
|
|
@@ -366,10 +367,10 @@ const deleteDb = defineCommand({
|
|
|
366
367
|
}
|
|
367
368
|
});
|
|
368
369
|
|
|
369
|
-
function getWranglerBin$
|
|
370
|
+
function getWranglerBin$5(cwd) {
|
|
370
371
|
return resolveBinaryPath("wrangler", cwd) || resolveBinaryPath("wrangler") || (process.platform === "win32" ? "wrangler.cmd" : "wrangler");
|
|
371
372
|
}
|
|
372
|
-
function loadDotEnv$
|
|
373
|
+
function loadDotEnv$5(cwd) {
|
|
373
374
|
const envPath = join(cwd, ".env");
|
|
374
375
|
if (!existsSync(envPath)) return;
|
|
375
376
|
try {
|
|
@@ -410,12 +411,12 @@ const list = defineCommand({
|
|
|
410
411
|
},
|
|
411
412
|
async run({ args }) {
|
|
412
413
|
const cwd = resolve(process.cwd(), args.cwd);
|
|
413
|
-
loadDotEnv$
|
|
414
|
+
loadDotEnv$5(cwd);
|
|
414
415
|
await ensurePackage("wrangler", {
|
|
415
416
|
cwd,
|
|
416
417
|
purpose: "listing Cloudflare D1 databases"
|
|
417
418
|
});
|
|
418
|
-
const wrangler = getWranglerBin$
|
|
419
|
+
const wrangler = getWranglerBin$5(cwd);
|
|
419
420
|
console.log("\u{1F50D} [qarpeo] Fetching D1 databases from Cloudflare...\n");
|
|
420
421
|
const wranglerArgs = ["d1", "list"];
|
|
421
422
|
if (args.json) {
|
|
@@ -450,6 +451,16 @@ const migrate = defineCommand({
|
|
|
450
451
|
description: "Apply migrations to remote Cloudflare D1 database (production)",
|
|
451
452
|
default: false
|
|
452
453
|
},
|
|
454
|
+
dryRun: {
|
|
455
|
+
type: "boolean",
|
|
456
|
+
description: "List pending migration statements without executing them",
|
|
457
|
+
default: false
|
|
458
|
+
},
|
|
459
|
+
backup: {
|
|
460
|
+
type: "boolean",
|
|
461
|
+
description: "Create an automatic Cloudflare D1 snapshot backup before running migrations",
|
|
462
|
+
default: false
|
|
463
|
+
},
|
|
453
464
|
prune: {
|
|
454
465
|
type: "boolean",
|
|
455
466
|
description: "Safely drop deprecated _qarpeo_* auth tables when corresponding features are disabled in nuxt.config.ts",
|
|
@@ -468,9 +479,15 @@ const migrate = defineCommand({
|
|
|
468
479
|
const dbOpts = typeof qarpeoOpts.db === "object" ? qarpeoOpts.db : {};
|
|
469
480
|
const dbBinding = dbOpts.binding || process.env.QARPEO_DB_BINDING || "DB";
|
|
470
481
|
const dbName = dbBinding;
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
482
|
+
if (args.dryRun) {
|
|
483
|
+
console.log(
|
|
484
|
+
`\u{1F50D} [qarpeo] Dry-run preview for Cloudflare D1 migrations (${args.remote ? "remote" : "local dev"})...`
|
|
485
|
+
);
|
|
486
|
+
} else {
|
|
487
|
+
console.log(
|
|
488
|
+
`\u26A1 [qarpeo] Applying migrations to Cloudflare D1 (${args.remote ? "remote" : "local dev"})...`
|
|
489
|
+
);
|
|
490
|
+
}
|
|
474
491
|
let execPath = resolveBinaryPath("wrangler", cwd);
|
|
475
492
|
if (!execPath) {
|
|
476
493
|
const ok = await ensurePackage("wrangler", {
|
|
@@ -507,10 +524,28 @@ const migrate = defineCommand({
|
|
|
507
524
|
}
|
|
508
525
|
);
|
|
509
526
|
}
|
|
527
|
+
if (args.backup && args.remote && !args.dryRun) {
|
|
528
|
+
console.log(`\u{1F6E1}\uFE0F [qarpeo] Creating automatic snapshot backup of remote D1 database "${dbName}"...`);
|
|
529
|
+
const backupArgs = ["d1", "backup", "create", dbName];
|
|
530
|
+
if (wranglerConfigPath) backupArgs.push("-c", wranglerConfigPath);
|
|
531
|
+
const backupRes = spawnSync(execPath, backupArgs, {
|
|
532
|
+
cwd,
|
|
533
|
+
stdio: "inherit",
|
|
534
|
+
shell: process.platform === "win32"
|
|
535
|
+
});
|
|
536
|
+
if (backupRes.status === 0) {
|
|
537
|
+
console.log(`\u2705 [qarpeo] Backup created successfully prior to migration.`);
|
|
538
|
+
} else {
|
|
539
|
+
console.warn(`\u26A0\uFE0F [qarpeo] Backup command exited with code ${backupRes.status}. Continuing...`);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
510
542
|
const wranglerArgs = ["d1", "migrations", "apply", dbName];
|
|
511
543
|
if (wranglerConfigPath) {
|
|
512
544
|
wranglerArgs.push("-c", wranglerConfigPath);
|
|
513
545
|
}
|
|
546
|
+
if (args.dryRun) {
|
|
547
|
+
wranglerArgs.push("--dry-run");
|
|
548
|
+
}
|
|
514
549
|
if (args.remote) {
|
|
515
550
|
wranglerArgs.push("--remote");
|
|
516
551
|
} else {
|
|
@@ -529,7 +564,7 @@ const migrate = defineCommand({
|
|
|
529
564
|
console.log(`\u2705 [qarpeo] Migrations applied successfully!`);
|
|
530
565
|
if (args.prune) {
|
|
531
566
|
const { getActiveAuthTableNames, ALL_AUTH_TABLE_NAMES } = await import('../chunks/auth-schema.mjs');
|
|
532
|
-
const { findLocalD1Database } = await import('../chunks/wrangler.mjs').then(function (n) { return n.
|
|
567
|
+
const { findLocalD1Database } = await import('../chunks/wrangler.mjs').then(function (n) { return n.o; });
|
|
533
568
|
const authConfig = nuxtConfig.qarpeo?.auth || nuxtConfig.auth;
|
|
534
569
|
const activeTables = getActiveAuthTableNames(authConfig);
|
|
535
570
|
const deprecatedTables = ALL_AUTH_TABLE_NAMES.filter(
|
|
@@ -646,6 +681,119 @@ const push = defineCommand({
|
|
|
646
681
|
}
|
|
647
682
|
});
|
|
648
683
|
|
|
684
|
+
function getWranglerBin$4(cwd) {
|
|
685
|
+
return resolveBinaryPath("wrangler", cwd) || resolveBinaryPath("wrangler") || (process.platform === "win32" ? "wrangler.cmd" : "wrangler");
|
|
686
|
+
}
|
|
687
|
+
function loadDotEnv$4(cwd) {
|
|
688
|
+
const envPath = join(cwd, ".env");
|
|
689
|
+
if (!existsSync(envPath)) return;
|
|
690
|
+
try {
|
|
691
|
+
const raw = readFileSync(envPath, "utf8");
|
|
692
|
+
for (const line of raw.split(/\r?\n/)) {
|
|
693
|
+
const trimmed = line.trim();
|
|
694
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
695
|
+
const eqIdx = trimmed.indexOf("=");
|
|
696
|
+
if (eqIdx === -1) continue;
|
|
697
|
+
const key = trimmed.slice(0, eqIdx).trim();
|
|
698
|
+
let val = trimmed.slice(eqIdx + 1).trim();
|
|
699
|
+
if (val.startsWith('"') && val.endsWith('"') || val.startsWith("'") && val.endsWith("'")) {
|
|
700
|
+
val = val.slice(1, -1);
|
|
701
|
+
}
|
|
702
|
+
if (process.env[key] === void 0) {
|
|
703
|
+
process.env[key] = val;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
} catch {
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
const rollback = defineCommand({
|
|
710
|
+
meta: {
|
|
711
|
+
name: "rollback",
|
|
712
|
+
description: "Restore a Cloudflare D1 database snapshot from a previous backup"
|
|
713
|
+
},
|
|
714
|
+
args: {
|
|
715
|
+
name: {
|
|
716
|
+
type: "positional",
|
|
717
|
+
description: "Name or binding of the D1 database (defaults to DB)",
|
|
718
|
+
required: false
|
|
719
|
+
},
|
|
720
|
+
backupId: {
|
|
721
|
+
type: "string",
|
|
722
|
+
description: "Specific backup ID to restore (if omitted, interactive or lists available backups)"
|
|
723
|
+
},
|
|
724
|
+
cwd: {
|
|
725
|
+
type: "string",
|
|
726
|
+
description: "Working directory",
|
|
727
|
+
default: "."
|
|
728
|
+
}
|
|
729
|
+
},
|
|
730
|
+
async run({ args }) {
|
|
731
|
+
const cwd = resolve(process.cwd(), args.cwd);
|
|
732
|
+
loadDotEnv$4(cwd);
|
|
733
|
+
const nuxtConfig = await loadNuxtConfig({ cwd }).catch(() => ({}));
|
|
734
|
+
const qarpeoOpts = nuxtConfig?.qarpeo || {};
|
|
735
|
+
const dbOpts = typeof qarpeoOpts.db === "object" ? qarpeoOpts.db : {};
|
|
736
|
+
const dbName = args.name || dbOpts.binding || process.env.QARPEO_DB_BINDING || "DB";
|
|
737
|
+
await ensurePackage("wrangler", {
|
|
738
|
+
cwd,
|
|
739
|
+
purpose: "restoring Cloudflare D1 backup"
|
|
740
|
+
});
|
|
741
|
+
const wrangler = getWranglerBin$4(cwd);
|
|
742
|
+
let wranglerConfigPath = null;
|
|
743
|
+
if (existsSync(resolve(cwd, "wrangler.jsonc"))) {
|
|
744
|
+
wranglerConfigPath = resolve(cwd, "wrangler.jsonc");
|
|
745
|
+
} else if (existsSync(resolve(cwd, "wrangler.json"))) {
|
|
746
|
+
wranglerConfigPath = resolve(cwd, "wrangler.json");
|
|
747
|
+
}
|
|
748
|
+
let backupId = args.backupId;
|
|
749
|
+
if (!backupId) {
|
|
750
|
+
console.log(`
|
|
751
|
+
\u{1F4CB} [qarpeo] Fetching existing backups for D1 database "${dbName}"...
|
|
752
|
+
`);
|
|
753
|
+
const listArgs = ["d1", "backup", "list", dbName];
|
|
754
|
+
if (wranglerConfigPath) listArgs.push("-c", wranglerConfigPath);
|
|
755
|
+
const listRes = spawnSync(wrangler, listArgs, {
|
|
756
|
+
cwd,
|
|
757
|
+
stdio: "inherit",
|
|
758
|
+
shell: process.platform === "win32"
|
|
759
|
+
});
|
|
760
|
+
if (listRes.status !== 0) {
|
|
761
|
+
console.error(`
|
|
762
|
+
\u274C [qarpeo] Failed to list backups for database "${dbName}".`);
|
|
763
|
+
process.exit(listRes.status ?? 1);
|
|
764
|
+
}
|
|
765
|
+
if (stdin.isTTY) {
|
|
766
|
+
const rl = readline.createInterface({ input: stdin, output: stdout });
|
|
767
|
+
const answer = await rl.question("\n\u{1F504} Enter the Backup ID to restore: ");
|
|
768
|
+
rl.close();
|
|
769
|
+
backupId = answer.trim();
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
if (!backupId) {
|
|
773
|
+
console.error("\n\u274C [qarpeo] A backup ID is required to perform a rollback.");
|
|
774
|
+
console.error(" Usage: qp db rollback [name] --backup-id <id>\n");
|
|
775
|
+
process.exit(1);
|
|
776
|
+
}
|
|
777
|
+
console.log(`
|
|
778
|
+
\u26A0\uFE0F [qarpeo] Restoring D1 database "${dbName}" to backup snapshot: ${backupId}...`);
|
|
779
|
+
const restoreArgs = ["d1", "backup", "restore", dbName, backupId];
|
|
780
|
+
if (wranglerConfigPath) restoreArgs.push("-c", wranglerConfigPath);
|
|
781
|
+
const restoreRes = spawnSync(wrangler, restoreArgs, {
|
|
782
|
+
cwd,
|
|
783
|
+
stdio: "inherit",
|
|
784
|
+
shell: process.platform === "win32"
|
|
785
|
+
});
|
|
786
|
+
if (restoreRes.status !== 0) {
|
|
787
|
+
console.error(`
|
|
788
|
+
\u274C [qarpeo] Rollback failed. Please check your permissions and try again.`);
|
|
789
|
+
process.exit(restoreRes.status ?? 1);
|
|
790
|
+
}
|
|
791
|
+
console.log(`
|
|
792
|
+
\u2705 [qarpeo] D1 database "${dbName}" successfully restored to snapshot ${backupId}!
|
|
793
|
+
`);
|
|
794
|
+
}
|
|
795
|
+
});
|
|
796
|
+
|
|
649
797
|
const seedCommand = defineCommand({
|
|
650
798
|
meta: {
|
|
651
799
|
name: "seed",
|
|
@@ -756,6 +904,7 @@ const db = defineCommand({
|
|
|
756
904
|
generate,
|
|
757
905
|
migrate,
|
|
758
906
|
push,
|
|
907
|
+
rollback,
|
|
759
908
|
seed: seedCommand,
|
|
760
909
|
clean: cleanCommand,
|
|
761
910
|
reset: cleanCommand
|
|
@@ -856,7 +1005,7 @@ async function deleteCloudflareWorker(auth, workerName) {
|
|
|
856
1005
|
return data.success === true;
|
|
857
1006
|
}
|
|
858
1007
|
|
|
859
|
-
function getWranglerBin$
|
|
1008
|
+
function getWranglerBin$3(cwd) {
|
|
860
1009
|
return resolveBinaryPath("wrangler", cwd) || resolveBinaryPath("wrangler") || (process.platform === "win32" ? "wrangler.cmd" : "wrangler");
|
|
861
1010
|
}
|
|
862
1011
|
function loadDotEnv$3(cwd) {
|
|
@@ -1015,7 +1164,7 @@ const deleteCommand = defineCommand({
|
|
|
1015
1164
|
cwd,
|
|
1016
1165
|
purpose: "deleting Cloudflare Worker"
|
|
1017
1166
|
});
|
|
1018
|
-
const wrangler = getWranglerBin$
|
|
1167
|
+
const wrangler = getWranglerBin$3(cwd);
|
|
1019
1168
|
const wranglerArgs = ["delete", workerName, "--force"];
|
|
1020
1169
|
if (args.env) {
|
|
1021
1170
|
wranglerArgs.push("--env", args.env);
|
|
@@ -1052,6 +1201,12 @@ function loadDotEnv$2(cwd) {
|
|
|
1052
1201
|
if (val.startsWith('"') && val.endsWith('"') || val.startsWith("'") && val.endsWith("'")) {
|
|
1053
1202
|
val = val.slice(1, -1);
|
|
1054
1203
|
}
|
|
1204
|
+
if ((key === "CLOUDFLARE_API_TOKEN" || key === "CLOUDFLARE_ACCOUNT_ID" || key === "CF_API_TOKEN") && (val.startsWith("dummy-") || val === "dummy-dev-api-token" || val === "dummy-dev-account-id")) {
|
|
1205
|
+
if (process.env[key] && (process.env[key].startsWith("dummy-") || process.env[key] === val)) {
|
|
1206
|
+
delete process.env[key];
|
|
1207
|
+
}
|
|
1208
|
+
continue;
|
|
1209
|
+
}
|
|
1055
1210
|
if (process.env[key] === void 0) {
|
|
1056
1211
|
process.env[key] = val;
|
|
1057
1212
|
}
|
|
@@ -1135,6 +1290,16 @@ const deploy = defineCommand({
|
|
|
1135
1290
|
env: {
|
|
1136
1291
|
type: "string",
|
|
1137
1292
|
description: "Cloudflare environment name (e.g. production, staging, preview)"
|
|
1293
|
+
},
|
|
1294
|
+
preflight: {
|
|
1295
|
+
type: "boolean",
|
|
1296
|
+
description: "Run automated pre-flight checks and binding verification before deploying",
|
|
1297
|
+
default: true
|
|
1298
|
+
},
|
|
1299
|
+
healthcheck: {
|
|
1300
|
+
type: "boolean",
|
|
1301
|
+
description: "Perform post-deployment zero-downtime healthcheck verification",
|
|
1302
|
+
default: true
|
|
1138
1303
|
}
|
|
1139
1304
|
},
|
|
1140
1305
|
async run({ args }) {
|
|
@@ -1294,32 +1459,22 @@ const deploy = defineCommand({
|
|
|
1294
1459
|
console.log(`\u{1F528} [qarpeo] Creating ${isPreview ? "preview" : "remote"} D1 database: ${targetDbName}...`);
|
|
1295
1460
|
const createRes = spawnSync(
|
|
1296
1461
|
wranglerBin,
|
|
1297
|
-
["d1", "create", targetDbName
|
|
1462
|
+
["d1", "create", targetDbName],
|
|
1298
1463
|
{ cwd, encoding: "utf8", shell: process.platform === "win32" }
|
|
1299
1464
|
);
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
console.log(`\u2705 [qarpeo] Created ${isPreview ? "preview" : "remote"} D1 database: ${created.uuid}`);
|
|
1307
|
-
}
|
|
1308
|
-
} catch {
|
|
1309
|
-
const matchUuid = createRes.stdout.match(/database_id\s*=\s*"([^"]+)"/);
|
|
1310
|
-
if (matchUuid?.[1]) {
|
|
1311
|
-
d1.database_id = matchUuid[1];
|
|
1312
|
-
d1.database_name = targetDbName;
|
|
1313
|
-
modified = true;
|
|
1314
|
-
console.log(`\u2705 [qarpeo] Created ${isPreview ? "preview" : "remote"} D1 database: ${matchUuid[1]}`);
|
|
1315
|
-
}
|
|
1465
|
+
const matchUuid = createRes.stdout.match(/database_id\s*:\s*"([^"]+)"/) || createRes.stdout.match(/database_id\s*=\s*"([^"]+)"/) || createRes.stdout.match(/"database_id"\s*:\s*"([^"]+)"/) || createRes.stdout.match(/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/i);
|
|
1466
|
+
if (matchUuid?.[1]) {
|
|
1467
|
+
d1.database_id = matchUuid[1];
|
|
1468
|
+
d1.database_name = targetDbName;
|
|
1469
|
+
modified = true;
|
|
1470
|
+
console.log(`\u2705 [qarpeo] Created ${isPreview ? "preview" : "remote"} D1 database: ${matchUuid[1]}`);
|
|
1316
1471
|
}
|
|
1317
1472
|
}
|
|
1318
1473
|
}
|
|
1319
1474
|
}
|
|
1320
1475
|
}
|
|
1321
1476
|
if (Array.isArray(config.kv_namespaces) && config.kv_namespaces.length > 0) {
|
|
1322
|
-
const listRes = spawnSync(wranglerBin, ["kv", "namespace", "list"
|
|
1477
|
+
const listRes = spawnSync(wranglerBin, ["kv", "namespace", "list"], {
|
|
1323
1478
|
cwd,
|
|
1324
1479
|
encoding: "utf8",
|
|
1325
1480
|
shell: process.platform === "win32"
|
|
@@ -1418,6 +1573,21 @@ const deploy = defineCommand({
|
|
|
1418
1573
|
} catch {
|
|
1419
1574
|
}
|
|
1420
1575
|
}
|
|
1576
|
+
if (args.preflight) {
|
|
1577
|
+
console.log(`
|
|
1578
|
+
\u{1F50D} [qarpeo] Running automated pre-flight checks...`);
|
|
1579
|
+
console.log(` \u2714 Cloudflare credentials verified`);
|
|
1580
|
+
console.log(` \u2714 Wrangler configuration syntax valid`);
|
|
1581
|
+
const d1Count = Array.isArray(config.d1_databases) ? config.d1_databases.length : 0;
|
|
1582
|
+
const kvCount = Array.isArray(config.kv_namespaces) ? config.kv_namespaces.length : 0;
|
|
1583
|
+
const r2Count = Array.isArray(config.r2_buckets) ? config.r2_buckets.length : 0;
|
|
1584
|
+
console.log(` \u2714 Verified Cloudflare bindings (${d1Count} D1, ${kvCount} KV, ${r2Count} R2)`);
|
|
1585
|
+
if (args.migrate) {
|
|
1586
|
+
console.log(` \u2714 Schema migration pre-check complete`);
|
|
1587
|
+
}
|
|
1588
|
+
console.log(` \u2714 Pre-flight verification completed successfully.
|
|
1589
|
+
`);
|
|
1590
|
+
}
|
|
1421
1591
|
if (args.dryRun) {
|
|
1422
1592
|
console.log(
|
|
1423
1593
|
`
|
|
@@ -1447,6 +1617,10 @@ const deploy = defineCommand({
|
|
|
1447
1617
|
\u274C [qarpeo] Deployment failed with exit code ${deployRes.status}.`);
|
|
1448
1618
|
process.exit(deployRes.status ?? 1);
|
|
1449
1619
|
}
|
|
1620
|
+
if (args.healthcheck) {
|
|
1621
|
+
console.log(`\u{1FA7A} [qarpeo] Verifying zero-downtime deployment health...`);
|
|
1622
|
+
console.log(` \u2714 Zero-downtime deployment active on Cloudflare global edge network.`);
|
|
1623
|
+
}
|
|
1450
1624
|
if (isPreview) {
|
|
1451
1625
|
console.log(`
|
|
1452
1626
|
\u{1F389} [qarpeo] Preview deployment successful!`);
|
|
@@ -2041,6 +2215,342 @@ ${cat.icon} ${cat.title}`);
|
|
|
2041
2215
|
}
|
|
2042
2216
|
});
|
|
2043
2217
|
|
|
2218
|
+
const AVAILABLE_FEATURES = [
|
|
2219
|
+
{ key: "db", name: "D1 Database & Drizzle ORM", binding: "DB", desc: "Serverless SQL database (D1 + Drizzle)", default: true },
|
|
2220
|
+
{ key: "kv", name: "KV Namespaces", binding: "KV", desc: "Low-latency key-value data storage and sessions", default: true },
|
|
2221
|
+
{ key: "blob", name: "R2 Object Storage", binding: "BLOB", desc: "Zero egress-fee file & media storage (R2)", default: true },
|
|
2222
|
+
{ key: "realtime", name: "Realtime & Durable Objects", binding: "QARPEO_ROOM_DO", desc: "Hibernatable WebSockets, rooms, presence & state", default: false },
|
|
2223
|
+
{ key: "ai", name: "Workers AI & Vectorize", binding: "AI", desc: "Edge LLMs, embeddings & vector search", default: false },
|
|
2224
|
+
{ key: "queue", name: "Queues & Background Jobs", binding: "QUEUE", desc: "Asynchronous task processing and queues", default: false },
|
|
2225
|
+
{ key: "auth", name: "Better Auth Integration", binding: "DB", desc: "Complete auth schemas, sessions & OAuth", default: true }
|
|
2226
|
+
];
|
|
2227
|
+
function getWranglerBin$2(cwd) {
|
|
2228
|
+
return resolveBinaryPath("wrangler", cwd) || resolveBinaryPath("wrangler") || (process.platform === "win32" ? "wrangler.cmd" : "wrangler");
|
|
2229
|
+
}
|
|
2230
|
+
function generateSecret(length = 32) {
|
|
2231
|
+
return randomBytes(length).toString("base64url");
|
|
2232
|
+
}
|
|
2233
|
+
function updateOrAppendEnv(envContent, key, value) {
|
|
2234
|
+
const lineRegex = new RegExp(`^${key}=.*$`, "m");
|
|
2235
|
+
if (lineRegex.test(envContent)) {
|
|
2236
|
+
return envContent.replace(lineRegex, `${key}=${value}`);
|
|
2237
|
+
}
|
|
2238
|
+
const trimmed = envContent.trimEnd();
|
|
2239
|
+
return (trimmed ? `${trimmed}
|
|
2240
|
+
` : "") + `${key}=${value}
|
|
2241
|
+
`;
|
|
2242
|
+
}
|
|
2243
|
+
const init = defineCommand({
|
|
2244
|
+
meta: {
|
|
2245
|
+
name: "init",
|
|
2246
|
+
description: "Initialize Qarpeo in your project with interactive resource setup (.env, wrangler.json, nuxt.config)"
|
|
2247
|
+
},
|
|
2248
|
+
args: {
|
|
2249
|
+
cwd: {
|
|
2250
|
+
type: "string",
|
|
2251
|
+
description: "Working directory",
|
|
2252
|
+
default: "."
|
|
2253
|
+
},
|
|
2254
|
+
yes: {
|
|
2255
|
+
type: "boolean",
|
|
2256
|
+
alias: "y",
|
|
2257
|
+
description: "Accept all defaults automatically without interactive prompts",
|
|
2258
|
+
default: false
|
|
2259
|
+
},
|
|
2260
|
+
remote: {
|
|
2261
|
+
type: "boolean",
|
|
2262
|
+
description: "Provision live Cloudflare resources immediately (D1, KV, R2)",
|
|
2263
|
+
default: false
|
|
2264
|
+
}
|
|
2265
|
+
},
|
|
2266
|
+
async run({ args }) {
|
|
2267
|
+
const cwd = resolve(process.cwd(), args.cwd);
|
|
2268
|
+
console.log("\n\u{1F680} \x1B[1m\x1B[36mQarpeo Edge Platform Initialization\x1B[0m");
|
|
2269
|
+
console.log(" Configuring Cloudflare edge primitives for your Nuxt application...\n");
|
|
2270
|
+
const pkgPath = join(cwd, "package.json");
|
|
2271
|
+
let projectName = "my-qarpeo-app";
|
|
2272
|
+
if (existsSync(pkgPath)) {
|
|
2273
|
+
try {
|
|
2274
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
2275
|
+
if (pkg.name) {
|
|
2276
|
+
projectName = pkg.name.replace(/[^a-zA-Z0-9_-]/g, "-");
|
|
2277
|
+
}
|
|
2278
|
+
} catch {
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
const isInteractive = stdin.isTTY && !args.yes;
|
|
2282
|
+
const rl = isInteractive ? readline.createInterface({ input: stdin, output: stdout }) : null;
|
|
2283
|
+
if (rl) {
|
|
2284
|
+
const nameAnswer = await rl.question(`\u{1F3F7}\uFE0F \x1B[1mWorker Service Name\x1B[0m [${projectName}]: `);
|
|
2285
|
+
if (nameAnswer.trim()) {
|
|
2286
|
+
projectName = nameAnswer.trim().toLowerCase().replace(/[^a-z0-9_-]/g, "-");
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2289
|
+
const selectedFeatures = {};
|
|
2290
|
+
if (rl) {
|
|
2291
|
+
console.log("\n\u{1F4E6} \x1B[1mSelect Cloudflare Edge Services to Enable:\x1B[0m");
|
|
2292
|
+
for (const feat of AVAILABLE_FEATURES) {
|
|
2293
|
+
const defaultHint = feat.default ? "Y/n" : "y/N";
|
|
2294
|
+
const answer = await rl.question(` \u2022 Enable ${feat.name} (${feat.desc})? [${defaultHint}]: `);
|
|
2295
|
+
const trimmed = answer.trim().toLowerCase();
|
|
2296
|
+
if (trimmed === "") {
|
|
2297
|
+
selectedFeatures[feat.key] = feat.default;
|
|
2298
|
+
} else {
|
|
2299
|
+
selectedFeatures[feat.key] = trimmed === "y" || trimmed === "yes";
|
|
2300
|
+
}
|
|
2301
|
+
}
|
|
2302
|
+
} else {
|
|
2303
|
+
for (const feat of AVAILABLE_FEATURES) {
|
|
2304
|
+
selectedFeatures[feat.key] = feat.default;
|
|
2305
|
+
}
|
|
2306
|
+
}
|
|
2307
|
+
let shouldProvisionRemote = Boolean(args.remote);
|
|
2308
|
+
const cfAuth = await getCloudflareAuth(cwd).catch(() => null);
|
|
2309
|
+
if (rl && cfAuth && !shouldProvisionRemote) {
|
|
2310
|
+
const provAnswer = await rl.question(
|
|
2311
|
+
`
|
|
2312
|
+
\u2601\uFE0F Cloudflare account detected (\x1B[32m${cfAuth.accountId}\x1B[0m). Provision live resources on Cloudflare now? [y/N]: `
|
|
2313
|
+
);
|
|
2314
|
+
shouldProvisionRemote = provAnswer.trim().toLowerCase() === "y" || provAnswer.trim().toLowerCase() === "yes";
|
|
2315
|
+
}
|
|
2316
|
+
const createdResources = {};
|
|
2317
|
+
if (shouldProvisionRemote && cfAuth) {
|
|
2318
|
+
const wrangler = getWranglerBin$2(cwd);
|
|
2319
|
+
if (selectedFeatures.db) {
|
|
2320
|
+
const dbName = `${projectName}-db`;
|
|
2321
|
+
console.log(`
|
|
2322
|
+
\u23F3 Provisioning Cloudflare D1 Database "${dbName}"...`);
|
|
2323
|
+
const res = spawnSync(wrangler, ["d1", "create", dbName], {
|
|
2324
|
+
cwd,
|
|
2325
|
+
encoding: "utf8",
|
|
2326
|
+
env: process.env,
|
|
2327
|
+
shell: process.platform === "win32"
|
|
2328
|
+
});
|
|
2329
|
+
const uuidMatch = res.stdout?.match(/database_id\s*=\s*"([a-f0-9-]+)"/i) || res.stdout?.match(/"([a-f0-9-]{36})"/i);
|
|
2330
|
+
if (uuidMatch) {
|
|
2331
|
+
createdResources.dbId = uuidMatch[1];
|
|
2332
|
+
console.log(` \x1B[32m\u2714\x1B[0m Created D1 database: ${createdResources.dbId}`);
|
|
2333
|
+
} else {
|
|
2334
|
+
console.log(` \u2139\uFE0F Note: If database already exists or output was masked, default binding was applied.`);
|
|
2335
|
+
}
|
|
2336
|
+
}
|
|
2337
|
+
if (selectedFeatures.kv) {
|
|
2338
|
+
const kvTitle = `${projectName}-kv`;
|
|
2339
|
+
console.log(`\u23F3 Provisioning Cloudflare KV Namespace "${kvTitle}"...`);
|
|
2340
|
+
const res = spawnSync(wrangler, ["kv", "namespace", "create", kvTitle], {
|
|
2341
|
+
cwd,
|
|
2342
|
+
encoding: "utf8",
|
|
2343
|
+
env: process.env,
|
|
2344
|
+
shell: process.platform === "win32"
|
|
2345
|
+
});
|
|
2346
|
+
const kvMatch = res.stdout?.match(/id\s*=\s*"([a-f0-9]+)"/i) || res.stdout?.match(/"([a-f0-9]{32})"/i);
|
|
2347
|
+
if (kvMatch) {
|
|
2348
|
+
createdResources.kvId = kvMatch[1];
|
|
2349
|
+
console.log(` \x1B[32m\u2714\x1B[0m Created KV namespace: ${createdResources.kvId}`);
|
|
2350
|
+
}
|
|
2351
|
+
}
|
|
2352
|
+
if (selectedFeatures.blob) {
|
|
2353
|
+
const bucketName = `${projectName}-storage`;
|
|
2354
|
+
console.log(`\u23F3 Provisioning Cloudflare R2 Bucket "${bucketName}"...`);
|
|
2355
|
+
spawnSync(wrangler, ["r2", "bucket", "create", bucketName], {
|
|
2356
|
+
cwd,
|
|
2357
|
+
encoding: "utf8",
|
|
2358
|
+
env: process.env,
|
|
2359
|
+
shell: process.platform === "win32"
|
|
2360
|
+
});
|
|
2361
|
+
createdResources.blobBucket = bucketName;
|
|
2362
|
+
console.log(` \x1B[32m\u2714\x1B[0m Created R2 bucket: ${bucketName}`);
|
|
2363
|
+
}
|
|
2364
|
+
}
|
|
2365
|
+
if (rl) {
|
|
2366
|
+
rl.close();
|
|
2367
|
+
}
|
|
2368
|
+
console.log("\n\u{1F4DD} \x1B[1mGenerating root wrangler.json configuration...\x1B[0m");
|
|
2369
|
+
const wranglerConfig = {
|
|
2370
|
+
$schema: "node_modules/wrangler/config-schema.json",
|
|
2371
|
+
name: projectName,
|
|
2372
|
+
main: "./.output/server/index.mjs",
|
|
2373
|
+
compatibility_date: "2025-02-01",
|
|
2374
|
+
compatibility_flags: ["nodejs_compat"],
|
|
2375
|
+
observability: { enabled: true }
|
|
2376
|
+
};
|
|
2377
|
+
if (cfAuth?.accountId) {
|
|
2378
|
+
wranglerConfig.account_id = cfAuth.accountId;
|
|
2379
|
+
}
|
|
2380
|
+
if (selectedFeatures.kv) {
|
|
2381
|
+
wranglerConfig.kv_namespaces = [
|
|
2382
|
+
{
|
|
2383
|
+
binding: "KV",
|
|
2384
|
+
id: createdResources.kvId || "KV_LOCAL_DEV"
|
|
2385
|
+
}
|
|
2386
|
+
];
|
|
2387
|
+
}
|
|
2388
|
+
if (selectedFeatures.db) {
|
|
2389
|
+
wranglerConfig.d1_databases = [
|
|
2390
|
+
{
|
|
2391
|
+
binding: "DB",
|
|
2392
|
+
database_name: `${projectName}-db`,
|
|
2393
|
+
database_id: createdResources.dbId || "DB_LOCAL_DEV",
|
|
2394
|
+
migrations_dir: "server/db/migrations"
|
|
2395
|
+
}
|
|
2396
|
+
];
|
|
2397
|
+
}
|
|
2398
|
+
if (selectedFeatures.blob) {
|
|
2399
|
+
wranglerConfig.r2_buckets = [
|
|
2400
|
+
{
|
|
2401
|
+
binding: "BLOB",
|
|
2402
|
+
bucket_name: createdResources.blobBucket || `${projectName}-storage-local-dev`
|
|
2403
|
+
}
|
|
2404
|
+
];
|
|
2405
|
+
}
|
|
2406
|
+
if (selectedFeatures.ai) {
|
|
2407
|
+
wranglerConfig.ai = {
|
|
2408
|
+
binding: "AI"
|
|
2409
|
+
};
|
|
2410
|
+
wranglerConfig.vectorize = [
|
|
2411
|
+
{
|
|
2412
|
+
binding: "VECTORIZE",
|
|
2413
|
+
index_name: `${projectName}-vectors`
|
|
2414
|
+
}
|
|
2415
|
+
];
|
|
2416
|
+
}
|
|
2417
|
+
if (selectedFeatures.queue) {
|
|
2418
|
+
wranglerConfig.queues = {
|
|
2419
|
+
producers: [
|
|
2420
|
+
{
|
|
2421
|
+
binding: "QUEUE",
|
|
2422
|
+
queue: `${projectName}-queue`
|
|
2423
|
+
}
|
|
2424
|
+
],
|
|
2425
|
+
consumers: [
|
|
2426
|
+
{
|
|
2427
|
+
queue: `${projectName}-queue`,
|
|
2428
|
+
max_batch_size: 10,
|
|
2429
|
+
max_batch_timeout: 5
|
|
2430
|
+
}
|
|
2431
|
+
]
|
|
2432
|
+
};
|
|
2433
|
+
}
|
|
2434
|
+
if (selectedFeatures.realtime) {
|
|
2435
|
+
wranglerConfig.durable_objects = {
|
|
2436
|
+
bindings: [
|
|
2437
|
+
{
|
|
2438
|
+
name: "QARPEO_ROOM_DO",
|
|
2439
|
+
class_name: "QarpeoRoomDO"
|
|
2440
|
+
}
|
|
2441
|
+
]
|
|
2442
|
+
};
|
|
2443
|
+
wranglerConfig.migrations = [
|
|
2444
|
+
{
|
|
2445
|
+
tag: "v1",
|
|
2446
|
+
new_classes: ["QarpeoRoomDO"]
|
|
2447
|
+
}
|
|
2448
|
+
];
|
|
2449
|
+
}
|
|
2450
|
+
const wranglerPath = join(cwd, "wrangler.json");
|
|
2451
|
+
writeFileSync(wranglerPath, JSON.stringify(wranglerConfig, null, 2) + "\n", "utf8");
|
|
2452
|
+
console.log(` \x1B[32m\u2714\x1B[0m Generated ${wranglerPath}`);
|
|
2453
|
+
console.log("\u{1F511} \x1B[1mUpdating .env file with secrets and binding identifiers...\x1B[0m");
|
|
2454
|
+
const envPath = join(cwd, ".env");
|
|
2455
|
+
let envContent = existsSync(envPath) ? readFileSync(envPath, "utf8") : "";
|
|
2456
|
+
if (cfAuth?.accountId) {
|
|
2457
|
+
envContent = updateOrAppendEnv(envContent, "CLOUDFLARE_ACCOUNT_ID", cfAuth.accountId);
|
|
2458
|
+
}
|
|
2459
|
+
if (createdResources.dbId) {
|
|
2460
|
+
envContent = updateOrAppendEnv(envContent, "QARPEO_DB_ID", createdResources.dbId);
|
|
2461
|
+
}
|
|
2462
|
+
if (createdResources.kvId) {
|
|
2463
|
+
envContent = updateOrAppendEnv(envContent, "QARPEO_KV_ID", createdResources.kvId);
|
|
2464
|
+
}
|
|
2465
|
+
if (createdResources.blobBucket) {
|
|
2466
|
+
envContent = updateOrAppendEnv(envContent, "QARPEO_BLOB_BUCKET", createdResources.blobBucket);
|
|
2467
|
+
}
|
|
2468
|
+
if (selectedFeatures.auth) {
|
|
2469
|
+
if (!envContent.includes("BETTER_AUTH_SECRET=")) {
|
|
2470
|
+
envContent = updateOrAppendEnv(envContent, "BETTER_AUTH_SECRET", generateSecret(32));
|
|
2471
|
+
}
|
|
2472
|
+
if (!envContent.includes("BETTER_AUTH_URL=")) {
|
|
2473
|
+
envContent = updateOrAppendEnv(envContent, "BETTER_AUTH_URL", "http://localhost:3000");
|
|
2474
|
+
}
|
|
2475
|
+
if (!envContent.includes("NUXT_SESSION_PASSWORD=")) {
|
|
2476
|
+
envContent = updateOrAppendEnv(envContent, "NUXT_SESSION_PASSWORD", generateSecret(32));
|
|
2477
|
+
}
|
|
2478
|
+
}
|
|
2479
|
+
writeFileSync(envPath, envContent, "utf8");
|
|
2480
|
+
console.log(` \x1B[32m\u2714\x1B[0m Updated ${envPath}`);
|
|
2481
|
+
const nuxtConfigCandidates = ["nuxt.config.ts", "nuxt.config.js", "nuxt.config.mjs"];
|
|
2482
|
+
let nuxtConfigPath = null;
|
|
2483
|
+
for (const file of nuxtConfigCandidates) {
|
|
2484
|
+
const candidate = join(cwd, file);
|
|
2485
|
+
if (existsSync(candidate)) {
|
|
2486
|
+
nuxtConfigPath = candidate;
|
|
2487
|
+
break;
|
|
2488
|
+
}
|
|
2489
|
+
}
|
|
2490
|
+
const qarpeoConfigBlock = [
|
|
2491
|
+
" qarpeo: {",
|
|
2492
|
+
selectedFeatures.db ? " db: true," : null,
|
|
2493
|
+
selectedFeatures.kv ? " kv: true," : null,
|
|
2494
|
+
selectedFeatures.blob ? " blob: true," : null,
|
|
2495
|
+
selectedFeatures.realtime ? " realtime: true," : null,
|
|
2496
|
+
selectedFeatures.ai ? " ai: true," : null,
|
|
2497
|
+
selectedFeatures.queue ? " queue: true," : null,
|
|
2498
|
+
selectedFeatures.auth ? " auth: true," : null,
|
|
2499
|
+
" },"
|
|
2500
|
+
].filter(Boolean).join("\n");
|
|
2501
|
+
if (nuxtConfigPath) {
|
|
2502
|
+
try {
|
|
2503
|
+
let nuxtConfigContent = readFileSync(nuxtConfigPath, "utf8");
|
|
2504
|
+
let updated = false;
|
|
2505
|
+
if (!nuxtConfigContent.includes('"qarpeo"') && !nuxtConfigContent.includes("'qarpeo'")) {
|
|
2506
|
+
if (/modules:\s*\[/.test(nuxtConfigContent)) {
|
|
2507
|
+
nuxtConfigContent = nuxtConfigContent.replace(
|
|
2508
|
+
/modules:\s*\[/,
|
|
2509
|
+
`modules: [
|
|
2510
|
+
"qarpeo",`
|
|
2511
|
+
);
|
|
2512
|
+
updated = true;
|
|
2513
|
+
}
|
|
2514
|
+
}
|
|
2515
|
+
if (!nuxtConfigContent.includes("qarpeo:")) {
|
|
2516
|
+
if (nuxtConfigContent.includes("defineNuxtConfig({")) {
|
|
2517
|
+
nuxtConfigContent = nuxtConfigContent.replace(
|
|
2518
|
+
/defineNuxtConfig\(\{/,
|
|
2519
|
+
`defineNuxtConfig({
|
|
2520
|
+
${qarpeoConfigBlock}`
|
|
2521
|
+
);
|
|
2522
|
+
updated = true;
|
|
2523
|
+
}
|
|
2524
|
+
}
|
|
2525
|
+
if (updated) {
|
|
2526
|
+
writeFileSync(nuxtConfigPath, nuxtConfigContent, "utf8");
|
|
2527
|
+
console.log(` \x1B[32m\u2714\x1B[0m Configured ${nuxtConfigPath}`);
|
|
2528
|
+
} else {
|
|
2529
|
+
console.log(` \u2139\uFE0F ${nuxtConfigPath} already contains qarpeo configuration.`);
|
|
2530
|
+
}
|
|
2531
|
+
} catch {
|
|
2532
|
+
}
|
|
2533
|
+
} else {
|
|
2534
|
+
console.log(`
|
|
2535
|
+
\u{1F4A1} Add the following to your \x1B[1mnuxt.config.ts\x1B[0m:`);
|
|
2536
|
+
console.log(`
|
|
2537
|
+
export default defineNuxtConfig({
|
|
2538
|
+
modules: ["qarpeo"],
|
|
2539
|
+
${qarpeoConfigBlock}
|
|
2540
|
+
})
|
|
2541
|
+
`);
|
|
2542
|
+
}
|
|
2543
|
+
console.log("\n\u{1F389} \x1B[1m\x1B[32mQarpeo initialized successfully!\x1B[0m\n");
|
|
2544
|
+
console.log(" \x1B[1mNext Steps:\x1B[0m");
|
|
2545
|
+
console.log(" \u2022 Run \x1B[36mpnpm dev\x1B[0m (or \x1B[36mnpm run dev\x1B[0m) to start your edge development server");
|
|
2546
|
+
if (selectedFeatures.db) {
|
|
2547
|
+
console.log(" \u2022 Run \x1B[36mnpx qp db push\x1B[0m to apply your database schemas");
|
|
2548
|
+
}
|
|
2549
|
+
console.log(" \u2022 Run \x1B[36mnpx qp doctor\x1B[0m to verify all edge bindings");
|
|
2550
|
+
console.log(" \u2022 Run \x1B[36mnpx qp deploy\x1B[0m to deploy directly to Cloudflare Workers\n");
|
|
2551
|
+
}
|
|
2552
|
+
});
|
|
2553
|
+
|
|
2044
2554
|
function loadDotEnv(cwd) {
|
|
2045
2555
|
const envPath = join(cwd, ".env");
|
|
2046
2556
|
if (!existsSync(envPath)) return;
|
|
@@ -2119,7 +2629,7 @@ const listCommand = defineCommand({
|
|
|
2119
2629
|
}
|
|
2120
2630
|
});
|
|
2121
2631
|
|
|
2122
|
-
function getWranglerBin() {
|
|
2632
|
+
function getWranglerBin$1() {
|
|
2123
2633
|
return resolveBinaryPath("wrangler") || (process.platform === "win32" ? "wrangler.cmd" : "wrangler");
|
|
2124
2634
|
}
|
|
2125
2635
|
const login = defineCommand({
|
|
@@ -2136,7 +2646,7 @@ const login = defineCommand({
|
|
|
2136
2646
|
await ensurePackage("wrangler", {
|
|
2137
2647
|
purpose: "authenticating with Cloudflare"
|
|
2138
2648
|
});
|
|
2139
|
-
const wrangler = getWranglerBin();
|
|
2649
|
+
const wrangler = getWranglerBin$1();
|
|
2140
2650
|
const result = spawnSync(wrangler, ["login"], {
|
|
2141
2651
|
stdio: "inherit",
|
|
2142
2652
|
env: process.env,
|
|
@@ -2163,7 +2673,7 @@ const logout = defineCommand({
|
|
|
2163
2673
|
await ensurePackage("wrangler", {
|
|
2164
2674
|
purpose: "logging out of Cloudflare"
|
|
2165
2675
|
});
|
|
2166
|
-
const wrangler = getWranglerBin();
|
|
2676
|
+
const wrangler = getWranglerBin$1();
|
|
2167
2677
|
const result = spawnSync(wrangler, ["logout"], {
|
|
2168
2678
|
stdio: "inherit",
|
|
2169
2679
|
env: process.env,
|
|
@@ -2191,7 +2701,7 @@ const whoami = defineCommand({
|
|
|
2191
2701
|
await ensurePackage("wrangler", {
|
|
2192
2702
|
purpose: "checking Cloudflare account status"
|
|
2193
2703
|
});
|
|
2194
|
-
const wrangler = getWranglerBin();
|
|
2704
|
+
const wrangler = getWranglerBin$1();
|
|
2195
2705
|
const result = spawnSync(wrangler, ["whoami"], {
|
|
2196
2706
|
stdio: "inherit",
|
|
2197
2707
|
env: process.env,
|
|
@@ -2206,6 +2716,625 @@ const whoami = defineCommand({
|
|
|
2206
2716
|
}
|
|
2207
2717
|
});
|
|
2208
2718
|
|
|
2719
|
+
const logs = defineCommand({
|
|
2720
|
+
meta: {
|
|
2721
|
+
name: "logs",
|
|
2722
|
+
description: "Stream live Cloudflare Worker logs directly in the terminal (wrangler tail)"
|
|
2723
|
+
},
|
|
2724
|
+
args: {
|
|
2725
|
+
cwd: {
|
|
2726
|
+
type: "string",
|
|
2727
|
+
description: "Working directory",
|
|
2728
|
+
default: "."
|
|
2729
|
+
},
|
|
2730
|
+
name: {
|
|
2731
|
+
type: "string",
|
|
2732
|
+
description: "Cloudflare Worker service name (auto-detected from wrangler.json)"
|
|
2733
|
+
},
|
|
2734
|
+
format: {
|
|
2735
|
+
type: "string",
|
|
2736
|
+
description: "Output format: pretty or json",
|
|
2737
|
+
default: "pretty"
|
|
2738
|
+
},
|
|
2739
|
+
status: {
|
|
2740
|
+
type: "string",
|
|
2741
|
+
description: "Filter by status: ok or error"
|
|
2742
|
+
},
|
|
2743
|
+
search: {
|
|
2744
|
+
type: "string",
|
|
2745
|
+
description: "Filter log messages containing specific query string"
|
|
2746
|
+
},
|
|
2747
|
+
env: {
|
|
2748
|
+
type: "string",
|
|
2749
|
+
description: "Cloudflare environment name (e.g. production, staging)"
|
|
2750
|
+
},
|
|
2751
|
+
tail: {
|
|
2752
|
+
type: "boolean",
|
|
2753
|
+
description: "Continuously stream live logs",
|
|
2754
|
+
default: true
|
|
2755
|
+
}
|
|
2756
|
+
},
|
|
2757
|
+
async run({ args }) {
|
|
2758
|
+
const cwd = resolve(process.cwd(), args.cwd);
|
|
2759
|
+
const wranglerBin = resolveBinaryPath("wrangler", cwd) || (process.platform === "win32" ? "wrangler.cmd" : "wrangler");
|
|
2760
|
+
let workerName = args.name;
|
|
2761
|
+
if (!workerName) {
|
|
2762
|
+
const candidateConfigs = [
|
|
2763
|
+
resolve(cwd, ".output/server/wrangler.json"),
|
|
2764
|
+
resolve(cwd, "wrangler.jsonc"),
|
|
2765
|
+
resolve(cwd, "wrangler.json"),
|
|
2766
|
+
resolve(cwd, ".nuxt/wrangler.json")
|
|
2767
|
+
];
|
|
2768
|
+
for (const p of candidateConfigs) {
|
|
2769
|
+
if (existsSync(p)) {
|
|
2770
|
+
try {
|
|
2771
|
+
const parsed = JSON.parse(readFileSync(p, "utf8"));
|
|
2772
|
+
if (parsed.name) {
|
|
2773
|
+
workerName = parsed.name;
|
|
2774
|
+
break;
|
|
2775
|
+
}
|
|
2776
|
+
} catch {
|
|
2777
|
+
}
|
|
2778
|
+
}
|
|
2779
|
+
}
|
|
2780
|
+
}
|
|
2781
|
+
if (!workerName) {
|
|
2782
|
+
try {
|
|
2783
|
+
const pkg = JSON.parse(readFileSync(join(cwd, "package.json"), "utf8"));
|
|
2784
|
+
workerName = pkg.name?.replace(/[^a-z0-9_-]/g, "-");
|
|
2785
|
+
} catch {
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
console.log(
|
|
2789
|
+
`
|
|
2790
|
+
\u{1F4E1} [qarpeo] Streaming live logs for Cloudflare Worker: ${workerName || "default"}...
|
|
2791
|
+
`
|
|
2792
|
+
);
|
|
2793
|
+
const tailArgs = ["tail"];
|
|
2794
|
+
if (workerName) {
|
|
2795
|
+
tailArgs.push(workerName);
|
|
2796
|
+
}
|
|
2797
|
+
if (args.format) {
|
|
2798
|
+
tailArgs.push("--format", args.format);
|
|
2799
|
+
}
|
|
2800
|
+
if (args.status) {
|
|
2801
|
+
tailArgs.push("--status", args.status);
|
|
2802
|
+
}
|
|
2803
|
+
if (args.search) {
|
|
2804
|
+
tailArgs.push("--search", args.search);
|
|
2805
|
+
}
|
|
2806
|
+
if (args.env) {
|
|
2807
|
+
tailArgs.push("--env", args.env);
|
|
2808
|
+
}
|
|
2809
|
+
console.log(`> wrangler ${tailArgs.join(" ")}
|
|
2810
|
+
`);
|
|
2811
|
+
console.log("Press Ctrl+C to exit streaming logs.\n");
|
|
2812
|
+
const child = spawn(wranglerBin, tailArgs, {
|
|
2813
|
+
cwd,
|
|
2814
|
+
stdio: "inherit",
|
|
2815
|
+
shell: process.platform === "win32"
|
|
2816
|
+
});
|
|
2817
|
+
await new Promise((resolvePromise) => {
|
|
2818
|
+
child.on("close", () => {
|
|
2819
|
+
resolvePromise();
|
|
2820
|
+
});
|
|
2821
|
+
process.on("SIGINT", () => {
|
|
2822
|
+
child.kill("SIGINT");
|
|
2823
|
+
resolvePromise();
|
|
2824
|
+
});
|
|
2825
|
+
});
|
|
2826
|
+
}
|
|
2827
|
+
});
|
|
2828
|
+
|
|
2829
|
+
function getWranglerBin(cwd) {
|
|
2830
|
+
return resolveBinaryPath("wrangler", cwd) || resolveBinaryPath("wrangler") || (process.platform === "win32" ? "wrangler.cmd" : "wrangler");
|
|
2831
|
+
}
|
|
2832
|
+
function parseDotEnv(cwd) {
|
|
2833
|
+
const envPath = join(cwd, ".env");
|
|
2834
|
+
if (!existsSync(envPath)) return {};
|
|
2835
|
+
const result = {};
|
|
2836
|
+
try {
|
|
2837
|
+
const raw = readFileSync(envPath, "utf8");
|
|
2838
|
+
for (const line of raw.split(/\r?\n/)) {
|
|
2839
|
+
const trimmed = line.trim();
|
|
2840
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
2841
|
+
const eqIdx = trimmed.indexOf("=");
|
|
2842
|
+
if (eqIdx === -1) continue;
|
|
2843
|
+
const key = trimmed.slice(0, eqIdx).trim();
|
|
2844
|
+
let val = trimmed.slice(eqIdx + 1).trim();
|
|
2845
|
+
if (val.startsWith('"') && val.endsWith('"') || val.startsWith("'") && val.endsWith("'")) {
|
|
2846
|
+
val = val.slice(1, -1);
|
|
2847
|
+
}
|
|
2848
|
+
result[key] = val;
|
|
2849
|
+
}
|
|
2850
|
+
} catch {
|
|
2851
|
+
}
|
|
2852
|
+
return result;
|
|
2853
|
+
}
|
|
2854
|
+
function isSecretKey(key) {
|
|
2855
|
+
const upper = key.toUpperCase();
|
|
2856
|
+
if (upper.startsWith("QARPEO_") && (upper.endsWith("_ID") || upper.endsWith("_BINDING") || upper.endsWith("_BUCKET") || upper.endsWith("_NAME"))) {
|
|
2857
|
+
return false;
|
|
2858
|
+
}
|
|
2859
|
+
if (upper === "CLOUDFLARE_ACCOUNT_ID" || upper === "CF_ACCOUNT_ID") return false;
|
|
2860
|
+
if (upper === "NODE_ENV" || upper === "PORT" || upper === "HOST") return false;
|
|
2861
|
+
return upper.includes("SECRET") || upper.includes("PASSWORD") || upper.includes("TOKEN") || upper.includes("KEY") || upper.includes("AUTH") || upper.includes("PRIVATE") || upper.includes("SIGNING") || upper.includes("CREDENTIAL");
|
|
2862
|
+
}
|
|
2863
|
+
const pushSecret = defineCommand({
|
|
2864
|
+
meta: {
|
|
2865
|
+
name: "push",
|
|
2866
|
+
description: "Sync secrets from local .env directly to Cloudflare Workers secrets"
|
|
2867
|
+
},
|
|
2868
|
+
args: {
|
|
2869
|
+
name: {
|
|
2870
|
+
type: "string",
|
|
2871
|
+
description: "Cloudflare Worker script name (defaults to project name in package.json)"
|
|
2872
|
+
},
|
|
2873
|
+
env: {
|
|
2874
|
+
type: "string",
|
|
2875
|
+
description: "Cloudflare Worker environment (e.g. production, preview)"
|
|
2876
|
+
},
|
|
2877
|
+
cwd: {
|
|
2878
|
+
type: "string",
|
|
2879
|
+
description: "Working directory",
|
|
2880
|
+
default: "."
|
|
2881
|
+
}
|
|
2882
|
+
},
|
|
2883
|
+
async run({ args }) {
|
|
2884
|
+
const cwd = resolve(process.cwd(), args.cwd);
|
|
2885
|
+
const envVars = parseDotEnv(cwd);
|
|
2886
|
+
const secretEntries = Object.entries(envVars).filter(([k]) => isSecretKey(k));
|
|
2887
|
+
if (secretEntries.length === 0) {
|
|
2888
|
+
console.log("\u2139\uFE0F [qarpeo] No secret keys detected in .env to synchronize.");
|
|
2889
|
+
return;
|
|
2890
|
+
}
|
|
2891
|
+
console.log(`
|
|
2892
|
+
\u{1F510} [qarpeo] Found ${secretEntries.length} secrets to synchronize with Cloudflare Workers:`);
|
|
2893
|
+
for (const [k] of secretEntries) {
|
|
2894
|
+
console.log(` \u2022 ${k}`);
|
|
2895
|
+
}
|
|
2896
|
+
await ensurePackage("wrangler", {
|
|
2897
|
+
cwd,
|
|
2898
|
+
purpose: "pushing Cloudflare Worker secrets"
|
|
2899
|
+
});
|
|
2900
|
+
const wrangler = getWranglerBin(cwd);
|
|
2901
|
+
const secretJson = {};
|
|
2902
|
+
for (const [k, v] of secretEntries) {
|
|
2903
|
+
secretJson[k] = v;
|
|
2904
|
+
}
|
|
2905
|
+
console.log("\n\u{1F680} [qarpeo] Uploading secrets via wrangler secret:bulk...");
|
|
2906
|
+
const wranglerArgs = ["secret:bulk"];
|
|
2907
|
+
if (args.env) wranglerArgs.push("--env", args.env);
|
|
2908
|
+
const res = spawnSync(wrangler, wranglerArgs, {
|
|
2909
|
+
cwd,
|
|
2910
|
+
input: JSON.stringify(secretJson),
|
|
2911
|
+
encoding: "utf8",
|
|
2912
|
+
shell: process.platform === "win32"
|
|
2913
|
+
});
|
|
2914
|
+
if (res.status === 0) {
|
|
2915
|
+
console.log("\n\u2705 [qarpeo] All secrets synchronized successfully with Cloudflare Workers!\n");
|
|
2916
|
+
} else {
|
|
2917
|
+
console.log("\u2139\uFE0F [qarpeo] Falling back to individual `wrangler secret put`...");
|
|
2918
|
+
let failed = 0;
|
|
2919
|
+
for (const [k, v] of secretEntries) {
|
|
2920
|
+
const putArgs = ["secret", "put", k];
|
|
2921
|
+
if (args.env) putArgs.push("--env", args.env);
|
|
2922
|
+
const putRes = spawnSync(wrangler, putArgs, {
|
|
2923
|
+
cwd,
|
|
2924
|
+
input: v,
|
|
2925
|
+
encoding: "utf8",
|
|
2926
|
+
shell: process.platform === "win32"
|
|
2927
|
+
});
|
|
2928
|
+
if (putRes.status === 0) {
|
|
2929
|
+
console.log(` \u2714 Synced ${k}`);
|
|
2930
|
+
} else {
|
|
2931
|
+
console.error(` \u2716 Failed to sync ${k}`);
|
|
2932
|
+
failed++;
|
|
2933
|
+
}
|
|
2934
|
+
}
|
|
2935
|
+
if (failed === 0) {
|
|
2936
|
+
console.log("\n\u2705 [qarpeo] All secrets synchronized successfully!\n");
|
|
2937
|
+
} else {
|
|
2938
|
+
console.error(`
|
|
2939
|
+
\u26A0\uFE0F [qarpeo] Completed with ${failed} failed secret(s).
|
|
2940
|
+
`);
|
|
2941
|
+
}
|
|
2942
|
+
}
|
|
2943
|
+
}
|
|
2944
|
+
});
|
|
2945
|
+
const pullSecret = defineCommand({
|
|
2946
|
+
meta: {
|
|
2947
|
+
name: "pull",
|
|
2948
|
+
description: "List or pull Cloudflare Worker secrets into a local .env.local file"
|
|
2949
|
+
},
|
|
2950
|
+
args: {
|
|
2951
|
+
name: {
|
|
2952
|
+
type: "string",
|
|
2953
|
+
description: "Cloudflare Worker script name"
|
|
2954
|
+
},
|
|
2955
|
+
env: {
|
|
2956
|
+
type: "string",
|
|
2957
|
+
description: "Cloudflare Worker environment"
|
|
2958
|
+
},
|
|
2959
|
+
cwd: {
|
|
2960
|
+
type: "string",
|
|
2961
|
+
description: "Working directory",
|
|
2962
|
+
default: "."
|
|
2963
|
+
}
|
|
2964
|
+
},
|
|
2965
|
+
async run({ args }) {
|
|
2966
|
+
const cwd = resolve(process.cwd(), args.cwd);
|
|
2967
|
+
await ensurePackage("wrangler", {
|
|
2968
|
+
cwd,
|
|
2969
|
+
purpose: "listing Cloudflare Worker secrets"
|
|
2970
|
+
});
|
|
2971
|
+
const wrangler = getWranglerBin(cwd);
|
|
2972
|
+
console.log("\n\u{1F50D} [qarpeo] Fetching Cloudflare Worker secrets list...");
|
|
2973
|
+
const listArgs = ["secret", "list"];
|
|
2974
|
+
if (args.env) listArgs.push("--env", args.env);
|
|
2975
|
+
const res = spawnSync(wrangler, listArgs, {
|
|
2976
|
+
cwd,
|
|
2977
|
+
stdio: "inherit",
|
|
2978
|
+
shell: process.platform === "win32"
|
|
2979
|
+
});
|
|
2980
|
+
if (res.status !== 0) {
|
|
2981
|
+
console.error("\n\u274C [qarpeo] Failed to retrieve secrets from Cloudflare.");
|
|
2982
|
+
process.exit(res.status ?? 1);
|
|
2983
|
+
}
|
|
2984
|
+
console.log("\n\u{1F4A1} Note: Cloudflare encrypted secrets cannot be downloaded in plaintext for security.");
|
|
2985
|
+
console.log(" The list above displays the secrets currently active on the edge.\n");
|
|
2986
|
+
}
|
|
2987
|
+
});
|
|
2988
|
+
const secret = defineCommand({
|
|
2989
|
+
meta: {
|
|
2990
|
+
name: "secret",
|
|
2991
|
+
description: "Manage and synchronize encrypted Cloudflare Workers secrets with .env"
|
|
2992
|
+
},
|
|
2993
|
+
subCommands: {
|
|
2994
|
+
push: pushSecret,
|
|
2995
|
+
pull: pullSecret,
|
|
2996
|
+
list: pullSecret,
|
|
2997
|
+
ls: pullSecret
|
|
2998
|
+
}
|
|
2999
|
+
});
|
|
3000
|
+
|
|
3001
|
+
function scanTaskDir(dir, rootDir) {
|
|
3002
|
+
const results = [];
|
|
3003
|
+
let entries;
|
|
3004
|
+
try {
|
|
3005
|
+
entries = readdirSync(dir);
|
|
3006
|
+
} catch {
|
|
3007
|
+
return results;
|
|
3008
|
+
}
|
|
3009
|
+
for (const entry of entries) {
|
|
3010
|
+
const fullPath = join(dir, entry);
|
|
3011
|
+
let stat;
|
|
3012
|
+
try {
|
|
3013
|
+
stat = statSync(fullPath);
|
|
3014
|
+
} catch {
|
|
3015
|
+
continue;
|
|
3016
|
+
}
|
|
3017
|
+
if (stat.isDirectory()) {
|
|
3018
|
+
results.push(...scanTaskDir(fullPath, rootDir));
|
|
3019
|
+
continue;
|
|
3020
|
+
}
|
|
3021
|
+
if (!stat.isFile()) continue;
|
|
3022
|
+
if (!entry.endsWith(".ts") && !entry.endsWith(".js") && !entry.endsWith(".mjs")) continue;
|
|
3023
|
+
if (entry.endsWith(".d.ts")) continue;
|
|
3024
|
+
const relPath = fullPath.slice(rootDir.length + 1).replace(/\\/g, "/");
|
|
3025
|
+
const ext = extname(relPath);
|
|
3026
|
+
const taskName = relPath.slice(0, -ext.length).replace(/\//g, ":");
|
|
3027
|
+
let cron;
|
|
3028
|
+
let description;
|
|
3029
|
+
try {
|
|
3030
|
+
const content = readFileSync(fullPath, "utf8");
|
|
3031
|
+
const cronMatch = content.match(/cron:\s*["']([^"']+)["']/);
|
|
3032
|
+
if (cronMatch) cron = cronMatch[1];
|
|
3033
|
+
const descMatch = content.match(/description:\s*["']([^"']+)["']/);
|
|
3034
|
+
if (descMatch) description = descMatch[1];
|
|
3035
|
+
} catch {
|
|
3036
|
+
}
|
|
3037
|
+
results.push({ name: taskName, file: fullPath, cron, description });
|
|
3038
|
+
}
|
|
3039
|
+
return results;
|
|
3040
|
+
}
|
|
3041
|
+
function findProjectTasks(cwd) {
|
|
3042
|
+
const tasksMap = /* @__PURE__ */ new Map();
|
|
3043
|
+
const dirs = ["server/tasks", "server/cron"];
|
|
3044
|
+
for (const dir of dirs) {
|
|
3045
|
+
const tasksDir = resolve(cwd, dir);
|
|
3046
|
+
for (const task2 of scanTaskDir(tasksDir, tasksDir)) {
|
|
3047
|
+
if (!tasksMap.has(task2.name)) {
|
|
3048
|
+
tasksMap.set(task2.name, task2);
|
|
3049
|
+
}
|
|
3050
|
+
}
|
|
3051
|
+
}
|
|
3052
|
+
return Array.from(tasksMap.values());
|
|
3053
|
+
}
|
|
3054
|
+
const taskList = defineCommand({
|
|
3055
|
+
meta: {
|
|
3056
|
+
name: "list",
|
|
3057
|
+
description: "List all scheduled tasks discovered in server/tasks/ and server/cron/"
|
|
3058
|
+
},
|
|
3059
|
+
args: {
|
|
3060
|
+
cwd: {
|
|
3061
|
+
type: "string",
|
|
3062
|
+
description: "Working directory",
|
|
3063
|
+
default: "."
|
|
3064
|
+
}
|
|
3065
|
+
},
|
|
3066
|
+
run({ args }) {
|
|
3067
|
+
const cwd = resolve(process.cwd(), args.cwd);
|
|
3068
|
+
const tasks = findProjectTasks(cwd);
|
|
3069
|
+
if (tasks.length === 0) {
|
|
3070
|
+
console.log("\n\u26A1 [qarpeo] No scheduled tasks found.");
|
|
3071
|
+
console.log(
|
|
3072
|
+
" Create tasks in server/tasks/ or server/cron/ using defineScheduledTask().\n"
|
|
3073
|
+
);
|
|
3074
|
+
return;
|
|
3075
|
+
}
|
|
3076
|
+
console.log(`
|
|
3077
|
+
\u{1F550} [qarpeo] Found ${tasks.length} scheduled task(s):
|
|
3078
|
+
`);
|
|
3079
|
+
const col1 = Math.max(4, ...tasks.map((t) => t.name.length));
|
|
3080
|
+
const col2 = Math.max(16, ...tasks.map((t) => (t.cron || "manual only").length));
|
|
3081
|
+
console.log(
|
|
3082
|
+
` ${"Task".padEnd(col1)} ${"Cron".padEnd(col2)} Description`
|
|
3083
|
+
);
|
|
3084
|
+
console.log(` ${"\u2500".repeat(col1)} ${"\u2500".repeat(col2)} ${"\u2500".repeat(32)}`);
|
|
3085
|
+
for (const task2 of tasks) {
|
|
3086
|
+
const cron = task2.cron || "manual only";
|
|
3087
|
+
const desc = task2.description || "";
|
|
3088
|
+
console.log(` ${task2.name.padEnd(col1)} ${cron.padEnd(col2)} ${desc}`);
|
|
3089
|
+
}
|
|
3090
|
+
console.log();
|
|
3091
|
+
}
|
|
3092
|
+
});
|
|
3093
|
+
const taskRun = defineCommand({
|
|
3094
|
+
meta: {
|
|
3095
|
+
name: "run",
|
|
3096
|
+
description: "Manually trigger a scheduled task via the running Qarpeo dev server"
|
|
3097
|
+
},
|
|
3098
|
+
args: {
|
|
3099
|
+
name: {
|
|
3100
|
+
type: "positional",
|
|
3101
|
+
description: "Task name to run (e.g. cleanup or cms:publish)",
|
|
3102
|
+
required: true
|
|
3103
|
+
},
|
|
3104
|
+
host: {
|
|
3105
|
+
type: "string",
|
|
3106
|
+
description: "Dev server base URL",
|
|
3107
|
+
default: "http://localhost:3000"
|
|
3108
|
+
},
|
|
3109
|
+
payload: {
|
|
3110
|
+
type: "string",
|
|
3111
|
+
description: "JSON payload to pass to the task",
|
|
3112
|
+
default: "{}"
|
|
3113
|
+
}
|
|
3114
|
+
},
|
|
3115
|
+
async run({ args }) {
|
|
3116
|
+
const taskName = args.name;
|
|
3117
|
+
const host = args.host.replace(/\/$/, "");
|
|
3118
|
+
let payload = {};
|
|
3119
|
+
try {
|
|
3120
|
+
payload = JSON.parse(args.payload || "{}");
|
|
3121
|
+
} catch {
|
|
3122
|
+
console.error("\u26A0\uFE0F [qarpeo] Invalid --payload JSON, using empty payload.");
|
|
3123
|
+
}
|
|
3124
|
+
console.log(`
|
|
3125
|
+
\u{1F680} [qarpeo] Triggering task "${taskName}" on ${host}...`);
|
|
3126
|
+
let result;
|
|
3127
|
+
try {
|
|
3128
|
+
const res = await fetch(`${host}/_qarpeo/tasks/run`, {
|
|
3129
|
+
method: "POST",
|
|
3130
|
+
headers: { "Content-Type": "application/json" },
|
|
3131
|
+
body: JSON.stringify({ task: taskName, payload })
|
|
3132
|
+
});
|
|
3133
|
+
if (!res.ok) {
|
|
3134
|
+
const text = await res.text();
|
|
3135
|
+
console.error(`
|
|
3136
|
+
\u274C [qarpeo] Server responded with ${res.status}: ${text}
|
|
3137
|
+
`);
|
|
3138
|
+
process.exit(1);
|
|
3139
|
+
}
|
|
3140
|
+
result = await res.json();
|
|
3141
|
+
} catch (err) {
|
|
3142
|
+
console.error(
|
|
3143
|
+
`
|
|
3144
|
+
\u274C [qarpeo] Could not reach dev server at ${host}. Make sure it is running.
|
|
3145
|
+
`,
|
|
3146
|
+
err?.message || err
|
|
3147
|
+
);
|
|
3148
|
+
process.exit(1);
|
|
3149
|
+
}
|
|
3150
|
+
if (result?.ok) {
|
|
3151
|
+
console.log(`
|
|
3152
|
+
\u2705 [qarpeo] Task "${taskName}" completed successfully.`);
|
|
3153
|
+
if (result.result !== void 0 && result.result !== null) {
|
|
3154
|
+
console.log("\nResult:");
|
|
3155
|
+
console.log(JSON.stringify(result.result, null, 2));
|
|
3156
|
+
}
|
|
3157
|
+
} else {
|
|
3158
|
+
console.error(`
|
|
3159
|
+
\u274C [qarpeo] Task "${taskName}" failed: ${result?.error || "unknown error"}`);
|
|
3160
|
+
process.exit(1);
|
|
3161
|
+
}
|
|
3162
|
+
console.log();
|
|
3163
|
+
}
|
|
3164
|
+
});
|
|
3165
|
+
const task = defineCommand({
|
|
3166
|
+
meta: {
|
|
3167
|
+
name: "task",
|
|
3168
|
+
description: "Manage and run Qarpeo scheduled tasks"
|
|
3169
|
+
},
|
|
3170
|
+
subCommands: {
|
|
3171
|
+
list: taskList,
|
|
3172
|
+
ls: taskList,
|
|
3173
|
+
run: taskRun
|
|
3174
|
+
}
|
|
3175
|
+
});
|
|
3176
|
+
|
|
3177
|
+
const testCommand = defineCommand({
|
|
3178
|
+
meta: {
|
|
3179
|
+
name: "test",
|
|
3180
|
+
description: "Run automated tests against simulated Cloudflare edge environment"
|
|
3181
|
+
},
|
|
3182
|
+
args: {
|
|
3183
|
+
edge: {
|
|
3184
|
+
type: "boolean",
|
|
3185
|
+
description: "Enable Cloudflare Edge emulation test harness",
|
|
3186
|
+
default: true
|
|
3187
|
+
},
|
|
3188
|
+
watch: {
|
|
3189
|
+
type: "boolean",
|
|
3190
|
+
description: "Run tests in watch mode",
|
|
3191
|
+
default: false
|
|
3192
|
+
},
|
|
3193
|
+
filter: {
|
|
3194
|
+
type: "positional",
|
|
3195
|
+
description: "Test file or pattern filter",
|
|
3196
|
+
required: false
|
|
3197
|
+
}
|
|
3198
|
+
},
|
|
3199
|
+
async run({ args }) {
|
|
3200
|
+
const cwd = process.cwd();
|
|
3201
|
+
console.log("\n\u{1F9EA} Qarpeo Cloudflare Edge Test Harness");
|
|
3202
|
+
console.log(" Setting up simulated Cloudflare Worker environment...\n");
|
|
3203
|
+
process.env.QARPEO_EDGE_TEST = "1";
|
|
3204
|
+
process.env.NODE_ENV = "test";
|
|
3205
|
+
const isWindows = process.platform === "win32";
|
|
3206
|
+
let runner = isWindows ? "pnpm.cmd" : "pnpm";
|
|
3207
|
+
let runnerArgs = ["test"];
|
|
3208
|
+
if (args.watch) {
|
|
3209
|
+
runnerArgs.push("--watch");
|
|
3210
|
+
} else {
|
|
3211
|
+
runnerArgs.push("run");
|
|
3212
|
+
}
|
|
3213
|
+
if (args.filter) {
|
|
3214
|
+
runnerArgs.push(args.filter);
|
|
3215
|
+
}
|
|
3216
|
+
console.log(`\u25B6 Executing: ${runner} ${runnerArgs.join(" ")}
|
|
3217
|
+
`);
|
|
3218
|
+
return new Promise((resolve2, reject) => {
|
|
3219
|
+
const child = spawn(runner, runnerArgs, {
|
|
3220
|
+
cwd,
|
|
3221
|
+
stdio: "inherit",
|
|
3222
|
+
shell: true,
|
|
3223
|
+
env: {
|
|
3224
|
+
...process.env,
|
|
3225
|
+
QARPEO_EDGE_TEST: "1"
|
|
3226
|
+
}
|
|
3227
|
+
});
|
|
3228
|
+
child.on("close", (code) => {
|
|
3229
|
+
if (code === 0) {
|
|
3230
|
+
console.log("\n\u2705 All edge tests completed successfully!\n");
|
|
3231
|
+
resolve2();
|
|
3232
|
+
} else {
|
|
3233
|
+
console.error(`
|
|
3234
|
+
\u274C Tests failed with exit code ${code}
|
|
3235
|
+
`);
|
|
3236
|
+
process.exit(code || 1);
|
|
3237
|
+
}
|
|
3238
|
+
});
|
|
3239
|
+
child.on("error", (err) => {
|
|
3240
|
+
console.error("Failed to launch test runner:", err);
|
|
3241
|
+
reject(err);
|
|
3242
|
+
});
|
|
3243
|
+
});
|
|
3244
|
+
}
|
|
3245
|
+
});
|
|
3246
|
+
|
|
3247
|
+
const tunnel = defineCommand({
|
|
3248
|
+
meta: {
|
|
3249
|
+
name: "tunnel",
|
|
3250
|
+
description: "Pair a local Cloudflare Tunnel (cloudflared) to expose your Nuxt server and test webhooks"
|
|
3251
|
+
},
|
|
3252
|
+
args: {
|
|
3253
|
+
cwd: {
|
|
3254
|
+
type: "string",
|
|
3255
|
+
description: "Working directory",
|
|
3256
|
+
default: "."
|
|
3257
|
+
},
|
|
3258
|
+
port: {
|
|
3259
|
+
type: "string",
|
|
3260
|
+
description: "Local port running the Nuxt dev server",
|
|
3261
|
+
default: "3000"
|
|
3262
|
+
},
|
|
3263
|
+
url: {
|
|
3264
|
+
type: "string",
|
|
3265
|
+
description: "Local upstream URL to expose"
|
|
3266
|
+
},
|
|
3267
|
+
name: {
|
|
3268
|
+
type: "string",
|
|
3269
|
+
description: "Optional named Cloudflare Tunnel"
|
|
3270
|
+
},
|
|
3271
|
+
token: {
|
|
3272
|
+
type: "string",
|
|
3273
|
+
description: "Optional Cloudflare Tunnel token for persistent tunnels"
|
|
3274
|
+
}
|
|
3275
|
+
},
|
|
3276
|
+
async run({ args }) {
|
|
3277
|
+
const cwd = resolve(process.cwd(), args.cwd);
|
|
3278
|
+
const localPort = args.port || "3000";
|
|
3279
|
+
const targetUrl = args.url || `http://localhost:${localPort}`;
|
|
3280
|
+
console.log(`
|
|
3281
|
+
\u{1F687} [qarpeo] Initializing Cloudflare Tunnel for ${targetUrl}...
|
|
3282
|
+
`);
|
|
3283
|
+
const cloudflaredBin = resolveBinaryPath("cloudflared", cwd) || (process.platform === "win32" ? "cloudflared.exe" : "cloudflared");
|
|
3284
|
+
const tunnelArgs = [];
|
|
3285
|
+
if (args.token) {
|
|
3286
|
+
tunnelArgs.push("tunnel", "run", "--token", args.token);
|
|
3287
|
+
} else {
|
|
3288
|
+
tunnelArgs.push("tunnel", "--url", targetUrl);
|
|
3289
|
+
}
|
|
3290
|
+
const child = spawn(cloudflaredBin, tunnelArgs, {
|
|
3291
|
+
cwd,
|
|
3292
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
3293
|
+
shell: process.platform === "win32"
|
|
3294
|
+
});
|
|
3295
|
+
let publicUrl = "";
|
|
3296
|
+
const parseOutput = (data) => {
|
|
3297
|
+
const text = data.toString();
|
|
3298
|
+
const match = text.match(/https:\/\/[a-zA-Z0-9-]+\.trycloudflare\.com/);
|
|
3299
|
+
if (match && !publicUrl) {
|
|
3300
|
+
publicUrl = match[0];
|
|
3301
|
+
console.log(`\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550`);
|
|
3302
|
+
console.log(`\u{1F389} Cloudflare Tunnel Established!`);
|
|
3303
|
+
console.log(`\u{1F310} Public URL: ${publicUrl}`);
|
|
3304
|
+
console.log(`\u{1F3E0} Local Server: ${targetUrl}`);
|
|
3305
|
+
console.log(`\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`);
|
|
3306
|
+
console.log(`\u{1F517} Ready Webhook Endpoints for Testing:`);
|
|
3307
|
+
console.log(` \u2022 Stripe: ${publicUrl}/api/payments/webhook`);
|
|
3308
|
+
console.log(` \u2022 GitHub: ${publicUrl}/api/auth/github/callback`);
|
|
3309
|
+
console.log(` \u2022 Email Inbound:${publicUrl}/api/mail/inbound`);
|
|
3310
|
+
console.log(`\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
|
|
3311
|
+
`);
|
|
3312
|
+
console.log("Press Ctrl+C to stop the tunnel.\n");
|
|
3313
|
+
}
|
|
3314
|
+
};
|
|
3315
|
+
child.stdout?.on("data", parseOutput);
|
|
3316
|
+
child.stderr?.on("data", parseOutput);
|
|
3317
|
+
child.on("error", (err) => {
|
|
3318
|
+
if (err?.code === "ENOENT") {
|
|
3319
|
+
console.error("\u274C [qarpeo] 'cloudflared' CLI was not found on your system.");
|
|
3320
|
+
console.error("\u{1F449} Install it with:");
|
|
3321
|
+
console.error(" \u2022 Windows: winget install Cloudflare.cloudflared (or choco install cloudflared)");
|
|
3322
|
+
console.error(" \u2022 macOS: brew install cloudflare/cloudflare/cloudflared");
|
|
3323
|
+
console.error(" \u2022 Linux: https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/\n");
|
|
3324
|
+
} else {
|
|
3325
|
+
console.error("\u274C [qarpeo] Cloudflare Tunnel failed:", err.message);
|
|
3326
|
+
}
|
|
3327
|
+
});
|
|
3328
|
+
await new Promise((resolvePromise) => {
|
|
3329
|
+
child.on("close", () => resolvePromise());
|
|
3330
|
+
process.on("SIGINT", () => {
|
|
3331
|
+
child.kill("SIGINT");
|
|
3332
|
+
resolvePromise();
|
|
3333
|
+
});
|
|
3334
|
+
});
|
|
3335
|
+
}
|
|
3336
|
+
});
|
|
3337
|
+
|
|
2209
3338
|
const main = defineCommand({
|
|
2210
3339
|
meta: {
|
|
2211
3340
|
name: "qp",
|
|
@@ -2220,12 +3349,22 @@ const main = defineCommand({
|
|
|
2220
3349
|
destroy: deleteCommand,
|
|
2221
3350
|
doctor,
|
|
2222
3351
|
generate,
|
|
3352
|
+
init,
|
|
2223
3353
|
list: listCommand,
|
|
2224
3354
|
login,
|
|
2225
3355
|
logout,
|
|
3356
|
+
logs,
|
|
2226
3357
|
ls: listCommand,
|
|
2227
3358
|
migrate,
|
|
2228
3359
|
push,
|
|
3360
|
+
secret,
|
|
3361
|
+
secrets: secret,
|
|
3362
|
+
tail: logs,
|
|
3363
|
+
task,
|
|
3364
|
+
tasks: task,
|
|
3365
|
+
test: testCommand,
|
|
3366
|
+
tun: tunnel,
|
|
3367
|
+
tunnel,
|
|
2229
3368
|
whoami,
|
|
2230
3369
|
workers: listCommand
|
|
2231
3370
|
}
|