@statikapi/adapter-cf
Advanced tools
+12
-30
@@ -7,4 +7,8 @@ #!/usr/bin/env node | ||
| import { bundle } from '../src/node/bundle.js'; | ||
| import { seedRemoteBuild, triggerRemoteBuild } from '../src/node/deploy.js'; | ||
| import { loadLocalEnv, refreshPreviewPrivateOutputs, startPreviewServer } from '../src/node/preview.js'; | ||
| import { formatManualSeedInstructions, triggerRemoteBuild } from '../src/node/deploy.js'; | ||
| import { | ||
| loadLocalEnv, | ||
| refreshPreviewPrivateOutputs, | ||
| startPreviewServer, | ||
| } from '../src/node/preview.js'; | ||
@@ -55,3 +59,3 @@ function parseArgs(argv) { | ||
| ` statikapi-cf dev [--cwd DIR] [--src src-api] [--out dist/worker.mjs] [--public-out public] [--host 127.0.0.1] [--port 8788] [--worker-port 8787] [--poll-ms 750] [--no-open]\n` + | ||
| ` statikapi-cf deploy [--cwd DIR] [--src src-api] [--out dist/worker.mjs] [--public-out public] [--worker https://your-app.example.com]\n` + | ||
| ` statikapi-cf deploy [--cwd DIR] [--src src-api] [--out dist/worker.mjs] [--public-out public]\n` + | ||
| ` statikapi-cf rebuild --worker https://your-app.example.com [--route /users/1] [--cwd DIR]\n` + | ||
@@ -134,3 +138,5 @@ `Auto-detects src from wrangler.toml [vars] STATIK_SRC and public assets directory from [assets].directory when present.` | ||
| const child = spawnWranglerProcess(args, cwd, env); | ||
| const code = await new Promise((resolve) => child.once('exit', (exitCode) => resolve(exitCode ?? 0))); | ||
| const code = await new Promise((resolve) => | ||
| child.once('exit', (exitCode) => resolve(exitCode ?? 0)) | ||
| ); | ||
| if (code !== 0) { | ||
@@ -399,4 +405,2 @@ throw new Error(`wrangler ${args.join(' ')} exited with code ${code}`); | ||
| useIndexJson, | ||
| workerOrigin, | ||
| buildToken, | ||
| env, | ||
@@ -415,24 +419,4 @@ }) { | ||
| if (!workerOrigin) { | ||
| console.log( | ||
| 'statikapi-cf deploy → public assets were rebuilt and deployed. To seed private outputs now, run `statikapi-cf rebuild --worker https://your-app.example.com` or set `STATIK_DEPLOY_ORIGIN` in `.dev.vars` before deploy.' | ||
| ); | ||
| return; | ||
| } | ||
| const seeded = await seedRemoteBuild(workerOrigin, buildToken, '/'); | ||
| if (seeded.seeded) { | ||
| console.log(`statikapi-cf deploy → seeded private outputs via ${workerOrigin}`); | ||
| return; | ||
| } | ||
| if (seeded.skipped) { | ||
| console.warn( | ||
| `statikapi-cf deploy → skipped private output seeding: ${seeded.reason}. Set deployed Worker secrets in Cloudflare, then seed manually with \`statikapi-cf rebuild --worker ${workerOrigin}\`.` | ||
| ); | ||
| return; | ||
| } | ||
| console.warn( | ||
| `statikapi-cf deploy → deployed successfully, but private output seeding failed (${seeded.error?.status || seeded.error?.message || 'unknown error'}). Set deployed Worker secrets in Cloudflare, then seed manually with \`statikapi-cf rebuild --worker ${workerOrigin}\`.` | ||
| console.log( | ||
| `statikapi-cf deploy → public assets were rebuilt and deployed.\n\n${formatManualSeedInstructions()}` | ||
| ); | ||
@@ -520,4 +504,2 @@ } | ||
| useIndexJson, | ||
| workerOrigin, | ||
| buildToken, | ||
| env: childEnv, | ||
@@ -524,0 +506,0 @@ }); |
+1
-1
| { | ||
| "name": "@statikapi/adapter-cf", | ||
| "version": "1.0.0-rc.5", | ||
| "version": "1.0.0-rc.6", | ||
| "type": "module", | ||
@@ -5,0 +5,0 @@ "bin": { |
+12
-2
@@ -332,6 +332,8 @@ import fs from 'node:fs/promises'; | ||
| function publicManifestEntryFor(sourceRoute, concreteRoute, filePath, body) { | ||
| function publicManifestEntryFor(sourceRoute, concreteRoute, filePath, body, policy) { | ||
| return { | ||
| route: concreteRoute === '/' ? '/public' : '/public' + concreteRoute, | ||
| srcRoute: sourceRoute, | ||
| webhookAvailable: policy?.webhook === true, | ||
| webhookRoute: sourceRoute, | ||
| filePath, | ||
@@ -365,3 +367,9 @@ bytes: new TextEncoder().encode(body).length, | ||
| const manifestEntry = publicManifestEntryFor(entry.route, output.route, displayKey, body); | ||
| const manifestEntry = publicManifestEntryFor( | ||
| entry.route, | ||
| output.route, | ||
| displayKey, | ||
| body, | ||
| policy | ||
| ); | ||
| manifestEntry.hash = await textHash(body); | ||
@@ -974,2 +982,4 @@ const owner = owners.get(manifestEntry.route); | ||
| srcRoute: sourceRoute, | ||
| webhookAvailable: policy.webhook === true, | ||
| webhookRoute: sourceRoute, | ||
| filePath: written.key, | ||
@@ -976,0 +986,0 @@ bytes: written.bytes, |
+15
-0
@@ -30,2 +30,17 @@ export async function triggerRemoteBuild(workerOrigin, buildToken, routePath = '/') { | ||
| export function formatManualSeedInstructions(workerUrl = 'YOUR_WORKER_URL') { | ||
| const origin = String(workerUrl || '').trim() || 'YOUR_WORKER_URL'; | ||
| return [ | ||
| 'To seed private outputs manually, send a POST request to your deployed Worker.', | ||
| '', | ||
| 'Example:', | ||
| '', | ||
| `curl -X POST "${origin}/" \\`, | ||
| ' -H "Authorization: Bearer YOUR_STATIK_BUILD_TOKEN"', | ||
| '', | ||
| 'Use `STATIK_BUILD_TOKEN` for this POST request.', | ||
| '`STATIK_PRIVATE_AUTH_HEADER_NAME` and `STATIK_PRIVATE_AUTH_HEADER_VALUE` are for private reads, not for seeding.', | ||
| ].join('\n'); | ||
| } | ||
| export async function seedRemoteBuild(workerOrigin, buildToken, routePath = '/') { | ||
@@ -32,0 +47,0 @@ const origin = String(workerOrigin || '').replace(/\/+$/, ''); |
@@ -21,3 +21,8 @@ import http from 'node:http'; | ||
| const ensurePrivateOutputs = createPrivateOutputPrimer(workerOrigin, localEnv, buildToken); | ||
| const loadManifestForUi = createPreviewManifestLoader(workerOrigin, uiMeta, localEnv, ensurePrivateOutputs); | ||
| const loadManifestForUi = createPreviewManifestLoader( | ||
| workerOrigin, | ||
| uiMeta, | ||
| localEnv, | ||
| ensurePrivateOutputs | ||
| ); | ||
| const sseClients = new Set(); | ||
@@ -214,3 +219,4 @@ let lastManifest = null; | ||
| export async function refreshPreviewPrivateOutputs(workerOrigin, localEnv = {}, options = {}) { | ||
| const buildToken = options.buildToken || localEnv.STATIK_BUILD_TOKEN || process.env.STATIK_BUILD_TOKEN; | ||
| const buildToken = | ||
| options.buildToken || localEnv.STATIK_BUILD_TOKEN || process.env.STATIK_BUILD_TOKEN; | ||
| if (!buildToken) return false; | ||
@@ -305,5 +311,3 @@ | ||
| const raw = await fs.readFile(wranglerPath, 'utf8'); | ||
| return ( | ||
| readTomlVar(raw, 'STATIK_BUILD_TOKEN') || process.env.STATIK_BUILD_TOKEN || '' | ||
| ); | ||
| return readTomlVar(raw, 'STATIK_BUILD_TOKEN') || process.env.STATIK_BUILD_TOKEN || ''; | ||
| } catch { | ||
@@ -310,0 +314,0 @@ return process.env.STATIK_BUILD_TOKEN || ''; |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
3295
0.4%1269815
-0.02%