@hintergrund/worker 0.3.2 → 0.3.3

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.
@@ -7,7 +7,7 @@ import { DEFAULT_EMAIL_SETTINGS, EMAIL_SETTINGS_PATH } from '../../emails/handle
7
7
  import Stripe from 'stripe';
8
8
  import { checkIntegrationKey } from '../../../lib/integration-health';
9
9
  import { createId, ensureSchema, issueSessionForUser, nowSeconds } from '../../../lib/project-db';
10
- import { AGENT_PROVIDERS, AGENT_PROVIDER_SECRETS, SETUP_PATH as WEBSITE_SETUP_PATH, SHOP_SETTINGS_PATH, normalizeProjectGoals, subscriptionAutomation, DEFAULT_SHOP_EMAIL_TEMPLATES } from '@hintergrund/runtime-contracts';
10
+ import { AGENT_PROVIDERS, AGENT_PROVIDER_SECRETS, CONFIG_PATH as WEBSITE_CONFIG_PATH, SHOP_SETTINGS_PATH, normalizeProjectFeatures, subscriptionAutomation, DEFAULT_SHOP_EMAIL_TEMPLATES } from '@hintergrund/runtime-contracts';
11
11
  import { validateI18nConfig, DEFAULT_I18N_CONFIG } from '@hintergrund/runtime-contracts';
12
12
  import { initializeWebsiteLanguages } from '../../../lib/website-i18n';
13
13
  const DEFAULT_SHOP_SETTINGS = {
@@ -59,10 +59,10 @@ export async function setupProject(c) {
59
59
  if (!(await hasValidSetupToken(c.env, body.setupToken)))
60
60
  return c.json({ error: 'Invalid setup link.' }, 403);
61
61
  const email = typeof body.email === 'string' ? body.email.trim().toLowerCase() : '';
62
- if (!body.goals || typeof body.goals !== 'object' || Array.isArray(body.goals)
63
- || typeof body.goals.sell !== 'boolean'
64
- || typeof body.goals.newsletters !== 'boolean') {
65
- return c.json({ error: 'Choose your project goals.' }, 400);
62
+ if (!body.features || typeof body.features !== 'object' || Array.isArray(body.features)
63
+ || typeof body.features.sell !== 'boolean'
64
+ || typeof body.features.newsletters !== 'boolean') {
65
+ return c.json({ error: 'Choose your project features.' }, 400);
66
66
  }
67
67
  let languages;
68
68
  try {
@@ -71,8 +71,8 @@ export async function setupProject(c) {
71
71
  catch (error) {
72
72
  return c.json({ error: error instanceof Error ? error.message : 'Invalid website languages.' }, 400);
73
73
  }
74
- const goals = normalizeProjectGoals(body.goals);
75
- const needsEmail = goals.sell || goals.newsletters;
74
+ const features = normalizeProjectFeatures(body.features);
75
+ const needsEmail = features.sell || features.newsletters;
76
76
  const MIN_PASSWORD_LENGTH = 12;
77
77
  const password = typeof body.password === 'string' ? body.password : '';
78
78
  const plunkApiKey = typeof body.plunkApiKey === 'string' ? body.plunkApiKey.trim() : '';
@@ -86,7 +86,7 @@ export async function setupProject(c) {
86
86
  if (typeof invoiceInput[key] === 'string')
87
87
  invoice[key] = invoiceInput[key].trim().slice(0, 4000);
88
88
  }
89
- if (goals.sell && (!invoice.companyName || !invoice.companyAddress))
89
+ if (features.sell && (!invoice.companyName || !invoice.companyAddress))
90
90
  return c.json({ error: 'Enter your business name and address for invoices.' }, 400);
91
91
  const footerText = typeof body.footerText === 'string' ? body.footerText.trim().slice(0, 8000) : 'If you have any questions, please contact us.';
92
92
  const footerHtml = `<p>${footerText.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('\n', '<br>')}</p>`;
@@ -100,16 +100,16 @@ export async function setupProject(c) {
100
100
  }
101
101
  if (!agentProvider || !agentProviderKey)
102
102
  return c.json({ error: 'Choose an AI provider and enter its API key.' }, 400);
103
- if (goals.sell && !paymentProvider)
103
+ if (features.sell && !paymentProvider)
104
104
  return c.json({ error: 'Choose a payment provider.' }, 400);
105
105
  const bankTransfer = typeof body.bankTransfer === 'object' && body.bankTransfer !== null ? body.bankTransfer : {};
106
106
  const accountHolder = typeof bankTransfer.accountHolder === 'string' ? bankTransfer.accountHolder.trim() : '';
107
107
  const iban = typeof bankTransfer.iban === 'string' ? bankTransfer.iban.trim() : '';
108
- const stripeSecretKey = goals.sell && paymentProvider === 'stripe' && typeof body.stripeSecretKey === 'string' ? body.stripeSecretKey.trim() : '';
109
- if (goals.sell && paymentProvider === 'bank_transfer' && (!accountHolder || !iban)) {
108
+ const stripeSecretKey = features.sell && paymentProvider === 'stripe' && typeof body.stripeSecretKey === 'string' ? body.stripeSecretKey.trim() : '';
109
+ if (features.sell && paymentProvider === 'bank_transfer' && (!accountHolder || !iban)) {
110
110
  return c.json({ error: 'An account holder and IBAN are required for bank transfers.' }, 400);
111
111
  }
112
- if (goals.sell && paymentProvider === 'stripe' && !stripeSecretKey) {
112
+ if (features.sell && paymentProvider === 'stripe' && !stripeSecretKey) {
113
113
  return c.json({ error: 'Your Stripe secret key is required for card payments.' }, 400);
114
114
  }
115
115
  // Validate credentials before creating an administrator or changing the repository.
@@ -178,29 +178,29 @@ export async function setupProject(c) {
178
178
  for (const [name, value] of [
179
179
  ['API_KEY', needsEmail ? plunkApiKey : ''],
180
180
  ['STRIPE_SECRET_KEY', stripeSecretKey],
181
- ['STRIPE_WEBHOOK_SECRET', goals.sell && paymentProvider === 'stripe' ? stripeWebhookSecret : ''],
181
+ ['STRIPE_WEBHOOK_SECRET', features.sell && paymentProvider === 'stripe' ? stripeWebhookSecret : ''],
182
182
  [AGENT_PROVIDER_SECRETS[agentProvider], agentProviderKey],
183
183
  ]) {
184
184
  if (typeof value === 'string' && value)
185
185
  secrets[name] = value;
186
186
  }
187
187
  await Promise.all(Object.entries(secrets).map(([secretName, value]) => client.setActionsSecret(secretName, value)));
188
- const { data: setupState, commitSha: setupCommitSha } = await readJsonConfig(client, WEBSITE_SETUP_PATH, {});
189
- await stageConfig(client, WEBSITE_SETUP_PATH, {
188
+ const { data: setupState, commitSha: setupCommitSha } = await readJsonConfig(client, WEBSITE_CONFIG_PATH, {});
189
+ await stageConfig(client, WEBSITE_CONFIG_PATH, {
190
190
  ...setupState,
191
191
  version: 1,
192
192
  complete: true,
193
- goals,
193
+ features,
194
194
  updatedAt: Date.now(),
195
- }, 'Record project goals [skip ci]', setupCommitSha);
195
+ }, 'Record project features [skip ci]', setupCommitSha);
196
196
  const { data: shopSettings, commitSha: shopCommitSha } = await readJsonConfig(client, SHOP_SETTINGS_PATH, DEFAULT_SHOP_SETTINGS);
197
197
  await stageConfig(client, SHOP_SETTINGS_PATH, {
198
198
  ...DEFAULT_SHOP_SETTINGS,
199
199
  ...shopSettings,
200
200
  // No shop means no payment method was chosen; leave it empty rather than
201
201
  // implying the shipped default was a decision.
202
- enabledPaymentMethods: goals.sell && paymentProvider ? [paymentProvider] : [],
203
- ...(goals.sell ? { emailTemplates: { ...DEFAULT_SHOP_EMAIL_TEMPLATES, ...shopSettings.emailTemplates } } : {}),
202
+ enabledPaymentMethods: features.sell && paymentProvider ? [paymentProvider] : [],
203
+ ...(features.sell ? { emailTemplates: { ...DEFAULT_SHOP_EMAIL_TEMPLATES, ...shopSettings.emailTemplates } } : {}),
204
204
  bankTransfer: {
205
205
  ...DEFAULT_SHOP_SETTINGS.bankTransfer,
206
206
  ...(shopSettings.bankTransfer ?? {}),
@@ -216,7 +216,7 @@ export async function setupProject(c) {
216
216
  ...emailSettings,
217
217
  invoice,
218
218
  footerHtml,
219
- automation: subscriptionAutomation(goals.newsletters, emailSettings.automation),
219
+ automation: subscriptionAutomation(features.newsletters, emailSettings.automation),
220
220
  fromEmail: typeof body.fromEmail === 'string' ? body.fromEmail.trim() : emailSettings.fromEmail,
221
221
  fromName: typeof body.fromName === 'string' ? body.fromName.trim() : emailSettings.fromName,
222
222
  replyTo: typeof body.replyTo === 'string' ? body.replyTo.trim() : emailSettings.replyTo,
@@ -1 +1 @@
1
- {"version":3,"file":"website-repo.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/cms/handlers/website-repo.handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAgC9C,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE1D;AA4CD,yFAAyF;AACzF,wBAAsB,eAAe,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CA0B5E;AAED,wBAAsB,eAAe,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAG5E;AAED,wBAAsB,eAAe,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAc5E;AAED,wBAAsB,iBAAiB,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAqD9E"}
1
+ {"version":3,"file":"website-repo.handler.d.ts","sourceRoot":"","sources":["../../../../src/api/cms/handlers/website-repo.handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAgC9C,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE1D;AA4CD,yFAAyF;AACzF,wBAAsB,eAAe,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CA0B5E;AAED,wBAAsB,eAAe,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAG5E;AAED,wBAAsB,eAAe,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAc5E;AAED,wBAAsB,iBAAiB,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CA+D9E"}
@@ -1,6 +1,6 @@
1
1
  import { getGitHubConfig } from '../../../lib/config';
2
2
  import { createGitHubClient } from '../../../lib/github';
3
- import { I18N_CONFIG_PATH, STATIC_DIR, isWebsitePath } from '@hintergrund/runtime-contracts';
3
+ import { CONFIG_PATH, STATIC_DIR, isDisabledFeaturePath, isWebsitePath, normalizeProjectConfig } from '@hintergrund/runtime-contracts';
4
4
  import { translateWebsite } from '../../../lib/website-i18n';
5
5
  const STATIC_MIME_TYPES = {
6
6
  '.jpg': 'image/jpeg',
@@ -126,6 +126,22 @@ export async function commitWebsiteRepo(c) {
126
126
  if (invalidPath) {
127
127
  return c.json({ error: `Path is not allowed for website sync: ${invalidPath}` }, 400);
128
128
  }
129
+ // Features are fixed at setup. Refuse writes that would reintroduce a disabled
130
+ // feature's code, so the repository keeps matching what the project actually does.
131
+ const configEntry = files.find((file) => file.path === CONFIG_PATH);
132
+ const configRaw = configEntry?.content ?? (await createGitHubClient(getGitHubConfig(c.env)).readFile(CONFIG_PATH))?.content;
133
+ if (configRaw) {
134
+ let features;
135
+ try {
136
+ features = normalizeProjectConfig(JSON.parse(configRaw)).features;
137
+ }
138
+ catch {
139
+ features = undefined;
140
+ }
141
+ const blocked = features && files.map((file) => file.path).find((path) => isDisabledFeaturePath(path, features));
142
+ if (blocked)
143
+ return c.json({ error: `This project does not use the feature that owns ${blocked}.` }, 422);
144
+ }
129
145
  const writtenPaths = new Set(files.map((file) => file.path));
130
146
  if (deletions.some((path) => writtenPaths.has(path))) {
131
147
  return c.json({ error: 'A path cannot be written and deleted in the same commit' }, 400);
@@ -143,7 +159,7 @@ export async function commitWebsiteRepo(c) {
143
159
  const baseCommitSha = body.baseCommitSha ? String(body.baseCommitSha) : await client.getCommitSha();
144
160
  let translation = null;
145
161
  try {
146
- if (files.some(file => file.path === I18N_CONFIG_PATH) || await client.readFile(I18N_CONFIG_PATH)) {
162
+ if (files.some(file => file.path === CONFIG_PATH) || await client.readFile(CONFIG_PATH)) {
147
163
  const snapshot = await listRepoFiles(c);
148
164
  const combined = new Map(Object.entries(snapshot).map(([path, file]) => [path, { path, content: file.content }]));
149
165
  for (const file of files)
@@ -1 +1 @@
1
- {"version":3,"file":"website-i18n.d.ts","sourceRoot":"","sources":["../../src/lib/website-i18n.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkL,KAAK,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACxP,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AA4GxD,sGAAsG;AACtG,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CA2B9G;AAED,kFAAkF;AAClF,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAY3I;AAED,gGAAgG;AAChG,wBAAsB,0BAA0B,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,iBAAiB,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAc5H"}
1
+ {"version":3,"file":"website-i18n.d.ts","sourceRoot":"","sources":["../../src/lib/website-i18n.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiL,KAAK,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACvP,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AA4GxD,sGAAsG;AACtG,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CA2B9G;AAED,kFAAkF;AAClF,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAY3I;AAED,gGAAgG;AAChG,wBAAsB,0BAA0B,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,iBAAiB,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAgB5H"}
@@ -1,4 +1,4 @@
1
- import { DEFAULT_I18N_CONFIG, I18N_CONFIG_PATH, I18N_CATALOG_PATH, I18N_RUNTIME_PATH, LIB_ROOT, SRC_ROOT, isTranslatableContentPath, validateI18nConfig } from '@hintergrund/runtime-contracts';
1
+ import { DEFAULT_I18N_CONFIG, CONFIG_PATH, I18N_CATALOG_PATH, I18N_RUNTIME_PATH, LIB_ROOT, SRC_ROOT, isTranslatableContentPath, normalizeProjectConfig } from '@hintergrund/runtime-contracts';
2
2
  import { parseJsonc, stringifyJsonc } from './jsonc';
3
3
  import { activeAgentProvider } from '../api/cms/handlers/agent-provider.handler';
4
4
  const textField = /(?:^|[A-Z_])(name|title|headline|heading|subheading|subtitle|tagline|description|excerpt|content|body|text|label|caption|alt|bio\d*|role|note|question|answer|quote|announcement|message|summary|paragraph|button|cta|eyebrow|intro|signoff|copyright)s?$/i;
@@ -124,10 +124,10 @@ async function translate(env, messages, target) {
124
124
  }
125
125
  /** Produces a complete catalogue before the atomic Git commit; never publishes stale translations. */
126
126
  export async function translateWebsite(files, env) {
127
- const configFile = files.get(I18N_CONFIG_PATH);
127
+ const configFile = files.get(CONFIG_PATH);
128
128
  if (!configFile)
129
- return null; // Not a website commit, or the template carries no language config.
130
- const config = validateI18nConfig(JSON.parse(configFile.content));
129
+ return null; // Not a website commit.
130
+ const config = normalizeProjectConfig(JSON.parse(configFile.content)).languages;
131
131
  if ((config.languages.length > 1 || config.sourceLanguage !== 'en') && !files.has(I18N_RUNTIME_PATH)) {
132
132
  throw new Error('This template needs the website language runtime. Use an updated template registry or integrate src/lib/i18n/runtime.svelte.ts before enabling languages.');
133
133
  }
@@ -159,12 +159,12 @@ export async function translateWebsite(files, env) {
159
159
  }
160
160
  /** Used by direct product API writes as well as the website working-copy save. */
161
161
  export async function translateWebsiteFiles(github, input, env, revision) {
162
- const config = await github.readFile(I18N_CONFIG_PATH);
162
+ const config = await github.readFile(CONFIG_PATH);
163
163
  if (!config)
164
164
  return input;
165
165
  const { owner, repo } = github.getRepoInfo();
166
166
  const tree = await (await github.getOctokit()).rest.git.getTree({ owner, repo, tree_sha: revision, recursive: 'true' });
167
- const paths = tree.data.tree.filter(item => item.type === 'blob' && item.path && (isTranslatableContentPath(item.path) || (item.path.startsWith(`${SRC_ROOT}/`) && item.path.endsWith('.svelte')) || [I18N_CONFIG_PATH, I18N_CATALOG_PATH, I18N_RUNTIME_PATH].includes(item.path))).map(item => item.path);
167
+ const paths = tree.data.tree.filter(item => item.type === 'blob' && item.path && (isTranslatableContentPath(item.path) || (item.path.startsWith(`${SRC_ROOT}/`) && item.path.endsWith('.svelte')) || [CONFIG_PATH, I18N_CATALOG_PATH, I18N_RUNTIME_PATH].includes(item.path))).map(item => item.path);
168
168
  const snapshot = await github.readFiles(paths);
169
169
  const files = new Map();
170
170
  for (const [path, file] of snapshot)
@@ -187,7 +187,9 @@ export async function initializeWebsiteLanguages(files, config, env) {
187
187
  file.content = file.path.endsWith('.jsonc') ? stringifyJsonc(value, file.content) : JSON.stringify(value, null, 2);
188
188
  }
189
189
  }
190
- map.set(I18N_CONFIG_PATH, { path: I18N_CONFIG_PATH, content: JSON.stringify(config, null, 2), encoding: 'utf8' });
190
+ const existing = map.get(CONFIG_PATH);
191
+ const current = existing ? JSON.parse(existing.content) : {};
192
+ map.set(CONFIG_PATH, { path: CONFIG_PATH, content: `${JSON.stringify({ ...current, languages: config }, null, 2)}\n`, encoding: 'utf8' });
191
193
  const catalog = await translateWebsite(map, env);
192
194
  if (catalog)
193
195
  map.set(catalog.path, catalog);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hintergrund/worker",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -29,7 +29,7 @@
29
29
  "postal-mime": "^3.0.0",
30
30
  "stripe": "^17.5.0",
31
31
  "tweetnacl": "^1.0.3",
32
- "@hintergrund/runtime-contracts": "0.3.2"
32
+ "@hintergrund/runtime-contracts": "0.3.3"
33
33
  },
34
34
  "scripts": {
35
35
  "build": "tsc",