@senseihq/emaki-posting 0.1.2 → 0.2.0

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 SenecaGlobal
3
+ Copyright (c) 2026 sensei-hq
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -10,7 +10,7 @@ npm i @senseihq/emaki-posting
10
10
 
11
11
  | Export | What |
12
12
  |---|---|
13
- | `@senseihq/emaki-posting` | rules (`contentSha`, `channelState`, `due`, `makeNext`, `signMedia`, `checkSignature`, `validKey`), access (`verifyCaller`, `callerOf`, `allowed`, roles admin / stager / poster), `PostingStore` + `MediaStore` interfaces and `memoryStore()`, and `createDesk(options)` → `{ api, signedMedia, desk }` |
13
+ | `@senseihq/emaki-posting` | rules (`contentSha`, `channelState`, `due`, `makeNext`, `signMedia(key, secret, { origin, path?, ttl?, now? })`, `checkSignature`, `validKey`), access (`verifyCaller`, `callerOf`, `allowed`, roles admin / stager / poster), `PostingStore` + `MediaStore` interfaces and `memoryStore()`, and `createDesk(options)` → `{ api, signedMedia, desk }` |
14
14
  | `/cloudflare` | `d1Store(db)` and `r2Media(bucket)` |
15
15
  | `/sveltekit` | `postingHandle({ env, dev })` (the guard hook), `apiRoutes(desk)`, `mediaRoute(desk)` |
16
16
  | `/migrations/*` | D1 / SQLite schema: staged, approvals, posts, audit, settings, schedule, production, requests |
@@ -52,4 +52,4 @@ Setup:
52
52
  `POST_MODE=dry-run` until you trust it; run `python3 node_modules/@senseihq/emaki-posting/poster/post.py`.
53
53
  5. Test in dry-run: stage → approve → change the text (the approval lapses) → re-approve → dry-run post.
54
54
 
55
- MIT © SenecaGlobal
55
+ MIT © sensei-hq
@@ -16,7 +16,7 @@ function queueRows(all, pieces) {
16
16
  }));
17
17
  }
18
18
  /** A media file of a due post, with a short-lived public link when the desk has a media secret. */
19
- const linked = async (d, x, base) => ({ ...x, url: d.o.mediaSecret ? await signMedia(x.key, d.o.mediaSecret, base, 3600, Date.now(), d.o.mediaPath ?? '/m') : null });
19
+ const linked = async (d, x, base) => ({ ...x, url: d.o.mediaSecret ? await signMedia(x.key, d.o.mediaSecret, { origin: base, path: d.o.mediaPath }) : null });
20
20
  const queueItem = async (d, s, pieces, base) => ({
21
21
  slug: s.slug, channel: s.channel, content_sha: s.content_sha, post: s.post, article: d.o.pieceUrl(s.slug),
22
22
  video: pieces.find((a) => a.slug === s.slug)?.video ?? 'short',
@@ -100,7 +100,7 @@ export async function putMedia(d, caller, key, request) {
100
100
  const got = await sha256(body);
101
101
  if (!want || got !== want)
102
102
  fail(400, `sha256 mismatch (got ${got})`);
103
- await d.media.put(key, body, { contentType: TYPES[key.split('.').pop() ?? ''] ?? 'application/octet-stream', sha256: got });
103
+ await d.media.put(key, body, { contentType: TYPES[key.split('.').pop()] ?? 'application/octet-stream', sha256: got });
104
104
  await d.store.audit(caller.id, 'upload', key.split('/')[0], null, `${key} ${got.slice(0, 12)}`);
105
105
  return { ok: true, key, sha256: got, bytes: body.byteLength };
106
106
  }
package/dist/rules.d.ts CHANGED
@@ -63,8 +63,16 @@ export declare function due(rows: {
63
63
  approvals: ApprovalRow[];
64
64
  posts: PostRow[];
65
65
  }[], today: string, paused: boolean): StagedRow[];
66
+ /** Where a signed media URL points and how long it lives: the site's origin, the media route's path (default /m),
67
+ * seconds until it expires (default an hour) and the clock (default now, in ms). */
68
+ export interface SignOptions {
69
+ origin: string;
70
+ path?: string;
71
+ ttl?: number;
72
+ now?: number;
73
+ }
66
74
  /** A short-lived, signed public URL for one media file (Instagram fetches media from a URL). */
67
- export declare function signMedia(key: string, secret: string, origin: string, ttl?: number, now?: number, path?: string): Promise<string>;
75
+ export declare function signMedia(key: string, secret: string, { origin, path, ttl, now }: SignOptions): Promise<string>;
68
76
  export declare function checkSignature(key: string, exp: string, sig: string, secret: string, now?: number): Promise<boolean>;
69
77
  /** Media keys: <slug>/<file>, lower-case, no path tricks. */
70
78
  export declare const validKey: (k: string) => boolean;
package/dist/rules.js CHANGED
@@ -50,7 +50,7 @@ export function due(rows, today, paused) {
50
50
  return out;
51
51
  }
52
52
  /** A short-lived, signed public URL for one media file (Instagram fetches media from a URL). */
53
- export async function signMedia(key, secret, origin, ttl = 3600, now = Date.now(), path = '/m') {
53
+ export async function signMedia(key, secret, { origin, path = '/m', ttl = 3600, now = Date.now() }) {
54
54
  const exp = Math.floor(now / 1000) + ttl;
55
55
  const sig = await hmac(secret, `${key}:${exp}`);
56
56
  return `${origin}${path}/${key.split('/').map(encodeURIComponent).join('/')}?exp=${exp}&sig=${sig}`;
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@senseihq/emaki-posting",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "The motion stories posting desk: stage, approve exactly what was staged, post on schedule. Framework-free core with Cloudflare (D1/R2/Access) and SvelteKit adapters.",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
- "author": "SenecaGlobal",
7
+ "author": "sensei-hq",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "git+https://github.com/sensei-hq/emaki.git",
@@ -23,7 +23,7 @@ function queueRows(all: DeskState, pieces: Piece[]) {
23
23
 
24
24
  /** A media file of a due post, with a short-lived public link when the desk has a media secret. */
25
25
  const linked = async (d: DeskContext, x: MediaRef, base: string) =>
26
- ({ ...x, url: d.o.mediaSecret ? await signMedia(x.key, d.o.mediaSecret, base, 3600, Date.now(), d.o.mediaPath ?? '/m') : null });
26
+ ({ ...x, url: d.o.mediaSecret ? await signMedia(x.key, d.o.mediaSecret, { origin: base, path: d.o.mediaPath }) : null });
27
27
 
28
28
  const queueItem = async (d: DeskContext, s: StagedRow, pieces: Piece[], base: string) => ({
29
29
  slug: s.slug, channel: s.channel, content_sha: s.content_sha, post: s.post, article: d.o.pieceUrl(s.slug),
@@ -106,7 +106,7 @@ export async function putMedia(d: DeskContext, caller: Caller, key: string, requ
106
106
  if (body.byteLength > MAX) fail(413, 'Too large');
107
107
  const got = await sha256(body);
108
108
  if (!want || got !== want) fail(400, `sha256 mismatch (got ${got})`);
109
- await d.media.put(key, body, { contentType: TYPES[key.split('.').pop() ?? ''] ?? 'application/octet-stream', sha256: got });
109
+ await d.media.put(key, body, { contentType: TYPES[key.split('.').pop()!] ?? 'application/octet-stream', sha256: got });
110
110
  await d.store.audit(caller.id, 'upload', key.split('/')[0], null, `${key} ${got.slice(0, 12)}`);
111
111
  return { ok: true, key, sha256: got, bytes: body.byteLength };
112
112
  }
package/src/rules.ts CHANGED
@@ -66,8 +66,12 @@ export function due(
66
66
  return out;
67
67
  }
68
68
 
69
+ /** Where a signed media URL points and how long it lives: the site's origin, the media route's path (default /m),
70
+ * seconds until it expires (default an hour) and the clock (default now, in ms). */
71
+ export interface SignOptions { origin: string; path?: string; ttl?: number; now?: number }
72
+
69
73
  /** A short-lived, signed public URL for one media file (Instagram fetches media from a URL). */
70
- export async function signMedia(key: string, secret: string, origin: string, ttl = 3600, now = Date.now(), path = '/m') {
74
+ export async function signMedia(key: string, secret: string, { origin, path = '/m', ttl = 3600, now = Date.now() }: SignOptions) {
71
75
  const exp = Math.floor(now / 1000) + ttl;
72
76
  const sig = await hmac(secret, `${key}:${exp}`);
73
77
  return `${origin}${path}/${key.split('/').map(encodeURIComponent).join('/')}?exp=${exp}&sig=${sig}`;