qarpeo 0.4.13 → 0.4.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (299) hide show
  1. package/README.md +12 -6
  2. package/dist/apps/cms.d.ts +1 -1
  3. package/dist/apps/comments.d.ts +1 -1
  4. package/dist/apps/payments.d.ts +1 -1
  5. package/dist/apps/store.d.ts +1 -1
  6. package/dist/chunks/{manifest.get.mjs → tools.mjs} +445 -430
  7. package/dist/cli/index.mjs +756 -746
  8. package/dist/core/aliases.d.ts +1 -1
  9. package/dist/core/context.d.ts +1 -1
  10. package/dist/core/d1-migrate.d.ts +1 -1
  11. package/dist/core/devtools.d.ts +1 -1
  12. package/dist/core/nitro.d.ts +1 -1
  13. package/dist/core/schema.d.ts +1 -1
  14. package/dist/core/server-utils.d.ts +1 -1
  15. package/dist/core/wrangler.d.ts +1 -1
  16. package/dist/fate/index.d.ts +8 -8
  17. package/dist/fate/index.mjs +3 -1
  18. package/dist/features/agents.d.ts +1 -1
  19. package/dist/features/auth.d.ts +1 -1
  20. package/dist/features/bots.d.ts +1 -1
  21. package/dist/features/console.d.ts +1 -1
  22. package/dist/features/fate.d.ts +1 -1
  23. package/dist/features/mail.d.ts +1 -1
  24. package/dist/features/mcp.d.ts +1 -1
  25. package/dist/features/multitenant.d.ts +1 -1
  26. package/dist/features/notifications.d.ts +1 -1
  27. package/dist/features/realtime.d.ts +1 -1
  28. package/dist/features/studio.d.ts +4 -0
  29. package/dist/module.d.ts +1 -1
  30. package/dist/module.mjs +5139 -5067
  31. package/dist/primitives/ai.d.ts +1 -1
  32. package/dist/primitives/analytics.d.ts +1 -1
  33. package/dist/primitives/blob.d.ts +1 -1
  34. package/dist/primitives/browser.d.ts +1 -1
  35. package/dist/primitives/cache.d.ts +1 -1
  36. package/dist/primitives/d1.d.ts +1 -1
  37. package/dist/primitives/do.d.ts +1 -1
  38. package/dist/primitives/email.d.ts +1 -1
  39. package/dist/primitives/hyperdrive.d.ts +1 -1
  40. package/dist/primitives/kv.d.ts +1 -1
  41. package/dist/primitives/queue.d.ts +1 -1
  42. package/dist/primitives/ratelimit.d.ts +1 -1
  43. package/dist/primitives/vectorize.d.ts +1 -1
  44. package/dist/primitives/workflows.d.ts +1 -1
  45. package/dist/runtime/ai.mjs +4 -1
  46. package/dist/runtime/app/components/CMSEditor.vue +439 -0
  47. package/dist/runtime/app/components/CMSEditorImageNode.vue +90 -0
  48. package/dist/runtime/app/components/CMSEditorLinkPopover.vue +120 -0
  49. package/dist/runtime/app/components/QDropZone.vue +327 -0
  50. package/dist/runtime/app/components/QImageCropper.vue +658 -0
  51. package/dist/runtime/app/components/QImageStudio.vue +300 -0
  52. package/dist/runtime/app/components/QImg.vue +7 -4
  53. package/dist/runtime/app/composables/analytics.d.ts +8 -8
  54. package/dist/runtime/app/composables/api-tokens.d.ts +5 -5
  55. package/dist/runtime/app/composables/auth.d.ts +23 -19
  56. package/dist/runtime/app/composables/chat.d.ts +7 -6
  57. package/dist/runtime/app/composables/cms-preview.d.ts +7 -8
  58. package/dist/runtime/app/composables/cms.d.ts +6 -6
  59. package/dist/runtime/app/composables/comments.d.ts +5 -5
  60. package/dist/runtime/app/composables/comments.mjs +7 -4
  61. package/dist/runtime/app/composables/console.d.ts +6 -14
  62. package/dist/runtime/app/composables/docs-version.d.ts +8 -8
  63. package/dist/runtime/app/composables/impersonation.d.ts +5 -5
  64. package/dist/runtime/app/composables/organization.d.ts +5 -5
  65. package/dist/runtime/app/composables/passkey.d.ts +5 -5
  66. package/dist/runtime/app/composables/passwordless.d.ts +5 -5
  67. package/dist/runtime/app/composables/payments.d.ts +5 -5
  68. package/dist/runtime/app/composables/rbac.d.ts +5 -5
  69. package/dist/runtime/app/composables/site.d.ts +2 -2
  70. package/dist/runtime/app/composables/sse.d.ts +20 -33
  71. package/dist/runtime/app/composables/sse.mjs +6 -3
  72. package/dist/runtime/app/composables/storage.d.ts +6 -8
  73. package/dist/runtime/app/composables/store.d.ts +37 -36
  74. package/dist/runtime/app/composables/store.mjs +7 -6
  75. package/dist/runtime/app/composables/studio.d.ts +59 -0
  76. package/dist/runtime/app/composables/studio.mjs +129 -0
  77. package/dist/runtime/app/composables/tenant.d.ts +7 -7
  78. package/dist/runtime/app/composables/turnstile.d.ts +5 -5
  79. package/dist/runtime/app/composables/two-factor.d.ts +5 -5
  80. package/dist/runtime/app/pages/devtools/notifications.vue +1 -6
  81. package/dist/runtime/app/plugins/pwa.mjs +1 -3
  82. package/dist/runtime/app/utils/cms-editor.d.ts +25 -0
  83. package/dist/runtime/app/utils/cms-editor.mjs +43 -0
  84. package/dist/runtime/auth.d.ts +9 -9
  85. package/dist/runtime/blob.d.ts +1 -3
  86. package/dist/runtime/blob.mjs +3 -1
  87. package/dist/runtime/cache.d.ts +8 -6
  88. package/dist/runtime/cache.mjs +8 -11
  89. package/dist/runtime/db.d.ts +4 -3
  90. package/dist/runtime/drizzle.d.ts +2 -1
  91. package/dist/runtime/drizzle.mjs +2 -2
  92. package/dist/runtime/queue.d.ts +1 -0
  93. package/dist/runtime/replica.d.ts +6 -10
  94. package/dist/runtime/replica.mjs +3 -1
  95. package/dist/runtime/schema-mysql.d.ts +16 -32
  96. package/dist/runtime/schema-pg.d.ts +15 -31
  97. package/dist/runtime/schema-shared.d.ts +20 -17
  98. package/dist/runtime/schema.d.ts +21 -33
  99. package/dist/runtime/server/durable-objects/agent.mjs +4 -1
  100. package/dist/runtime/server/durable-objects/room.d.ts +4 -6
  101. package/dist/runtime/server/durable-objects/room.mjs +18 -8
  102. package/dist/runtime/server/plugins/comments.d.ts +2 -3
  103. package/dist/runtime/server/plugins/email-inbound.d.ts +1 -3
  104. package/dist/runtime/server/plugins/store.d.ts +2 -3
  105. package/dist/runtime/server/routes/__qarpeo/cloud/agents/run.post.d.ts +2 -2
  106. package/dist/runtime/server/routes/__qarpeo/cloud/cms/entry.get.mjs +10 -2
  107. package/dist/runtime/server/routes/__qarpeo/cloud/cms/entry.post.d.ts +2 -2
  108. package/dist/runtime/server/routes/__qarpeo/cloud/cms/entry.post.mjs +10 -2
  109. package/dist/runtime/server/routes/__qarpeo/cloud/cms.get.d.ts +2 -2
  110. package/dist/runtime/server/routes/__qarpeo/cloud/cms.get.mjs +7 -1
  111. package/dist/runtime/server/routes/__qarpeo/cloud/comments/moderate.post.d.ts +2 -2
  112. package/dist/runtime/server/routes/__qarpeo/cloud/comments/moderate.post.mjs +5 -1
  113. package/dist/runtime/server/routes/__qarpeo/cloud/comments.get.d.ts +1 -3
  114. package/dist/runtime/server/routes/__qarpeo/cloud/extras.get.d.ts +2 -2
  115. package/dist/runtime/server/routes/__qarpeo/cloud/extras.get.mjs +15 -4
  116. package/dist/runtime/server/routes/__qarpeo/cloud/mail/unsuppress.post.d.ts +2 -2
  117. package/dist/runtime/server/routes/__qarpeo/cloud/migrate/cms.post.mjs +13 -4
  118. package/dist/runtime/server/routes/__qarpeo/cloud/migrate/products.post.mjs +1 -1
  119. package/dist/runtime/server/routes/__qarpeo/cloud/migrate.post.d.ts +3 -3
  120. package/dist/runtime/server/routes/__qarpeo/cloud/migrate.post.mjs +22 -6
  121. package/dist/runtime/server/routes/__qarpeo/cloud/notifications/test.post.d.ts +2 -2
  122. package/dist/runtime/server/routes/__qarpeo/cloud/operations.get.d.ts +6 -5
  123. package/dist/runtime/server/routes/__qarpeo/cloud/store/order-status.post.d.ts +1 -3
  124. package/dist/runtime/server/routes/__qarpeo/cloud/store/order-status.post.mjs +14 -2
  125. package/dist/runtime/server/routes/__qarpeo/cloud/store/orders.get.d.ts +1 -3
  126. package/dist/runtime/server/routes/__qarpeo/cloud/store/orders.get.mjs +7 -1
  127. package/dist/runtime/server/routes/__qarpeo/cloud/store/products.get.d.ts +1 -3
  128. package/dist/runtime/server/routes/__qarpeo/cloud/tasks/run.post.d.ts +2 -2
  129. package/dist/runtime/server/routes/__qarpeo/cloud/users/action.post.d.ts +2 -2
  130. package/dist/runtime/server/routes/__qarpeo/cloud/users/action.post.mjs +5 -1
  131. package/dist/runtime/server/routes/__qarpeo/cloud/users.get.d.ts +6 -5
  132. package/dist/runtime/server/routes/__qarpeo/cloud/users.get.mjs +1 -3
  133. package/dist/runtime/server/routes/__qarpeo/mail/track/click/[id].get.mjs +2 -2
  134. package/dist/runtime/server/routes/__qarpeo/manifest.get.d.ts +2 -2
  135. package/dist/runtime/server/routes/__qarpeo/og.get.d.ts +2 -2
  136. package/dist/runtime/server/routes/__qarpeo/rbac/me.get.d.ts +2 -2
  137. package/dist/runtime/server/routes/__qarpeo/rbac/roles.delete.d.ts +2 -2
  138. package/dist/runtime/server/routes/__qarpeo/rbac/roles.delete.mjs +5 -1
  139. package/dist/runtime/server/routes/__qarpeo/rbac/roles.get.d.ts +2 -2
  140. package/dist/runtime/server/routes/__qarpeo/rbac/roles.get.mjs +1 -5
  141. package/dist/runtime/server/routes/__qarpeo/rbac/roles.post.d.ts +2 -2
  142. package/dist/runtime/server/routes/__qarpeo/rbac/roles.post.mjs +5 -1
  143. package/dist/runtime/server/routes/__qarpeo/rbac/users.post.d.ts +2 -2
  144. package/dist/runtime/server/routes/agents/[agent]/chat.post.mjs +1 -6
  145. package/dist/runtime/server/routes/agents/[agent]/clear.post.mjs +1 -6
  146. package/dist/runtime/server/routes/agents/[agent]/history.get.mjs +1 -6
  147. package/dist/runtime/server/routes/auth/2fa/disable.post.mjs +5 -1
  148. package/dist/runtime/server/routes/auth/2fa/verify.post.mjs +7 -1
  149. package/dist/runtime/server/routes/auth/magic-link/send.post.mjs +1 -1
  150. package/dist/runtime/server/routes/auth/otp/send.post.mjs +1 -1
  151. package/dist/runtime/server/routes/cms/search.get.mjs +2 -6
  152. package/dist/runtime/server/routes/comments/[id]/report.post.mjs +1 -4
  153. package/dist/runtime/server/routes/comments/[id].patch.mjs +1 -4
  154. package/dist/runtime/server/routes/comments/batch.post.mjs +1 -3
  155. package/dist/runtime/server/routes/comments/index.post.mjs +1 -5
  156. package/dist/runtime/server/routes/fate.mjs +1 -1
  157. package/dist/runtime/server/routes/mail/webhooks.post.mjs +1 -1
  158. package/dist/runtime/server/routes/sitemap.xml.get.mjs +2 -1
  159. package/dist/runtime/server/routes/storage/presigned-r2.post.d.ts +5 -6
  160. package/dist/runtime/server/routes/storage/presigned-r2.post.mjs +1 -1
  161. package/dist/runtime/server/routes/store/cart/items/[id].delete.mjs +1 -1
  162. package/dist/runtime/server/routes/store/cart/items/[id].patch.mjs +1 -1
  163. package/dist/runtime/server/routes/store/currencies.get.mjs +1 -4
  164. package/dist/runtime/server/routes/store/orders/[id].get.mjs +1 -1
  165. package/dist/runtime/server/routes/store/orders/download/[token].get.mjs +13 -4
  166. package/dist/runtime/server/routes/store/orders/index.get.mjs +1 -1
  167. package/dist/runtime/server/routes/store/tax/calculate.post.d.ts +2 -1
  168. package/dist/runtime/server/routes/store/tax/calculate.post.mjs +12 -3
  169. package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.mjs +4 -1
  170. package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.mjs +4 -1
  171. package/dist/runtime/server/utils/ai.d.ts +38 -35
  172. package/dist/runtime/server/utils/ai.mjs +7 -11
  173. package/dist/runtime/server/utils/analytics-query.d.ts +4 -4
  174. package/dist/runtime/server/utils/auth.d.ts +25 -25
  175. package/dist/runtime/server/utils/auth.mjs +22 -8
  176. package/dist/runtime/server/utils/bots.d.ts +7 -7
  177. package/dist/runtime/server/utils/browser-utils.d.ts +26 -27
  178. package/dist/runtime/server/utils/cache.d.ts +20 -20
  179. package/dist/runtime/server/utils/cms/collections.mjs +1 -6
  180. package/dist/runtime/server/utils/cms/common.mjs +1 -0
  181. package/dist/runtime/server/utils/cms/markdown.d.ts +2 -2
  182. package/dist/runtime/server/utils/cms/markdown.mjs +5 -5
  183. package/dist/runtime/server/utils/cms/mutations.mjs +8 -23
  184. package/dist/runtime/server/utils/cms/navigation.mjs +4 -4
  185. package/dist/runtime/server/utils/cms/path.d.ts +1 -0
  186. package/dist/runtime/server/utils/cms/path.mjs +8 -2
  187. package/dist/runtime/server/utils/cms/references.mjs +1 -7
  188. package/dist/runtime/server/utils/cms/search.d.ts +2 -2
  189. package/dist/runtime/server/utils/cms/sync.mjs +4 -2
  190. package/dist/runtime/server/utils/cms/taxonomy.d.ts +2 -2
  191. package/dist/runtime/server/utils/cms.d.ts +1 -1
  192. package/dist/runtime/server/utils/cms.mjs +1 -5
  193. package/dist/runtime/server/utils/comments-filter.d.ts +9 -7
  194. package/dist/runtime/server/utils/comments.d.ts +68 -55
  195. package/dist/runtime/server/utils/comments.mjs +21 -9
  196. package/dist/runtime/server/utils/config.d.ts +2 -2
  197. package/dist/runtime/server/utils/console.d.ts +3 -5
  198. package/dist/runtime/server/utils/context.d.ts +10 -10
  199. package/dist/runtime/server/utils/crypto.d.ts +20 -20
  200. package/dist/runtime/server/utils/domains.mjs +3 -1
  201. package/dist/runtime/server/utils/drizzle.d.ts +24 -25
  202. package/dist/runtime/server/utils/drizzle.mjs +17 -17
  203. package/dist/runtime/server/utils/durable-object.d.ts +27 -25
  204. package/dist/runtime/server/utils/durable-object.mjs +3 -10
  205. package/dist/runtime/server/utils/email-inbound.d.ts +10 -10
  206. package/dist/runtime/server/utils/impersonation.d.ts +18 -18
  207. package/dist/runtime/server/utils/legacy-hash.d.ts +23 -27
  208. package/dist/runtime/server/utils/lock.d.ts +20 -23
  209. package/dist/runtime/server/utils/mail.d.ts +19 -19
  210. package/dist/runtime/server/utils/mail.mjs +4 -2
  211. package/dist/runtime/server/utils/mcp.d.ts +20 -20
  212. package/dist/runtime/server/utils/mcp.mjs +22 -38
  213. package/dist/runtime/server/utils/notifications.d.ts +49 -38
  214. package/dist/runtime/server/utils/oauth.d.ts +3 -9
  215. package/dist/runtime/server/utils/organization.d.ts +28 -28
  216. package/dist/runtime/server/utils/organization.mjs +15 -5
  217. package/dist/runtime/server/utils/passwordless.d.ts +24 -24
  218. package/dist/runtime/server/utils/payments/checkout.d.ts +12 -12
  219. package/dist/runtime/server/utils/payments/checkout.mjs +1 -3
  220. package/dist/runtime/server/utils/payments/common.d.ts +3 -3
  221. package/dist/runtime/server/utils/payments/paddle.d.ts +4 -1
  222. package/dist/runtime/server/utils/payments/polar.d.ts +4 -1
  223. package/dist/runtime/server/utils/payments/stripe.mjs +5 -7
  224. package/dist/runtime/server/utils/payments/subscriptions.d.ts +14 -14
  225. package/dist/runtime/server/utils/payments/subscriptions.mjs +2 -6
  226. package/dist/runtime/server/utils/payments/usage.mjs +1 -3
  227. package/dist/runtime/server/utils/payments/webhooks.mjs +2 -2
  228. package/dist/runtime/server/utils/queue.d.ts +54 -58
  229. package/dist/runtime/server/utils/queue.mjs +2 -6
  230. package/dist/runtime/server/utils/rag.d.ts +23 -23
  231. package/dist/runtime/server/utils/rag.mjs +10 -5
  232. package/dist/runtime/server/utils/ratelimit.d.ts +21 -18
  233. package/dist/runtime/server/utils/rbac.d.ts +13 -15
  234. package/dist/runtime/server/utils/rbac.mjs +44 -10
  235. package/dist/runtime/server/utils/realtime.d.ts +53 -52
  236. package/dist/runtime/server/utils/role-env.d.ts +5 -4
  237. package/dist/runtime/server/utils/scheduled-task.d.ts +14 -15
  238. package/dist/runtime/server/utils/session.d.ts +40 -40
  239. package/dist/runtime/server/utils/sse.d.ts +23 -33
  240. package/dist/runtime/server/utils/sse.mjs +5 -14
  241. package/dist/runtime/server/utils/sso.mjs +3 -1
  242. package/dist/runtime/server/utils/storage.d.ts +20 -22
  243. package/dist/runtime/server/utils/storage.mjs +2 -2
  244. package/dist/runtime/server/utils/store/cart.d.ts +5 -3
  245. package/dist/runtime/server/utils/store/cart.mjs +14 -10
  246. package/dist/runtime/server/utils/store/checkout.mjs +4 -1
  247. package/dist/runtime/server/utils/store/common.d.ts +1 -1
  248. package/dist/runtime/server/utils/store/common.mjs +36 -12
  249. package/dist/runtime/server/utils/store/inventory.mjs +3 -1
  250. package/dist/runtime/server/utils/store/orders.mjs +32 -24
  251. package/dist/runtime/server/utils/store-localization.d.ts +9 -27
  252. package/dist/runtime/server/utils/store-localization.mjs +3 -3
  253. package/dist/runtime/server/utils/table-names.d.ts +15 -15
  254. package/dist/runtime/server/utils/table-names.mjs +1 -1
  255. package/dist/runtime/server/utils/tenant.d.ts +12 -12
  256. package/dist/runtime/server/utils/tenant.mjs +7 -4
  257. package/dist/runtime/server/utils/totp.d.ts +18 -18
  258. package/dist/runtime/server/utils/tracker.d.ts +5 -5
  259. package/dist/runtime/server/utils/turnstile.d.ts +9 -9
  260. package/dist/runtime/server/utils/urn.d.ts +5 -8
  261. package/dist/runtime/server/utils/workflows.d.ts +30 -31
  262. package/dist/runtime/server/utils/workflows.mjs +2 -4
  263. package/dist/runtime/server.d.ts +2 -2
  264. package/dist/runtime/service.d.ts +10 -10
  265. package/dist/runtime/test-utils.d.ts +10 -10
  266. package/dist/runtime/test-utils.mjs +9 -2
  267. package/dist/runtime/types/ai.d.ts +14 -14
  268. package/dist/runtime/types/d1.d.ts +6 -11
  269. package/dist/runtime/types/durable-object.d.ts +4 -8
  270. package/dist/runtime/types/email.d.ts +3 -9
  271. package/dist/runtime/types/index.d.ts +15 -21
  272. package/dist/runtime/types/r2.d.ts +5 -5
  273. package/dist/runtime/types/workflows.d.ts +5 -6
  274. package/dist/runtime/workflows.d.ts +1 -3
  275. package/dist/types/ai.d.ts +10 -17
  276. package/dist/types/auth.d.ts +5 -3
  277. package/dist/types/cache.d.ts +7 -7
  278. package/dist/types/cms.d.ts +30 -5
  279. package/dist/types/comments.d.ts +23 -21
  280. package/dist/types/console.d.ts +1 -3
  281. package/dist/types/db.d.ts +7 -7
  282. package/dist/types/index.d.ts +1 -0
  283. package/dist/types/options.d.ts +36 -24
  284. package/dist/types/site.d.ts +8 -2
  285. package/dist/types/storage.d.ts +2 -1
  286. package/dist/types/store-options.d.ts +10 -26
  287. package/dist/types/studio.d.ts +79 -0
  288. package/dist/utils/bots.d.ts +7 -3
  289. package/dist/utils/cms-table-names.d.ts +1 -1
  290. package/dist/utils/drizzle.d.ts +13 -14
  291. package/dist/utils/email-inbound.d.ts +4 -4
  292. package/dist/utils/features.d.ts +19 -5
  293. package/dist/utils/mcp.d.ts +1 -0
  294. package/dist/utils/migration-lock.d.ts +15 -29
  295. package/dist/utils/pkg.d.ts +6 -7
  296. package/dist/utils/schema-diff.d.ts +7 -11
  297. package/dist/utils/store-schema.d.ts +4 -6
  298. package/dist/utils/tools.d.ts +3 -3
  299. package/package.json +55 -5
@@ -1,17 +1,17 @@
1
1
  #!/usr/bin/env node
2
2
  import { defineCommand, runMain } from 'citty';
3
- import { r as resolveFeatureInstall, g as getFeatureNames, F as FEATURE_DEPS, a as resolveDatabaseTarget, b as resolveBinaryPath, e as ensurePackage, c as getLocalDatabaseContext, d as getActiveAuthTableNames, A as ALL_CMS_TABLE_NAMES, f as ALL_STORE_TABLE_NAMES, h as ALL_COMMENTS_TABLE_NAMES, s as scanSchemaExports, i as discoverDatabases, j as findLocalD1Database, k as spawnBinSync, l as getJiti, m as resolveProjectName, n as checkDrizzleVersion, o as findSchemaFiles, p as findAgentFiles, q as findToolFiles, t as findBotFiles, u as findMcpFiles, v as findJobFiles, w as findWorkflowFiles, x as findEmailHandlerFiles, y as buildQarpeoManifest, z as version } from '../chunks/manifest.get.mjs';
3
+ import { r as resolveFeatureInstall, g as getFeatureNames, F as FEATURE_DEPS, b as buildQarpeoManifest, v as version, a as resolveDatabaseTarget, c as resolveBinaryPath, e as ensurePackage, d as getLocalDatabaseContext, f as getActiveAuthTableNames, A as ALL_CMS_TABLE_NAMES, h as ALL_STORE_TABLE_NAMES, i as ALL_COMMENTS_TABLE_NAMES, s as scanSchemaExports, j as discoverDatabases, k as findLocalD1Database, l as spawnBinSync, m as getJiti, n as resolveProjectName, o as checkDrizzleVersion, p as findSchemaFiles, q as findAgentFiles, t as findToolFiles, u as findBotFiles, w as findMcpFiles, x as findJobFiles, y as findWorkflowFiles, z as findEmailHandlerFiles } from '../chunks/tools.mjs';
4
4
  import { resolve, join, dirname, relative, basename, extname } from 'pathe';
5
- import { spawnSync, spawn } from 'node:child_process';
6
- import { existsSync, mkdirSync, writeFileSync, readFileSync, rmSync, readdirSync, statSync } from 'node:fs';
5
+ import { randomBytes } from 'node:crypto';
6
+ import { existsSync, readFileSync, mkdirSync, writeFileSync, rmSync, readdirSync, statSync } from 'node:fs';
7
7
  import { loadNuxtConfig } from '@nuxt/kit';
8
+ import { spawnSync, spawn } from 'node:child_process';
8
9
  import { stdin, stdout } from 'node:process';
9
10
  import readline from 'node:readline/promises';
10
11
  import { hostname, homedir } from 'node:os';
11
- import { randomBytes } from 'node:crypto';
12
+ import 'nuxt/server';
12
13
  import 'node:module';
13
14
  import 'node:url';
14
- import 'nuxt/server';
15
15
  import 'node:fs/promises';
16
16
  import 'defu';
17
17
 
@@ -92,6 +92,75 @@ const addCommand = defineCommand({
92
92
  }
93
93
  });
94
94
 
95
+ const inspect = defineCommand({
96
+ meta: {
97
+ name: "inspect",
98
+ description: "Inspect enabled Qarpeo features, expected bindings, and secrets for Qarpeo Cloud"
99
+ },
100
+ args: {
101
+ cwd: { type: "string", description: "Project root directory", default: "." },
102
+ json: { type: "boolean", description: "Output raw manifest JSON", default: false }
103
+ },
104
+ async run({ args }) {
105
+ const cwd = resolve(args.cwd);
106
+ const nuxtConfig = await loadNuxtConfig({ cwd }).catch(() => ({}));
107
+ const qarpeoOpts = nuxtConfig.qarpeo || {};
108
+ const manifest = buildQarpeoManifest(qarpeoOpts, version);
109
+ if (args.json) {
110
+ console.log(JSON.stringify(manifest, null, 2));
111
+ return;
112
+ }
113
+ const enabled = Object.entries(manifest.features).filter(([, on]) => on).map(([k]) => k);
114
+ console.log(`
115
+ Qarpeo Cloud Manifest (v${manifest.qarpeoVersion})`);
116
+ console.log(`Enabled features (${enabled.length}): ${enabled.join(", ") || "none"}`);
117
+ if (manifest.expectedBindings.length > 0) {
118
+ console.log("\nExpected Cloudflare Bindings:");
119
+ for (const b of manifest.expectedBindings) {
120
+ console.log(` - ${b.name} (${b.type}) [${b.feature}]${b.required ? " *required" : ""}`);
121
+ }
122
+ }
123
+ if (manifest.expectedSecrets.length > 0) {
124
+ console.log("\nExpected Secrets:");
125
+ for (const s of manifest.expectedSecrets) {
126
+ console.log(` - ${s.key} [${s.feature}] \u2014 ${s.description}`);
127
+ }
128
+ }
129
+ const envPath = join(cwd, ".env");
130
+ const hasCloudSecret = Boolean(process.env.QARPEO_CLOUD_SECRET) || existsSync(envPath) && readFileSync(envPath, "utf8").includes("QARPEO_CLOUD_SECRET=");
131
+ console.log(
132
+ `
133
+ QARPEO_CLOUD_SECRET: ${hasCloudSecret ? "detected locally" : "not set (use Qarpeo Cloud -> Connect Runtime or 'qp cloud keygen')"}`
134
+ );
135
+ console.log("");
136
+ }
137
+ });
138
+ const keygen = defineCommand({
139
+ meta: {
140
+ name: "keygen",
141
+ description: "Generate a cryptographically random QARPEO_CLOUD_SECRET token"
142
+ },
143
+ run() {
144
+ const token = `qpc_${randomBytes(32).toString("hex")}`;
145
+ console.log(`
146
+ QARPEO_CLOUD_SECRET=${token}
147
+ `);
148
+ console.log(
149
+ "Add this to your Worker secrets via `qp secret push` or Qarpeo Cloud -> Connect Runtime."
150
+ );
151
+ }
152
+ });
153
+ const cloud = defineCommand({
154
+ meta: {
155
+ name: "cloud",
156
+ description: "Qarpeo Cloud inspection and runtime bridge utilities"
157
+ },
158
+ subCommands: {
159
+ inspect,
160
+ keygen
161
+ }
162
+ });
163
+
95
164
  const generate = defineCommand({
96
165
  meta: {
97
166
  name: "generate",
@@ -480,11 +549,7 @@ const DEFAULT_NOTIFICATIONS_TABLES = [
480
549
  "push_subscriptions",
481
550
  "notification_preferences"
482
551
  ];
483
- const DEFAULT_TENANTS_TABLES = [
484
- "tenants",
485
- "tenant_domains",
486
- "tenant_members"
487
- ];
552
+ const DEFAULT_TENANTS_TABLES = ["tenants", "tenant_domains", "tenant_members"];
488
553
  function extractSchemaTableNames(schemaFiles) {
489
554
  const tableNames = /* @__PURE__ */ new Set();
490
555
  const explicitVars = /* @__PURE__ */ new Set();
@@ -675,25 +740,37 @@ const diff = defineCommand({
675
740
  sqlitePath,
676
741
  qarpeoConfig: qarpeoOpts
677
742
  });
678
- console.log(`\u{1F4E6} Database: ${target.name} [binding: ${target.binding}, dialect: ${target.dialect}]`);
743
+ console.log(
744
+ `\u{1F4E6} Database: ${target.name} [binding: ${target.binding}, dialect: ${target.dialect}]`
745
+ );
679
746
  if (!diffResult.hasLocalDb) {
680
747
  console.log(` \u2139\uFE0F No physical local database found to compare against.`);
681
- console.log(` \u2139\uFE0F Expected tables defined in schema (${diffResult.expectedTables.length}): ${diffResult.expectedTables.join(", ") || "(none)"}
682
- `);
748
+ console.log(
749
+ ` \u2139\uFE0F Expected tables defined in schema (${diffResult.expectedTables.length}): ${diffResult.expectedTables.join(", ") || "(none)"}
750
+ `
751
+ );
683
752
  continue;
684
753
  }
685
754
  totalMissing += diffResult.missingTables.length;
686
755
  totalExtra += diffResult.extraTables.length;
687
756
  totalMatching += diffResult.matchingTables.length;
688
757
  if (diffResult.matchingTables.length > 0) {
689
- console.log(` \u2705 In Sync (${diffResult.matchingTables.length}): ${diffResult.matchingTables.join(", ")}`);
758
+ console.log(
759
+ ` \u2705 In Sync (${diffResult.matchingTables.length}): ${diffResult.matchingTables.join(", ")}`
760
+ );
690
761
  }
691
762
  if (diffResult.missingTables.length > 0) {
692
- console.log(` \u274C Missing in DB (${diffResult.missingTables.length}): ${diffResult.missingTables.join(", ")}`);
693
- console.log(` \u21B3 Action: Run \`qp db migrate\` or \`qp db push\` to create missing tables.`);
763
+ console.log(
764
+ ` \u274C Missing in DB (${diffResult.missingTables.length}): ${diffResult.missingTables.join(", ")}`
765
+ );
766
+ console.log(
767
+ ` \u21B3 Action: Run \`qp db migrate\` or \`qp db push\` to create missing tables.`
768
+ );
694
769
  }
695
770
  if (diffResult.extraTables.length > 0) {
696
- console.log(` \u26A0\uFE0F Unmanaged in schema (${diffResult.extraTables.length}): ${diffResult.extraTables.join(", ")}`);
771
+ console.log(
772
+ ` \u26A0\uFE0F Unmanaged in schema (${diffResult.extraTables.length}): ${diffResult.extraTables.join(", ")}`
773
+ );
697
774
  }
698
775
  if (!diffResult.hasDrift && diffResult.extraTables.length === 0) {
699
776
  console.log(` \u2728 Fully synchronized! No schema drift detected.`);
@@ -701,7 +778,9 @@ const diff = defineCommand({
701
778
  console.log();
702
779
  }
703
780
  if (totalMissing > 0 && args.failOnDrift) {
704
- console.error(`\u274C [qarpeo] Schema drift detected: ${totalMissing} table(s) missing from database.`);
781
+ console.error(
782
+ `\u274C [qarpeo] Schema drift detected: ${totalMissing} table(s) missing from database.`
783
+ );
705
784
  process.exit(1);
706
785
  }
707
786
  }
@@ -1400,7 +1479,7 @@ const migrate = defineCommand({
1400
1479
  } else if (existsSync(resolve(cwd, ".nuxt/wrangler.json"))) {
1401
1480
  wranglerConfigPath = resolve(cwd, ".nuxt/wrangler.json");
1402
1481
  } else {
1403
- const { generateDevWranglerConfig } = await import('../chunks/manifest.get.mjs').then(function (n) { return n.Y; });
1482
+ const { generateDevWranglerConfig } = await import('../chunks/tools.mjs').then(function (n) { return n.Y; });
1404
1483
  const buildDir = resolve(cwd, ".nuxt");
1405
1484
  wranglerConfigPath = await generateDevWranglerConfig(
1406
1485
  {
@@ -1475,8 +1554,10 @@ const migrate = defineCommand({
1475
1554
  if (args.unlock) {
1476
1555
  console.log(`
1477
1556
  \u{1F513} [qarpeo] Releasing Migration Lock(s)`);
1478
- console.log(` Environment: ${args.remote ? "\u2601\uFE0F Remote (Production)" : "\u{1F4BB} Local Development"}
1479
- `);
1557
+ console.log(
1558
+ ` Environment: ${args.remote ? "\u2601\uFE0F Remote (Production)" : "\u{1F4BB} Local Development"}
1559
+ `
1560
+ );
1480
1561
  for (const target of targets) {
1481
1562
  const unlockRes = await safeForceUnlockMigration(target.binding, {
1482
1563
  cwd,
@@ -1570,8 +1651,10 @@ const migrate = defineCommand({
1570
1651
  console.error(`
1571
1652
  \u274C [qarpeo] Cannot run migrations on database "${dbName}":`);
1572
1653
  console.error(` ${lockRes.error}`);
1573
- console.error(` Use --force-unlock (with --force if active) or --no-lock to bypass locking.
1574
- `);
1654
+ console.error(
1655
+ ` Use --force-unlock (with --force if active) or --no-lock to bypass locking.
1656
+ `
1657
+ );
1575
1658
  migrationResults.push({
1576
1659
  name: target.name,
1577
1660
  binding: dbName,
@@ -1582,7 +1665,9 @@ const migrate = defineCommand({
1582
1665
  process.exit(1);
1583
1666
  }
1584
1667
  lockToken = lockRes.lock?.token || null;
1585
- console.log(`\u{1F512} [qarpeo] Migration lock acquired for "${dbName}" (lease: ${args.lockTtl}, heartbeat active).`);
1668
+ console.log(
1669
+ `\u{1F512} [qarpeo] Migration lock acquired for "${dbName}" (lease: ${args.lockTtl}, heartbeat active).`
1670
+ );
1586
1671
  }
1587
1672
  if (args.backup && args.remote && !args.dryRun) {
1588
1673
  console.log(
@@ -1672,8 +1757,8 @@ const migrate = defineCommand({
1672
1757
  if (args.prune && targets.some((t) => t.isPrimary)) {
1673
1758
  const primaryTarget = targets.find((t) => t.isPrimary);
1674
1759
  const primaryBinding = primaryTarget.binding;
1675
- const { getActiveAuthTableNames, ALL_AUTH_TABLE_NAMES } = await import('../chunks/manifest.get.mjs').then(function (n) { return n.X; });
1676
- const { findLocalD1Database } = await import('../chunks/manifest.get.mjs').then(function (n) { return n.W; });
1760
+ const { getActiveAuthTableNames, ALL_AUTH_TABLE_NAMES } = await import('../chunks/tools.mjs').then(function (n) { return n.X; });
1761
+ const { findLocalD1Database } = await import('../chunks/tools.mjs').then(function (n) { return n.W; });
1677
1762
  const authConfig = nuxtConfig.qarpeo?.auth || nuxtConfig.auth;
1678
1763
  const activeTables = getActiveAuthTableNames(authConfig);
1679
1764
  const unusedTables = ALL_AUTH_TABLE_NAMES.filter(
@@ -2545,7 +2630,7 @@ const deploy = defineCommand({
2545
2630
  if (!wranglerConfigPath) {
2546
2631
  try {
2547
2632
  const { loadNuxtConfig } = await import('@nuxt/kit');
2548
- const { generateDevWranglerConfig } = await import('../chunks/manifest.get.mjs').then(function (n) { return n.Y; });
2633
+ const { generateDevWranglerConfig } = await import('../chunks/tools.mjs').then(function (n) { return n.Y; });
2549
2634
  const nuxtConfig = await loadNuxtConfig({ cwd });
2550
2635
  const qarpeoOpts = nuxtConfig.qarpeo || {};
2551
2636
  const buildDir = resolve(cwd, ".nuxt");
@@ -2629,12 +2714,15 @@ const deploy = defineCommand({
2629
2714
  return true;
2630
2715
  });
2631
2716
  };
2632
- if (Array.isArray(config.kv_namespaces)) config.kv_namespaces = dedupeBindingArray(config.kv_namespaces);
2633
- if (Array.isArray(config.d1_databases)) config.d1_databases = dedupeBindingArray(config.d1_databases);
2717
+ if (Array.isArray(config.kv_namespaces))
2718
+ config.kv_namespaces = dedupeBindingArray(config.kv_namespaces);
2719
+ if (Array.isArray(config.d1_databases))
2720
+ config.d1_databases = dedupeBindingArray(config.d1_databases);
2634
2721
  if (Array.isArray(config.r2_buckets)) config.r2_buckets = dedupeBindingArray(config.r2_buckets);
2635
2722
  if (Array.isArray(config.vectorize)) config.vectorize = dedupeBindingArray(config.vectorize);
2636
2723
  if (Array.isArray(config.workflows)) config.workflows = dedupeBindingArray(config.workflows);
2637
- if (Array.isArray(config.analytics_engine_datasets)) config.analytics_engine_datasets = dedupeBindingArray(config.analytics_engine_datasets);
2724
+ if (Array.isArray(config.analytics_engine_datasets))
2725
+ config.analytics_engine_datasets = dedupeBindingArray(config.analytics_engine_datasets);
2638
2726
  if (Array.isArray(config.ratelimits)) config.ratelimits = dedupeBindingArray(config.ratelimits);
2639
2727
  if (Array.isArray(config.compatibility_flags)) {
2640
2728
  const flags = Array.from(new Set(config.compatibility_flags));
@@ -3683,6 +3771,9 @@ ${cat.icon} ${cat.title}`);
3683
3771
  }
3684
3772
  });
3685
3773
 
3774
+ function getWranglerBin$3(cwd) {
3775
+ return resolveBinaryPath("wrangler", cwd) || resolveBinaryPath("wrangler") || (process.platform === "win32" ? "wrangler.cmd" : "wrangler");
3776
+ }
3686
3777
  function loadDotEnv$2(cwd) {
3687
3778
  const envPath = join(cwd, ".env");
3688
3779
  if (!existsSync(envPath)) return;
@@ -3705,15 +3796,79 @@ function loadDotEnv$2(cwd) {
3705
3796
  } catch {
3706
3797
  }
3707
3798
  }
3708
- const listCommand = defineCommand({
3799
+ function readWranglerConfig$1(cwd) {
3800
+ const candidateConfigs = [
3801
+ resolve(cwd, ".output/server/wrangler.json"),
3802
+ resolve(cwd, "wrangler.jsonc"),
3803
+ resolve(cwd, "wrangler.json"),
3804
+ resolve(cwd, ".nuxt/wrangler.json")
3805
+ ];
3806
+ for (const p of candidateConfigs) {
3807
+ if (existsSync(p)) {
3808
+ try {
3809
+ return JSON.parse(readFileSync(p, "utf8"));
3810
+ } catch {
3811
+ }
3812
+ }
3813
+ }
3814
+ return null;
3815
+ }
3816
+ function resolveKvTargetArgs(cwd, args) {
3817
+ const result = [];
3818
+ if (args.namespaceId) {
3819
+ result.push("--namespace-id", args.namespaceId);
3820
+ } else if (args.binding) {
3821
+ result.push("--binding", args.binding);
3822
+ } else if (process.env.QARPEO_KV_ID || process.env.KV_ID) {
3823
+ result.push("--namespace-id", process.env.QARPEO_KV_ID || process.env.KV_ID);
3824
+ } else if (process.env.QARPEO_KV_BINDING || process.env.KV_BINDING) {
3825
+ result.push("--binding", process.env.QARPEO_KV_BINDING || process.env.KV_BINDING);
3826
+ } else {
3827
+ const config = readWranglerConfig$1(cwd);
3828
+ const firstKv = config?.kv_namespaces?.[0];
3829
+ if (firstKv?.binding) {
3830
+ result.push("--binding", firstKv.binding);
3831
+ } else if (firstKv?.id) {
3832
+ result.push("--namespace-id", firstKv.id);
3833
+ } else {
3834
+ result.push("--binding", "KV");
3835
+ }
3836
+ }
3837
+ if (args.remote) {
3838
+ result.push("--remote");
3839
+ } else if (args.local) {
3840
+ result.push("--local");
3841
+ }
3842
+ return result;
3843
+ }
3844
+
3845
+ const deleteKv = defineCommand({
3709
3846
  meta: {
3710
- name: "list",
3711
- description: "List all deployed Worker services in your Cloudflare account"
3847
+ name: "delete",
3848
+ description: "Delete a key from Cloudflare KV"
3712
3849
  },
3713
3850
  args: {
3714
- json: {
3851
+ key: {
3852
+ type: "positional",
3853
+ description: "Key name to delete",
3854
+ required: true
3855
+ },
3856
+ binding: {
3857
+ type: "string",
3858
+ description: "KV binding name from wrangler.json (defaults to auto-detected or 'KV')"
3859
+ },
3860
+ namespaceId: {
3861
+ type: "string",
3862
+ description: "KV namespace ID"
3863
+ },
3864
+ local: {
3715
3865
  type: "boolean",
3716
- description: "Output in JSON format",
3866
+ description: "Interact with local development KV store",
3867
+ default: false
3868
+ },
3869
+ remote: {
3870
+ type: "boolean",
3871
+ description: "Interact with remote Cloudflare KV store",
3717
3872
  default: false
3718
3873
  },
3719
3874
  cwd: {
@@ -3725,322 +3880,298 @@ const listCommand = defineCommand({
3725
3880
  async run({ args }) {
3726
3881
  const cwd = resolve(process.cwd(), args.cwd);
3727
3882
  loadDotEnv$2(cwd);
3728
- const auth = await getCloudflareAuth(cwd);
3729
- if (!auth) {
3730
- console.error("\n\u274C [qarpeo] Not authenticated with Cloudflare.");
3731
- console.error(" Run `qp login` to authenticate or set CLOUDFLARE_API_TOKEN in .env\n");
3732
- process.exit(1);
3733
- }
3734
- console.log("\u{1F50D} [qarpeo] Fetching deployed Workers from Cloudflare...\n");
3735
- try {
3736
- const workers = await listCloudflareWorkers(auth);
3737
- if (args.json) {
3738
- console.log(JSON.stringify(workers, null, 2));
3739
- return;
3740
- }
3741
- if (workers.length === 0) {
3742
- console.log("\u2139\uFE0F No Workers found in this Cloudflare account.\n");
3743
- return;
3744
- }
3745
- const tableData = workers.map((w) => ({
3746
- "Worker Name": w.id,
3747
- Created: w.created_on ? w.created_on.slice(0, 19).replace("T", " ") : "-",
3748
- "Last Modified": w.modified_on ? w.modified_on.slice(0, 19).replace("T", " ") : "-",
3749
- Assets: w.has_assets ? "Yes" : "No"
3750
- }));
3751
- console.table(tableData);
3752
- console.log(`
3753
- \u{1F4E6} Total Workers: ${workers.length}`);
3754
- console.log(
3755
- "\u{1F4A1} Tip: Run `qp delete <worker-name>` or simply `qp delete` to interactively select and delete.\n"
3756
- );
3757
- } catch (err) {
3758
- console.error(`
3759
- \u274C [qarpeo] ${err?.message || err}
3760
- `);
3761
- process.exit(1);
3762
- }
3763
- }
3764
- });
3765
-
3766
- function getWranglerBin$3() {
3767
- return resolveBinaryPath("wrangler") || (process.platform === "win32" ? "wrangler.cmd" : "wrangler");
3768
- }
3769
- const login = defineCommand({
3770
- meta: {
3771
- name: "login",
3772
- description: "Authenticate with Cloudflare via browser OAuth (powered by Wrangler)"
3773
- },
3774
- args: {
3775
- browser: {
3776
- type: "boolean",
3777
- description: "Automatically open the link in your default browser (use --no-browser for headless environments)",
3778
- default: true
3779
- }
3780
- },
3781
- async run({ args }) {
3782
- console.log("\u{1F510} [qarpeo] Authenticating with Cloudflare...");
3783
- console.log(" After login, your credentials will be stored in ~/.wrangler/config/\n");
3784
3883
  await ensurePackage("wrangler", {
3785
- purpose: "authenticating with Cloudflare"
3884
+ cwd,
3885
+ purpose: "managing Cloudflare KV"
3786
3886
  });
3787
- const wrangler = getWranglerBin$3();
3788
- const wranglerArgs = ["login"];
3789
- if (!args.browser) {
3790
- wranglerArgs.push("--no-browser");
3791
- }
3792
- const result = spawnBinSync(wrangler, wranglerArgs, {
3887
+ const wrangler = getWranglerBin$3(cwd);
3888
+ const targetArgs = resolveKvTargetArgs(cwd, args);
3889
+ const wranglerArgs = ["kv", "key", "delete", args.key, ...targetArgs];
3890
+ console.log(`\u{1F5D1}\uFE0F [qarpeo] Deleting KV key "${args.key}"...`);
3891
+ const result = spawnSync(wrangler, wranglerArgs, {
3892
+ cwd,
3793
3893
  stdio: "inherit",
3794
- env: process.env
3894
+ env: process.env,
3895
+ shell: process.platform === "win32"
3795
3896
  });
3796
3897
  if (result.status !== 0) {
3797
- console.error(
3798
- "\n\u274C [qarpeo] Login failed. Please try again or check your network connection."
3799
- );
3800
3898
  process.exit(result.status ?? 1);
3801
3899
  }
3802
- console.log("\n\u2705 [qarpeo] Successfully authenticated with Cloudflare!");
3803
- console.log(" Run `qp whoami` to verify your account.\n");
3804
3900
  }
3805
3901
  });
3806
- const logout = defineCommand({
3902
+
3903
+ const get = defineCommand({
3807
3904
  meta: {
3808
- name: "logout",
3809
- description: "Log out of Cloudflare and revoke OAuth credentials"
3905
+ name: "get",
3906
+ description: "Get the value of a key in Cloudflare KV"
3810
3907
  },
3811
- args: {},
3812
- async run() {
3813
- console.log("\u{1F513} [qarpeo] Logging out of Cloudflare...");
3908
+ args: {
3909
+ key: {
3910
+ type: "positional",
3911
+ description: "Key name to retrieve",
3912
+ required: true
3913
+ },
3914
+ binding: {
3915
+ type: "string",
3916
+ description: "KV binding name from wrangler.json (defaults to auto-detected or 'KV')"
3917
+ },
3918
+ namespaceId: {
3919
+ type: "string",
3920
+ description: "KV namespace ID"
3921
+ },
3922
+ text: {
3923
+ type: "boolean",
3924
+ description: "Decode value as plain text",
3925
+ default: true
3926
+ },
3927
+ local: {
3928
+ type: "boolean",
3929
+ description: "Interact with local development KV store",
3930
+ default: false
3931
+ },
3932
+ remote: {
3933
+ type: "boolean",
3934
+ description: "Interact with remote Cloudflare KV store",
3935
+ default: false
3936
+ },
3937
+ cwd: {
3938
+ type: "string",
3939
+ description: "Working directory",
3940
+ default: "."
3941
+ }
3942
+ },
3943
+ async run({ args }) {
3944
+ const cwd = resolve(process.cwd(), args.cwd);
3945
+ loadDotEnv$2(cwd);
3814
3946
  await ensurePackage("wrangler", {
3815
- purpose: "logging out of Cloudflare"
3947
+ cwd,
3948
+ purpose: "managing Cloudflare KV"
3816
3949
  });
3817
- const wrangler = getWranglerBin$3();
3818
- const result = spawnBinSync(wrangler, ["logout"], {
3950
+ const wrangler = getWranglerBin$3(cwd);
3951
+ const targetArgs = resolveKvTargetArgs(cwd, args);
3952
+ const wranglerArgs = ["kv", "key", "get", args.key, ...targetArgs];
3953
+ if (args.text) {
3954
+ wranglerArgs.push("--text");
3955
+ }
3956
+ const result = spawnSync(wrangler, wranglerArgs, {
3957
+ cwd,
3819
3958
  stdio: "inherit",
3820
- env: process.env
3959
+ env: process.env,
3960
+ shell: process.platform === "win32"
3821
3961
  });
3822
3962
  if (result.status !== 0) {
3823
- console.error("\n\u274C [qarpeo] Logout failed. You may not have been logged in.");
3824
3963
  process.exit(result.status ?? 1);
3825
3964
  }
3826
- console.log("\n\u2705 [qarpeo] Successfully logged out of Cloudflare.");
3827
- console.log(" To re-authenticate, run `qp login` or set CLOUDFLARE_API_TOKEN in .env\n");
3828
3965
  }
3829
3966
  });
3830
- const whoami = defineCommand({
3967
+
3968
+ const list$1 = defineCommand({
3831
3969
  meta: {
3832
- name: "whoami",
3833
- description: "Show the currently authenticated Cloudflare account"
3970
+ name: "list",
3971
+ description: "List keys in a Cloudflare KV namespace"
3834
3972
  },
3835
- args: {},
3836
- async run() {
3973
+ args: {
3974
+ prefix: {
3975
+ type: "string",
3976
+ description: "Filter keys with a specific prefix"
3977
+ },
3978
+ binding: {
3979
+ type: "string",
3980
+ description: "KV binding name from wrangler.json (defaults to auto-detected or 'KV')"
3981
+ },
3982
+ namespaceId: {
3983
+ type: "string",
3984
+ description: "KV namespace ID"
3985
+ },
3986
+ local: {
3987
+ type: "boolean",
3988
+ description: "Interact with local development KV store",
3989
+ default: false
3990
+ },
3991
+ remote: {
3992
+ type: "boolean",
3993
+ description: "Interact with remote Cloudflare KV store",
3994
+ default: false
3995
+ },
3996
+ json: {
3997
+ type: "boolean",
3998
+ description: "Output in JSON format",
3999
+ default: false
4000
+ },
4001
+ cwd: {
4002
+ type: "string",
4003
+ description: "Working directory",
4004
+ default: "."
4005
+ }
4006
+ },
4007
+ async run({ args }) {
4008
+ const cwd = resolve(process.cwd(), args.cwd);
4009
+ loadDotEnv$2(cwd);
3837
4010
  await ensurePackage("wrangler", {
3838
- purpose: "checking Cloudflare account status"
4011
+ cwd,
4012
+ purpose: "managing Cloudflare KV"
3839
4013
  });
3840
- const wrangler = getWranglerBin$3();
3841
- const result = spawnBinSync(wrangler, ["whoami"], {
4014
+ const wrangler = getWranglerBin$3(cwd);
4015
+ const targetArgs = resolveKvTargetArgs(cwd, args);
4016
+ const wranglerArgs = ["kv", "key", "list", ...targetArgs];
4017
+ if (args.prefix) {
4018
+ wranglerArgs.push("--prefix", args.prefix);
4019
+ }
4020
+ if (args.json) {
4021
+ wranglerArgs.push("--json");
4022
+ }
4023
+ console.log(`\u{1F50D} [qarpeo] Listing KV keys...`);
4024
+ const result = spawnSync(wrangler, wranglerArgs, {
4025
+ cwd,
3842
4026
  stdio: "inherit",
3843
- env: process.env
4027
+ env: process.env,
4028
+ shell: process.platform === "win32"
3844
4029
  });
3845
4030
  if (result.status !== 0) {
3846
- console.error(
3847
- "\n\u274C [qarpeo] Not authenticated. Run `qp login` or set CLOUDFLARE_API_TOKEN in .env\n"
3848
- );
3849
4031
  process.exit(result.status ?? 1);
3850
4032
  }
3851
4033
  }
3852
4034
  });
3853
4035
 
3854
- const logs = defineCommand({
4036
+ const namespaces = defineCommand({
3855
4037
  meta: {
3856
- name: "logs",
3857
- description: "Stream live Cloudflare Worker logs directly in the terminal (wrangler tail)"
4038
+ name: "namespaces",
4039
+ description: "List all KV namespaces in your Cloudflare account"
3858
4040
  },
3859
4041
  args: {
4042
+ json: {
4043
+ type: "boolean",
4044
+ description: "Output in JSON format",
4045
+ default: false
4046
+ },
3860
4047
  cwd: {
3861
4048
  type: "string",
3862
4049
  description: "Working directory",
3863
4050
  default: "."
4051
+ }
4052
+ },
4053
+ async run({ args }) {
4054
+ const cwd = resolve(process.cwd(), args.cwd);
4055
+ loadDotEnv$2(cwd);
4056
+ await ensurePackage("wrangler", {
4057
+ cwd,
4058
+ purpose: "managing Cloudflare KV"
4059
+ });
4060
+ const wrangler = getWranglerBin$3(cwd);
4061
+ console.log(`\u{1F4CB} [qarpeo] Fetching Cloudflare KV namespaces...
4062
+ `);
4063
+ const wranglerArgs = ["kv", "namespace", "list"];
4064
+ if (args.json) {
4065
+ wranglerArgs.push("--json");
4066
+ }
4067
+ const result = spawnSync(wrangler, wranglerArgs, {
4068
+ cwd,
4069
+ stdio: "inherit",
4070
+ env: process.env,
4071
+ shell: process.platform === "win32"
4072
+ });
4073
+ if (result.status !== 0) {
4074
+ process.exit(result.status ?? 1);
4075
+ }
4076
+ }
4077
+ });
4078
+
4079
+ const set = defineCommand({
4080
+ meta: {
4081
+ name: "set",
4082
+ description: "Set the value of a key in Cloudflare KV"
4083
+ },
4084
+ args: {
4085
+ key: {
4086
+ type: "positional",
4087
+ description: "Key name to store",
4088
+ required: true
3864
4089
  },
3865
- name: {
3866
- type: "string",
3867
- description: "Cloudflare Worker service name (auto-detected from wrangler.json)"
4090
+ value: {
4091
+ type: "positional",
4092
+ description: "Value to store",
4093
+ required: true
3868
4094
  },
3869
- format: {
4095
+ ttl: {
3870
4096
  type: "string",
3871
- description: "Output format: pretty or json",
3872
- default: "pretty"
4097
+ description: "Time to live in seconds (minimum 60 seconds)"
3873
4098
  },
3874
- status: {
4099
+ expiration: {
3875
4100
  type: "string",
3876
- description: "Filter by status: ok or error"
4101
+ description: "Expiration timestamp (seconds since Unix epoch)"
3877
4102
  },
3878
- search: {
4103
+ binding: {
3879
4104
  type: "string",
3880
- description: "Filter log messages containing specific query string"
4105
+ description: "KV binding name from wrangler.json (defaults to auto-detected or 'KV')"
3881
4106
  },
3882
- env: {
4107
+ namespaceId: {
3883
4108
  type: "string",
3884
- description: "Cloudflare environment name (e.g. production, staging)"
4109
+ description: "KV namespace ID"
3885
4110
  },
3886
- tail: {
4111
+ local: {
3887
4112
  type: "boolean",
3888
- description: "Continuously stream live logs",
3889
- default: true
4113
+ description: "Interact with local development KV store",
4114
+ default: false
4115
+ },
4116
+ remote: {
4117
+ type: "boolean",
4118
+ description: "Interact with remote Cloudflare KV store",
4119
+ default: false
4120
+ },
4121
+ cwd: {
4122
+ type: "string",
4123
+ description: "Working directory",
4124
+ default: "."
3890
4125
  }
3891
4126
  },
3892
4127
  async run({ args }) {
3893
4128
  const cwd = resolve(process.cwd(), args.cwd);
3894
- const wranglerBin = resolveBinaryPath("wrangler", cwd) || (process.platform === "win32" ? "wrangler.cmd" : "wrangler");
3895
- let workerName = args.name;
3896
- if (!workerName) {
3897
- const candidateConfigs = [
3898
- resolve(cwd, ".output/server/wrangler.json"),
3899
- resolve(cwd, "wrangler.jsonc"),
3900
- resolve(cwd, "wrangler.json"),
3901
- resolve(cwd, ".nuxt/wrangler.json")
3902
- ];
3903
- for (const p of candidateConfigs) {
3904
- if (existsSync(p)) {
3905
- try {
3906
- const parsed = JSON.parse(readFileSync(p, "utf8"));
3907
- if (parsed.name) {
3908
- workerName = parsed.name;
3909
- break;
3910
- }
3911
- } catch {
3912
- }
3913
- }
3914
- }
4129
+ loadDotEnv$2(cwd);
4130
+ await ensurePackage("wrangler", {
4131
+ cwd,
4132
+ purpose: "managing Cloudflare KV"
4133
+ });
4134
+ const wrangler = getWranglerBin$3(cwd);
4135
+ const targetArgs = resolveKvTargetArgs(cwd, args);
4136
+ const wranglerArgs = ["kv", "key", "put", args.key, args.value, ...targetArgs];
4137
+ if (args.ttl) {
4138
+ wranglerArgs.push("--ttl", args.ttl);
3915
4139
  }
3916
- if (!workerName) {
3917
- try {
3918
- const pkg = JSON.parse(readFileSync(join(cwd, "package.json"), "utf8"));
3919
- workerName = pkg.name?.replace(/[^a-z0-9_-]/g, "-");
3920
- } catch {
3921
- }
4140
+ if (args.expiration) {
4141
+ wranglerArgs.push("--expiration", args.expiration);
3922
4142
  }
3923
- console.log(
3924
- `
3925
- \u{1F4E1} [qarpeo] Streaming live logs for Cloudflare Worker: ${workerName || "default"}...
3926
- `
3927
- );
3928
- const tailArgs = ["tail"];
3929
- if (workerName) {
3930
- tailArgs.push(workerName);
3931
- }
3932
- if (args.format) {
3933
- tailArgs.push("--format", args.format);
3934
- }
3935
- if (args.status) {
3936
- tailArgs.push("--status", args.status);
3937
- }
3938
- if (args.search) {
3939
- tailArgs.push("--search", args.search);
3940
- }
3941
- if (args.env) {
3942
- tailArgs.push("--env", args.env);
3943
- }
3944
- console.log(`> wrangler ${tailArgs.join(" ")}
3945
- `);
3946
- console.log("Press Ctrl+C to exit streaming logs.\n");
3947
- let child;
3948
- if (process.platform === "win32" && (wranglerBin.endsWith(".cmd") || wranglerBin.endsWith(".bat"))) {
3949
- const cmd = process.env.ComSpec || "cmd.exe";
3950
- child = spawn(cmd, ["/d", "/s", "/c", wranglerBin, ...tailArgs], {
3951
- cwd,
3952
- stdio: "inherit",
3953
- shell: false
3954
- });
3955
- } else {
3956
- child = spawn(wranglerBin, tailArgs, {
3957
- cwd,
3958
- stdio: "inherit",
3959
- shell: false
3960
- });
3961
- }
3962
- await new Promise((resolvePromise) => {
3963
- child.on("close", () => {
3964
- resolvePromise();
3965
- });
3966
- process.on("SIGINT", () => {
3967
- child.kill("SIGINT");
3968
- resolvePromise();
3969
- });
4143
+ console.log(`\u26A1 [qarpeo] Setting KV key "${args.key}"...`);
4144
+ const result = spawnSync(wrangler, wranglerArgs, {
4145
+ cwd,
4146
+ stdio: "inherit",
4147
+ env: process.env,
4148
+ shell: process.platform === "win32"
3970
4149
  });
3971
- }
3972
- });
3973
-
3974
- const inspect = defineCommand({
3975
- meta: {
3976
- name: "inspect",
3977
- description: "Inspect enabled Qarpeo features, expected bindings, and secrets for Qarpeo Cloud"
3978
- },
3979
- args: {
3980
- cwd: { type: "string", description: "Project root directory", default: "." },
3981
- json: { type: "boolean", description: "Output raw manifest JSON", default: false }
3982
- },
3983
- async run({ args }) {
3984
- const cwd = resolve(args.cwd);
3985
- const nuxtConfig = await loadNuxtConfig({ cwd }).catch(() => ({}));
3986
- const qarpeoOpts = nuxtConfig.qarpeo || {};
3987
- const manifest = buildQarpeoManifest(qarpeoOpts, version);
3988
- if (args.json) {
3989
- console.log(JSON.stringify(manifest, null, 2));
3990
- return;
3991
- }
3992
- const enabled = Object.entries(manifest.features).filter(([, on]) => on).map(([k]) => k);
3993
- console.log(`
3994
- Qarpeo Cloud Manifest (v${manifest.qarpeoVersion})`);
3995
- console.log(`Enabled features (${enabled.length}): ${enabled.join(", ") || "none"}`);
3996
- if (manifest.expectedBindings.length > 0) {
3997
- console.log("\nExpected Cloudflare Bindings:");
3998
- for (const b of manifest.expectedBindings) {
3999
- console.log(` - ${b.name} (${b.type}) [${b.feature}]${b.required ? " *required" : ""}`);
4000
- }
4001
- }
4002
- if (manifest.expectedSecrets.length > 0) {
4003
- console.log("\nExpected Secrets:");
4004
- for (const s of manifest.expectedSecrets) {
4005
- console.log(` - ${s.key} [${s.feature}] \u2014 ${s.description}`);
4006
- }
4150
+ if (result.status !== 0) {
4151
+ process.exit(result.status ?? 1);
4007
4152
  }
4008
- const envPath = join(cwd, ".env");
4009
- const hasCloudSecret = Boolean(process.env.QARPEO_CLOUD_SECRET) || existsSync(envPath) && readFileSync(envPath, "utf8").includes("QARPEO_CLOUD_SECRET=");
4010
- console.log(
4011
- `
4012
- QARPEO_CLOUD_SECRET: ${hasCloudSecret ? "detected locally" : "not set (use Qarpeo Cloud -> Connect Runtime or 'qp cloud keygen')"}`
4013
- );
4014
- console.log("");
4015
4153
  }
4016
4154
  });
4017
- const keygen = defineCommand({
4018
- meta: {
4019
- name: "keygen",
4020
- description: "Generate a cryptographically random QARPEO_CLOUD_SECRET token"
4021
- },
4022
- run() {
4023
- const token = `qpc_${randomBytes(32).toString("hex")}`;
4024
- console.log(`
4025
- QARPEO_CLOUD_SECRET=${token}
4026
- `);
4027
- console.log("Add this to your Worker secrets via `qp secret push` or Qarpeo Cloud -> Connect Runtime.");
4028
- }
4029
- });
4030
- const cloud = defineCommand({
4155
+
4156
+ const kv = defineCommand({
4031
4157
  meta: {
4032
- name: "cloud",
4033
- description: "Qarpeo Cloud inspection and runtime bridge utilities"
4158
+ name: "kv",
4159
+ description: "Manage Cloudflare Workers KV key-value storage"
4034
4160
  },
4035
4161
  subCommands: {
4036
- inspect,
4037
- keygen
4162
+ list: list$1,
4163
+ ls: list$1,
4164
+ get,
4165
+ set,
4166
+ put: set,
4167
+ delete: deleteKv,
4168
+ del: deleteKv,
4169
+ rm: deleteKv,
4170
+ namespaces,
4171
+ ns: namespaces
4038
4172
  }
4039
4173
  });
4040
4174
 
4041
- function getWranglerBin$2(cwd) {
4042
- return resolveBinaryPath("wrangler", cwd) || resolveBinaryPath("wrangler") || (process.platform === "win32" ? "wrangler.cmd" : "wrangler");
4043
- }
4044
4175
  function loadDotEnv$1(cwd) {
4045
4176
  const envPath = join(cwd, ".env");
4046
4177
  if (!existsSync(envPath)) return;
@@ -4063,79 +4194,15 @@ function loadDotEnv$1(cwd) {
4063
4194
  } catch {
4064
4195
  }
4065
4196
  }
4066
- function readWranglerConfig$1(cwd) {
4067
- const candidateConfigs = [
4068
- resolve(cwd, ".output/server/wrangler.json"),
4069
- resolve(cwd, "wrangler.jsonc"),
4070
- resolve(cwd, "wrangler.json"),
4071
- resolve(cwd, ".nuxt/wrangler.json")
4072
- ];
4073
- for (const p of candidateConfigs) {
4074
- if (existsSync(p)) {
4075
- try {
4076
- return JSON.parse(readFileSync(p, "utf8"));
4077
- } catch {
4078
- }
4079
- }
4080
- }
4081
- return null;
4082
- }
4083
- function resolveKvTargetArgs(cwd, args) {
4084
- const result = [];
4085
- if (args.namespaceId) {
4086
- result.push("--namespace-id", args.namespaceId);
4087
- } else if (args.binding) {
4088
- result.push("--binding", args.binding);
4089
- } else if (process.env.QARPEO_KV_ID || process.env.KV_ID) {
4090
- result.push("--namespace-id", process.env.QARPEO_KV_ID || process.env.KV_ID);
4091
- } else if (process.env.QARPEO_KV_BINDING || process.env.KV_BINDING) {
4092
- result.push("--binding", process.env.QARPEO_KV_BINDING || process.env.KV_BINDING);
4093
- } else {
4094
- const config = readWranglerConfig$1(cwd);
4095
- const firstKv = config?.kv_namespaces?.[0];
4096
- if (firstKv?.binding) {
4097
- result.push("--binding", firstKv.binding);
4098
- } else if (firstKv?.id) {
4099
- result.push("--namespace-id", firstKv.id);
4100
- } else {
4101
- result.push("--binding", "KV");
4102
- }
4103
- }
4104
- if (args.remote) {
4105
- result.push("--remote");
4106
- } else if (args.local) {
4107
- result.push("--local");
4108
- }
4109
- return result;
4110
- }
4111
-
4112
- const deleteKv = defineCommand({
4197
+ const listCommand = defineCommand({
4113
4198
  meta: {
4114
- name: "delete",
4115
- description: "Delete a key from Cloudflare KV"
4199
+ name: "list",
4200
+ description: "List all deployed Worker services in your Cloudflare account"
4116
4201
  },
4117
4202
  args: {
4118
- key: {
4119
- type: "positional",
4120
- description: "Key name to delete",
4121
- required: true
4122
- },
4123
- binding: {
4124
- type: "string",
4125
- description: "KV binding name from wrangler.json (defaults to auto-detected or 'KV')"
4126
- },
4127
- namespaceId: {
4128
- type: "string",
4129
- description: "KV namespace ID"
4130
- },
4131
- local: {
4132
- type: "boolean",
4133
- description: "Interact with local development KV store",
4134
- default: false
4135
- },
4136
- remote: {
4203
+ json: {
4137
4204
  type: "boolean",
4138
- description: "Interact with remote Cloudflare KV store",
4205
+ description: "Output in JSON format",
4139
4206
  default: false
4140
4207
  },
4141
4208
  cwd: {
@@ -4147,169 +4214,299 @@ const deleteKv = defineCommand({
4147
4214
  async run({ args }) {
4148
4215
  const cwd = resolve(process.cwd(), args.cwd);
4149
4216
  loadDotEnv$1(cwd);
4150
- await ensurePackage("wrangler", {
4151
- cwd,
4152
- purpose: "managing Cloudflare KV"
4153
- });
4154
- const wrangler = getWranglerBin$2(cwd);
4155
- const targetArgs = resolveKvTargetArgs(cwd, args);
4156
- const wranglerArgs = ["kv", "key", "delete", args.key, ...targetArgs];
4157
- console.log(`\u{1F5D1}\uFE0F [qarpeo] Deleting KV key "${args.key}"...`);
4158
- const result = spawnSync(wrangler, wranglerArgs, {
4159
- cwd,
4160
- stdio: "inherit",
4161
- env: process.env,
4162
- shell: process.platform === "win32"
4163
- });
4164
- if (result.status !== 0) {
4165
- process.exit(result.status ?? 1);
4217
+ const auth = await getCloudflareAuth(cwd);
4218
+ if (!auth) {
4219
+ console.error("\n\u274C [qarpeo] Not authenticated with Cloudflare.");
4220
+ console.error(" Run `qp login` to authenticate or set CLOUDFLARE_API_TOKEN in .env\n");
4221
+ process.exit(1);
4222
+ }
4223
+ console.log("\u{1F50D} [qarpeo] Fetching deployed Workers from Cloudflare...\n");
4224
+ try {
4225
+ const workers = await listCloudflareWorkers(auth);
4226
+ if (args.json) {
4227
+ console.log(JSON.stringify(workers, null, 2));
4228
+ return;
4229
+ }
4230
+ if (workers.length === 0) {
4231
+ console.log("\u2139\uFE0F No Workers found in this Cloudflare account.\n");
4232
+ return;
4233
+ }
4234
+ const tableData = workers.map((w) => ({
4235
+ "Worker Name": w.id,
4236
+ Created: w.created_on ? w.created_on.slice(0, 19).replace("T", " ") : "-",
4237
+ "Last Modified": w.modified_on ? w.modified_on.slice(0, 19).replace("T", " ") : "-",
4238
+ Assets: w.has_assets ? "Yes" : "No"
4239
+ }));
4240
+ console.table(tableData);
4241
+ console.log(`
4242
+ \u{1F4E6} Total Workers: ${workers.length}`);
4243
+ console.log(
4244
+ "\u{1F4A1} Tip: Run `qp delete <worker-name>` or simply `qp delete` to interactively select and delete.\n"
4245
+ );
4246
+ } catch (err) {
4247
+ console.error(`
4248
+ \u274C [qarpeo] ${err?.message || err}
4249
+ `);
4250
+ process.exit(1);
4166
4251
  }
4167
4252
  }
4168
4253
  });
4169
4254
 
4170
- const get = defineCommand({
4255
+ function getWranglerBin$2() {
4256
+ return resolveBinaryPath("wrangler") || (process.platform === "win32" ? "wrangler.cmd" : "wrangler");
4257
+ }
4258
+ const login = defineCommand({
4171
4259
  meta: {
4172
- name: "get",
4173
- description: "Get the value of a key in Cloudflare KV"
4260
+ name: "login",
4261
+ description: "Authenticate with Cloudflare via browser OAuth (powered by Wrangler)"
4174
4262
  },
4175
4263
  args: {
4176
- key: {
4177
- type: "positional",
4178
- description: "Key name to retrieve",
4179
- required: true
4180
- },
4181
- binding: {
4182
- type: "string",
4183
- description: "KV binding name from wrangler.json (defaults to auto-detected or 'KV')"
4184
- },
4185
- namespaceId: {
4186
- type: "string",
4187
- description: "KV namespace ID"
4188
- },
4189
- text: {
4264
+ browser: {
4190
4265
  type: "boolean",
4191
- description: "Decode value as plain text",
4266
+ description: "Automatically open the link in your default browser (use --no-browser for headless environments)",
4192
4267
  default: true
4193
- },
4194
- local: {
4195
- type: "boolean",
4196
- description: "Interact with local development KV store",
4197
- default: false
4198
- },
4199
- remote: {
4200
- type: "boolean",
4201
- description: "Interact with remote Cloudflare KV store",
4202
- default: false
4203
- },
4204
- cwd: {
4205
- type: "string",
4206
- description: "Working directory",
4207
- default: "."
4208
4268
  }
4209
4269
  },
4210
4270
  async run({ args }) {
4211
- const cwd = resolve(process.cwd(), args.cwd);
4212
- loadDotEnv$1(cwd);
4271
+ console.log("\u{1F510} [qarpeo] Authenticating with Cloudflare...");
4272
+ console.log(" After login, your credentials will be stored in ~/.wrangler/config/\n");
4213
4273
  await ensurePackage("wrangler", {
4214
- cwd,
4215
- purpose: "managing Cloudflare KV"
4274
+ purpose: "authenticating with Cloudflare"
4216
4275
  });
4217
- const wrangler = getWranglerBin$2(cwd);
4218
- const targetArgs = resolveKvTargetArgs(cwd, args);
4219
- const wranglerArgs = ["kv", "key", "get", args.key, ...targetArgs];
4220
- if (args.text) {
4221
- wranglerArgs.push("--text");
4276
+ const wrangler = getWranglerBin$2();
4277
+ const wranglerArgs = ["login"];
4278
+ if (!args.browser) {
4279
+ wranglerArgs.push("--no-browser");
4222
4280
  }
4223
- const result = spawnSync(wrangler, wranglerArgs, {
4224
- cwd,
4281
+ const result = spawnBinSync(wrangler, wranglerArgs, {
4225
4282
  stdio: "inherit",
4226
- env: process.env,
4227
- shell: process.platform === "win32"
4283
+ env: process.env
4284
+ });
4285
+ if (result.status !== 0) {
4286
+ console.error(
4287
+ "\n\u274C [qarpeo] Login failed. Please try again or check your network connection."
4288
+ );
4289
+ process.exit(result.status ?? 1);
4290
+ }
4291
+ console.log("\n\u2705 [qarpeo] Successfully authenticated with Cloudflare!");
4292
+ console.log(" Run `qp whoami` to verify your account.\n");
4293
+ }
4294
+ });
4295
+ const logout = defineCommand({
4296
+ meta: {
4297
+ name: "logout",
4298
+ description: "Log out of Cloudflare and revoke OAuth credentials"
4299
+ },
4300
+ args: {},
4301
+ async run() {
4302
+ console.log("\u{1F513} [qarpeo] Logging out of Cloudflare...");
4303
+ await ensurePackage("wrangler", {
4304
+ purpose: "logging out of Cloudflare"
4305
+ });
4306
+ const wrangler = getWranglerBin$2();
4307
+ const result = spawnBinSync(wrangler, ["logout"], {
4308
+ stdio: "inherit",
4309
+ env: process.env
4228
4310
  });
4229
4311
  if (result.status !== 0) {
4312
+ console.error("\n\u274C [qarpeo] Logout failed. You may not have been logged in.");
4313
+ process.exit(result.status ?? 1);
4314
+ }
4315
+ console.log("\n\u2705 [qarpeo] Successfully logged out of Cloudflare.");
4316
+ console.log(" To re-authenticate, run `qp login` or set CLOUDFLARE_API_TOKEN in .env\n");
4317
+ }
4318
+ });
4319
+ const whoami = defineCommand({
4320
+ meta: {
4321
+ name: "whoami",
4322
+ description: "Show the currently authenticated Cloudflare account"
4323
+ },
4324
+ args: {},
4325
+ async run() {
4326
+ await ensurePackage("wrangler", {
4327
+ purpose: "checking Cloudflare account status"
4328
+ });
4329
+ const wrangler = getWranglerBin$2();
4330
+ const result = spawnBinSync(wrangler, ["whoami"], {
4331
+ stdio: "inherit",
4332
+ env: process.env
4333
+ });
4334
+ if (result.status !== 0) {
4335
+ console.error(
4336
+ "\n\u274C [qarpeo] Not authenticated. Run `qp login` or set CLOUDFLARE_API_TOKEN in .env\n"
4337
+ );
4230
4338
  process.exit(result.status ?? 1);
4231
4339
  }
4232
4340
  }
4233
4341
  });
4234
4342
 
4235
- const list$1 = defineCommand({
4343
+ const logs = defineCommand({
4236
4344
  meta: {
4237
- name: "list",
4238
- description: "List keys in a Cloudflare KV namespace"
4345
+ name: "logs",
4346
+ description: "Stream live Cloudflare Worker logs directly in the terminal (wrangler tail)"
4239
4347
  },
4240
4348
  args: {
4241
- prefix: {
4349
+ cwd: {
4242
4350
  type: "string",
4243
- description: "Filter keys with a specific prefix"
4351
+ description: "Working directory",
4352
+ default: "."
4244
4353
  },
4245
- binding: {
4354
+ name: {
4246
4355
  type: "string",
4247
- description: "KV binding name from wrangler.json (defaults to auto-detected or 'KV')"
4356
+ description: "Cloudflare Worker service name (auto-detected from wrangler.json)"
4248
4357
  },
4249
- namespaceId: {
4358
+ format: {
4250
4359
  type: "string",
4251
- description: "KV namespace ID"
4252
- },
4253
- local: {
4254
- type: "boolean",
4255
- description: "Interact with local development KV store",
4256
- default: false
4360
+ description: "Output format: pretty or json",
4361
+ default: "pretty"
4257
4362
  },
4258
- remote: {
4259
- type: "boolean",
4260
- description: "Interact with remote Cloudflare KV store",
4261
- default: false
4363
+ status: {
4364
+ type: "string",
4365
+ description: "Filter by status: ok or error"
4262
4366
  },
4263
- json: {
4264
- type: "boolean",
4265
- description: "Output in JSON format",
4266
- default: false
4367
+ search: {
4368
+ type: "string",
4369
+ description: "Filter log messages containing specific query string"
4267
4370
  },
4268
- cwd: {
4371
+ env: {
4269
4372
  type: "string",
4270
- description: "Working directory",
4271
- default: "."
4373
+ description: "Cloudflare environment name (e.g. production, staging)"
4374
+ },
4375
+ tail: {
4376
+ type: "boolean",
4377
+ description: "Continuously stream live logs",
4378
+ default: true
4272
4379
  }
4273
4380
  },
4274
4381
  async run({ args }) {
4275
4382
  const cwd = resolve(process.cwd(), args.cwd);
4276
- loadDotEnv$1(cwd);
4277
- await ensurePackage("wrangler", {
4278
- cwd,
4279
- purpose: "managing Cloudflare KV"
4280
- });
4281
- const wrangler = getWranglerBin$2(cwd);
4282
- const targetArgs = resolveKvTargetArgs(cwd, args);
4283
- const wranglerArgs = ["kv", "key", "list", ...targetArgs];
4284
- if (args.prefix) {
4285
- wranglerArgs.push("--prefix", args.prefix);
4383
+ const wranglerBin = resolveBinaryPath("wrangler", cwd) || (process.platform === "win32" ? "wrangler.cmd" : "wrangler");
4384
+ let workerName = args.name;
4385
+ if (!workerName) {
4386
+ const candidateConfigs = [
4387
+ resolve(cwd, ".output/server/wrangler.json"),
4388
+ resolve(cwd, "wrangler.jsonc"),
4389
+ resolve(cwd, "wrangler.json"),
4390
+ resolve(cwd, ".nuxt/wrangler.json")
4391
+ ];
4392
+ for (const p of candidateConfigs) {
4393
+ if (existsSync(p)) {
4394
+ try {
4395
+ const parsed = JSON.parse(readFileSync(p, "utf8"));
4396
+ if (parsed.name) {
4397
+ workerName = parsed.name;
4398
+ break;
4399
+ }
4400
+ } catch {
4401
+ }
4402
+ }
4403
+ }
4286
4404
  }
4287
- if (args.json) {
4288
- wranglerArgs.push("--json");
4405
+ if (!workerName) {
4406
+ try {
4407
+ const pkg = JSON.parse(readFileSync(join(cwd, "package.json"), "utf8"));
4408
+ workerName = pkg.name?.replace(/[^a-z0-9_-]/g, "-");
4409
+ } catch {
4410
+ }
4289
4411
  }
4290
- console.log(`\u{1F50D} [qarpeo] Listing KV keys...`);
4291
- const result = spawnSync(wrangler, wranglerArgs, {
4292
- cwd,
4293
- stdio: "inherit",
4294
- env: process.env,
4295
- shell: process.platform === "win32"
4296
- });
4297
- if (result.status !== 0) {
4298
- process.exit(result.status ?? 1);
4412
+ console.log(
4413
+ `
4414
+ \u{1F4E1} [qarpeo] Streaming live logs for Cloudflare Worker: ${workerName || "default"}...
4415
+ `
4416
+ );
4417
+ const tailArgs = ["tail"];
4418
+ if (workerName) {
4419
+ tailArgs.push(workerName);
4420
+ }
4421
+ if (args.format) {
4422
+ tailArgs.push("--format", args.format);
4423
+ }
4424
+ if (args.status) {
4425
+ tailArgs.push("--status", args.status);
4426
+ }
4427
+ if (args.search) {
4428
+ tailArgs.push("--search", args.search);
4429
+ }
4430
+ if (args.env) {
4431
+ tailArgs.push("--env", args.env);
4432
+ }
4433
+ console.log(`> wrangler ${tailArgs.join(" ")}
4434
+ `);
4435
+ console.log("Press Ctrl+C to exit streaming logs.\n");
4436
+ let child;
4437
+ if (process.platform === "win32" && (wranglerBin.endsWith(".cmd") || wranglerBin.endsWith(".bat"))) {
4438
+ const cmd = process.env.ComSpec || "cmd.exe";
4439
+ child = spawn(cmd, ["/d", "/s", "/c", wranglerBin, ...tailArgs], {
4440
+ cwd,
4441
+ stdio: "inherit",
4442
+ shell: false
4443
+ });
4444
+ } else {
4445
+ child = spawn(wranglerBin, tailArgs, {
4446
+ cwd,
4447
+ stdio: "inherit",
4448
+ shell: false
4449
+ });
4299
4450
  }
4451
+ await new Promise((resolvePromise) => {
4452
+ child.on("close", () => {
4453
+ resolvePromise();
4454
+ });
4455
+ process.on("SIGINT", () => {
4456
+ child.kill("SIGINT");
4457
+ resolvePromise();
4458
+ });
4459
+ });
4300
4460
  }
4301
4461
  });
4302
4462
 
4303
- const namespaces = defineCommand({
4463
+ function getWranglerBin$1(cwd) {
4464
+ return resolveBinaryPath("wrangler", cwd) || resolveBinaryPath("wrangler") || (process.platform === "win32" ? "wrangler.cmd" : "wrangler");
4465
+ }
4466
+ function parseDotEnv(cwd) {
4467
+ const envPath = join(cwd, ".env");
4468
+ if (!existsSync(envPath)) return {};
4469
+ const result = {};
4470
+ try {
4471
+ const raw = readFileSync(envPath, "utf8");
4472
+ for (const line of raw.split(/\r?\n/)) {
4473
+ const trimmed = line.trim();
4474
+ if (!trimmed || trimmed.startsWith("#")) continue;
4475
+ const eqIdx = trimmed.indexOf("=");
4476
+ if (eqIdx === -1) continue;
4477
+ const key = trimmed.slice(0, eqIdx).trim();
4478
+ let val = trimmed.slice(eqIdx + 1).trim();
4479
+ if (val.startsWith('"') && val.endsWith('"') || val.startsWith("'") && val.endsWith("'")) {
4480
+ val = val.slice(1, -1);
4481
+ }
4482
+ result[key] = val;
4483
+ }
4484
+ } catch {
4485
+ }
4486
+ return result;
4487
+ }
4488
+ function isSecretKey(key) {
4489
+ const upper = key.toUpperCase();
4490
+ if (upper.startsWith("QARPEO_") && (upper.endsWith("_ID") || upper.endsWith("_BINDING") || upper.endsWith("_BUCKET") || upper.endsWith("_NAME"))) {
4491
+ return false;
4492
+ }
4493
+ if (upper === "CLOUDFLARE_ACCOUNT_ID" || upper === "CF_ACCOUNT_ID") return false;
4494
+ if (upper === "NODE_ENV" || upper === "PORT" || upper === "HOST") return false;
4495
+ 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");
4496
+ }
4497
+ const pushSecret = defineCommand({
4304
4498
  meta: {
4305
- name: "namespaces",
4306
- description: "List all KV namespaces in your Cloudflare account"
4499
+ name: "push",
4500
+ description: "Sync secrets from local .env directly to Cloudflare Workers secrets"
4307
4501
  },
4308
4502
  args: {
4309
- json: {
4310
- type: "boolean",
4311
- description: "Output in JSON format",
4312
- default: false
4503
+ name: {
4504
+ type: "string",
4505
+ description: "Cloudflare Worker script name (defaults to project name in package.json)"
4506
+ },
4507
+ env: {
4508
+ type: "string",
4509
+ description: "Cloudflare Worker environment (e.g. production, preview)"
4313
4510
  },
4314
4511
  cwd: {
4315
4512
  type: "string",
@@ -4319,71 +4516,79 @@ const namespaces = defineCommand({
4319
4516
  },
4320
4517
  async run({ args }) {
4321
4518
  const cwd = resolve(process.cwd(), args.cwd);
4322
- loadDotEnv$1(cwd);
4519
+ const envVars = parseDotEnv(cwd);
4520
+ const secretEntries = Object.entries(envVars).filter(([k]) => isSecretKey(k));
4521
+ if (secretEntries.length === 0) {
4522
+ console.log("\u2139\uFE0F [qarpeo] No secret keys detected in .env to synchronize.");
4523
+ return;
4524
+ }
4525
+ console.log(
4526
+ `
4527
+ \u{1F510} [qarpeo] Found ${secretEntries.length} secrets to synchronize with Cloudflare Workers:`
4528
+ );
4529
+ for (const [k] of secretEntries) {
4530
+ console.log(` \u2022 ${k}`);
4531
+ }
4323
4532
  await ensurePackage("wrangler", {
4324
4533
  cwd,
4325
- purpose: "managing Cloudflare KV"
4534
+ purpose: "pushing Cloudflare Worker secrets"
4326
4535
  });
4327
- const wrangler = getWranglerBin$2(cwd);
4328
- console.log(`\u{1F4CB} [qarpeo] Fetching Cloudflare KV namespaces...
4329
- `);
4330
- const wranglerArgs = ["kv", "namespace", "list"];
4331
- if (args.json) {
4332
- wranglerArgs.push("--json");
4536
+ const wrangler = getWranglerBin$1(cwd);
4537
+ const secretJson = {};
4538
+ for (const [k, v] of secretEntries) {
4539
+ secretJson[k] = v;
4333
4540
  }
4334
- const result = spawnSync(wrangler, wranglerArgs, {
4541
+ console.log("\n\u{1F680} [qarpeo] Uploading secrets via wrangler secret:bulk...");
4542
+ const wranglerArgs = ["secret:bulk"];
4543
+ if (args.env) wranglerArgs.push("--env", args.env);
4544
+ const res = spawnBinSync(wrangler, wranglerArgs, {
4335
4545
  cwd,
4336
- stdio: "inherit",
4337
- env: process.env,
4338
- shell: process.platform === "win32"
4546
+ input: JSON.stringify(secretJson),
4547
+ encoding: "utf8"
4339
4548
  });
4340
- if (result.status !== 0) {
4341
- process.exit(result.status ?? 1);
4549
+ if (res.status === 0) {
4550
+ console.log("\n\u2705 [qarpeo] All secrets synchronized successfully with Cloudflare Workers!\n");
4551
+ } else {
4552
+ console.log("\u2139\uFE0F [qarpeo] Falling back to individual `wrangler secret put`...");
4553
+ let failed = 0;
4554
+ for (const [k, v] of secretEntries) {
4555
+ const putArgs = ["secret", "put", k];
4556
+ if (args.env) putArgs.push("--env", args.env);
4557
+ const putRes = spawnBinSync(wrangler, putArgs, {
4558
+ cwd,
4559
+ input: v,
4560
+ encoding: "utf8"
4561
+ });
4562
+ if (putRes.status === 0) {
4563
+ console.log(` \u2714 Synced ${k}`);
4564
+ } else {
4565
+ console.error(` \u2716 Failed to sync ${k}`);
4566
+ failed++;
4567
+ }
4568
+ }
4569
+ if (failed === 0) {
4570
+ console.log("\n\u2705 [qarpeo] All secrets synchronized successfully!\n");
4571
+ } else {
4572
+ console.error(`
4573
+ \u26A0\uFE0F [qarpeo] Completed with ${failed} failed secret(s).
4574
+ `);
4575
+ }
4342
4576
  }
4343
4577
  }
4344
4578
  });
4345
-
4346
- const set = defineCommand({
4579
+ const pullSecret = defineCommand({
4347
4580
  meta: {
4348
- name: "set",
4349
- description: "Set the value of a key in Cloudflare KV"
4581
+ name: "pull",
4582
+ description: "List or pull Cloudflare Worker secrets into a local .env.local file"
4350
4583
  },
4351
4584
  args: {
4352
- key: {
4353
- type: "positional",
4354
- description: "Key name to store",
4355
- required: true
4356
- },
4357
- value: {
4358
- type: "positional",
4359
- description: "Value to store",
4360
- required: true
4361
- },
4362
- ttl: {
4363
- type: "string",
4364
- description: "Time to live in seconds (minimum 60 seconds)"
4365
- },
4366
- expiration: {
4367
- type: "string",
4368
- description: "Expiration timestamp (seconds since Unix epoch)"
4369
- },
4370
- binding: {
4371
- type: "string",
4372
- description: "KV binding name from wrangler.json (defaults to auto-detected or 'KV')"
4373
- },
4374
- namespaceId: {
4375
- type: "string",
4376
- description: "KV namespace ID"
4377
- },
4378
- local: {
4379
- type: "boolean",
4380
- description: "Interact with local development KV store",
4381
- default: false
4585
+ name: {
4586
+ type: "string",
4587
+ description: "Cloudflare Worker script name"
4382
4588
  },
4383
- remote: {
4384
- type: "boolean",
4385
- description: "Interact with remote Cloudflare KV store",
4386
- default: false
4589
+ env: {
4590
+ type: "string",
4591
+ description: "Cloudflare Worker environment"
4387
4592
  },
4388
4593
  cwd: {
4389
4594
  type: "string",
@@ -4393,53 +4598,42 @@ const set = defineCommand({
4393
4598
  },
4394
4599
  async run({ args }) {
4395
4600
  const cwd = resolve(process.cwd(), args.cwd);
4396
- loadDotEnv$1(cwd);
4397
4601
  await ensurePackage("wrangler", {
4398
4602
  cwd,
4399
- purpose: "managing Cloudflare KV"
4603
+ purpose: "listing Cloudflare Worker secrets"
4400
4604
  });
4401
- const wrangler = getWranglerBin$2(cwd);
4402
- const targetArgs = resolveKvTargetArgs(cwd, args);
4403
- const wranglerArgs = ["kv", "key", "put", args.key, args.value, ...targetArgs];
4404
- if (args.ttl) {
4405
- wranglerArgs.push("--ttl", args.ttl);
4406
- }
4407
- if (args.expiration) {
4408
- wranglerArgs.push("--expiration", args.expiration);
4409
- }
4410
- console.log(`\u26A1 [qarpeo] Setting KV key "${args.key}"...`);
4411
- const result = spawnSync(wrangler, wranglerArgs, {
4605
+ const wrangler = getWranglerBin$1(cwd);
4606
+ console.log("\n\u{1F50D} [qarpeo] Fetching Cloudflare Worker secrets list...");
4607
+ const listArgs = ["secret", "list"];
4608
+ if (args.env) listArgs.push("--env", args.env);
4609
+ const res = spawnBinSync(wrangler, listArgs, {
4412
4610
  cwd,
4413
- stdio: "inherit",
4414
- env: process.env,
4415
- shell: process.platform === "win32"
4611
+ stdio: "inherit"
4416
4612
  });
4417
- if (result.status !== 0) {
4418
- process.exit(result.status ?? 1);
4613
+ if (res.status !== 0) {
4614
+ console.error("\n\u274C [qarpeo] Failed to retrieve secrets from Cloudflare.");
4615
+ process.exit(res.status ?? 1);
4419
4616
  }
4617
+ console.log(
4618
+ "\n\u{1F4A1} Note: Cloudflare encrypted secrets cannot be downloaded in plaintext for security."
4619
+ );
4620
+ console.log(" The list above displays the secrets currently active on the edge.\n");
4420
4621
  }
4421
4622
  });
4422
-
4423
- const kv = defineCommand({
4623
+ const secret = defineCommand({
4424
4624
  meta: {
4425
- name: "kv",
4426
- description: "Manage Cloudflare Workers KV key-value storage"
4625
+ name: "secret",
4626
+ description: "Manage and synchronize encrypted Cloudflare Workers secrets with .env"
4427
4627
  },
4428
4628
  subCommands: {
4429
- list: list$1,
4430
- ls: list$1,
4431
- get,
4432
- set,
4433
- put: set,
4434
- delete: deleteKv,
4435
- del: deleteKv,
4436
- rm: deleteKv,
4437
- namespaces,
4438
- ns: namespaces
4629
+ push: pushSecret,
4630
+ pull: pullSecret,
4631
+ list: pullSecret,
4632
+ ls: pullSecret
4439
4633
  }
4440
4634
  });
4441
4635
 
4442
- function getWranglerBin$1(cwd) {
4636
+ function getWranglerBin(cwd) {
4443
4637
  return resolveBinaryPath("wrangler", cwd) || resolveBinaryPath("wrangler") || (process.platform === "win32" ? "wrangler.cmd" : "wrangler");
4444
4638
  }
4445
4639
  function loadDotEnv(cwd) {
@@ -4525,7 +4719,7 @@ const buckets = defineCommand({
4525
4719
  cwd,
4526
4720
  purpose: "managing Cloudflare R2 / Storage"
4527
4721
  });
4528
- const wrangler = getWranglerBin$1(cwd);
4722
+ const wrangler = getWranglerBin(cwd);
4529
4723
  console.log(`\u{1F4CB} [qarpeo] Fetching Cloudflare R2 buckets...
4530
4724
  `);
4531
4725
  const wranglerArgs = ["r2", "bucket", "list"];
@@ -4586,7 +4780,7 @@ const deleteStorage = defineCommand({
4586
4780
  cwd,
4587
4781
  purpose: "managing Cloudflare R2 / Storage"
4588
4782
  });
4589
- const wrangler = getWranglerBin$1(cwd);
4783
+ const wrangler = getWranglerBin(cwd);
4590
4784
  const bucket = resolveStorageBucket(cwd, args);
4591
4785
  console.log(`\u{1F5D1}\uFE0F [qarpeo] Deleting "${bucket}/${args.key}" from storage...`);
4592
4786
  const wranglerArgs = ["r2", "object", "delete", `${bucket}/${args.key}`];
@@ -4655,19 +4849,10 @@ const download = defineCommand({
4655
4849
  cwd,
4656
4850
  purpose: "managing Cloudflare R2 / Storage"
4657
4851
  });
4658
- const wrangler = getWranglerBin$1(cwd);
4852
+ const wrangler = getWranglerBin(cwd);
4659
4853
  const bucket = resolveStorageBucket(cwd, args);
4660
- console.log(
4661
- `\u2B07\uFE0F [qarpeo] Downloading "${bucket}/${args.key}" to "${destinationFile}"...`
4662
- );
4663
- const wranglerArgs = [
4664
- "r2",
4665
- "object",
4666
- "get",
4667
- `${bucket}/${args.key}`,
4668
- "--file",
4669
- destinationFile
4670
- ];
4854
+ console.log(`\u2B07\uFE0F [qarpeo] Downloading "${bucket}/${args.key}" to "${destinationFile}"...`);
4855
+ const wranglerArgs = ["r2", "object", "get", `${bucket}/${args.key}`, "--file", destinationFile];
4671
4856
  if (args.local) {
4672
4857
  wranglerArgs.push("--local");
4673
4858
  } else if (args.remote) {
@@ -4731,7 +4916,7 @@ const list = defineCommand({
4731
4916
  cwd,
4732
4917
  purpose: "managing Cloudflare R2 / Storage"
4733
4918
  });
4734
- const wrangler = getWranglerBin$1(cwd);
4919
+ const wrangler = getWranglerBin(cwd);
4735
4920
  const bucket = resolveStorageBucket(cwd, args);
4736
4921
  console.log(`\u{1F50D} [qarpeo] Listing objects in bucket "${bucket}"...`);
4737
4922
  const wranglerArgs = ["r2", "object", "list", bucket];
@@ -4811,11 +4996,9 @@ const upload = defineCommand({
4811
4996
  cwd,
4812
4997
  purpose: "managing Cloudflare R2 / Storage"
4813
4998
  });
4814
- const wrangler = getWranglerBin$1(cwd);
4999
+ const wrangler = getWranglerBin(cwd);
4815
5000
  const bucket = resolveStorageBucket(cwd, args);
4816
- console.log(
4817
- `\u2B06\uFE0F [qarpeo] Uploading "${args.file}" to "${bucket}/${destinationKey}"...`
4818
- );
5001
+ console.log(`\u2B06\uFE0F [qarpeo] Uploading "${args.file}" to "${bucket}/${destinationKey}"...`);
4819
5002
  const wranglerArgs = [
4820
5003
  "r2",
4821
5004
  "object",
@@ -4860,179 +5043,6 @@ const storage = defineCommand({
4860
5043
  }
4861
5044
  });
4862
5045
 
4863
- function getWranglerBin(cwd) {
4864
- return resolveBinaryPath("wrangler", cwd) || resolveBinaryPath("wrangler") || (process.platform === "win32" ? "wrangler.cmd" : "wrangler");
4865
- }
4866
- function parseDotEnv(cwd) {
4867
- const envPath = join(cwd, ".env");
4868
- if (!existsSync(envPath)) return {};
4869
- const result = {};
4870
- try {
4871
- const raw = readFileSync(envPath, "utf8");
4872
- for (const line of raw.split(/\r?\n/)) {
4873
- const trimmed = line.trim();
4874
- if (!trimmed || trimmed.startsWith("#")) continue;
4875
- const eqIdx = trimmed.indexOf("=");
4876
- if (eqIdx === -1) continue;
4877
- const key = trimmed.slice(0, eqIdx).trim();
4878
- let val = trimmed.slice(eqIdx + 1).trim();
4879
- if (val.startsWith('"') && val.endsWith('"') || val.startsWith("'") && val.endsWith("'")) {
4880
- val = val.slice(1, -1);
4881
- }
4882
- result[key] = val;
4883
- }
4884
- } catch {
4885
- }
4886
- return result;
4887
- }
4888
- function isSecretKey(key) {
4889
- const upper = key.toUpperCase();
4890
- if (upper.startsWith("QARPEO_") && (upper.endsWith("_ID") || upper.endsWith("_BINDING") || upper.endsWith("_BUCKET") || upper.endsWith("_NAME"))) {
4891
- return false;
4892
- }
4893
- if (upper === "CLOUDFLARE_ACCOUNT_ID" || upper === "CF_ACCOUNT_ID") return false;
4894
- if (upper === "NODE_ENV" || upper === "PORT" || upper === "HOST") return false;
4895
- 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");
4896
- }
4897
- const pushSecret = defineCommand({
4898
- meta: {
4899
- name: "push",
4900
- description: "Sync secrets from local .env directly to Cloudflare Workers secrets"
4901
- },
4902
- args: {
4903
- name: {
4904
- type: "string",
4905
- description: "Cloudflare Worker script name (defaults to project name in package.json)"
4906
- },
4907
- env: {
4908
- type: "string",
4909
- description: "Cloudflare Worker environment (e.g. production, preview)"
4910
- },
4911
- cwd: {
4912
- type: "string",
4913
- description: "Working directory",
4914
- default: "."
4915
- }
4916
- },
4917
- async run({ args }) {
4918
- const cwd = resolve(process.cwd(), args.cwd);
4919
- const envVars = parseDotEnv(cwd);
4920
- const secretEntries = Object.entries(envVars).filter(([k]) => isSecretKey(k));
4921
- if (secretEntries.length === 0) {
4922
- console.log("\u2139\uFE0F [qarpeo] No secret keys detected in .env to synchronize.");
4923
- return;
4924
- }
4925
- console.log(
4926
- `
4927
- \u{1F510} [qarpeo] Found ${secretEntries.length} secrets to synchronize with Cloudflare Workers:`
4928
- );
4929
- for (const [k] of secretEntries) {
4930
- console.log(` \u2022 ${k}`);
4931
- }
4932
- await ensurePackage("wrangler", {
4933
- cwd,
4934
- purpose: "pushing Cloudflare Worker secrets"
4935
- });
4936
- const wrangler = getWranglerBin(cwd);
4937
- const secretJson = {};
4938
- for (const [k, v] of secretEntries) {
4939
- secretJson[k] = v;
4940
- }
4941
- console.log("\n\u{1F680} [qarpeo] Uploading secrets via wrangler secret:bulk...");
4942
- const wranglerArgs = ["secret:bulk"];
4943
- if (args.env) wranglerArgs.push("--env", args.env);
4944
- const res = spawnBinSync(wrangler, wranglerArgs, {
4945
- cwd,
4946
- input: JSON.stringify(secretJson),
4947
- encoding: "utf8"
4948
- });
4949
- if (res.status === 0) {
4950
- console.log("\n\u2705 [qarpeo] All secrets synchronized successfully with Cloudflare Workers!\n");
4951
- } else {
4952
- console.log("\u2139\uFE0F [qarpeo] Falling back to individual `wrangler secret put`...");
4953
- let failed = 0;
4954
- for (const [k, v] of secretEntries) {
4955
- const putArgs = ["secret", "put", k];
4956
- if (args.env) putArgs.push("--env", args.env);
4957
- const putRes = spawnBinSync(wrangler, putArgs, {
4958
- cwd,
4959
- input: v,
4960
- encoding: "utf8"
4961
- });
4962
- if (putRes.status === 0) {
4963
- console.log(` \u2714 Synced ${k}`);
4964
- } else {
4965
- console.error(` \u2716 Failed to sync ${k}`);
4966
- failed++;
4967
- }
4968
- }
4969
- if (failed === 0) {
4970
- console.log("\n\u2705 [qarpeo] All secrets synchronized successfully!\n");
4971
- } else {
4972
- console.error(`
4973
- \u26A0\uFE0F [qarpeo] Completed with ${failed} failed secret(s).
4974
- `);
4975
- }
4976
- }
4977
- }
4978
- });
4979
- const pullSecret = defineCommand({
4980
- meta: {
4981
- name: "pull",
4982
- description: "List or pull Cloudflare Worker secrets into a local .env.local file"
4983
- },
4984
- args: {
4985
- name: {
4986
- type: "string",
4987
- description: "Cloudflare Worker script name"
4988
- },
4989
- env: {
4990
- type: "string",
4991
- description: "Cloudflare Worker environment"
4992
- },
4993
- cwd: {
4994
- type: "string",
4995
- description: "Working directory",
4996
- default: "."
4997
- }
4998
- },
4999
- async run({ args }) {
5000
- const cwd = resolve(process.cwd(), args.cwd);
5001
- await ensurePackage("wrangler", {
5002
- cwd,
5003
- purpose: "listing Cloudflare Worker secrets"
5004
- });
5005
- const wrangler = getWranglerBin(cwd);
5006
- console.log("\n\u{1F50D} [qarpeo] Fetching Cloudflare Worker secrets list...");
5007
- const listArgs = ["secret", "list"];
5008
- if (args.env) listArgs.push("--env", args.env);
5009
- const res = spawnBinSync(wrangler, listArgs, {
5010
- cwd,
5011
- stdio: "inherit"
5012
- });
5013
- if (res.status !== 0) {
5014
- console.error("\n\u274C [qarpeo] Failed to retrieve secrets from Cloudflare.");
5015
- process.exit(res.status ?? 1);
5016
- }
5017
- console.log(
5018
- "\n\u{1F4A1} Note: Cloudflare encrypted secrets cannot be downloaded in plaintext for security."
5019
- );
5020
- console.log(" The list above displays the secrets currently active on the edge.\n");
5021
- }
5022
- });
5023
- const secret = defineCommand({
5024
- meta: {
5025
- name: "secret",
5026
- description: "Manage and synchronize encrypted Cloudflare Workers secrets with .env"
5027
- },
5028
- subCommands: {
5029
- push: pushSecret,
5030
- pull: pullSecret,
5031
- list: pullSecret,
5032
- ls: pullSecret
5033
- }
5034
- });
5035
-
5036
5046
  function scanTaskDir(dir, rootDir) {
5037
5047
  const results = [];
5038
5048
  let entries;