@coreframe/deploy 0.1.15-next.3 → 0.1.16
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/access-token-secret.d.ts +2 -6
- package/dist/access-token-secret.js +1 -1
- package/dist/built-client.js +1 -1
- package/dist/built-worker.d.ts +32 -0
- package/dist/built-worker.js +1 -0
- package/dist/deploy-descriptor.js +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -1
- package/dist/primary-worker.d.ts +2 -15
- package/dist/primary-worker.js +1 -1
- package/dist/worker-environment.d.ts +1 -3
- package/dist/worker-environment.js +1 -1
- package/package.json +2 -2
|
@@ -2,11 +2,10 @@ import { DeployEnvironment } from "./config.js";
|
|
|
2
2
|
|
|
3
3
|
//#region src/access-token-secret.d.ts
|
|
4
4
|
declare const accessTokenSigningSecretName = "COREFRAME_ACCESS_TOKEN_SECRET";
|
|
5
|
-
type SecretNamesReader = (environment: DeployEnvironment, cwd: string
|
|
6
|
-
type SecretWriter = (environment: DeployEnvironment, name: string, value: string, cwd: string
|
|
5
|
+
type SecretNamesReader = (environment: DeployEnvironment, cwd: string) => Promise<readonly string[]>;
|
|
6
|
+
type SecretWriter = (environment: DeployEnvironment, name: string, value: string, cwd: string) => Promise<void>;
|
|
7
7
|
type AccessTokenSigningSecretOptions = {
|
|
8
8
|
cwd?: string;
|
|
9
|
-
env?: NodeJS.ProcessEnv;
|
|
10
9
|
environment: DeployEnvironment;
|
|
11
10
|
generateSecret?: () => string;
|
|
12
11
|
listSecretNames?: SecretNamesReader;
|
|
@@ -17,20 +16,17 @@ type PreparedAccessTokenSigningSecret = {
|
|
|
17
16
|
};
|
|
18
17
|
declare function prepareAccessTokenSigningSecret({
|
|
19
18
|
cwd,
|
|
20
|
-
env,
|
|
21
19
|
environment,
|
|
22
20
|
generateSecret,
|
|
23
21
|
listSecretNames
|
|
24
22
|
}: AccessTokenSigningSecretOptions): Promise<PreparedAccessTokenSigningSecret>;
|
|
25
23
|
declare function verifyAccessTokenSigningSecret({
|
|
26
24
|
cwd,
|
|
27
|
-
env,
|
|
28
25
|
environment,
|
|
29
26
|
listSecretNames
|
|
30
27
|
}: Omit<AccessTokenSigningSecretOptions, "generateSecret">): Promise<void>;
|
|
31
28
|
declare function rotateAccessTokenSigningSecret({
|
|
32
29
|
cwd,
|
|
33
|
-
env,
|
|
34
30
|
environment,
|
|
35
31
|
generateSecret,
|
|
36
32
|
listSecretNames,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{randomBytes as e}from"node:crypto";import t,{SubprocessError as n}from"nano-spawn";const r=`COREFRAME_ACCESS_TOKEN_SECRET`;async function i({cwd:e=process.cwd(),
|
|
1
|
+
import{randomBytes as e}from"node:crypto";import t,{SubprocessError as n}from"nano-spawn";const r=`COREFRAME_ACCESS_TOKEN_SECRET`;async function i({cwd:e=process.cwd(),environment:t,generateSecret:n=s,listSecretNames:i=c}){try{if((await i(t,e)).includes(`COREFRAME_ACCESS_TOKEN_SECRET`))return{provisioned:!1}}catch(e){if(!u(e))throw Error(`Could not inspect the ${t} Worker before provisioning ${r}. Refusing to risk replacing an existing signing secret.`,{cause:e})}return{provisioned:!0,value:n()}}async function a({cwd:e=process.cwd(),environment:t,listSecretNames:n=c}){if(!(await n(t,e)).includes(`COREFRAME_ACCESS_TOKEN_SECRET`))throw Error(`Cloudflare deployed the ${t} Worker without ${r}.`)}async function o({cwd:e=process.cwd(),environment:t,generateSecret:n=s,listSecretNames:i=c,writeSecret:o=l}){await o(t,r,n(),e),await a({cwd:e,environment:t,listSecretNames:i})}function s(){return e(32).toString(`base64url`)}async function c(e,n){let{stdout:r}=await t(`pnpm`,[`exec`,`wrangler`,`secret`,`list`,`--env`,e,`--format`,`json`],{cwd:n,stdin:`ignore`}),i=JSON.parse(r);if(!Array.isArray(i))throw Error(`Wrangler returned an invalid Worker secret list.`);return i.flatMap(e=>e&&typeof e==`object`&&`name`in e&&typeof e.name==`string`?[e.name]:[])}async function l(e,n,r,i){await t(`pnpm`,[`exec`,`wrangler`,`secret`,`put`,n,`--env`,e],{cwd:i,stdin:{string:r},stdout:`inherit`,stderr:`inherit`})}function u(e){return e instanceof n&&e.stderr.includes(`not found`)&&e.stderr.includes("If this is a new Worker, run `wrangler deploy` first")}export{r as accessTokenSigningSecretName,s as generateAccessTokenSigningSecret,i as prepareAccessTokenSigningSecret,o as rotateAccessTokenSigningSecret,a as verifyAccessTokenSigningSecret};
|
package/dist/built-client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{readBuiltDeployConfig as e,writeBuiltDeployConfigCopy as t}from"./deploy-descriptor.js";const n=[`account_id`,`compatibility_date`,`compatibility_flags`,`keep_vars`,`name`,`preview_urls`,`route`,`routes`,`send_metrics`,`workers_dev`];async function r(r=process.cwd()){let a=await e(r),o=a.config.assets;if(`main`in a.config)throw Error(`Client deployment build contains a Worker entrypoint. Configure the Cloudflare Vite plugin with assetsOnly when deploy.mode is "client".`);if(!i(o)||typeof o.directory!=`string`||!o.directory)throw Error(`Client deployment build does not contain a static asset directory.`);let{binding:s,run_worker_first:c,...l}=o,u={assets:l};for(let e of n){let t=a.config[e];t!==void 0&&(u[e]=t)}let d=await t(a.path,`.coreframe-client-`,u);return{config:u,dispose:d.dispose,path:d.path}}function i(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}export{r as materializeBuiltClientDeployConfig};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { DeployEnvironment } from "./config.js";
|
|
2
|
+
import { CoreframeConfig, JsonObject, PrimaryWorkerContributions } from "@coreframe/config";
|
|
3
|
+
|
|
4
|
+
//#region src/built-worker.d.ts
|
|
5
|
+
/** Temporary Wrangler configuration derived from a completed Worker build. */
|
|
6
|
+
type MaterializedBuiltWorkerDeployConfig = {
|
|
7
|
+
config: JsonObject;
|
|
8
|
+
dispose: () => Promise<void>;
|
|
9
|
+
path: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Materializes a deployable Worker artifact from the Cloudflare build output, layering Coreframe
|
|
13
|
+
* environment contributions onto the environment-flattened config emitted by the Vite plugin. The
|
|
14
|
+
* emitted config owns the bundled entrypoint, resolved asset directory, and environment selection;
|
|
15
|
+
* wrangler.jsonc remains the source of Worker inventory ownership checks.
|
|
16
|
+
*
|
|
17
|
+
* @throws When the Cloudflare build output is missing, has no Worker entrypoint, or was built for a
|
|
18
|
+
* different environment.
|
|
19
|
+
*/
|
|
20
|
+
declare function materializeBuiltWorkerDeployConfig({
|
|
21
|
+
coreframeConfig,
|
|
22
|
+
cwd,
|
|
23
|
+
environment,
|
|
24
|
+
contributions
|
|
25
|
+
}: {
|
|
26
|
+
coreframeConfig: CoreframeConfig;
|
|
27
|
+
cwd?: string;
|
|
28
|
+
environment: DeployEnvironment;
|
|
29
|
+
contributions?: PrimaryWorkerContributions;
|
|
30
|
+
}): Promise<MaterializedBuiltWorkerDeployConfig>;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { MaterializedBuiltWorkerDeployConfig, materializeBuiltWorkerDeployConfig };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{readBuiltDeployConfig as e,writeBuiltDeployConfigCopy as t}from"./deploy-descriptor.js";import{primaryWorkerRequiredSecrets as n,readPrimaryWorkerConfig as r}from"./primary-worker.js";import{derivePrimaryWorkerConfig as i,validateWorkerInventoryOwnership as a}from"@coreframe/config";async function o({coreframeConfig:o,cwd:c=process.cwd(),environment:l,contributions:u={}}){let d=await e(c);if(typeof d.config.main!=`string`||!d.config.main)throw Error(`Full deployment build does not contain a Worker entrypoint. Check the Cloudflare Vite plugin configuration, or use deploy.mode "client" for assets-only deployments.`);if(d.config.targetEnvironment!==void 0&&d.config.targetEnvironment!==l)throw Error(`The Cloudflare build output targets the "${String(d.config.targetEnvironment)}" environment, but this deploy is for "${l}". Re-run the build for ${l} before deploying.`);a(await r(c),o.worker?.environment);let f=[...n(o,l),...u.requiredSecrets??[]],p=i({config:{env:{[l]:d.config}},environment:l,contributions:{...u,requiredSecrets:f}}).env,m=s(p)?p[l]:void 0;if(!s(m))throw Error(`Could not derive the ${l} Worker deploy configuration.`);let h=await t(d.path,`.coreframe-worker-`,m);return{config:m,dispose:h.dispose,path:h.path}}function s(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}export{o as materializeBuiltWorkerDeployConfig};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{randomUUID as e}from"node:crypto";import{readFile as t,rm as n,writeFile as r}from"node:fs/promises";import{dirname as i,join as a,resolve as o}from"node:path";const s=`.wrangler/deploy/config.json`;async function c(e){let t=o(e,s),n=(await u(t,`Cloudflare deploy descriptor`)).configPath;if(typeof n!=`string`||!n)throw Error(`Cloudflare deploy descriptor ${s} has no configPath.`);let r=o(i(t),n);return{path:r,config:await u(r,`Cloudflare generated deploy config`)}}async function l(t,o,s){let c=a(i(t),`${o}${e()}.json`);return await r(c,`${JSON.stringify(s,null,2)}\n`,{flag:`wx`,mode:384}),{path:c,dispose:()=>n(c,{force:!0})}}async function u(e,n){let r;try{r=JSON.parse(await t(e,`utf8`))}catch(t){throw Error(`Could not read ${n.toLowerCase()} at ${e}: ${f(t)}`)}if(!d(r))throw Error(`${n} at ${e} must contain a JSON object.`);return r}function d(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function f(e){return e instanceof Error?e.message:String(e)}export{c as readBuiltDeployConfig,u as readJsonObject,l as writeBuiltDeployConfigCopy};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { DeployConfig, DeployContext, DeployEnvironment, DeployEnvironmentConfig, DeployMode, DeploySmokeCheck, ResolvedDeployConfig, StagingHostnameConfig, deployEnvironments, resolveDeployConfig } from "./config.js";
|
|
2
2
|
import { PreparedAccessTokenSigningSecret, accessTokenSigningSecretName, generateAccessTokenSigningSecret, prepareAccessTokenSigningSecret, rotateAccessTokenSigningSecret, verifyAccessTokenSigningSecret } from "./access-token-secret.js";
|
|
3
3
|
import { MaterializedBuiltClientDeployConfig, materializeBuiltClientDeployConfig } from "./built-client.js";
|
|
4
|
+
import { MaterializedBuiltWorkerDeployConfig, materializeBuiltWorkerDeployConfig } from "./built-worker.js";
|
|
4
5
|
import { runAfterWorkerDeploy, runDeploySmokeChecks, runPostDeployChecks } from "./checks.js";
|
|
5
|
-
import { MaterializedPrimaryWorkerConfig,
|
|
6
|
+
import { MaterializedPrimaryWorkerConfig, materializePrimaryWorkerTypeConfig, primaryWorkerRequiredSecrets, readPrimaryWorkerConfig } from "./primary-worker.js";
|
|
6
7
|
import { StagingAssignment, discoverManagedDomain, discoverStagingUrl, generateAvailableHostname, generateStagingHostname, reassignStagingHostname, stagingHostnameWords } from "./staging.js";
|
|
7
8
|
import { formatReleaseDate, nextReleaseVersion, readPackageJson, releaseName, resolveReleaseVersion, stagingReleaseVersion, writePackageVersion } from "./version.js";
|
|
8
9
|
import { DeclaredWorkerSecret, DeployedWorkerEnvironmentState, LocalWorkerEnvironmentState, PendingWorkerSecretSnapshot, WorkerEnvironmentEntryStatus, WorkerEnvironmentKind, WorkerEnvironmentProviderStatus, WorkerEnvironmentStatus, WorkerEnvironmentVariableConfig, clearAppliedPendingWorkerSecrets, discardPendingWorkerSecret, inspectWorkerEnvironment, parseDeclaredWorkerSecretEnv, queueWorkerSecret, queueWorkerSecrets, readDeclaredWorkerSecrets, readPendingWorkerSecretSnapshot, validateWorkerEnvironmentForDeploy, workerEnvironmentKinds } from "./worker-environment.js";
|
|
9
|
-
export { DeclaredWorkerSecret, type DeployConfig, type DeployContext, type DeployEnvironment, type DeployEnvironmentConfig, type DeployMode, type DeploySmokeCheck, DeployedWorkerEnvironmentState, LocalWorkerEnvironmentState, MaterializedBuiltClientDeployConfig, MaterializedPrimaryWorkerConfig, PendingWorkerSecretSnapshot, PreparedAccessTokenSigningSecret, ResolvedDeployConfig, StagingAssignment, type StagingHostnameConfig, WorkerEnvironmentEntryStatus, type WorkerEnvironmentKind, WorkerEnvironmentProviderStatus, WorkerEnvironmentStatus, type WorkerEnvironmentVariableConfig, accessTokenSigningSecretName, clearAppliedPendingWorkerSecrets, deployEnvironments, discardPendingWorkerSecret, discoverManagedDomain, discoverStagingUrl, formatReleaseDate, generateAccessTokenSigningSecret, generateAvailableHostname, generateStagingHostname, inspectWorkerEnvironment, materializeBuiltClientDeployConfig,
|
|
10
|
+
export { DeclaredWorkerSecret, type DeployConfig, type DeployContext, type DeployEnvironment, type DeployEnvironmentConfig, type DeployMode, type DeploySmokeCheck, DeployedWorkerEnvironmentState, LocalWorkerEnvironmentState, MaterializedBuiltClientDeployConfig, MaterializedBuiltWorkerDeployConfig, MaterializedPrimaryWorkerConfig, PendingWorkerSecretSnapshot, PreparedAccessTokenSigningSecret, ResolvedDeployConfig, StagingAssignment, type StagingHostnameConfig, WorkerEnvironmentEntryStatus, type WorkerEnvironmentKind, WorkerEnvironmentProviderStatus, WorkerEnvironmentStatus, type WorkerEnvironmentVariableConfig, accessTokenSigningSecretName, clearAppliedPendingWorkerSecrets, deployEnvironments, discardPendingWorkerSecret, discoverManagedDomain, discoverStagingUrl, formatReleaseDate, generateAccessTokenSigningSecret, generateAvailableHostname, generateStagingHostname, inspectWorkerEnvironment, materializeBuiltClientDeployConfig, materializeBuiltWorkerDeployConfig, materializePrimaryWorkerTypeConfig, nextReleaseVersion, parseDeclaredWorkerSecretEnv, prepareAccessTokenSigningSecret, primaryWorkerRequiredSecrets, queueWorkerSecret, queueWorkerSecrets, readDeclaredWorkerSecrets, readPackageJson, readPendingWorkerSecretSnapshot, readPrimaryWorkerConfig, reassignStagingHostname, releaseName, resolveDeployConfig, resolveReleaseVersion, rotateAccessTokenSigningSecret, runAfterWorkerDeploy, runDeploySmokeChecks, runPostDeployChecks, stagingHostnameWords, stagingReleaseVersion, validateWorkerEnvironmentForDeploy, verifyAccessTokenSigningSecret, workerEnvironmentKinds, writePackageVersion };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{accessTokenSigningSecretName as e,generateAccessTokenSigningSecret as t,prepareAccessTokenSigningSecret as n,rotateAccessTokenSigningSecret as r,verifyAccessTokenSigningSecret as i}from"./access-token-secret.js";import{materializeBuiltClientDeployConfig as a}from"./built-client.js";import{
|
|
1
|
+
import{accessTokenSigningSecretName as e,generateAccessTokenSigningSecret as t,prepareAccessTokenSigningSecret as n,rotateAccessTokenSigningSecret as r,verifyAccessTokenSigningSecret as i}from"./access-token-secret.js";import{materializeBuiltClientDeployConfig as a}from"./built-client.js";import{materializePrimaryWorkerTypeConfig as o,primaryWorkerRequiredSecrets as s,readPrimaryWorkerConfig as c}from"./primary-worker.js";import{materializeBuiltWorkerDeployConfig as l}from"./built-worker.js";import{runAfterWorkerDeploy as u,runDeploySmokeChecks as d,runPostDeployChecks as f}from"./checks.js";import{deployEnvironments as p,resolveDeployConfig as m}from"./config.js";import{discoverManagedDomain as h,discoverStagingUrl as g,generateAvailableHostname as _,generateStagingHostname as v,reassignStagingHostname as y,stagingHostnameWords as b}from"./staging.js";import{formatReleaseDate as x,nextReleaseVersion as S,readPackageJson as C,releaseName as w,resolveReleaseVersion as T,stagingReleaseVersion as E,writePackageVersion as D}from"./version.js";import{clearAppliedPendingWorkerSecrets as O,discardPendingWorkerSecret as k,inspectWorkerEnvironment as A,parseDeclaredWorkerSecretEnv as j,queueWorkerSecret as M,queueWorkerSecrets as N,readDeclaredWorkerSecrets as P,readPendingWorkerSecretSnapshot as F,validateWorkerEnvironmentForDeploy as I,workerEnvironmentKinds as L}from"./worker-environment.js";export{e as accessTokenSigningSecretName,O as clearAppliedPendingWorkerSecrets,p as deployEnvironments,k as discardPendingWorkerSecret,h as discoverManagedDomain,g as discoverStagingUrl,x as formatReleaseDate,t as generateAccessTokenSigningSecret,_ as generateAvailableHostname,v as generateStagingHostname,A as inspectWorkerEnvironment,a as materializeBuiltClientDeployConfig,l as materializeBuiltWorkerDeployConfig,o as materializePrimaryWorkerTypeConfig,S as nextReleaseVersion,j as parseDeclaredWorkerSecretEnv,n as prepareAccessTokenSigningSecret,s as primaryWorkerRequiredSecrets,M as queueWorkerSecret,N as queueWorkerSecrets,P as readDeclaredWorkerSecrets,C as readPackageJson,F as readPendingWorkerSecretSnapshot,c as readPrimaryWorkerConfig,y as reassignStagingHostname,w as releaseName,m as resolveDeployConfig,T as resolveReleaseVersion,r as rotateAccessTokenSigningSecret,u as runAfterWorkerDeploy,d as runDeploySmokeChecks,f as runPostDeployChecks,b as stagingHostnameWords,E as stagingReleaseVersion,I as validateWorkerEnvironmentForDeploy,i as verifyAccessTokenSigningSecret,L as workerEnvironmentKinds,D as writePackageVersion};
|
package/dist/primary-worker.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CoreframeConfig,
|
|
1
|
+
import { CoreframeConfig, PrimaryWorkerEnvironment, WranglerConfig } from "@coreframe/config";
|
|
2
2
|
|
|
3
3
|
//#region src/primary-worker.d.ts
|
|
4
4
|
type MaterializedPrimaryWorkerConfig = {
|
|
@@ -8,19 +8,6 @@ type MaterializedPrimaryWorkerConfig = {
|
|
|
8
8
|
};
|
|
9
9
|
declare function readPrimaryWorkerConfig(cwd?: string): Promise<WranglerConfig>;
|
|
10
10
|
declare function primaryWorkerRequiredSecrets(config: CoreframeConfig, environment: PrimaryWorkerEnvironment): string[];
|
|
11
|
-
declare function materializePrimaryWorkerConfig({
|
|
12
|
-
config,
|
|
13
|
-
coreframeConfig,
|
|
14
|
-
cwd,
|
|
15
|
-
environment,
|
|
16
|
-
contributions
|
|
17
|
-
}: {
|
|
18
|
-
config?: WranglerConfig;
|
|
19
|
-
coreframeConfig: CoreframeConfig;
|
|
20
|
-
cwd?: string;
|
|
21
|
-
environment: PrimaryWorkerEnvironment;
|
|
22
|
-
contributions?: PrimaryWorkerContributions;
|
|
23
|
-
}): Promise<MaterializedPrimaryWorkerConfig>;
|
|
24
11
|
declare function materializePrimaryWorkerTypeConfig({
|
|
25
12
|
coreframeConfig,
|
|
26
13
|
cwd
|
|
@@ -29,4 +16,4 @@ declare function materializePrimaryWorkerTypeConfig({
|
|
|
29
16
|
cwd?: string;
|
|
30
17
|
}): Promise<MaterializedPrimaryWorkerConfig>;
|
|
31
18
|
//#endregion
|
|
32
|
-
export { MaterializedPrimaryWorkerConfig,
|
|
19
|
+
export { MaterializedPrimaryWorkerConfig, materializePrimaryWorkerTypeConfig, primaryWorkerRequiredSecrets, readPrimaryWorkerConfig };
|
package/dist/primary-worker.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{randomUUID as e}from"node:crypto";import{readFile as t,rm as n,writeFile as r}from"node:fs/promises";import{resolve as i}from"node:path";import{coreframeLocalWorkerVariables as a,coreframeManagedWorkerSecrets as o,derivePrimaryWorkerConfig as s,normalizeWorkerEnvironment as c,primaryWorkerConfigPath as l,primaryWorkerEnvironments as u,validateWorkerInventoryOwnership as d}from"@coreframe/config";import f from"json5";async function p(e=process.cwd()){let n=i(e,l),r;try{r=f.parse(await t(n,`utf8`))}catch(e){throw Error(`Could not read ${l}: ${
|
|
1
|
+
import{randomUUID as e}from"node:crypto";import{readFile as t,rm as n,writeFile as r}from"node:fs/promises";import{resolve as i}from"node:path";import{coreframeLocalWorkerVariables as a,coreframeManagedWorkerSecrets as o,derivePrimaryWorkerConfig as s,normalizeWorkerEnvironment as c,primaryWorkerConfigPath as l,primaryWorkerEnvironments as u,validateWorkerInventoryOwnership as d}from"@coreframe/config";import f from"json5";async function p(e=process.cwd()){let n=i(e,l),r;try{r=f.parse(await t(n,`utf8`))}catch(e){throw Error(`Could not read ${l}: ${y(e)}`)}if(!_(r))throw Error(`${l} must contain a JSON object.`);return r}function m(e,t){let n=c(e.worker?.environment).filter(e=>e.kind===`secret`&&t!==`development`&&e.requiredIn.includes(t)).map(e=>e.name);return[...new Set([...o,...n])].sort()}async function h({coreframeConfig:e,cwd:t=process.cwd()}){let n=await p(t);d(n,e.worker?.environment);for(let t of u)n=s({config:n,environment:t,contributions:{generatedValues:t===`development`?Object.fromEntries(a.map(e=>[e,`coreframe-local`])):{DEPLOY_ENV:t,POSTHOG_RELEASE:`coreframe-type-generation`},requiredSecrets:m(e,t)}});return g(t,n)}async function g(t,a){let o=i(t,`.coreframe-wrangler-${e()}.json`);return await r(o,`${JSON.stringify(a,null,2)}\n`,{flag:`wx`,mode:384}),{config:a,path:o,dispose:()=>n(o,{force:!0})}}function _(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.values(e).every(v)}function v(e){return e===null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`||Array.isArray(e)&&e.every(v)||_(e)}function y(e){return e instanceof Error?e.message:String(e)}export{h as materializePrimaryWorkerTypeConfig,m as primaryWorkerRequiredSecrets,p as readPrimaryWorkerConfig};
|
|
@@ -35,9 +35,8 @@ type PendingWorkerSecretSnapshot = {
|
|
|
35
35
|
};
|
|
36
36
|
type InspectWorkerEnvironmentOptions = {
|
|
37
37
|
cwd?: string;
|
|
38
|
-
env?: NodeJS.ProcessEnv;
|
|
39
38
|
environment?: DeployEnvironment;
|
|
40
|
-
listBindings?: (environment: DeployEnvironment, cwd: string
|
|
39
|
+
listBindings?: (environment: DeployEnvironment, cwd: string) => Promise<string[]>;
|
|
41
40
|
};
|
|
42
41
|
type QueueWorkerSecretOptions = {
|
|
43
42
|
cwd?: string;
|
|
@@ -54,7 +53,6 @@ type QueueWorkerSecretsOptions = {
|
|
|
54
53
|
};
|
|
55
54
|
declare function inspectWorkerEnvironment({
|
|
56
55
|
cwd,
|
|
57
|
-
env,
|
|
58
56
|
environment,
|
|
59
57
|
listBindings
|
|
60
58
|
}?: InspectWorkerEnvironmentOptions): Promise<WorkerEnvironmentStatus>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{accessTokenSigningSecretName as e}from"./access-token-secret.js";import{
|
|
1
|
+
import{accessTokenSigningSecretName as e}from"./access-token-secret.js";import{readPrimaryWorkerConfig as t}from"./primary-worker.js";import{deployEnvironments as n}from"./config.js";import{randomUUID as r}from"node:crypto";import i from"nano-spawn";import{chmod as a,mkdir as o,readFile as s,rename as c,rm as l,stat as u,writeFile as d}from"node:fs/promises";import{resolve as f}from"node:path";import{normalizeWorkerEnvironment as p,readProjectConfig as m}from"@coreframe/config";import{parseEnv as h}from"node:util";const g=[`secret`,`variable`,`generated`];function _(e,t,{availableNames:n=[]}={}){let r=new Set(n),i=e.entries.filter(e=>!e.requiredIn.includes(t)||r.has(e.name)?!1:e.deployed[t]===`missing`);if(i.length>0)throw Error(`Required ${t} Worker environment is not ready: ${i.map(e=>`${e.name} (${e.deployed[t].replaceAll(`_`,` `)})`).join(`, `)}.`)}const v=/^[A-Z][A-Z0-9_]*$/,y=`.coreframe/deploy-secrets`;async function b({cwd:r=process.cwd(),environment:i,listBindings:a=R}={}){let o=p((await m({cwd:r})).worker?.environment),s=await t(r),c=await k(r),l=i?[i]:n,u=new Map,d=new Map,f=new Map(n.map(e=>[e,j(s,e)])),h=Object.fromEntries(n.map(e=>[e,{state:`not_checked`}]));await Promise.all(l.map(async e=>{if(d.set(e,new Set(Object.keys((await E({cwd:r,environment:e})).values))),o.some(t=>t.kind===`secret`||t.kind===`variable`&&!f.get(e)?.has(t.name)))try{u.set(e,new Set(await a(e,r))),h[e]={state:`available`}}catch{h[e]={state:`unavailable`,message:`Could not read ${e} Worker secrets. Check Wrangler authentication and whether the Worker exists.`}}}));let g=new Set([e,...o.map(e=>e.name)]),_=Object.fromEntries(n.map(e=>[e,[...u.get(e)??[]].filter(e=>!g.has(e)).sort()]));return{entries:o.map(e=>({...e,local:c.has(e.name)?`override`:`default`,deployed:Object.fromEntries(n.map(t=>[t,A(e,t,h[t],u.get(t),d.get(t),f.get(t))]))})),providers:h,undeclaredSecrets:_}}async function x({cwd:e=process.cwd(),environment:t,name:n,value:r,ensureIgnored:i=F}){await S({cwd:e,environment:t,values:{[n]:r},ensureIgnored:i})}async function S({cwd:e=process.cwd(),environment:t,values:n,ensureIgnored:r=F}){let i=new Map((await C(e)).map(e=>[e.name,e]));for(let[t,r]of Object.entries(n))if(i.has(t)||await O(e,t),!r.trim())throw Error(`Worker secret ${t} cannot be empty.`);Object.keys(n).length!==0&&(await r(t,e),await P(e,t,{...(await E({cwd:e,environment:t})).values,...n}))}async function C(e=process.cwd()){return p((await m({cwd:e})).worker?.environment).filter(e=>e.kind===`secret`)}function w(e,t){let n;try{n=h(e)}catch{throw Error(`Could not parse the pasted dotenv contents.`)}let r=new Set(t.map(({name:e})=>e)),i=Object.fromEntries(Object.entries(n).filter(e=>r.has(e[0])&&typeof e[1]==`string`)),a=Object.entries(i).filter(([,e])=>!e.trim()).map(([e])=>e);if(a.length>0)throw Error(`Worker secrets cannot be empty: ${a.join(`, `)}.`);if(Object.keys(i).length===0)throw Error(`The dotenv contents do not contain any declared Worker secrets.`);return{ignoredNames:Object.keys(n).filter(e=>!r.has(e)).sort(),values:i}}async function T({cwd:e=process.cwd(),environment:t,name:n}){await O(e,n);let r=await E({cwd:e,environment:t});if(!(n in r.values))return!1;let i={...r.values};return delete i[n],await P(e,t,i),!0}async function E({cwd:e=process.cwd(),environment:t}){let n=await N(e,t),r=p((await m({cwd:e})).worker?.environment),i=new Set(r.filter(e=>e.kind===`secret`).map(e=>e.name)),a=Object.keys(n).filter(e=>!i.has(e));if(a.length>0)throw Error(`Pending ${t} Worker secrets are not declared as secrets in coreframe.config.ts: ${a.join(`, `)}.`);return{environment:t,values:n}}async function D(e,t=process.cwd()){let n=await N(t,e.environment),r=Object.fromEntries(Object.entries(n).filter(([t,n])=>e.values[t]!==n));await P(t,e.environment,r)}async function O(e,t){let n=p((await m({cwd:e})).worker?.environment).find(e=>e.name===t);if(!n)throw Error(`${t} is not declared in coreframe.config.ts.`);if(n.kind!==`secret`)throw Error(`${t} is declared as ${n.kind}, not a Worker secret.`)}async function k(e){try{let t=h(await s(f(e,`.env`),`utf8`));return new Set(Object.entries(t).filter(([,e])=>!!e?.trim()).map(([e])=>e))}catch(e){if(z(e)&&e.code===`ENOENT`)return new Set;throw e}}function A(e,t,n,r,i,a){return e.kind===`generated`?`generated`:e.kind===`variable`?a?.has(e.name)||r?.has(e.name)?`configured`:`unknown`: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`}function j(e,t){let n=M(M(e.env)[t]);return new Set(Object.keys(M(n.vars)))}function M(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:{}}async function N(e,t){let n=I(e,t);try{let e=await u(n);if(process.platform!==`win32`&&e.mode&63)throw Error(`Pending Worker secret file ${n} must use mode 0600.`);let t=JSON.parse(await s(n,`utf8`));if(!L(t))throw Error(`Pending Worker secret file ${n} must contain a JSON object of strings.`);return t}catch(e){if(z(e)&&e.code===`ENOENT`)return{};throw e}}async function P(e,t,n){let i=I(e,t);if(Object.keys(n).length===0){await l(i,{force:!0});return}let s=f(e,y);await o(s,{mode:448,recursive:!0}),process.platform!==`win32`&&await a(s,448);let u=`${i}.${process.pid}.${r()}.tmp`;try{await d(u,`${JSON.stringify(n,null,2)}\n`,{flag:`wx`,mode:384}),await c(u,i)}finally{await l(u,{force:!0})}process.platform!==`win32`&&await a(i,384)}async function F(e,t){let n=`${y}/${e}.json`,r=`${y}/.coreframe-ignore-check`;try{await i(`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 I(e,t){return f(e,y,`${t}.json`)}function L(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.entries(e).every(([e,t])=>v.test(e)&&typeof t==`string`&&t.length>0)}async function R(e,t){let{stdout:n}=await i(`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 z(e){return e instanceof Error&&`code`in e}export{D as clearAppliedPendingWorkerSecrets,T as discardPendingWorkerSecret,b as inspectWorkerEnvironment,w as parseDeclaredWorkerSecretEnv,x as queueWorkerSecret,S as queueWorkerSecrets,C as readDeclaredWorkerSecrets,E as readPendingWorkerSecretSnapshot,_ as validateWorkerEnvironmentForDeploy,g as workerEnvironmentKinds};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coreframe/deploy",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"description": "Deployment configuration, validation, and release utilities for Coreframe apps",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"json5": "^2.2.3",
|
|
22
22
|
"nano-spawn": "^2.1.0",
|
|
23
23
|
"tinyglobby": "^0.2.17",
|
|
24
|
-
"@coreframe/config": "^0.1.15
|
|
24
|
+
"@coreframe/config": "^0.1.15"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/node": "^26.1.0",
|