ampless 1.0.0-beta.58 → 1.0.0-beta.60

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/dist/index.d.ts CHANGED
@@ -1660,6 +1660,15 @@ interface AiConfig {
1660
1660
  llmsTxt?: boolean | {
1661
1661
  limit?: number;
1662
1662
  };
1663
+ /**
1664
+ * Expose an anonymous, read-only MCP endpoint at `/api/mcp`
1665
+ * (JSON-RPC 2.0 over POST). Serves published posts only and can never
1666
+ * write. **Default: false** — because the endpoint is unauthenticated,
1667
+ * it is opt-in. The route ships a coarse warm-instance circuit breaker,
1668
+ * not a per-IP rate limiter; pair it with CloudFront / WAF for real
1669
+ * abuse protection.
1670
+ */
1671
+ publicMcp?: boolean;
1663
1672
  }
1664
1673
  type Role = 'reader' | 'editor' | 'admin';
1665
1674
  interface AuthContext {
@@ -2001,6 +2010,57 @@ declare function resolvePluginSettings(manifest: PluginSettingsManifest | undefi
2001
2010
  */
2002
2011
  declare function extractFirstImageUrl(post: Post): string | null;
2003
2012
 
2013
+ /** How the scan ended. `null` = the fetcher was exhausted cleanly. */
2014
+ type BoundedScanTruncation = 'limit' | 'early' | null;
2015
+ interface BoundedScanResult<T> {
2016
+ items: T[];
2017
+ /**
2018
+ * - `'limit'` — a `limit + 1`th item was actually fetched, so more
2019
+ * items exist beyond the returned `limit`; the extra item is
2020
+ * dropped from `items`.
2021
+ * - `'early'` — one of the safety bounds tripped (`maxPages` reached
2022
+ * or the same `nextToken` came back twice), so the scan may have
2023
+ * stopped with more items unread.
2024
+ * - `null` — the fetcher signalled exhaustion (no `nextToken`) at or
2025
+ * below `limit`.
2026
+ */
2027
+ truncated: BoundedScanTruncation;
2028
+ }
2029
+ interface BoundedScanOptions {
2030
+ /**
2031
+ * Target item count. The walk collects until it has `limit + 1`
2032
+ * items (the extra confirms there really are more), the fetcher is
2033
+ * exhausted, or a safety bound trips.
2034
+ */
2035
+ limit: number;
2036
+ /** Max items requested per page (default 50). */
2037
+ pageSizeCap?: number;
2038
+ /** Hard cap on pages walked regardless of items collected (default 21). */
2039
+ maxPages?: number;
2040
+ }
2041
+ interface BoundedScanPage<T> {
2042
+ items: T[];
2043
+ nextToken: string | null;
2044
+ }
2045
+ /**
2046
+ * Walk `fetchPage` pages until we have `limit + 1` items (the extra
2047
+ * item confirms there really are more items beyond `limit` — a present
2048
+ * `nextToken` alone doesn't guarantee that, since a paginated backend
2049
+ * can return a token alongside zero remaining items), the token is
2050
+ * exhausted, or one of the two safety bounds below trips:
2051
+ *
2052
+ * - `maxPages` pages walked without reaching either stop condition
2053
+ * - the same `nextToken` comes back twice (defends against a
2054
+ * misbehaving resolver looping forever)
2055
+ *
2056
+ * Returns at most `limit` items (the confirming `limit + 1`th item is
2057
+ * dropped) alongside how the scan ended.
2058
+ */
2059
+ declare function collectBounded<T>(fetchPage: (args: {
2060
+ limit: number;
2061
+ nextToken?: string;
2062
+ }) => Promise<BoundedScanPage<T>>, opts: BoundedScanOptions): Promise<BoundedScanResult<T>>;
2063
+
2004
2064
  type PostListStatusFilter = 'all' | 'draft' | 'published';
2005
2065
  type PostListSort = 'updated-desc' | 'updated-asc' | 'published-desc' | 'published-asc' | 'title-asc' | 'title-desc';
2006
2066
  interface PostListFilterOptions {
@@ -2102,4 +2162,4 @@ declare function pickDefaultEntrypoint(files: readonly {
2102
2162
 
2103
2163
  declare const VERSION = "0.0.1";
2104
2164
 
2105
- export { type AiConfig, type AmplessEvent, type AmplessPlugin, type AuthContext, type BundleExtractResult, type CacheConfig, type CacheStrategy, type Config, type ContentEventPayload, type ContentEventType, type ContentFieldRenderer, type ContentFormat, type ContentTypeDefinition, type CreatePostInput, DEFAULT_ENTRYPOINT, type DateFormat, type EventPayloadOf, type EventType, type ExtractedFile, type FieldDefinition, type FieldType, type HistoryConfig, type ImageDisplay, type KvItem, type KvStore, type LinkListItem, type ListOptions, type ListPostHistoryOptions, type LocalizedString, MAX_BUNDLE_BYTES, type MarkdownEmbedMatch, type Media, type MediaEventPayload, type MediaEventType, type MediaMetadata, type MediaProcessingDefaults, type OgImageConfig, type OgImageFont, type OgImageRenderContext, PLUGIN_KEY_PATTERN, type Page, type PluginBooleanField, type PluginCapability, type PluginCodeField, type PluginEventHandler, type PluginHookResult, type PluginJsonField, type PluginMetadata, type PluginNumberField, type PluginPackageManifest, type PluginPublicRenderContext, type PluginRepeatableField, type PluginRepeatableSubField, type PluginRuntimeContext, type PluginSecretField, type PluginSelectField, type PluginSettingField, type PluginSettingsManifest, type PluginTextField, type PluginTextareaField, type PluginUninstallContext, type PluginUrlField, type Post, type PostIndexEventPayload, type PostIndexEventType, type PostListFilterOptions, type PostListSort, type PostListStatusFilter, type PostMetadata, type PostRevision, type PostRevisionConnection, type PostStatus, type PostSummary, type PostsProvider, type PublicBodyDescriptor, type PublicHeadDescriptor, type PublicPostBodyDescriptor, type PublicPostHtmlDescriptor, type PublicPostHtmlPosition, type PublicPostScriptDescriptor, type Role, SITE_CONFIG_PK, type ScriptStrategy, type SiteSettingsEventPayload, type SiteSettingsEventType, type StaticPostBody, type StaticPostFileMeta, type StreamEventName, type SummaryListOptions, TEXT_EXTENSIONS, type ThemeColorField, type ThemeField, type ThemeFieldType, type ThemeFontFamilyField, type ThemeImageField, type ThemeLengthField, type ThemeLinkListField, type ThemeManifest, type ThemeModule, type ThemeRouteContext, type ThemeSelectField, type ThemeTextField, type TiptapNodeHtmlAdapters, type TiptapNodeMarkdownAdapters, type TiptapNodeToHtml, type TiptapNodeToMarkdown, type TiptapRenderNode, type TrustLevel, type TrustedPluginRuntimeContext, VERSION, type ValidationIssue, bundlePrefix, collectTags, createPost, decodeAwsJson, defineConfig, definePlugin, defineSchema, defineTheme, defineThemeModule, deletePost, deleteSiteSetting, detectContentEvents, encodeAwsJson, escapeXml, extractFirstImageUrl, filterSortPostSummaries, findAbsolutePathRefs, flattenSettings, formatColorPair, formatDate, formatPublicAssetUrl, getKvStore, getPost, getPostById, getSiteSetting, hasKvStore, hasPostsProvider, isTagListUrl, isValidPluginKey, listPostHistory, listPostSummaries, listPosts, listSiteSettings, mimeTypeFor, parseColorPair, parseLinkList, pickDefaultEntrypoint, resolveLocalized, resolvePluginSettings, resolveThemeValues, setKvStore, setPostsProvider, setSiteSetting, stringifyLinkList, stripCommonPrefix, themeSettingKey, unflattenSettings, updatePost, validateBundle, validateBundlePath, validatePluginSettingValue, validatePublicAssetKey, validateThemeValue };
2165
+ export { type AiConfig, type AmplessEvent, type AmplessPlugin, type AuthContext, type BoundedScanOptions, type BoundedScanPage, type BoundedScanResult, type BoundedScanTruncation, type BundleExtractResult, type CacheConfig, type CacheStrategy, type Config, type ContentEventPayload, type ContentEventType, type ContentFieldRenderer, type ContentFormat, type ContentTypeDefinition, type CreatePostInput, DEFAULT_ENTRYPOINT, type DateFormat, type EventPayloadOf, type EventType, type ExtractedFile, type FieldDefinition, type FieldType, type HistoryConfig, type ImageDisplay, type KvItem, type KvStore, type LinkListItem, type ListOptions, type ListPostHistoryOptions, type LocalizedString, MAX_BUNDLE_BYTES, type MarkdownEmbedMatch, type Media, type MediaEventPayload, type MediaEventType, type MediaMetadata, type MediaProcessingDefaults, type OgImageConfig, type OgImageFont, type OgImageRenderContext, PLUGIN_KEY_PATTERN, type Page, type PluginBooleanField, type PluginCapability, type PluginCodeField, type PluginEventHandler, type PluginHookResult, type PluginJsonField, type PluginMetadata, type PluginNumberField, type PluginPackageManifest, type PluginPublicRenderContext, type PluginRepeatableField, type PluginRepeatableSubField, type PluginRuntimeContext, type PluginSecretField, type PluginSelectField, type PluginSettingField, type PluginSettingsManifest, type PluginTextField, type PluginTextareaField, type PluginUninstallContext, type PluginUrlField, type Post, type PostIndexEventPayload, type PostIndexEventType, type PostListFilterOptions, type PostListSort, type PostListStatusFilter, type PostMetadata, type PostRevision, type PostRevisionConnection, type PostStatus, type PostSummary, type PostsProvider, type PublicBodyDescriptor, type PublicHeadDescriptor, type PublicPostBodyDescriptor, type PublicPostHtmlDescriptor, type PublicPostHtmlPosition, type PublicPostScriptDescriptor, type Role, SITE_CONFIG_PK, type ScriptStrategy, type SiteSettingsEventPayload, type SiteSettingsEventType, type StaticPostBody, type StaticPostFileMeta, type StreamEventName, type SummaryListOptions, TEXT_EXTENSIONS, type ThemeColorField, type ThemeField, type ThemeFieldType, type ThemeFontFamilyField, type ThemeImageField, type ThemeLengthField, type ThemeLinkListField, type ThemeManifest, type ThemeModule, type ThemeRouteContext, type ThemeSelectField, type ThemeTextField, type TiptapNodeHtmlAdapters, type TiptapNodeMarkdownAdapters, type TiptapNodeToHtml, type TiptapNodeToMarkdown, type TiptapRenderNode, type TrustLevel, type TrustedPluginRuntimeContext, VERSION, type ValidationIssue, bundlePrefix, collectBounded, collectTags, createPost, decodeAwsJson, defineConfig, definePlugin, defineSchema, defineTheme, defineThemeModule, deletePost, deleteSiteSetting, detectContentEvents, encodeAwsJson, escapeXml, extractFirstImageUrl, filterSortPostSummaries, findAbsolutePathRefs, flattenSettings, formatColorPair, formatDate, formatPublicAssetUrl, getKvStore, getPost, getPostById, getSiteSetting, hasKvStore, hasPostsProvider, isTagListUrl, isValidPluginKey, listPostHistory, listPostSummaries, listPosts, listSiteSettings, mimeTypeFor, parseColorPair, parseLinkList, pickDefaultEntrypoint, resolveLocalized, resolvePluginSettings, resolveThemeValues, setKvStore, setPostsProvider, setSiteSetting, stringifyLinkList, stripCommonPrefix, themeSettingKey, unflattenSettings, updatePost, validateBundle, validateBundlePath, validatePluginSettingValue, validatePublicAssetKey, validateThemeValue };
package/dist/index.js CHANGED
@@ -501,6 +501,55 @@ function findHtmlImage(body) {
501
501
  return m ? m[1] : null;
502
502
  }
503
503
 
504
+ // src/paging.ts
505
+ var DEFAULT_PAGE_SIZE_CAP = 50;
506
+ var DEFAULT_MAX_PAGES = 21;
507
+ function requirePositiveInt(name, value) {
508
+ if (!Number.isInteger(value) || value <= 0) {
509
+ throw new TypeError(
510
+ `collectBounded: \`${name}\` must be a finite positive integer, received ${String(value)}`
511
+ );
512
+ }
513
+ }
514
+ async function collectBounded(fetchPage, opts) {
515
+ const limit = opts.limit;
516
+ const pageSizeCap = opts.pageSizeCap ?? DEFAULT_PAGE_SIZE_CAP;
517
+ const maxPages = opts.maxPages ?? DEFAULT_MAX_PAGES;
518
+ requirePositiveInt("limit", limit);
519
+ requirePositiveInt("pageSizeCap", pageSizeCap);
520
+ requirePositiveInt("maxPages", maxPages);
521
+ const items = [];
522
+ const seenTokens = /* @__PURE__ */ new Set();
523
+ let token;
524
+ let truncated = null;
525
+ for (let page = 0; page < maxPages; page++) {
526
+ const remaining = limit + 1 - items.length;
527
+ const pageLimit = Math.min(pageSizeCap, remaining);
528
+ const res = await fetchPage({ limit: pageLimit, nextToken: token });
529
+ items.push(...res.items);
530
+ if (items.length > limit) {
531
+ truncated = "limit";
532
+ break;
533
+ }
534
+ if (!res.nextToken) {
535
+ break;
536
+ }
537
+ if (seenTokens.has(res.nextToken)) {
538
+ truncated = "early";
539
+ break;
540
+ }
541
+ seenTokens.add(res.nextToken);
542
+ token = res.nextToken;
543
+ if (page === maxPages - 1) {
544
+ truncated = "early";
545
+ }
546
+ }
547
+ return {
548
+ items: truncated === "limit" ? items.slice(0, limit) : items,
549
+ truncated
550
+ };
551
+ }
552
+
504
553
  // src/post-list-filter.ts
505
554
  function filterSortPostSummaries(rows, options = {}) {
506
555
  const query = options.query?.trim().toLowerCase() ?? "";
@@ -869,6 +918,7 @@ export {
869
918
  TEXT_EXTENSIONS,
870
919
  VERSION,
871
920
  bundlePrefix,
921
+ collectBounded,
872
922
  collectTags,
873
923
  createPost,
874
924
  decodeAwsJson,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ampless",
3
- "version": "1.0.0-beta.58",
3
+ "version": "1.0.0-beta.60",
4
4
  "description": "Serverless CMS for AWS Amplify",
5
5
  "license": "MIT",
6
6
  "type": "module",