@coreframe/preview 0.1.8 → 0.1.10
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/cloudflare.js +1 -1
- package/package.json +3 -3
package/dist/cloudflare.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{keyring as e}from"./keyring.js";import{mkdir as t,mkdtemp as n,readFile as r,rm as i,writeFile as a}from"node:fs/promises";import{join as o}from"node:path";import s from"nano-spawn";import{tmpdir as c}from"node:os";const l=process.platform===`win32`?`cloudflared.exe`:`cloudflared`,u=`dev.coreframe.preview.cloudflare.account`,d=`dev.coreframe.preview.cloudflare.tunnel`;async function f({config:e,cwd:t,env:r=process.env,now:s=()=>new Date().toISOString(),run:l=j}){let u=await p({config:e,env:r,now:s,run:l}),d=await m({account:u,config:e,cwd:t,env:r,now:s,run:l});e.dns===`managed`&&await _({account:u,config:e,cwd:t,env:r,run:l,tunnel:d});let f=await n(o(c(),`coreframe-preview-tunnel-`)),h=o(f,`tunnel.json`),g=!1;try{await a(h,`${JSON.stringify(d.credentials)}\n`,{mode:384})}catch(e){throw await i(f,{force:!0,recursive:!0}),e}return{credentialsFile:h,async dispose(){g||(g=!0,await i(f,{force:!0,recursive:!0}))},tunnel:{name:d.name,profile:d.profile,tunnelId:d.tunnelId}}}async function p({config:t,env:n,now:r,run:i}){let a=await e.get(u,t.profile);if(a)return C(a,t.profile);console.log([`Cloudflare authentication is required for preview tunnel "${t.profile}/${t.name}".`,"Coreframe will run `cloudflared tunnel login` now.",`Follow the browser prompt or URL, sign in to Cloudflare, and authorize the zone for ${t.hostname}.`,`Coreframe will store the resulting credentials in your operating system credential store.`].join(` `));let o=await v({env:n,run:i}),s={createdAt:r(),profile:t.profile,originCertificate:o,version:1};return await e.set(u,t.profile,JSON.stringify(s)),s}async function m({account:t,config:n,cwd:r,env:i,now:a,run:o}){let s=A(n.profile,n.name),c=await e.get(d,s);if(c)return w(c,n);let l=(await h({account:t,cwd:r,env:i,run:o})).find(e=>e.name===n.name);if(l)throw Error(`Cloudflare tunnel "${n.name}" already exists as ${l.id}, but Coreframe has no Keychain credentials for it. Coreframe will not adopt an existing tunnel; choose a new preview.tunnel.name.`);let f=await g({account:t,config:n,cwd:r,env:i,run:o}),p={accountTag:f.AccountTag,createdAt:a(),credentials:f,hostname:n.hostname,name:n.name,profile:n.profile,tunnelId:f.TunnelID,version:1};return await e.set(d,s,JSON.stringify(p)),await e.set(u,n.profile,JSON.stringify({...t,lastAccountTag:p.accountTag,lastTunnelId:p.tunnelId,lastTunnelName:p.name})),p}async function h({account:e,cwd:t,env:n,run:r}){return y(e,async e=>D((await r([`tunnel`,`--origincert`,e,`list`,`--output`,`json`],{cwd:t,env:n})).stdout))}async function g({account:e,config:t,cwd:n,env:i,run:a}){return b(`coreframe-cloudflared-create-`,async s=>{let c=o(s,`cert.pem`),l=o(s,`tunnel.json`);return await x(c,e.originCertificate),await a([`tunnel`,`--origincert`,c,`create`,`--credentials-file`,l,t.name],{cwd:n,env:i}),T(E(await r(l,`utf8`),`tunnel credentials`))})}async function _({account:e,config:t,cwd:n,env:r,run:i,tunnel:a}){await y(e,async e=>{await i([`tunnel`,`--origincert`,e,`route`,`dns`,`--overwrite-dns`,a.tunnelId,t.hostname],{cwd:n,env:r})})}async function v({env:e,run:a}){let s=await n(o(c(),`coreframe-cloudflared-login-`)),l=o(s,`.cloudflared`);await t(l,{mode:448});try{await a([`tunnel`,`login`],{cwd:s,env:S(e,s),stdio:`inherit`});let t=await r(o(l,`cert.pem`),`utf8`);if(!t.trim())throw Error(`Cloudflare login completed without producing an origin certificate.`);return t}finally{await i(s,{force:!0,recursive:!0})}}async function y(e,t){return b(`coreframe-cloudflared-command-`,async n=>{let r=o(n,`cert.pem`);return await x(r,e.originCertificate),t(r)})}async function b(e,t){let r=await n(o(c(),e));try{return await t(r)}finally{await i(r,{force:!0,recursive:!0})}}async function x(e,t){await a(e,t,{mode:384})}function S(e,t){let n={...e};return delete n.TUNNEL_ORIGIN_CERT,{...n,HOME:t,USERPROFILE:t}}function C(e,t){let n;try{n=JSON.parse(e)}catch{throw k(`account`,t)}if(!O(n)||n.version!==1||n.profile!==t||typeof n.createdAt!=`string`||typeof n.originCertificate!=`string`||!n.originCertificate.trim())throw k(`account`,t);return n}function w(e,t){let n;try{n=JSON.parse(e)}catch{throw k(`tunnel`,`${t.profile}/${t.name}`)}if(!O(n)||n.version!==1||n.profile!==t.profile||n.name!==t.name||n.hostname!==t.hostname||typeof n.accountTag!=`string`||typeof n.createdAt!=`string`||typeof n.tunnelId!=`string`)throw k(`tunnel`,`${t.profile}/${t.name}`);let r=T(n.credentials);if(r.TunnelID!==n.tunnelId||r.AccountTag!==n.accountTag)throw k(`tunnel`,`${t.profile}/${t.name}`);return{...n,credentials:r}}function T(e){if(!O(e)||typeof e.AccountTag!=`string`||!e.AccountTag.trim()||typeof e.TunnelID!=`string`||!e.TunnelID.trim()||typeof e.TunnelSecret!=`string`||!e.TunnelSecret.trim()||e.Endpoint!==void 0&&typeof e.Endpoint!=`string`)throw Error(`Cloudflare returned invalid tunnel credentials.`);return{AccountTag:e.AccountTag,Endpoint:e.Endpoint,TunnelID:e.TunnelID,TunnelSecret:e.TunnelSecret}}function E(e,t){try{return JSON.parse(e)}catch{throw Error(`Cloudflare returned invalid ${t}.`)}}function D(e){let t;try{t=JSON.parse(e)}catch{throw Error(`Cloudflare returned an invalid tunnel list.`)}let n=Array.isArray(t)?t:O(t)&&Array.isArray(t.result)?t.result:void 0;if(!n)throw Error(`Cloudflare returned an invalid tunnel list.`);return n.map(e=>{if(!O(e)||typeof e.id!=`string`||!e.id.trim()||typeof e.name!=`string`||!e.name.trim())throw Error(`Cloudflare returned an invalid tunnel list.`);return{id:e.id,name:e.name}})}function O(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function k(e,t){return Error(`The Coreframe Cloudflare ${e} credential for "${t}" is invalid. Clear the matching Coreframe Keychain entry and run coreframe preview again.`)}function A(e,t){return`${e}/${t}`}async function j(e,{cwd:t,env:n,stdio:r=`pipe`}){let i=await s(l,e,{cwd:t,env:n,stdio:r});return{stderr:i.stderr,stdout:i.stdout}}export{f as preparePreviewTunnel};
|
|
1
|
+
import{keyring as e}from"./keyring.js";import{mkdir as t,mkdtemp as n,readFile as r,rm as i,writeFile as a}from"node:fs/promises";import{join as o}from"node:path";import s from"nano-spawn";import{tmpdir as c}from"node:os";const l=process.platform===`win32`?`cloudflared.exe`:`cloudflared`,u=`dev.coreframe.preview.cloudflare.account`,d=`dev.coreframe.preview.cloudflare.tunnel`;async function f({config:e,cwd:t,env:r=process.env,now:s=()=>new Date().toISOString(),run:l=j}){let u=await p({config:e,env:r,now:s,run:l}),d=await m({account:u,config:e,cwd:t,env:r,now:s,run:l});e.dns===`managed`&&await _({account:u,config:e,cwd:t,env:r,run:l,tunnel:d});let f=await n(o(c(),`coreframe-preview-tunnel-`)),h=o(f,`tunnel.json`),g=!1;try{await a(h,`${JSON.stringify(d.credentials)}\n`,{mode:384})}catch(e){throw await i(f,{force:!0,recursive:!0}),e}return{credentialsFile:h,async dispose(){g||(g=!0,await i(f,{force:!0,recursive:!0}))},tunnel:{name:d.name,profile:d.profile,tunnelId:d.tunnelId}}}async function p({config:t,env:n,now:r,run:i}){let a=await e.get(u,t.profile);if(a)return C(a,t.profile);console.log([`Cloudflare authentication is required for preview tunnel "${t.profile}/${t.name}".`,"Coreframe will run `cloudflared tunnel login` now.",`Follow the browser prompt or URL, sign in to Cloudflare, and authorize the zone for ${t.hostname}.`,`Coreframe will store the resulting credentials in your operating system credential store.`].join(` `));let o=await v({env:n,run:i}),s={createdAt:r(),profile:t.profile,originCertificate:o,version:1};return await e.set(u,t.profile,JSON.stringify(s)),s}async function m({account:t,config:n,cwd:r,env:i,now:a,run:o}){let s=A(n.profile,n.name),c=await e.get(d,s);if(c)return w(c,n);let l=(await h({account:t,cwd:r,env:i,run:o})).find(e=>e.name===n.name);if(l)throw Error(`Cloudflare tunnel "${n.name}" already exists as ${l.id}, but Coreframe has no Keychain credentials for it. Coreframe will not adopt an existing tunnel; choose a new preview.tunnel.name.`);let f=await g({account:t,config:n,cwd:r,env:i,run:o}),p={accountTag:f.AccountTag,createdAt:a(),credentials:f,hostname:n.hostname,name:n.name,profile:n.profile,tunnelId:f.TunnelID,version:1};return await e.set(d,s,JSON.stringify(p)),await e.set(u,n.profile,JSON.stringify({...t,lastAccountTag:p.accountTag,lastTunnelId:p.tunnelId,lastTunnelName:p.name})),p}async function h({account:e,cwd:t,env:n,run:r}){return y(e,async e=>D((await r([`tunnel`,`--origincert`,e,`list`,`--output`,`json`],{cwd:t,env:n})).stdout))}async function g({account:e,config:t,cwd:n,env:i,run:a}){return b(`coreframe-cloudflared-create-`,async s=>{let c=o(s,`cert.pem`),l=o(s,`tunnel.json`);return await x(c,e.originCertificate),await a([`tunnel`,`--origincert`,c,`create`,`--credentials-file`,l,t.name],{cwd:n,env:i}),T(E(await r(l,`utf8`),`tunnel credentials`))})}async function _({account:e,config:t,cwd:n,env:r,run:i,tunnel:a}){await y(e,async e=>{await i([`tunnel`,`--origincert`,e,`route`,`dns`,`--overwrite-dns`,a.tunnelId,t.hostname],{cwd:n,env:r})})}async function v({env:e,run:a}){let s=await n(o(c(),`coreframe-cloudflared-login-`)),l=o(s,`.cloudflared`);await t(l,{mode:448});try{await a([`tunnel`,`login`],{cwd:s,env:S(e,s),stdio:`inherit`});let t=await r(o(l,`cert.pem`),`utf8`);if(!t.trim())throw Error(`Cloudflare login completed without producing an origin certificate.`);return t}finally{await i(s,{force:!0,recursive:!0})}}async function y(e,t){return b(`coreframe-cloudflared-command-`,async n=>{let r=o(n,`cert.pem`);return await x(r,e.originCertificate),t(r)})}async function b(e,t){let r=await n(o(c(),e));try{return await t(r)}finally{await i(r,{force:!0,recursive:!0})}}async function x(e,t){await a(e,t,{mode:384})}function S(e,t){let n={...e};return delete n.TUNNEL_ORIGIN_CERT,{...n,HOME:t,USERPROFILE:t}}function C(e,t){let n;try{n=JSON.parse(e)}catch{throw k(`account`,t)}if(!O(n)||n.version!==1||n.profile!==t||typeof n.createdAt!=`string`||typeof n.originCertificate!=`string`||!n.originCertificate.trim())throw k(`account`,t);return n}function w(e,t){let n;try{n=JSON.parse(e)}catch{throw k(`tunnel`,`${t.profile}/${t.name}`)}if(!O(n)||n.version!==1||n.profile!==t.profile||n.name!==t.name||n.hostname!==t.hostname||typeof n.accountTag!=`string`||typeof n.createdAt!=`string`||typeof n.tunnelId!=`string`)throw k(`tunnel`,`${t.profile}/${t.name}`);let r=T(n.credentials);if(r.TunnelID!==n.tunnelId||r.AccountTag!==n.accountTag)throw k(`tunnel`,`${t.profile}/${t.name}`);return{...n,credentials:r}}function T(e){if(!O(e)||typeof e.AccountTag!=`string`||!e.AccountTag.trim()||typeof e.TunnelID!=`string`||!e.TunnelID.trim()||typeof e.TunnelSecret!=`string`||!e.TunnelSecret.trim()||e.Endpoint!==void 0&&typeof e.Endpoint!=`string`)throw Error(`Cloudflare returned invalid tunnel credentials.`);return{AccountTag:e.AccountTag,Endpoint:e.Endpoint,TunnelID:e.TunnelID,TunnelSecret:e.TunnelSecret}}function E(e,t){try{return JSON.parse(e)}catch{throw Error(`Cloudflare returned invalid ${t}.`)}}function D(e){let t;try{t=JSON.parse(e)}catch{throw Error(`Cloudflare returned an invalid tunnel list.`)}if(t===null)return[];let n=Array.isArray(t)?t:O(t)&&Array.isArray(t.result)?t.result:void 0;if(!n)throw Error(`Cloudflare returned an invalid tunnel list.`);return n.map(e=>{if(!O(e)||typeof e.id!=`string`||!e.id.trim()||typeof e.name!=`string`||!e.name.trim())throw Error(`Cloudflare returned an invalid tunnel list.`);return{id:e.id,name:e.name}})}function O(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function k(e,t){return Error(`The Coreframe Cloudflare ${e} credential for "${t}" is invalid. Clear the matching Coreframe Keychain entry and run coreframe preview again.`)}function A(e,t){return`${e}/${t}`}async function j(e,{cwd:t,env:n,stdio:r=`pipe`}){let i=await s(l,e,{cwd:t,env:n,stdio:r});return{stderr:i.stderr,stdout:i.stdout}}export{f as preparePreviewTunnel};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coreframe/preview",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "Production-like local preview lifecycle utilities for Coreframe apps",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"@napi-rs/keyring": "1.3.0",
|
|
22
22
|
"nano-spawn": "^2.1.0",
|
|
23
23
|
"procband": "^0.3.8",
|
|
24
|
-
"@coreframe/config": "^0.1.
|
|
25
|
-
"@coreframe/db": "^0.1.
|
|
24
|
+
"@coreframe/config": "^0.1.9",
|
|
25
|
+
"@coreframe/db": "^0.1.11"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node": "^26.1.0",
|