@ampless/backend 1.0.0-alpha.27 → 1.0.0-alpha.29

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.
@@ -1,5 +1,3 @@
1
- import "../chunk-BYXBJQAS.js";
2
-
3
1
  // src/auth/post-confirmation.ts
4
2
  import {
5
3
  CognitoIdentityProviderClient,
@@ -1,5 +1,3 @@
1
- import "../chunk-BYXBJQAS.js";
2
-
3
1
  // src/auth/user-admin.ts
4
2
  import {
5
3
  CognitoIdentityProviderClient,
@@ -1,12 +1,12 @@
1
- import "../chunk-BYXBJQAS.js";
2
-
3
1
  // src/events/dispatcher.ts
4
2
  import { unmarshall } from "@aws-sdk/util-dynamodb";
5
3
  import {
6
4
  SQSClient,
7
5
  SendMessageBatchCommand
8
6
  } from "@aws-sdk/client-sqs";
9
- import { detectContentEvents } from "ampless";
7
+ import {
8
+ detectContentEvents
9
+ } from "ampless";
10
10
  function requireEnv(name) {
11
11
  const v = process.env[name];
12
12
  if (!v) throw new Error(`event-dispatcher: missing required env var ${name}`);
@@ -20,15 +20,37 @@ function tableNameFromArn(arn) {
20
20
  const match = arn.match(/:table\/([^/]+)/);
21
21
  return match ? match[1] : null;
22
22
  }
23
+ function projectPost(raw) {
24
+ if (!raw || !raw.postId || !raw.slug || !raw.title) return null;
25
+ return {
26
+ postId: raw.postId,
27
+ slug: raw.slug,
28
+ title: raw.title,
29
+ status: raw.status ?? "draft",
30
+ publishedAt: raw.publishedAt,
31
+ tags: raw.tags
32
+ };
33
+ }
23
34
  function emitContentEvents(record, timestamp) {
24
35
  const oldItem = record.dynamodb?.OldImage ? unmarshall(record.dynamodb.OldImage) : null;
25
36
  const newItem = record.dynamodb?.NewImage ? unmarshall(record.dynamodb.NewImage) : null;
37
+ const events = [];
38
+ const previous = oldItem ? projectPost(oldItem) : null;
39
+ const next = newItem ? projectPost(newItem) : null;
40
+ if (previous || next) {
41
+ const indexPayload = { previous, next };
42
+ events.push({
43
+ type: "post.index.refresh",
44
+ payload: indexPayload,
45
+ timestamp
46
+ });
47
+ }
26
48
  const types = detectContentEvents({
27
49
  eventName: record.eventName,
28
50
  oldStatus: oldItem?.status,
29
51
  newStatus: newItem?.status
30
52
  });
31
- if (types.length === 0) return [];
53
+ if (types.length === 0) return events;
32
54
  const item = newItem ?? oldItem ?? {};
33
55
  const payload = {
34
56
  postId: item.postId,
@@ -38,7 +60,10 @@ function emitContentEvents(record, timestamp) {
38
60
  publishedAt: item.publishedAt,
39
61
  tags: item.tags
40
62
  };
41
- return types.map((type) => ({ type, payload, timestamp }));
63
+ for (const type of types) {
64
+ events.push({ type, payload, timestamp });
65
+ }
66
+ return events;
42
67
  }
43
68
  function emitKvEvents(record, timestamp) {
44
69
  const item = record.dynamodb?.NewImage ?? record.dynamodb?.OldImage ? unmarshall(record.dynamodb.NewImage ?? record.dynamodb.OldImage) : {};
@@ -1,12 +1,44 @@
1
- import "../chunk-BYXBJQAS.js";
2
-
3
1
  // src/events/processor-trusted.ts
4
2
  import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
5
3
  import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
6
- import { DynamoDBDocumentClient, QueryCommand } from "@aws-sdk/lib-dynamodb";
4
+ import {
5
+ DynamoDBDocumentClient,
6
+ DeleteCommand,
7
+ PutCommand,
8
+ QueryCommand
9
+ } from "@aws-sdk/lib-dynamodb";
7
10
  import {
8
11
  formatPublicAssetUrl
9
12
  } from "ampless";
13
+
14
+ // src/events/posttag-sync.ts
15
+ function computePostTagDiff(payload) {
16
+ const previousEntries = postTagItemsFromPost(payload.previous);
17
+ const nextEntries = postTagItemsFromPost(payload.next);
18
+ const nextKeys = new Set(nextEntries.map(itemKey));
19
+ const deletes = previousEntries.filter((p) => !nextKeys.has(itemKey(p))).map((p) => ({ tag: p.tag, publishedAtPostId: p.publishedAtPostId }));
20
+ return { deletes, puts: nextEntries };
21
+ }
22
+ function postTagItemsFromPost(p) {
23
+ if (!p) return [];
24
+ if (p.status !== "published") return [];
25
+ if (!p.publishedAt) return [];
26
+ const tags = Array.isArray(p.tags) ? p.tags : [];
27
+ return tags.filter((t) => typeof t === "string" && t.length > 0).map((tag) => ({
28
+ tag,
29
+ publishedAtPostId: `${p.publishedAt}#${p.postId}`,
30
+ postId: p.postId,
31
+ publishedAt: p.publishedAt,
32
+ slug: p.slug,
33
+ title: p.title,
34
+ tags
35
+ }));
36
+ }
37
+ function itemKey(item) {
38
+ return `${item.tag}|${item.publishedAtPostId}`;
39
+ }
40
+
41
+ // src/events/processor-trusted.ts
10
42
  function requireEnv(name) {
11
43
  const v = process.env[name];
12
44
  if (!v) throw new Error(`processor-trusted: missing required env var ${name}`);
@@ -30,6 +62,7 @@ function createProcessorTrustedHandler(opts) {
30
62
  const BUCKET = requireEnv("AMPLESS_BUCKET_NAME");
31
63
  const POST_TABLE = requireEnv("AMPLESS_POST_TABLE");
32
64
  const KV_TABLE = requireEnv("AMPLESS_KV_TABLE");
65
+ const POSTTAG_TABLE = requireEnv("AMPLESS_POSTTAG_TABLE");
33
66
  const REGION = requireEnv("AWS_REGION");
34
67
  async function listPublished() {
35
68
  const items = [];
@@ -82,6 +115,31 @@ function createProcessorTrustedHandler(opts) {
82
115
  }
83
116
  };
84
117
  }
118
+ async function rebuildPostTagsForPost(payload) {
119
+ const { deletes, puts } = computePostTagDiff(payload);
120
+ await Promise.all([
121
+ ...deletes.map(
122
+ (key) => ddb.send(
123
+ new DeleteCommand({
124
+ TableName: POSTTAG_TABLE,
125
+ Key: key
126
+ })
127
+ )
128
+ ),
129
+ ...puts.map(
130
+ (item) => ddb.send(
131
+ new PutCommand({
132
+ TableName: POSTTAG_TABLE,
133
+ Item: item
134
+ })
135
+ )
136
+ )
137
+ ]);
138
+ const postId = payload.next?.postId ?? payload.previous?.postId ?? "(unknown)";
139
+ console.log(
140
+ `[posttag-sync] postId=${postId} removed=${deletes.length} upserted=${puts.length}`
141
+ );
142
+ }
85
143
  async function rebuildSiteSettingsCache() {
86
144
  const settings = {};
87
145
  let exclusiveStartKey;
@@ -136,6 +194,14 @@ function createProcessorTrustedHandler(opts) {
136
194
  throw err;
137
195
  }
138
196
  }
197
+ if (parsed.type === "post.index.refresh") {
198
+ try {
199
+ await rebuildPostTagsForPost(parsed.payload);
200
+ } catch (err) {
201
+ console.error("[trusted-processor] posttag-sync failed", err);
202
+ throw err;
203
+ }
204
+ }
139
205
  for (const plugin of trustedPlugins) {
140
206
  const hook = plugin.hooks?.[parsed.type];
141
207
  if (!hook) continue;
@@ -1,5 +1,3 @@
1
- import "../chunk-BYXBJQAS.js";
2
-
3
1
  // src/events/processor-untrusted.ts
4
2
  function createProcessorUntrustedHandler(opts) {
5
3
  const untrustedPlugins = (opts.plugins ?? []).filter(
@@ -1,5 +1,3 @@
1
- import "../chunk-BYXBJQAS.js";
2
-
3
1
  // src/functions/api-key-renewer.ts
4
2
  import {
5
3
  AppSyncClient,
@@ -1,11 +1,9 @@
1
- import "../chunk-BYXBJQAS.js";
2
-
3
1
  // src/functions/mcp-handler.ts
4
2
  import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
5
3
  import { DynamoDBDocumentClient, GetCommand } from "@aws-sdk/lib-dynamodb";
6
4
  import { createHash } from "crypto";
7
5
 
8
- // ../mcp-server/dist/chunk-HVSLKTKC.js
6
+ // ../mcp-server/dist/index.js
9
7
  import {
10
8
  decodeAwsJson
11
9
  } from "ampless";
@@ -21,7 +19,7 @@ import {
21
19
  pickDefaultEntrypoint,
22
20
  validateBundle
23
21
  } from "ampless";
24
- import { unzipSync, strFromU8 } from "fflate";
22
+ import { createRequire } from "module";
25
23
  import {
26
24
  validateBundlePath,
27
25
  stripCommonPrefix
@@ -159,92 +157,6 @@ async function getPost(client, args) {
159
157
  const item = data.listPosts.items[0];
160
158
  return item ? toCorePost(item) : null;
161
159
  }
162
- function entries(post) {
163
- if (post.status !== "published" || !post.publishedAt || !post.tags?.length) return [];
164
- return post.tags.map((tag) => ({
165
- tag,
166
- publishedAtPostId: `${post.publishedAt}#${post.postId}`
167
- }));
168
- }
169
- function entryKey(e) {
170
- return `${e.tag}|${e.publishedAtPostId}`;
171
- }
172
- var CREATE_POST_TAG = (
173
- /* GraphQL */
174
- `
175
- mutation CreatePostTag($input: CreatePostTagInput!) {
176
- createPostTag(input: $input) {
177
- tag
178
- publishedAtPostId
179
- }
180
- }
181
- `
182
- );
183
- var UPDATE_POST_TAG = (
184
- /* GraphQL */
185
- `
186
- mutation UpdatePostTag($input: UpdatePostTagInput!) {
187
- updatePostTag(input: $input) {
188
- tag
189
- publishedAtPostId
190
- }
191
- }
192
- `
193
- );
194
- var DELETE_POST_TAG = (
195
- /* GraphQL */
196
- `
197
- mutation DeletePostTag($input: DeletePostTagInput!) {
198
- deletePostTag(input: $input) {
199
- tag
200
- publishedAtPostId
201
- }
202
- }
203
- `
204
- );
205
- async function syncPostTags(client, post, oldPost) {
206
- const oldEntries = oldPost ? entries(oldPost) : [];
207
- const newEntries = entries(post);
208
- const oldKeys = new Set(oldEntries.map(entryKey));
209
- const newKeys = new Set(newEntries.map(entryKey));
210
- await Promise.all(
211
- oldEntries.filter((e) => !newKeys.has(entryKey(e))).map(
212
- (e) => client.query(DELETE_POST_TAG, {
213
- input: { tag: e.tag, publishedAtPostId: e.publishedAtPostId }
214
- })
215
- )
216
- );
217
- await Promise.all(
218
- newEntries.filter((e) => !oldKeys.has(entryKey(e))).map(
219
- (e) => client.query(CREATE_POST_TAG, {
220
- input: {
221
- tag: e.tag,
222
- publishedAtPostId: e.publishedAtPostId,
223
- postId: post.postId,
224
- publishedAt: post.publishedAt,
225
- slug: post.slug,
226
- title: post.title,
227
- excerpt: post.excerpt,
228
- tags: post.tags ?? []
229
- }
230
- })
231
- )
232
- );
233
- await Promise.all(
234
- newEntries.filter((e) => oldKeys.has(entryKey(e))).map(
235
- (e) => client.query(UPDATE_POST_TAG, {
236
- input: {
237
- tag: e.tag,
238
- publishedAtPostId: e.publishedAtPostId,
239
- slug: post.slug,
240
- title: post.title,
241
- excerpt: post.excerpt,
242
- tags: post.tags ?? []
243
- }
244
- })
245
- )
246
- );
247
- }
248
160
  var MUTATION = (
249
161
  /* GraphQL */
250
162
  `
@@ -312,9 +224,7 @@ async function createPost(client, args) {
312
224
  metadata: args.metadata !== void 0 ? encodeAwsJson(args.metadata) : void 0
313
225
  }
314
226
  });
315
- const created = toCorePost(data.createPost);
316
- await syncPostTags(client, created, null);
317
- return created;
227
+ return toCorePost(data.createPost);
318
228
  }
319
229
  var MUTATION2 = (
320
230
  /* GraphQL */
@@ -364,7 +274,6 @@ var updatePostSchema = {
364
274
  }
365
275
  };
366
276
  async function updatePost(client, args) {
367
- const oldPost = await getPost(client, { postId: args.postId });
368
277
  const input = { postId: args.postId };
369
278
  if (args.slug !== void 0) input.slug = args.slug;
370
279
  if (args.title !== void 0) input.title = args.title;
@@ -376,9 +285,7 @@ async function updatePost(client, args) {
376
285
  if (args.tags !== void 0) input.tags = args.tags;
377
286
  if (args.metadata !== void 0) input.metadata = encodeAwsJson2(args.metadata);
378
287
  const data = await client.query(MUTATION2, { input });
379
- const updated = toCorePost(data.updatePost);
380
- await syncPostTags(client, updated, oldPost);
381
- return updated;
288
+ return toCorePost(data.updatePost);
382
289
  }
383
290
  var MUTATION3 = (
384
291
  /* GraphQL */
@@ -398,10 +305,6 @@ var deletePostSchema = {
398
305
  }
399
306
  };
400
307
  async function deletePost(client, args) {
401
- const oldPost = await getPost(client, { postId: args.postId });
402
- if (oldPost) {
403
- await syncPostTags(client, { ...oldPost, status: "draft" }, oldPost);
404
- }
405
308
  const data = await client.query(MUTATION3, { input: { postId: args.postId } });
406
309
  return { deleted: data.deletePost };
407
310
  }
@@ -523,14 +426,494 @@ function getSchema() {
523
426
  }
524
427
  };
525
428
  }
429
+ var require2 = createRequire("/");
430
+ var _a;
431
+ var Worker;
432
+ var isMarkedAsUntransferable;
433
+ try {
434
+ _a = require2("worker_threads"), Worker = _a.Worker, isMarkedAsUntransferable = _a.isMarkedAsUntransferable;
435
+ } catch (e) {
436
+ }
437
+ var u8 = Uint8Array;
438
+ var u16 = Uint16Array;
439
+ var i32 = Int32Array;
440
+ var fleb = new u8([
441
+ 0,
442
+ 0,
443
+ 0,
444
+ 0,
445
+ 0,
446
+ 0,
447
+ 0,
448
+ 0,
449
+ 1,
450
+ 1,
451
+ 1,
452
+ 1,
453
+ 2,
454
+ 2,
455
+ 2,
456
+ 2,
457
+ 3,
458
+ 3,
459
+ 3,
460
+ 3,
461
+ 4,
462
+ 4,
463
+ 4,
464
+ 4,
465
+ 5,
466
+ 5,
467
+ 5,
468
+ 5,
469
+ 0,
470
+ /* unused */
471
+ 0,
472
+ 0,
473
+ /* impossible */
474
+ 0
475
+ ]);
476
+ var fdeb = new u8([
477
+ 0,
478
+ 0,
479
+ 0,
480
+ 0,
481
+ 1,
482
+ 1,
483
+ 2,
484
+ 2,
485
+ 3,
486
+ 3,
487
+ 4,
488
+ 4,
489
+ 5,
490
+ 5,
491
+ 6,
492
+ 6,
493
+ 7,
494
+ 7,
495
+ 8,
496
+ 8,
497
+ 9,
498
+ 9,
499
+ 10,
500
+ 10,
501
+ 11,
502
+ 11,
503
+ 12,
504
+ 12,
505
+ 13,
506
+ 13,
507
+ /* unused */
508
+ 0,
509
+ 0
510
+ ]);
511
+ var clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
512
+ var freb = function(eb, start) {
513
+ var b = new u16(31);
514
+ for (var i2 = 0; i2 < 31; ++i2) {
515
+ b[i2] = start += 1 << eb[i2 - 1];
516
+ }
517
+ var r = new i32(b[30]);
518
+ for (var i2 = 1; i2 < 30; ++i2) {
519
+ for (var j = b[i2]; j < b[i2 + 1]; ++j) {
520
+ r[j] = j - b[i2] << 5 | i2;
521
+ }
522
+ }
523
+ return { b, r };
524
+ };
525
+ var _a = freb(fleb, 2);
526
+ var fl = _a.b;
527
+ var revfl = _a.r;
528
+ fl[28] = 258, revfl[258] = 28;
529
+ var _b = freb(fdeb, 0);
530
+ var fd = _b.b;
531
+ var revfd = _b.r;
532
+ var rev = new u16(32768);
533
+ for (i = 0; i < 32768; ++i) {
534
+ x = (i & 43690) >> 1 | (i & 21845) << 1;
535
+ x = (x & 52428) >> 2 | (x & 13107) << 2;
536
+ x = (x & 61680) >> 4 | (x & 3855) << 4;
537
+ rev[i] = ((x & 65280) >> 8 | (x & 255) << 8) >> 1;
538
+ }
539
+ var x;
540
+ var i;
541
+ var hMap = (function(cd, mb, r) {
542
+ var s = cd.length;
543
+ var i2 = 0;
544
+ var l = new u16(mb);
545
+ for (; i2 < s; ++i2) {
546
+ if (cd[i2])
547
+ ++l[cd[i2] - 1];
548
+ }
549
+ var le = new u16(mb);
550
+ for (i2 = 1; i2 < mb; ++i2) {
551
+ le[i2] = le[i2 - 1] + l[i2 - 1] << 1;
552
+ }
553
+ var co;
554
+ if (r) {
555
+ co = new u16(1 << mb);
556
+ var rvb = 15 - mb;
557
+ for (i2 = 0; i2 < s; ++i2) {
558
+ if (cd[i2]) {
559
+ var sv = i2 << 4 | cd[i2];
560
+ var r_1 = mb - cd[i2];
561
+ var v = le[cd[i2] - 1]++ << r_1;
562
+ for (var m = v | (1 << r_1) - 1; v <= m; ++v) {
563
+ co[rev[v] >> rvb] = sv;
564
+ }
565
+ }
566
+ }
567
+ } else {
568
+ co = new u16(s);
569
+ for (i2 = 0; i2 < s; ++i2) {
570
+ if (cd[i2]) {
571
+ co[i2] = rev[le[cd[i2] - 1]++] >> 15 - cd[i2];
572
+ }
573
+ }
574
+ }
575
+ return co;
576
+ });
577
+ var flt = new u8(288);
578
+ for (i = 0; i < 144; ++i)
579
+ flt[i] = 8;
580
+ var i;
581
+ for (i = 144; i < 256; ++i)
582
+ flt[i] = 9;
583
+ var i;
584
+ for (i = 256; i < 280; ++i)
585
+ flt[i] = 7;
586
+ var i;
587
+ for (i = 280; i < 288; ++i)
588
+ flt[i] = 8;
589
+ var i;
590
+ var fdt = new u8(32);
591
+ for (i = 0; i < 32; ++i)
592
+ fdt[i] = 5;
593
+ var i;
594
+ var flrm = /* @__PURE__ */ hMap(flt, 9, 1);
595
+ var fdrm = /* @__PURE__ */ hMap(fdt, 5, 1);
596
+ var max = function(a) {
597
+ var m = a[0];
598
+ for (var i2 = 1; i2 < a.length; ++i2) {
599
+ if (a[i2] > m)
600
+ m = a[i2];
601
+ }
602
+ return m;
603
+ };
604
+ var bits = function(d, p, m) {
605
+ var o = p / 8 | 0;
606
+ return (d[o] | d[o + 1] << 8) >> (p & 7) & m;
607
+ };
608
+ var bits16 = function(d, p) {
609
+ var o = p / 8 | 0;
610
+ return (d[o] | d[o + 1] << 8 | d[o + 2] << 16) >> (p & 7);
611
+ };
612
+ var shft = function(p) {
613
+ return (p + 7) / 8 | 0;
614
+ };
615
+ var slc = function(v, s, e) {
616
+ if (s == null || s < 0)
617
+ s = 0;
618
+ if (e == null || e > v.length)
619
+ e = v.length;
620
+ return new u8(v.subarray(s, e));
621
+ };
622
+ var ec = [
623
+ "unexpected EOF",
624
+ "invalid block type",
625
+ "invalid length/literal",
626
+ "invalid distance",
627
+ "stream finished",
628
+ "no stream handler",
629
+ ,
630
+ // determined by compression function
631
+ "no callback",
632
+ "invalid UTF-8 data",
633
+ "extra field too long",
634
+ "date not in range 1980-2099",
635
+ "filename too long",
636
+ "stream finishing",
637
+ "invalid zip data"
638
+ // determined by unknown compression method
639
+ ];
640
+ var err = function(ind, msg, nt) {
641
+ var e = new Error(msg || ec[ind]);
642
+ e.code = ind;
643
+ if (Error.captureStackTrace)
644
+ Error.captureStackTrace(e, err);
645
+ if (!nt)
646
+ throw e;
647
+ return e;
648
+ };
649
+ var inflt = function(dat, st, buf, dict) {
650
+ var sl = dat.length, dl = dict ? dict.length : 0;
651
+ if (!sl || st.f && !st.l)
652
+ return buf || new u8(0);
653
+ var noBuf = !buf;
654
+ var resize = noBuf || st.i != 2;
655
+ var noSt = st.i;
656
+ if (noBuf)
657
+ buf = new u8(sl * 3);
658
+ var cbuf = function(l2) {
659
+ var bl = buf.length;
660
+ if (l2 > bl) {
661
+ var nbuf = new u8(Math.max(bl * 2, l2));
662
+ nbuf.set(buf);
663
+ buf = nbuf;
664
+ }
665
+ };
666
+ var final = st.f || 0, pos = st.p || 0, bt = st.b || 0, lm = st.l, dm = st.d, lbt = st.m, dbt = st.n;
667
+ var tbts = sl * 8;
668
+ do {
669
+ if (!lm) {
670
+ final = bits(dat, pos, 1);
671
+ var type = bits(dat, pos + 1, 3);
672
+ pos += 3;
673
+ if (!type) {
674
+ var s = shft(pos) + 4, l = dat[s - 4] | dat[s - 3] << 8, t = s + l;
675
+ if (t > sl) {
676
+ if (noSt)
677
+ err(0);
678
+ break;
679
+ }
680
+ if (resize)
681
+ cbuf(bt + l);
682
+ buf.set(dat.subarray(s, t), bt);
683
+ st.b = bt += l, st.p = pos = t * 8, st.f = final;
684
+ continue;
685
+ } else if (type == 1)
686
+ lm = flrm, dm = fdrm, lbt = 9, dbt = 5;
687
+ else if (type == 2) {
688
+ var hLit = bits(dat, pos, 31) + 257, hcLen = bits(dat, pos + 10, 15) + 4;
689
+ var tl = hLit + bits(dat, pos + 5, 31) + 1;
690
+ pos += 14;
691
+ var ldt = new u8(tl);
692
+ var clt = new u8(19);
693
+ for (var i2 = 0; i2 < hcLen; ++i2) {
694
+ clt[clim[i2]] = bits(dat, pos + i2 * 3, 7);
695
+ }
696
+ pos += hcLen * 3;
697
+ var clb = max(clt), clbmsk = (1 << clb) - 1;
698
+ var clm = hMap(clt, clb, 1);
699
+ for (var i2 = 0; i2 < tl; ) {
700
+ var r = clm[bits(dat, pos, clbmsk)];
701
+ pos += r & 15;
702
+ var s = r >> 4;
703
+ if (s < 16) {
704
+ ldt[i2++] = s;
705
+ } else {
706
+ var c = 0, n = 0;
707
+ if (s == 16)
708
+ n = 3 + bits(dat, pos, 3), pos += 2, c = ldt[i2 - 1];
709
+ else if (s == 17)
710
+ n = 3 + bits(dat, pos, 7), pos += 3;
711
+ else if (s == 18)
712
+ n = 11 + bits(dat, pos, 127), pos += 7;
713
+ while (n--)
714
+ ldt[i2++] = c;
715
+ }
716
+ }
717
+ var lt = ldt.subarray(0, hLit), dt = ldt.subarray(hLit);
718
+ lbt = max(lt);
719
+ dbt = max(dt);
720
+ lm = hMap(lt, lbt, 1);
721
+ dm = hMap(dt, dbt, 1);
722
+ } else
723
+ err(1);
724
+ if (pos > tbts) {
725
+ if (noSt)
726
+ err(0);
727
+ break;
728
+ }
729
+ }
730
+ if (resize)
731
+ cbuf(bt + 131072);
732
+ var lms = (1 << lbt) - 1, dms = (1 << dbt) - 1;
733
+ var lpos = pos;
734
+ for (; ; lpos = pos) {
735
+ var c = lm[bits16(dat, pos) & lms], sym = c >> 4;
736
+ pos += c & 15;
737
+ if (pos > tbts) {
738
+ if (noSt)
739
+ err(0);
740
+ break;
741
+ }
742
+ if (!c)
743
+ err(2);
744
+ if (sym < 256)
745
+ buf[bt++] = sym;
746
+ else if (sym == 256) {
747
+ lpos = pos, lm = null;
748
+ break;
749
+ } else {
750
+ var add = sym - 254;
751
+ if (sym > 264) {
752
+ var i2 = sym - 257, b = fleb[i2];
753
+ add = bits(dat, pos, (1 << b) - 1) + fl[i2];
754
+ pos += b;
755
+ }
756
+ var d = dm[bits16(dat, pos) & dms], dsym = d >> 4;
757
+ if (!d)
758
+ err(3);
759
+ pos += d & 15;
760
+ var dt = fd[dsym];
761
+ if (dsym > 3) {
762
+ var b = fdeb[dsym];
763
+ dt += bits16(dat, pos) & (1 << b) - 1, pos += b;
764
+ }
765
+ if (pos > tbts) {
766
+ if (noSt)
767
+ err(0);
768
+ break;
769
+ }
770
+ if (resize)
771
+ cbuf(bt + 131072);
772
+ var end = bt + add;
773
+ if (bt < dt) {
774
+ var shift = dl - dt, dend = Math.min(dt, end);
775
+ if (shift + bt < 0)
776
+ err(3);
777
+ for (; bt < dend; ++bt)
778
+ buf[bt] = dict[shift + bt];
779
+ }
780
+ for (; bt < end; ++bt)
781
+ buf[bt] = buf[bt - dt];
782
+ }
783
+ }
784
+ st.l = lm, st.p = lpos, st.b = bt, st.f = final;
785
+ if (lm)
786
+ final = 1, st.m = lbt, st.d = dm, st.n = dbt;
787
+ } while (!final);
788
+ return bt != buf.length && noBuf ? slc(buf, 0, bt) : buf.subarray(0, bt);
789
+ };
790
+ var et = /* @__PURE__ */ new u8(0);
791
+ var b2 = function(d, b) {
792
+ return d[b] | d[b + 1] << 8;
793
+ };
794
+ var b4 = function(d, b) {
795
+ return (d[b] | d[b + 1] << 8 | d[b + 2] << 16 | d[b + 3] << 24) >>> 0;
796
+ };
797
+ var b8 = function(d, b) {
798
+ return b4(d, b) + b4(d, b + 4) * 4294967296;
799
+ };
800
+ function inflateSync(data, opts) {
801
+ return inflt(data, { i: 2 }, opts && opts.out, opts && opts.dictionary);
802
+ }
803
+ var td = typeof TextDecoder != "undefined" && /* @__PURE__ */ new TextDecoder();
804
+ var tds = 0;
805
+ try {
806
+ td.decode(et, { stream: true });
807
+ tds = 1;
808
+ } catch (e) {
809
+ }
810
+ var dutf8 = function(d) {
811
+ for (var r = "", i2 = 0; ; ) {
812
+ var c = d[i2++];
813
+ var eb = (c > 127) + (c > 223) + (c > 239);
814
+ if (i2 + eb > d.length)
815
+ return { s: r, r: slc(d, i2 - 1) };
816
+ if (!eb)
817
+ r += String.fromCharCode(c);
818
+ else if (eb == 3) {
819
+ c = ((c & 15) << 18 | (d[i2++] & 63) << 12 | (d[i2++] & 63) << 6 | d[i2++] & 63) - 65536, r += String.fromCharCode(55296 | c >> 10, 56320 | c & 1023);
820
+ } else if (eb & 1)
821
+ r += String.fromCharCode((c & 31) << 6 | d[i2++] & 63);
822
+ else
823
+ r += String.fromCharCode((c & 15) << 12 | (d[i2++] & 63) << 6 | d[i2++] & 63);
824
+ }
825
+ };
826
+ function strFromU8(dat, latin1) {
827
+ if (latin1) {
828
+ var r = "";
829
+ for (var i2 = 0; i2 < dat.length; i2 += 16384)
830
+ r += String.fromCharCode.apply(null, dat.subarray(i2, i2 + 16384));
831
+ return r;
832
+ } else if (td) {
833
+ return td.decode(dat);
834
+ } else {
835
+ var _a2 = dutf8(dat), s = _a2.s, r = _a2.r;
836
+ if (r.length)
837
+ err(8);
838
+ return s;
839
+ }
840
+ }
841
+ var slzh = function(d, b) {
842
+ return b + 30 + b2(d, b + 26) + b2(d, b + 28);
843
+ };
844
+ var zh = function(d, b, z) {
845
+ var fnl = b2(d, b + 28), efl = b2(d, b + 30), fn = strFromU8(d.subarray(b + 46, b + 46 + fnl), !(b2(d, b + 8) & 2048)), es = b + 46 + fnl;
846
+ var _a2 = z64hs(d, es, efl, z, b4(d, b + 20), b4(d, b + 24), b4(d, b + 42)), sc = _a2[0], su = _a2[1], off = _a2[2];
847
+ return [b2(d, b + 10), sc, su, fn, es + efl + b2(d, b + 32), off];
848
+ };
849
+ var z64hs = function(d, b, l, z, sc, su, off) {
850
+ var nsc = sc == 4294967295, nsu = su == 4294967295, noff = off == 4294967295, e = b + l;
851
+ var nf = nsc + nsu + noff;
852
+ if (z && nf) {
853
+ for (; b + 4 < e; b += 4 + b2(d, b + 2)) {
854
+ if (b2(d, b) == 1) {
855
+ return [
856
+ nsc ? b8(d, b + 4 + 8 * nsu) : sc,
857
+ nsu ? b8(d, b + 4) : su,
858
+ noff ? b8(d, b + 4 + 8 * (nsu + nsc)) : off,
859
+ 1
860
+ ];
861
+ }
862
+ }
863
+ if (z < 2)
864
+ err(13);
865
+ }
866
+ return [sc, su, off, 0];
867
+ };
868
+ function unzipSync(data, opts) {
869
+ var files = {};
870
+ var e = data.length - 22;
871
+ for (; b4(data, e) != 101010256; --e) {
872
+ if (!e || data.length - e > 65558)
873
+ err(13);
874
+ }
875
+ ;
876
+ var c = b2(data, e + 8);
877
+ if (!c)
878
+ return {};
879
+ var o = b4(data, e + 16);
880
+ var z = b4(data, e - 20) == 117853008;
881
+ if (z) {
882
+ var ze = b4(data, e - 12);
883
+ z = b4(data, ze) == 101075792;
884
+ if (z) {
885
+ c = b4(data, ze + 32);
886
+ o = b4(data, ze + 48);
887
+ }
888
+ }
889
+ var fltr = opts && opts.filter;
890
+ for (var i2 = 0; i2 < c; ++i2) {
891
+ var _a2 = zh(data, o, z), c_2 = _a2[0], sc = _a2[1], su = _a2[2], fn = _a2[3], no = _a2[4], off = _a2[5], b = slzh(data, off);
892
+ o = no;
893
+ if (!fltr || fltr({
894
+ name: fn,
895
+ size: sc,
896
+ originalSize: su,
897
+ compression: c_2
898
+ })) {
899
+ if (!c_2)
900
+ files[fn] = slc(data, b, b + sc);
901
+ else if (c_2 == 8)
902
+ files[fn] = inflateSync(data.subarray(b, b + sc), { out: new u8(su) });
903
+ else
904
+ err(14, "unknown compression type " + c_2);
905
+ }
906
+ }
907
+ return files;
908
+ }
526
909
  var DEFAULT_MAX_BYTES = 50 * 1024 * 1024;
527
910
  function extractZipFromBuffer(buffer, opts = {}) {
528
911
  const maxBytes = opts.maxBytes ?? DEFAULT_MAX_BYTES;
529
- const entries2 = unzipSync(buffer);
912
+ const entries = unzipSync(buffer);
530
913
  const files = [];
531
914
  const issues = [];
532
915
  let totalBytes = 0;
533
- for (const [name, data] of Object.entries(entries2)) {
916
+ for (const [name, data] of Object.entries(entries)) {
534
917
  if (name.endsWith("/")) continue;
535
918
  const reason = validateBundlePath(name);
536
919
  if (reason) {
@@ -588,7 +971,6 @@ async function upsertStaticPost(graphql, slug, body, fields) {
588
971
  }
589
972
  const data2 = await graphql.query(UPDATE_MUTATION, { input: input2 });
590
973
  const updated = toCorePost(data2.updatePost);
591
- await syncPostTags(graphql, updated, existing);
592
974
  return { post: updated, created: false };
593
975
  }
594
976
  if (!fields.title) {
@@ -613,7 +995,6 @@ async function upsertStaticPost(graphql, slug, body, fields) {
613
995
  if (fields.metadata !== void 0) input.metadata = encodeAwsJson3(fields.metadata);
614
996
  const data = await graphql.query(CREATE_MUTATION, { input });
615
997
  const created = toCorePost(data.createPost);
616
- await syncPostTags(graphql, created, null);
617
998
  return { post: created, created: true };
618
999
  }
619
1000
  var uploadStaticBundleSchema = {
@@ -654,7 +1035,7 @@ async function uploadStaticBundle(graphql, storage, args) {
654
1035
  const { files, issues } = extractZipFromBuffer(zipBytes);
655
1036
  if (issues.length > 0) {
656
1037
  throw new Error(
657
- `upload_static_bundle: rejected bundle path(s): ${issues.map((i) => `${i.path} (${i.reason})`).join("; ")}`
1038
+ `upload_static_bundle: rejected bundle path(s): ${issues.map((i2) => `${i2.path} (${i2.reason})`).join("; ")}`
658
1039
  );
659
1040
  }
660
1041
  if (files.length === 0) {
@@ -663,7 +1044,7 @@ async function uploadStaticBundle(graphql, storage, args) {
663
1044
  const contentIssues = validateBundle(files);
664
1045
  if (contentIssues.length > 0) {
665
1046
  throw new Error(
666
- `upload_static_bundle: bundle contains absolute / protocol-relative refs: ${contentIssues.map((i) => `${i.path}: ${i.reason}`).join("; ")}`
1047
+ `upload_static_bundle: bundle contains absolute / protocol-relative refs: ${contentIssues.map((i2) => `${i2.path}: ${i2.reason}`).join("; ")}`
667
1048
  );
668
1049
  }
669
1050
  const entrypoint = args.entrypoint ?? pickDefaultEntrypoint(files);
@@ -673,8 +1054,8 @@ async function uploadStaticBundle(graphql, storage, args) {
673
1054
  );
674
1055
  }
675
1056
  const prefix = bundlePrefix(slug);
676
- const existing = await storage.listObjects(prefix).catch((err) => {
677
- console.error("[upload_static_bundle] listObjects failed (proceeding)", err);
1057
+ const existing = await storage.listObjects(prefix).catch((err2) => {
1058
+ console.error("[upload_static_bundle] listObjects failed (proceeding)", err2);
678
1059
  return [];
679
1060
  });
680
1061
  for (const obj of existing) {
@@ -736,7 +1117,7 @@ async function uploadStaticFile(storage, args) {
736
1117
  const issues = findAbsolutePathRefs(filename, text);
737
1118
  if (issues.length > 0) {
738
1119
  throw new Error(
739
- `upload_static_file: ${filename} contains absolute / protocol-relative refs: ${issues.map((i) => i.reason).join("; ")}`
1120
+ `upload_static_file: ${filename} contains absolute / protocol-relative refs: ${issues.map((i2) => i2.reason).join("; ")}`
740
1121
  );
741
1122
  }
742
1123
  }
@@ -1130,8 +1511,8 @@ async function dispatchJsonRpc(req) {
1130
1511
  return jsonRpcResult(req.id, {
1131
1512
  content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
1132
1513
  });
1133
- } catch (err) {
1134
- const message = err instanceof Error ? err.message : String(err);
1514
+ } catch (err2) {
1515
+ const message = err2 instanceof Error ? err2.message : String(err2);
1135
1516
  console.error("[mcp-handler] tool dispatch failed", {
1136
1517
  tool: params.name,
1137
1518
  message
@@ -1182,8 +1563,8 @@ var handler = async (event) => {
1182
1563
  try {
1183
1564
  const response = await dispatchJsonRpc(req);
1184
1565
  return jsonResponse(200, response);
1185
- } catch (err) {
1186
- const message = err instanceof Error ? err.message : String(err);
1566
+ } catch (err2) {
1567
+ const message = err2 instanceof Error ? err2.message : String(err2);
1187
1568
  console.error("[mcp-handler] dispatch threw", { method: req.method, message });
1188
1569
  return jsonResponse(
1189
1570
  500,
package/dist/index.js CHANGED
@@ -1,5 +1,3 @@
1
- import "./chunk-BYXBJQAS.js";
2
-
3
1
  // src/backend.ts
4
2
  import { defineBackend } from "@aws-amplify/backend";
5
3
  import { Effect, PolicyStatement, AnyPrincipal } from "aws-cdk-lib/aws-iam";
@@ -133,6 +131,8 @@ function defineAmplessBackend(opts) {
133
131
  })
134
132
  );
135
133
  kvTable.grantReadData(trustedFn);
134
+ const postTagTable = backend.data.resources.tables["PostTag"];
135
+ postTagTable.grantWriteData(trustedFn);
136
136
  trustedFn.addToRolePolicy(
137
137
  new PolicyStatement({
138
138
  effect: Effect.ALLOW,
@@ -140,13 +140,12 @@ function defineAmplessBackend(opts) {
140
140
  resources: [
141
141
  `${backend.storage.resources.bucket.bucketArn}/public/plugins/*`,
142
142
  // Built-in cache: rebuildSiteSettingsCache writes the single
143
- // JSON file the public site reads. Exact-match resource —
144
- // historically this was `public/site-settings/<siteId>.json`
145
- // (multi-site era) and the wildcard pattern that worked then
146
- // (`public/site-settings/*`) does NOT match the current
147
- // single-file key `public/site-settings.json`. Wrong pattern
148
- // fails the PutObject silently with AccessDenied, so the
149
- // public site never sees admin-side theme / settings changes.
143
+ // JSON file the public site reads. Exact-match resource — a
144
+ // wildcard like `public/site-settings/*` would NOT match the
145
+ // single-file key `public/site-settings.json` and the
146
+ // PutObject would fail silently with AccessDenied, so the
147
+ // public site would never see admin-side theme / settings
148
+ // changes.
150
149
  `${backend.storage.resources.bucket.bucketArn}/public/site-settings.json`
151
150
  ]
152
151
  })
@@ -154,6 +153,7 @@ function defineAmplessBackend(opts) {
154
153
  trustedFn.addEnvironment("AMPLESS_BUCKET_NAME", backend.storage.resources.bucket.bucketName);
155
154
  trustedFn.addEnvironment("AMPLESS_POST_TABLE", postTable.tableName);
156
155
  trustedFn.addEnvironment("AMPLESS_KV_TABLE", kvTable.tableName);
156
+ trustedFn.addEnvironment("AMPLESS_POSTTAG_TABLE", postTagTable.tableName);
157
157
  const untrustedFn = backend.processorUntrusted.resources.lambda;
158
158
  untrustedFn.addEventSource(new SqsEventSource(untrustedQueue, { batchSize: 5 }));
159
159
  const graphqlApi = backend.data.resources.cfnResources.cfnGraphqlApi;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ampless/backend",
3
- "version": "1.0.0-alpha.27",
3
+ "version": "1.0.0-alpha.29",
4
4
  "description": "Amplify Gen 2 backend factories for ampless: auth, data, storage, event processors, API key renewer",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -65,8 +65,8 @@
65
65
  "@smithy/protocol-http": "^5.4.4",
66
66
  "@smithy/signature-v4": "^5.4.4",
67
67
  "fflate": "^0.8.3",
68
- "ampless": "1.0.0-alpha.14",
69
- "@ampless/mcp-server": "1.0.0-alpha.16"
68
+ "ampless": "1.0.0-alpha.15",
69
+ "@ampless/mcp-server": "1.0.0-alpha.18"
70
70
  },
71
71
  "peerDependencies": {
72
72
  "@aws-amplify/backend": "^1",
File without changes