@runeditrun/rer 0.2.119 → 0.2.121

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.
@@ -41,7 +41,7 @@ export async function ownerSecret({api: provider, target, statePath, changes, fe
41
41
  assert(names, 'invalid-secret-list');
42
42
  // Removing secrets the Worker does not hold changes nothing; the rest of a removal still runs.
43
43
  const writes = present ? changes : changes.filter(change => names.includes(change.binding));
44
- const existed = writes.some(change => names.includes(change.binding)), changed = writes.length > 0, copy = writes.length > 1;
44
+ const existed = writes.some(change => names.includes(change.binding)), changed = writes.length > 0, copy = writes.length > 1 || writes.some(change => change.publicDefault !== undefined);
45
45
  state.pendingSecret = {bindings, present, versionId:state.receipt.provider.versionId, names:names.filter(name => !bindings.includes(name)).sort(), ...(copy ? {copy:randomBytes(16).toString('hex')} : {})};
46
46
  await writeOwnerState(statePath, state);
47
47
  let failure, unchanged = false, confirming = false, uploaded = false;
@@ -144,7 +144,7 @@ export function localOnlyBinding(declaration, localOnlyKeys = []) {
144
144
  return names.find(name => refused.has(name)) ?? null;
145
145
  }
146
146
  /** A seed declares bindings, never names. Migrations come from the packaged artifact. */
147
- export function ownerPlan(target, declaration, artifact, { localOnlyKeys = [], env = {} } = {}) {
147
+ export function ownerPlan(target, declaration, artifact, { localOnlyKeys = [], env = {}, publicDefaults = {} } = {}) {
148
148
  assert(declaration?.version === 1 && typeof declaration === 'object' && Object.keys(declaration).every(key => DECLARATION_KEYS.includes(key)), 'invalid-owner-declaration');
149
149
  assert(declaration.publicSettings === undefined || Array.isArray(declaration.publicSettings) && new Set(declaration.publicSettings).size === declaration.publicSettings.length && declaration.publicSettings.every(name => typeof name === 'string' && /^[A-Z][A-Z0-9_]*$/.test(name)), 'invalid-public-settings');
150
150
  ownerPlatforms(declaration);
@@ -165,6 +165,7 @@ export function ownerPlan(target, declaration, artifact, { localOnlyKeys = [], e
165
165
  const queues = entries(declaration,'queues');
166
166
  for (const item of queues) assert(item.deadLetterQueue === undefined || queues.some(other => other.binding === item.deadLetterQueue), 'invalid-dead-letter-queue');
167
167
  const vars = {...(declaration.vars ?? {})};
168
+ for (const name of Object.keys(publicDefaults)) if (declaration.secrets?.some(item => item.binding === name)) delete vars[name];
168
169
  const origin = publicOrigin(declaration, env);
169
170
  if (declaration.originVar !== undefined) {
170
171
  assert(identifier(declaration.originVar) && !Object.hasOwn(vars,declaration.originVar), 'invalid-owner-origin-variable');
@@ -183,7 +184,7 @@ export function ownerPlan(target, declaration, artifact, { localOnlyKeys = [], e
183
184
  durableObjects:entries(declaration,'durableObjects').map(item => ({...item})),
184
185
  // verifyStandIn is only `rer verify`'s hosted-check value: never planned, sent or stored.
185
186
  // An optional secret (`"optional": true`, an integration's credential) may stay unset: it is bound only once supplied.
186
- secrets:entries(declaration,'secrets').map(({verifyStandIn,...item}) => { assert(verifyStandIn === undefined || typeof verifyStandIn === 'string' && verifyStandIn.length > 0 && verifyStandIn.length <= 1024, 'invalid-verify-stand-in'); return item; }),
187
+ secrets:entries(declaration,'secrets').map(({verifyStandIn,...item}) => { assert(verifyStandIn === undefined || typeof verifyStandIn === 'string' && verifyStandIn.length > 0 && verifyStandIn.length <= 1024, 'invalid-verify-stand-in'); return Object.hasOwn(publicDefaults,item.binding) ? {...item,publicDefault:publicDefaults[item.binding]} : item; }),
187
188
  crons:[...(declaration.crons ?? [])],vars,
188
189
  // Only declarations using these add the keys, so earlier plans and fingerprints are unchanged.
189
190
  ...(services.length ? {services} : {}),...(declaration.workersDev === false ? {workersDev:false} : {})});
@@ -32,6 +32,7 @@ export function validatePlan(plan) {
32
32
  for (const entry of plan.durableObjects) assert(identifier(entry.className) && ['sqlite','classic'].includes(entry.storage), 'invalid-durable-object');
33
33
  for (const secret of plan.secrets) assert(identifier(secret.environment), 'invalid-secret-environment');
34
34
  for (const secret of plan.secrets) assert(secret.optional === undefined || secret.optional === true, 'invalid-optional-secret');
35
+ for (const secret of plan.secrets) assert(secret.publicDefault === undefined || secret.optional === true && typeof secret.publicDefault === 'string', 'invalid-public-secret-default');
35
36
  for (const item of plan.services ?? []) assert(Object.keys(item).every(k => ['binding','service','entrypoint','props','grant'].includes(k)) && resourceName(item.service) && item.service !== plan.worker
36
37
  && (item.entrypoint === undefined || identifier(item.entrypoint))
37
38
  && (item.props === undefined || Object.keys(item.props).join() === 'allowedHosts' && Array.isArray(item.props.allowedHosts)
@@ -58,6 +58,7 @@ export async function secretBindings(api, worker, plan, env, exists) {
58
58
  }
59
59
  for (const item of plan.secrets) {
60
60
  if (names.includes(item.binding)) bindings.push({type:'inherit',name:item.binding});
61
+ else if (unset.includes(item.binding) && item.publicDefault !== undefined) bindings.push({type:'plain_text',name:item.binding,text:item.publicDefault});
61
62
  else if (!unset.includes(item.binding)) {
62
63
  bindings.push({type:'secret_text',name:item.binding,text:env[item.environment]});
63
64
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runeditrun/rer",
3
- "version": "0.2.119",
3
+ "version": "0.2.121",
4
4
  "description": "The rer command: install, set up, run and launch Run Edit Run checkouts.",
5
5
  "license": "MIT",
6
6
  "type": "module",