@coreframe/scripts 0.1.39 → 0.1.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/runner.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as cmdts from "cmd-ts";
1
+ import * as cmdts from "@alloc/cmd-ts";
2
2
 
3
3
  //#region runner.d.ts
4
4
  type CliErrorReporterOptions = {
package/dist/runner.js CHANGED
@@ -1 +1 @@
1
- import{join as e}from"node:path";import{tmpdir as t}from"node:os";import*as n from"cmd-ts";import{mkdtempSync as r,writeFileSync as i}from"node:fs";import{inspect as a}from"node:util";function o(n,{formatMessage:a,temporaryDirectory:o=t(),write:s=e=>console.error(e)}={}){let u=f(n),d=m(c(n,a),u);try{let t=e(r(e(o,`coreframe-error-`)),`error.log`);return i(t,`${m(l(n),u)}\n`,{mode:384}),s(`Error: ${d}\nFull diagnostic: ${t}`),t}catch{s(`Error: ${d}\nThe full diagnostic could not be written to the temporary directory.`);return}}function s(e,t={}){let r=typeof e==`function`?e:()=>n.run(n.binary(e),process.argv),i=!1,a=e=>{i||(i=!0,o(e,t),process.exit(1))};process.once(`uncaughtException`,a),process.once(`unhandledRejection`,a),Promise.resolve().then(r).catch(a)}function c(e,t){try{return t?.(e)||(e instanceof Error?e.message:String(e)).split(/\r?\n/,1)[0]||`Unknown error`}catch{return`Unknown error`}}function l(e){try{let t=u(e);if(!(e instanceof Error)||!d(t))return a(t,{customInspect:!1,depth:10});let n=typeof t.stack==`string`?t.stack:`${e.name}: ${e.message}`;return delete t.name,delete t.message,delete t.stack,`${n}${Reflect.ownKeys(t).length?`\n${a(t,{customInspect:!1,depth:10})}`:``}`}catch{return`The thrown value could not be inspected.`}}function u(e,t=new WeakMap){if((typeof e!=`object`||!e)&&typeof e!=`function`)return e;let n=e,r=t.get(n);if(r)return r;if(typeof e==`function`)return`[Function${e.name?`: ${e.name}`:``}]`;let i=Array.isArray(e)?[]:{};t.set(n,i),e instanceof Error&&(i.name=e.name,i.message=e.message,i.stack=e.stack??`${e.name}: ${e.message}`);for(let r of Reflect.ownKeys(n)){if(typeof r!=`string`||r.toLowerCase()===`env`||Array.isArray(e)&&r===`length`||e instanceof Error&&(r===`name`||r===`message`||r===`stack`))continue;let a=Object.getOwnPropertyDescriptor(n,r);!a||!(`value`in a)||Object.defineProperty(i,r,{configurable:!0,enumerable:!0,value:u(a.value,t),writable:!0})}return i}function d(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function f(e,t=new WeakSet){let n=new Set;function r(e){if((typeof e!=`object`||!e)&&typeof e!=`function`)return;let i=e;if(!t.has(i)){t.add(i);for(let e of Reflect.ownKeys(i)){if(typeof e!=`string`)continue;let t=Object.getOwnPropertyDescriptor(i,e);!t||!(`value`in t)||(e.toLowerCase()===`env`?p(t.value,n):r(t.value))}}}try{r(e)}catch{}return n}function p(e,t){if(!(typeof e!=`object`||!e))for(let n of Reflect.ownKeys(e)){let r=Object.getOwnPropertyDescriptor(e,n);r&&`value`in r&&typeof r.value==`string`&&r.value&&t.add(r.value)}}function m(e,t){return[...t].sort((e,t)=>t.length-e.length).reduce((e,t)=>e.replaceAll(t,`[redacted environment value]`),e)}export{o as reportCliError,s as run};
1
+ import{join as e}from"node:path";import{mkdtempSync as t,writeFileSync as n}from"node:fs";import{tmpdir as r}from"node:os";import*as i from"@alloc/cmd-ts";import{inspect as a}from"node:util";function o(i,{formatMessage:a,temporaryDirectory:o=r(),write:s=e=>console.error(e)}={}){let u=f(i),d=m(c(i,a),u);try{let r=e(t(e(o,`coreframe-error-`)),`error.log`);return n(r,`${m(l(i),u)}\n`,{mode:384}),s(`Error: ${d}\nFull diagnostic: ${r}`),r}catch{s(`Error: ${d}\nThe full diagnostic could not be written to the temporary directory.`);return}}function s(e,t={}){let n=typeof e==`function`?e:()=>i.run(i.binary(e),process.argv),r=!1,a=e=>{r||(r=!0,o(e,t),process.exit(1))};process.once(`uncaughtException`,a),process.once(`unhandledRejection`,a),Promise.resolve().then(n).catch(a)}function c(e,t){try{return t?.(e)||(e instanceof Error?e.message:String(e)).split(/\r?\n/,1)[0]||`Unknown error`}catch{return`Unknown error`}}function l(e){try{let t=u(e);if(!(e instanceof Error)||!d(t))return a(t,{customInspect:!1,depth:10});let n=typeof t.stack==`string`?t.stack:`${e.name}: ${e.message}`;return delete t.name,delete t.message,delete t.stack,`${n}${Reflect.ownKeys(t).length?`\n${a(t,{customInspect:!1,depth:10})}`:``}`}catch{return`The thrown value could not be inspected.`}}function u(e,t=new WeakMap){if((typeof e!=`object`||!e)&&typeof e!=`function`)return e;let n=e,r=t.get(n);if(r)return r;if(typeof e==`function`)return`[Function${e.name?`: ${e.name}`:``}]`;let i=Array.isArray(e)?[]:{};t.set(n,i),e instanceof Error&&(i.name=e.name,i.message=e.message,i.stack=e.stack??`${e.name}: ${e.message}`);for(let r of Reflect.ownKeys(n)){if(typeof r!=`string`||r.toLowerCase()===`env`||Array.isArray(e)&&r===`length`||e instanceof Error&&(r===`name`||r===`message`||r===`stack`))continue;let a=Object.getOwnPropertyDescriptor(n,r);!a||!(`value`in a)||Object.defineProperty(i,r,{configurable:!0,enumerable:!0,value:u(a.value,t),writable:!0})}return i}function d(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function f(e,t=new WeakSet){let n=new Set;function r(e){if((typeof e!=`object`||!e)&&typeof e!=`function`)return;let i=e;if(!t.has(i)){t.add(i);for(let e of Reflect.ownKeys(i)){if(typeof e!=`string`)continue;let t=Object.getOwnPropertyDescriptor(i,e);!t||!(`value`in t)||(e.toLowerCase()===`env`?p(t.value,n):r(t.value))}}}try{r(e)}catch{}return n}function p(e,t){if(!(typeof e!=`object`||!e))for(let n of Reflect.ownKeys(e)){let r=Object.getOwnPropertyDescriptor(e,n);r&&`value`in r&&typeof r.value==`string`&&r.value&&t.add(r.value)}}function m(e,t){return[...t].sort((e,t)=>t.length-e.length).reduce((e,t)=>e.replaceAll(t,`[redacted environment value]`),e)}export{o as reportCliError,s as run};
@@ -1,2 +1,2 @@
1
- import{mkdtemp as e}from"node:fs/promises";import t from"node:path";import{tmpdir as n}from"node:os";import{createWriteStream as r}from"node:fs";import{stripVTControlCharacters as i}from"node:util";import{once as a}from"node:events";import{finished as o}from"node:stream/promises";async function s({output:i,temporaryDirectory:o=n()}){let s=await e(t.join(o,`coreframe-ios-dev-`)),l=t.join(s,`tauri.log`),u=r(l,{flags:`wx`,mode:384});return await a(u,`open`),new c(l,u,i)}var c=class{logFile;closed=!1;failureLines=[];log;output;runtime=!1;showInstalledBundleId=!1;constructor(e,t,n){this.logFile=e,this.log=t,this.output=n}async consume(e){try{for await(let t of e)await d(this.log,`${t}\n`),this.rememberFailureLine(t),this.shouldShow(t)&&await d(this.output,`${t}\n`)}catch{}}async reportFailure(){await d(this.output,`iOS development failed. Recent diagnostic output:
2
- `);for(let e of this.failureLines)await d(this.output,`${e}\n`);await d(this.output,`Full iOS log: ${this.logFile}\n`)}async close(){this.closed||(this.closed=!0,this.log.end(),await o(this.log))}shouldShow(e){let t=i(e).trim();if(t===`Building app...`)return this.runtime=!1,!0;if(l(t))return!1;if(t.startsWith(`Launched application with `))return this.runtime=!0,!0;if(this.runtime)return!0;if(t===`App installed:`)return this.showInstalledBundleId=!0,!0;if(this.showInstalledBundleId){if(t.length===0)return!1;if(this.showInstalledBundleId=!1,t.startsWith(`• bundleID:`))return!0}return/^(Archiving app|Exporting app|Extracting IPA|Deploying app to device|Pairing with device)\.\.\.$/u.test(t)||/^\*\* BUILD (?:SUCCEEDED|FAILED) \*\*$/u.test(t)||/^(?:Compiling|Checking|Finished)\b/u.test(t)||/^(?:Warn|Error)\b/u.test(t)||/(?:^|:\d+:\d+: )(?:warning|error)(?:\[[^\]]+\])?:/iu.test(t)||/^(?:fatal:|thread .+ panicked|Failed to |No device found\.|The following build commands failed:|command \[.+\] exited)/iu.test(t)||/^Info Watching\b/u.test(t)||/^note: run with RUST_BACKTRACE=/u.test(t)}rememberFailureLine(e){u(i(e).trim())||(this.failureLines.push(e),this.failureLines.length>40&&this.failureLines.shift())}};function l(e){return e.startsWith(`--- xcodebuild: WARNING: Using the first of multiple matching destinations:`)||/^Failed to load provisioning param(?:e)?ter list due to error:/u.test(e)||e==="`devicectl manage create` may support a reduced set of arguments."||/(?:^|\/)idevicesyslog$/u.test(e)}function u(e){return e.length===0||e.startsWith(`export `)||e.startsWith(`inflating:`)||e.startsWith(`Archive:`)||e.startsWith(`cd `)||e.startsWith(`/bin/sh -c `)||e.startsWith(`Command line invocation:`)||e.startsWith(`Build settings from command line:`)}async function d(e,t){e.write(t)||await a(e,`drain`)}export{s as createTauriDevOutput};
1
+ import{mkdtemp as e}from"node:fs/promises";import t from"node:path";import{createWriteStream as n}from"node:fs";import{tmpdir as r}from"node:os";import{finished as i}from"node:stream/promises";import{stripVTControlCharacters as a}from"node:util";import{once as o}from"node:events";async function s({output:i,temporaryDirectory:a=r()}){let s=await e(t.join(a,`coreframe-ios-dev-`)),l=t.join(s,`tauri.log`),u=n(l,{flags:`wx`,mode:384});return await o(u,`open`),new c(l,u,i)}var c=class{logFile;closed=!1;failureLines=[];log;output;runtime=!1;showInstalledBundleId=!1;constructor(e,t,n){this.logFile=e,this.log=t,this.output=n}async consume(e){try{for await(let t of e)await d(this.log,`${t}\n`),this.rememberFailureLine(t),this.shouldShow(t)&&await d(this.output,`${t}\n`)}catch{}}async reportFailure(){await d(this.output,`iOS development failed. Recent diagnostic output:
2
+ `);for(let e of this.failureLines)await d(this.output,`${e}\n`);await d(this.output,`Full iOS log: ${this.logFile}\n`)}async close(){this.closed||(this.closed=!0,this.log.end(),await i(this.log))}shouldShow(e){let t=a(e).trim();if(t===`Building app...`)return this.runtime=!1,!0;if(l(t))return!1;if(t.startsWith(`Launched application with `))return this.runtime=!0,!0;if(this.runtime)return!0;if(t===`App installed:`)return this.showInstalledBundleId=!0,!0;if(this.showInstalledBundleId){if(t.length===0)return!1;if(this.showInstalledBundleId=!1,t.startsWith(`• bundleID:`))return!0}return/^(Archiving app|Exporting app|Extracting IPA|Deploying app to device|Pairing with device)\.\.\.$/u.test(t)||/^\*\* BUILD (?:SUCCEEDED|FAILED) \*\*$/u.test(t)||/^(?:Compiling|Checking|Finished)\b/u.test(t)||/^(?:Warn|Error)\b/u.test(t)||/(?:^|:\d+:\d+: )(?:warning|error)(?:\[[^\]]+\])?:/iu.test(t)||/^(?:fatal:|thread .+ panicked|Failed to |No device found\.|The following build commands failed:|command \[.+\] exited)/iu.test(t)||/^Info Watching\b/u.test(t)||/^note: run with RUST_BACKTRACE=/u.test(t)}rememberFailureLine(e){u(a(e).trim())||(this.failureLines.push(e),this.failureLines.length>40&&this.failureLines.shift())}};function l(e){return e.startsWith(`--- xcodebuild: WARNING: Using the first of multiple matching destinations:`)||/^Failed to load provisioning param(?:e)?ter list due to error:/u.test(e)||e==="`devicectl manage create` may support a reduced set of arguments."||/(?:^|\/)idevicesyslog$/u.test(e)}function u(e){return e.length===0||e.startsWith(`export `)||e.startsWith(`inflating:`)||e.startsWith(`Archive:`)||e.startsWith(`cd `)||e.startsWith(`/bin/sh -c `)||e.startsWith(`Command line invocation:`)||e.startsWith(`Build settings from command line:`)}async function d(e,t){e.write(t)||await o(e,`drain`)}export{s as createTauriDevOutput};
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{coreframeGitRef as e,coreframeTemplateFile as t}from"./template-ref.js";import{join as n}from"node:path";import{tmpdir as r}from"node:os";import{existsSync as i,mkdtempSync as a,readFileSync as o,rmSync as s,writeFileSync as c}from"node:fs";import{spawnSync as l}from"node:child_process";const u=`.agents/skills/coreframe-upgrade/SKILL.md`;function d(e,t={}){return l(`git`,e,t)}function f(e){return e.stderr.toString(`utf8`).trim()||e.stdout.toString(`utf8`).trim()}function p(e,n){let r=t(e,n),i=d([`show`,r],{encoding:`utf8`});if(i.status!==0){let e=f(i);throw Error(`Could not read ${r}.${e?` ${e}`:``}`)}return i.stdout.toString()}function m(){let e=d([`rev-parse`,`--show-toplevel`],{encoding:`utf8`});if(e.status!==0){let t=f(e);throw Error(`Could not find git repository root.${t?` ${t}`:``}`)}return e.stdout.toString().trim()}function h(e,t){let i=a(n(r(),`coreframe-upgrade-skill-`)),o=n(i,`SKILL.md`);try{c(o,t);let n=f(d([`--no-pager`,`diff`,`--no-index`,`--color=never`,`--`,e,o]));n&&console.log(n)}finally{s(i,{force:!0,recursive:!0})}}function g({apply:t,target:r}){let a=n(m(),u),s=e(r);if(!i(a))throw Error(`Local ${u} does not exist.`);let l=o(a,`utf8`),d=p(r,u);return l===d?(console.log(`Coreframe upgrade skill matches ${s}:template/${u}.`),0):t?(c(a,d),console.error(`Updated ${u} from ${s}:template. Reread it before continuing the upgrade.`),20):(console.error(`Coreframe upgrade skill differs from ${s}:template/${u}.`),console.error(`Run again with --apply to update it, then reread ${u} before continuing.`),h(a,d),20)}export{g as checkUpgradeSkillCurrent};
2
+ import{coreframeGitRef as e,coreframeTemplateFile as t}from"./template-ref.js";import{join as n}from"node:path";import{existsSync as r,mkdtempSync as i,readFileSync as a,rmSync as o,writeFileSync as s}from"node:fs";import{tmpdir as c}from"node:os";import{spawnSync as l}from"node:child_process";const u=`.agents/skills/coreframe-upgrade/SKILL.md`;function d(e,t={}){return l(`git`,e,t)}function f(e){return e.stderr.toString(`utf8`).trim()||e.stdout.toString(`utf8`).trim()}function p(e,n){let r=t(e,n),i=d([`show`,r],{encoding:`utf8`});if(i.status!==0){let e=f(i);throw Error(`Could not read ${r}.${e?` ${e}`:``}`)}return i.stdout.toString()}function m(){let e=d([`rev-parse`,`--show-toplevel`],{encoding:`utf8`});if(e.status!==0){let t=f(e);throw Error(`Could not find git repository root.${t?` ${t}`:``}`)}return e.stdout.toString().trim()}function h(e,t){let r=i(n(c(),`coreframe-upgrade-skill-`)),a=n(r,`SKILL.md`);try{s(a,t);let n=f(d([`--no-pager`,`diff`,`--no-index`,`--color=never`,`--`,e,a]));n&&console.log(n)}finally{o(r,{force:!0,recursive:!0})}}function g({apply:t,target:i}){let o=n(m(),u),c=e(i);if(!r(o))throw Error(`Local ${u} does not exist.`);let l=a(o,`utf8`),d=p(i,u);return l===d?(console.log(`Coreframe upgrade skill matches ${c}:template/${u}.`),0):t?(s(o,d),console.error(`Updated ${u} from ${c}:template. Reread it before continuing the upgrade.`),20):(console.error(`Coreframe upgrade skill differs from ${c}:template/${u}.`),console.error(`Run again with --apply to update it, then reread ${u} before continuing.`),h(o,d),20)}export{g as checkUpgradeSkillCurrent};
@@ -1 +1 @@
1
- import{readProjectConfig as e}from"./config.js";import{accessTokenSigningSecretName as t}from"./deploy/access-token-secret.js";import{deployEnvironments as n}from"./deploy/config.js";import{chmod as r,mkdir as i,readFile as a,rename as o,rm as s,stat as c,writeFile as l}from"node:fs/promises";import{resolve as u}from"node:path";import d from"nano-spawn";import{randomUUID as f}from"node:crypto";import{parseEnv as p}from"node:util";const m=[`secret`,`variable`,`generated`],h=/^[A-Z][A-Z0-9_]*$/,g=`.coreframe/deploy-secrets`;async function _({cwd:r=process.cwd(),environment:i,listSecrets:a=j}={}){let o=S((await e({cwd:r})).worker?.environment),s=await w(r),c=i?[i]:n,l=new Map,u=new Map,d=Object.fromEntries(n.map(e=>[e,{state:`not_checked`}]));await Promise.all(c.map(async e=>{if(u.set(e,new Set(Object.keys((await b({cwd:r,environment:e})).values))),o.some(e=>e.kind===`secret`))try{l.set(e,new Set(await a(e,r))),d[e]={state:`available`}}catch{d[e]={state:`unavailable`,message:`Could not read ${e} Worker secrets. Check Wrangler authentication and whether the Worker exists.`}}}));let f=new Set([t,...o.filter(e=>e.kind===`secret`).map(e=>e.name)]),p=Object.fromEntries(n.map(e=>[e,[...l.get(e)??[]].filter(e=>!f.has(e)).sort()]));return{entries:o.map(e=>({...e,local:s.has(e.name)?`override`:`default`,deployed:Object.fromEntries(n.map(t=>[t,T(e,t,d[t],l.get(t),u.get(t))]))})),providers:d,undeclaredSecrets:p}}async function v({cwd:e=process.cwd(),environment:t,name:n,value:r,ensureIgnored:i=O}){if(await C(e,n),!r.trim())throw Error(`Worker secret values cannot be empty.`);await i(t,e),await D(e,t,{...(await b({cwd:e,environment:t})).values,[n]:r})}async function y({cwd:e=process.cwd(),environment:t,name:n}){await C(e,n);let r=await b({cwd:e,environment:t});if(!(n in r.values))return!1;let i={...r.values};return delete i[n],await D(e,t,i),!0}async function b({cwd:t=process.cwd(),environment:n}){let r=await E(t,n),i=S((await e({cwd:t})).worker?.environment),a=new Set(i.filter(e=>e.kind===`secret`).map(e=>e.name)),o=Object.keys(r).filter(e=>!a.has(e));if(o.length>0)throw Error(`Pending ${n} Worker secrets are not declared as secrets in coreframe.config.ts: ${o.join(`, `)}.`);return{environment:n,values:r}}async function x(e,t=process.cwd()){let n=await E(t,e.environment),r=Object.fromEntries(Object.entries(n).filter(([t,n])=>e.values[t]!==n));await D(t,e.environment,r)}function S(e){return Object.entries(e??{}).map(([e,t])=>{if(!h.test(e))throw Error(`Invalid Worker environment name ${JSON.stringify(e)} in coreframe.config.ts. Use uppercase letters, numbers, and underscores.`);return{...t,name:e,requiredIn:[...new Set(t.requiredIn??[])]}}).sort((e,t)=>e.name.localeCompare(t.name))}async function C(t,n){let r=S((await e({cwd:t})).worker?.environment).find(e=>e.name===n);if(!r)throw Error(`${n} is not declared in coreframe.config.ts.`);if(r.kind!==`secret`)throw Error(`${n} is declared as ${r.kind}, not a Worker secret.`)}async function w(e){try{let t=p(await a(u(e,`.env`),`utf8`));return new Set(Object.entries(t).filter(([,e])=>!!e?.trim()).map(([e])=>e))}catch(e){if(M(e)&&e.code===`ENOENT`)return new Set;throw e}}function T(e,t,n,r,i){return e.kind===`generated`?`generated`:e.kind===`variable`?`declared`:i?.has(e.name)?n.state!==`available`||!r?`pending_update`:r.has(e.name)?`pending_replacement`:`pending_addition`:n.state!==`available`||!r?`unknown`:r.has(e.name)?`configured`:e.requiredIn.includes(t)?`missing`:`not_configured`}async function E(e,t){let n=k(e,t);try{let e=await c(n);if(process.platform!==`win32`&&e.mode&63)throw Error(`Pending Worker secret file ${n} must use mode 0600.`);let t=JSON.parse(await a(n,`utf8`));if(!A(t))throw Error(`Pending Worker secret file ${n} must contain a JSON object of strings.`);return t}catch(e){if(M(e)&&e.code===`ENOENT`)return{};throw e}}async function D(e,t,n){let a=k(e,t);if(Object.keys(n).length===0){await s(a,{force:!0});return}let c=u(e,g);await i(c,{mode:448,recursive:!0}),process.platform!==`win32`&&await r(c,448);let d=`${a}.${process.pid}.${f()}.tmp`;try{await l(d,`${JSON.stringify(n,null,2)}\n`,{flag:`wx`,mode:384}),await o(d,a)}finally{await s(d,{force:!0})}process.platform!==`win32`&&await r(a,384)}async function O(e,t){let n=`${g}/${e}.json`,r=`${g}/.coreframe-ignore-check`;try{await d(`git`,[`check-ignore`,`--quiet`,r],{cwd:t,stdin:`ignore`,stdout:`ignore`,stderr:`ignore`})}catch{throw Error(`Refusing to store plaintext Worker secrets because ${n} is not git-ignored. Add .coreframe/ to .gitignore.`)}}function k(e,t){return u(e,g,`${t}.json`)}function A(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.entries(e).every(([e,t])=>h.test(e)&&typeof t==`string`&&t.length>0)}async function j(e,t){let{stdout:n}=await d(`pnpm`,[`exec`,`wrangler`,`secret`,`list`,`--env`,e,`--format`,`json`],{cwd:t,env:{CI:`true`},stdin:`ignore`,timeout:5e3}),r=JSON.parse(n);if(!Array.isArray(r))throw Error(`Wrangler returned an invalid secret list.`);return r.flatMap(e=>e&&typeof e==`object`&&`name`in e&&typeof e.name==`string`?[e.name]:[])}function M(e){return e instanceof Error&&`code`in e}export{x as clearAppliedPendingWorkerSecrets,y as discardPendingWorkerSecret,_ as inspectWorkerEnvironment,v as queueWorkerSecret,b as readPendingWorkerSecretSnapshot,m as workerEnvironmentKinds};
1
+ import{readProjectConfig as e}from"./config.js";import{accessTokenSigningSecretName as t}from"./deploy/access-token-secret.js";import{deployEnvironments as n}from"./deploy/config.js";import{randomUUID as r}from"node:crypto";import{chmod as i,mkdir as a,readFile as o,rename as s,rm as c,stat as l,writeFile as u}from"node:fs/promises";import{resolve as d}from"node:path";import f from"nano-spawn";import{parseEnv as p}from"node:util";const m=[`secret`,`variable`,`generated`],h=/^[A-Z][A-Z0-9_]*$/,g=`.coreframe/deploy-secrets`;async function _({cwd:r=process.cwd(),environment:i,listSecrets:a=j}={}){let o=S((await e({cwd:r})).worker?.environment),s=await w(r),c=i?[i]:n,l=new Map,u=new Map,d=Object.fromEntries(n.map(e=>[e,{state:`not_checked`}]));await Promise.all(c.map(async e=>{if(u.set(e,new Set(Object.keys((await b({cwd:r,environment:e})).values))),o.some(e=>e.kind===`secret`))try{l.set(e,new Set(await a(e,r))),d[e]={state:`available`}}catch{d[e]={state:`unavailable`,message:`Could not read ${e} Worker secrets. Check Wrangler authentication and whether the Worker exists.`}}}));let f=new Set([t,...o.filter(e=>e.kind===`secret`).map(e=>e.name)]),p=Object.fromEntries(n.map(e=>[e,[...l.get(e)??[]].filter(e=>!f.has(e)).sort()]));return{entries:o.map(e=>({...e,local:s.has(e.name)?`override`:`default`,deployed:Object.fromEntries(n.map(t=>[t,T(e,t,d[t],l.get(t),u.get(t))]))})),providers:d,undeclaredSecrets:p}}async function v({cwd:e=process.cwd(),environment:t,name:n,value:r,ensureIgnored:i=O}){if(await C(e,n),!r.trim())throw Error(`Worker secret values cannot be empty.`);await i(t,e),await D(e,t,{...(await b({cwd:e,environment:t})).values,[n]:r})}async function y({cwd:e=process.cwd(),environment:t,name:n}){await C(e,n);let r=await b({cwd:e,environment:t});if(!(n in r.values))return!1;let i={...r.values};return delete i[n],await D(e,t,i),!0}async function b({cwd:t=process.cwd(),environment:n}){let r=await E(t,n),i=S((await e({cwd:t})).worker?.environment),a=new Set(i.filter(e=>e.kind===`secret`).map(e=>e.name)),o=Object.keys(r).filter(e=>!a.has(e));if(o.length>0)throw Error(`Pending ${n} Worker secrets are not declared as secrets in coreframe.config.ts: ${o.join(`, `)}.`);return{environment:n,values:r}}async function x(e,t=process.cwd()){let n=await E(t,e.environment),r=Object.fromEntries(Object.entries(n).filter(([t,n])=>e.values[t]!==n));await D(t,e.environment,r)}function S(e){return Object.entries(e??{}).map(([e,t])=>{if(!h.test(e))throw Error(`Invalid Worker environment name ${JSON.stringify(e)} in coreframe.config.ts. Use uppercase letters, numbers, and underscores.`);return{...t,name:e,requiredIn:[...new Set(t.requiredIn??[])]}}).sort((e,t)=>e.name.localeCompare(t.name))}async function C(t,n){let r=S((await e({cwd:t})).worker?.environment).find(e=>e.name===n);if(!r)throw Error(`${n} is not declared in coreframe.config.ts.`);if(r.kind!==`secret`)throw Error(`${n} is declared as ${r.kind}, not a Worker secret.`)}async function w(e){try{let t=p(await o(d(e,`.env`),`utf8`));return new Set(Object.entries(t).filter(([,e])=>!!e?.trim()).map(([e])=>e))}catch(e){if(M(e)&&e.code===`ENOENT`)return new Set;throw e}}function T(e,t,n,r,i){return e.kind===`generated`?`generated`:e.kind===`variable`?`declared`:i?.has(e.name)?n.state!==`available`||!r?`pending_update`:r.has(e.name)?`pending_replacement`:`pending_addition`:n.state!==`available`||!r?`unknown`:r.has(e.name)?`configured`:e.requiredIn.includes(t)?`missing`:`not_configured`}async function E(e,t){let n=k(e,t);try{let e=await l(n);if(process.platform!==`win32`&&e.mode&63)throw Error(`Pending Worker secret file ${n} must use mode 0600.`);let t=JSON.parse(await o(n,`utf8`));if(!A(t))throw Error(`Pending Worker secret file ${n} must contain a JSON object of strings.`);return t}catch(e){if(M(e)&&e.code===`ENOENT`)return{};throw e}}async function D(e,t,n){let o=k(e,t);if(Object.keys(n).length===0){await c(o,{force:!0});return}let l=d(e,g);await a(l,{mode:448,recursive:!0}),process.platform!==`win32`&&await i(l,448);let f=`${o}.${process.pid}.${r()}.tmp`;try{await u(f,`${JSON.stringify(n,null,2)}\n`,{flag:`wx`,mode:384}),await s(f,o)}finally{await c(f,{force:!0})}process.platform!==`win32`&&await i(o,384)}async function O(e,t){let n=`${g}/${e}.json`,r=`${g}/.coreframe-ignore-check`;try{await f(`git`,[`check-ignore`,`--quiet`,r],{cwd:t,stdin:`ignore`,stdout:`ignore`,stderr:`ignore`})}catch{throw Error(`Refusing to store plaintext Worker secrets because ${n} is not git-ignored. Add .coreframe/ to .gitignore.`)}}function k(e,t){return d(e,g,`${t}.json`)}function A(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.entries(e).every(([e,t])=>h.test(e)&&typeof t==`string`&&t.length>0)}async function j(e,t){let{stdout:n}=await f(`pnpm`,[`exec`,`wrangler`,`secret`,`list`,`--env`,e,`--format`,`json`],{cwd:t,env:{CI:`true`},stdin:`ignore`,timeout:5e3}),r=JSON.parse(n);if(!Array.isArray(r))throw Error(`Wrangler returned an invalid secret list.`);return r.flatMap(e=>e&&typeof e==`object`&&`name`in e&&typeof e.name==`string`?[e.name]:[])}function M(e){return e instanceof Error&&`code`in e}export{x as clearAppliedPendingWorkerSecrets,y as discardPendingWorkerSecret,_ as inspectWorkerEnvironment,v as queueWorkerSecret,b as readPendingWorkerSecretSnapshot,m as workerEnvironmentKinds};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coreframe/scripts",
3
- "version": "0.1.39",
3
+ "version": "0.1.41",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/airlock-labs/coreframe.git",
@@ -21,15 +21,19 @@
21
21
  }
22
22
  },
23
23
  "dependencies": {
24
+ "@alloc/cmd-ts": "0.17.1",
24
25
  "@aws-sdk/client-s3": "^3.1090.0",
25
26
  "@clack/prompts": "^1.6.0",
26
- "cmd-ts": "0.15.0",
27
+ "@vercel/detect-agent": "^1.2.3",
27
28
  "cross-keychain": "1.1.0",
28
29
  "drizzle-orm": "1.0.0-rc.4",
29
30
  "import-meta-resolve": "^4.2.0",
30
31
  "local-postgres": "0.3.1",
32
+ "mp4box": "^2.4.1",
33
+ "music-metadata": "^11.14.0",
31
34
  "nano-spawn": "^2.1.0",
32
- "procband": "^0.3.7",
35
+ "procband": "^0.3.8",
36
+ "saxes": "^6.0.0",
33
37
  "tinyglobby": "^0.2.17",
34
38
  "yaml": "^2.9.0"
35
39
  },