@hazem3500/palette 0.9.111 → 0.9.113

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/NODE.md CHANGED
@@ -191,3 +191,68 @@ grant are refused behind the proxy even after opt-in. Bounded, explicitly scoped
191
191
  existing tokens remain usable. Nonproxy token policy is unchanged. Snapshot GET
192
192
  requires `comments:read`, the granted project and an allowed Origin. No deployment
193
193
  is enabled by this configuration example.
194
+
195
+ ### Webhook delivery and snapshot readiness
196
+
197
+ Apply PostgreSQL migration 008 (automatic at Node startup) or D1 migration
198
+ 0022 before running this version. Comment creation, replies and resolution
199
+ commit their selected webhook into `webhook_outbox` in the same transaction as
200
+ the mutation. No destination is configured by default. The outbox pins the URL,
201
+ encrypted signing secret, event ID and exact JSON bytes at creation. Changing or
202
+ disabling project webhook settings affects future events; queued events retain
203
+ their destination. Keep old encryption keys available until those entries drain.
204
+
205
+ Node drains every 10 seconds. Workers must configure a recurring Cron Trigger
206
+ (for example every minute); the exported Worker `scheduled` handler drains the
207
+ outbox. Custom runtimes can import `drainWebhooks` from the server export and
208
+ call `await drainWebhooks(env)` periodically. Request `waitUntil` only accelerates
209
+ these committed deliveries. Worker deployments must supply their existing
210
+ `PALETTE_WEBHOOK_SEND` transport; it must reject non-2xx responses, reject within
211
+ 5 seconds, validate DNS against private addresses, pin the validated address,
212
+ and never follow redirects. No unsafe fetch transport is installed implicitly.
213
+ The built-in Node transport enforces public DNS/IP pinning and bounded DNS/send
214
+ timeouts, and now rejects all non-2xx responses.
215
+
216
+ Each drain claims at most 20 entries, one at a time, with an atomic conditional
217
+ UPDATE and a 30-second lease. Six attempts maximum, including interrupted
218
+ attempts; failed attempts wait 10, 20, 40, 80 and 160 seconds (plus scheduling
219
+ latency). Expired claims can be recovered by another process. Completion uses
220
+ the claim token so a stale worker cannot acknowledge a newer claim. The drain
221
+ stops waiting for an attempt after 5 seconds. Custom transports must enforce
222
+ that bound themselves: a Promise timeout cannot cancel their network effects.
223
+ Delivery is at least once: a crash after remote acceptance can cause duplicates.
224
+ Deduplicate by `X-Palette-Delivery` (legacy `X-Komo-Delivery` is identical).
225
+ Each attempt signs the stored body with a fresh current Unix-second timestamp;
226
+ header aliases and the `timestamp + "." + body` HMAC format are unchanged.
227
+
228
+ Operators can inspect `id,project,attempts,state,next_attempt,claim_until` in
229
+ `webhook_outbox`; attempt/lease times are Unix milliseconds.
230
+ `delivered` and `exhausted` are retained; no automatic purge or
231
+ external delivery-management endpoint is provided. After fixing a receiver,
232
+ explicitly reset an exhausted entry's `attempts=0,state='pending',next_attempt=0,
233
+ claim_until=0,claim_token=''` to replay its same ID/body. Do not reset an active
234
+ lease. Purge retained entries using your database retention policy; bodies may
235
+ contain comment content. Outbox rows are independent of thread deletion.
236
+
237
+ `config.snapshots.readiness: true` advertises this protocol; clients omit new
238
+ intent fields and terminal reports on older servers.
239
+ `POST /threads` accepts optional boolean `snapshotIntent`. Its `comment.created`
240
+ event gains `snapshotStatus: 'pending'` for true or `'skipped'` for false.
241
+ Omitting intent leaves status unknown and preserves the existing event fields,
242
+ so older clients can still upload later without claiming an intentional skip.
243
+ Legacy intent is never inferred from an image 404. There is no new snapshot event.
244
+
245
+ Authenticated `GET /threads/:id/snapshot` returns `{status,kinds}`. `status` is
246
+ `pending`, `ready`, `skipped`, `failed`, or `unknown` (legacy/imported threads).
247
+ `kinds` lists stored `image`/`html` captures. Any successfully stored kind means
248
+ ready; it does not promise both kinds. The upload transaction sets ready.
249
+ Pending capture older than ten minutes reads as failed, bounding abandoned
250
+ client captures. A later successful upload can still make it ready.
251
+ `POST /threads/:id/snapshot` with JSON `{status:'skipped'}` or `{status:'failed'}`
252
+ terminates a pending capture; clients report intentional omissions and upload
253
+ failures this way. A failed status report falls back to the ten-minute deadline.
254
+ Deleting the final stored kind makes status skipped. Kind-specific GET routes
255
+ retain their existing 404 semantics. Snapshot status reads use existing
256
+ project/repo/branch authentication and PAT `comments:read`; writes retain guest
257
+ consent and author/reviewer checks and PAT `comments:write`. No token enablement
258
+ policy changes are included.
package/cli/config.mjs CHANGED
@@ -45,6 +45,13 @@ export function branchName(env, cwd) {
45
45
  gitValue(["symbolic-ref", "--short", "HEAD"], cwd)
46
46
  );
47
47
  }
48
- export function clientModule(config) {
49
- return `import { definePalette } from '@hazem3500/palette/setup';\n\nexport const initPalette = definePalette(${JSON.stringify(config, null, 2)});\n\n/** @deprecated Use initPalette. */\nexport const initKomo = initPalette;\n`;
48
+ export function packageName(env = process.env) {
49
+ const name = env.PALETTE_PACKAGE_NAME ?? "@hazem3500/palette";
50
+ if (typeof name !== "string" || name.length > 214 || !/^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/.test(name))
51
+ throw Error("PALETTE_PACKAGE_NAME must be an npm package name, such as @scope/palette.");
52
+ return name;
53
+ }
54
+
55
+ export function clientModule(config, env = process.env) {
56
+ return `import { definePalette } from '${packageName(env)}/setup';\n\nexport const initPalette = definePalette(${JSON.stringify(config, null, 2)});\n\n/** @deprecated Use initPalette. */\nexport const initKomo = initPalette;\n`;
50
57
  }
package/cli/index.mjs CHANGED
@@ -5,7 +5,7 @@ import { fileURLToPath } from "node:url";
5
5
  import { spawn } from "node:child_process";
6
6
  import { createInterface } from "node:readline/promises";
7
7
  import { randomUUID, randomBytes, createHash } from "node:crypto";
8
- import { branchName, clientModule, gitValue, projectLayout, repository, setting } from "./config.mjs";
8
+ import { branchName, clientModule, gitValue, projectLayout, repository, setting, packageName } from "./config.mjs";
9
9
 
10
10
  import { installAgentWorkflow } from "./workflow.mjs";
11
11
  import { agentCommands, agentHelp, runAgent } from "./agent.mjs";
@@ -315,10 +315,10 @@ async function init() {
315
315
  return;
316
316
  } else {
317
317
  if (
318
- !(await exists(resolve(cwd, "node_modules/@hazem3500/palette/package.json")))
318
+ !(await exists(resolve(cwd, `node_modules/${packageName()}/package.json`)))
319
319
  )
320
320
  throw Error(
321
- "Install Palette in this project before self-hosting: npm install @hazem3500/palette (or install the preview tarball before publication)."
321
+ `Install Palette in this project before self-hosting: npm install ${packageName()} (or install the preview tarball before publication).`
322
322
  );
323
323
  await protectLocalFiles();
324
324
  const name = `komo-${basename(cwd)
@@ -337,7 +337,7 @@ async function init() {
337
337
  );
338
338
  await writeFile(
339
339
  join(dir, "index.ts"),
340
- 'export { default } from "@hazem3500/palette/server";\n'
340
+ `export { default } from "${packageName()}/server";\n`
341
341
  );
342
342
  const wrangler = {
343
343
  name,
@@ -376,16 +376,17 @@ async function init() {
376
376
  await installAgentWorkflow(cwd);
377
377
  console.log("Added the Palette comment workflow to AGENTS.md");
378
378
  console.log(
379
- `\nMount after the page loads:\n\nimport { initPalette } from '@hazem3500/palette';\ninitPalette(${JSON.stringify({ ...config, origin: undefined, ...(config.scope === "branch" ? { branch: branchName(process.env, cwd) } : {}) }, null, 2)});\n\nFor automatic branch detection, use the generated ${layout.module} helper and run palette sync before your build.\n`
379
+ `\nMount after the page loads:\n\nimport { initPalette } from '${packageName()}';\ninitPalette(${JSON.stringify({ ...config, origin: undefined, ...(config.scope === "branch" ? { branch: branchName(process.env, cwd) } : {}) }, null, 2)});\n\nFor automatic branch detection, use the generated ${layout.module} helper and run palette sync before your build.\n`
380
380
  );
381
381
  } finally {
382
382
  rl.close();
383
383
  }
384
384
  }
385
385
  try {
386
+ packageName();
386
387
  if (args.includes("--help") || !command)
387
388
  console.log(
388
- `Palette\n\n palette init --endpoint API_URL Connect to an existing Palette server\n palette init --self-host Deploy your own Worker and D1 database\n palette init --node Prepare a Node/PostgreSQL project\n palette deploy Resume self-hosted deployment\n palette sync Regenerate client settings; detect the current branch\n\nOptions: --origin URL --endpoint API_URL --repo OWNER/REPO --branch-scope\nSelf-host: --google-client-id ID; Node: --preview-origin HTTPS_WILDCARD\n\nComments are shared across deployments unless --branch-scope is set.${
389
+ `Palette\n\n palette init --endpoint API_URL Connect to an existing Palette server\n palette init --self-host Deploy your own Worker and D1 database\n palette init --node Prepare a Node/PostgreSQL project\n palette deploy Resume self-hosted deployment\n palette sync Regenerate client settings; detect the current branch\n\nOptions: --origin URL --endpoint API_URL --repo OWNER/REPO --branch-scope\nSelf-host: --google-client-id ID; Node: --preview-origin HTTPS_WILDCARD\nWrappers: PALETTE_PACKAGE_NAME changes generated imports (default @hazem3500/palette).\n\nComments are shared across deployments unless --branch-scope is set.${
389
390
  agentHelp
390
391
  }`
391
392
  );