create-feedbax 0.1.0 → 0.2.1
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 +201 -21
- package/README.md +11 -1
- package/dist/cli.js +3283 -22
- package/dist/index.js +3394 -160
- package/package.json +40 -14
- package/template/.feedbax-template.sha256 +1 -0
- package/template/.gitignore.template +6 -0
- package/template/.npmignore.template +5 -0
- package/template/.prettierignore.template +4 -0
- package/template/AGENTS.md +13 -0
- package/template/CONNECTED.md +404 -0
- package/template/LICENSE +201 -0
- package/template/README.md +56 -5
- package/template/components.json +25 -0
- package/template/eslint.config.mjs +48 -0
- package/template/migrations/0001_connected.sql +6 -0
- package/template/migrations/0002_participation.sql +8 -0
- package/template/migrations/0003_images.sql +3 -0
- package/template/migrations/0004_followed_status.sql +9 -0
- package/template/package.json +74 -14
- package/template/public/feedbax-mark.svg +4 -0
- package/template/public/robots.txt +3 -0
- package/template/src/authorized-draft-post.test.tsx +212 -0
- package/template/src/authorized-draft-post.tsx +205 -0
- package/template/src/authorized-draft-query.ts +74 -0
- package/template/src/browser-post-state.test.ts +120 -0
- package/template/src/browser-post-state.ts +134 -0
- package/template/src/browser-vote-state.test.ts +14 -0
- package/template/src/browser-vote-state.ts +27 -0
- package/template/src/capability-authorization-error.ts +3 -0
- package/template/src/changelog-page.test.tsx +139 -0
- package/template/src/changelog-page.tsx +228 -0
- package/template/src/changelog-query.ts +13 -0
- package/template/src/changelog-runtime.ts +27 -0
- package/template/src/cloudflare-turnstile.ts +31 -0
- package/template/src/cloudflare-workers-test.ts +3 -0
- package/template/src/cloudflare-workers.d.ts +24 -0
- package/template/src/comment-creation.test.tsx +311 -0
- package/template/src/comment-profile.ts +5 -0
- package/template/src/comment-thread-page.ts +28 -0
- package/template/src/components/command-palette-context.tsx +71 -0
- package/template/src/components/command-palette.tsx +275 -0
- package/template/src/components/connected-identity-provider.tsx +108 -0
- package/template/src/components/create-post-trigger.tsx +44 -0
- package/template/src/components/device-profile-provider.tsx +324 -0
- package/template/src/components/follow-post-button.tsx +89 -0
- package/template/src/components/header.tsx +97 -0
- package/template/src/components/image-attachments.tsx +187 -0
- package/template/src/components/loader.tsx +53 -0
- package/template/src/components/notification-inbox.tsx +232 -0
- package/template/src/components/portal-footer.tsx +14 -0
- package/template/src/components/profile-menu.tsx +119 -0
- package/template/src/components/ui/components/alert-dialog.tsx +185 -0
- package/template/src/components/ui/components/attachment.tsx +207 -0
- package/template/src/components/ui/components/avatar.tsx +107 -0
- package/template/src/components/ui/components/badge.tsx +52 -0
- package/template/src/components/ui/components/bubble.tsx +128 -0
- package/template/src/components/ui/components/button-group.tsx +87 -0
- package/template/src/components/ui/components/button.tsx +56 -0
- package/template/src/components/ui/components/card.tsx +103 -0
- package/template/src/components/ui/components/checkbox.tsx +26 -0
- package/template/src/components/ui/components/command.tsx +195 -0
- package/template/src/components/ui/components/dialog.tsx +154 -0
- package/template/src/components/ui/components/drawer.tsx +229 -0
- package/template/src/components/ui/components/dropdown-menu.tsx +270 -0
- package/template/src/components/ui/components/empty.tsx +101 -0
- package/template/src/components/ui/components/field.tsx +236 -0
- package/template/src/components/ui/components/input-group.tsx +155 -0
- package/template/src/components/ui/components/input.tsx +20 -0
- package/template/src/components/ui/components/item.tsx +201 -0
- package/template/src/components/ui/components/kbd.tsx +26 -0
- package/template/src/components/ui/components/label.tsx +18 -0
- package/template/src/components/ui/components/marker.tsx +71 -0
- package/template/src/components/ui/components/message-scroller.tsx +128 -0
- package/template/src/components/ui/components/message.tsx +92 -0
- package/template/src/components/ui/components/native-select.tsx +65 -0
- package/template/src/components/ui/components/popover.tsx +88 -0
- package/template/src/components/ui/components/portal-primitives.test.tsx +85 -0
- package/template/src/components/ui/components/radio-group.tsx +36 -0
- package/template/src/components/ui/components/scroll-area.tsx +51 -0
- package/template/src/components/ui/components/secondary-form-actions.test.tsx +23 -0
- package/template/src/components/ui/components/select.tsx +199 -0
- package/template/src/components/ui/components/separator.tsx +23 -0
- package/template/src/components/ui/components/sheet.tsx +135 -0
- package/template/src/components/ui/components/skeleton.tsx +13 -0
- package/template/src/components/ui/components/sonner.tsx +43 -0
- package/template/src/components/ui/components/spinner.tsx +16 -0
- package/template/src/components/ui/components/switch.tsx +29 -0
- package/template/src/components/ui/components/tabs.tsx +80 -0
- package/template/src/components/ui/components/textarea.tsx +18 -0
- package/template/src/components/ui/components/tooltip.tsx +64 -0
- package/template/src/components/ui/hooks/.gitkeep +0 -0
- package/template/src/components/ui/lib/utils.ts +6 -0
- package/template/src/components/ui/styles/globals.css +151 -0
- package/template/src/connected-identity.test.ts +144 -0
- package/template/src/connected-identity.ts +122 -0
- package/template/src/connected-participation.test.tsx +67 -0
- package/template/src/connected-runtime.test.ts +241 -0
- package/template/src/connected-runtime.ts +176 -0
- package/template/src/connected-social.test.tsx +158 -0
- package/template/src/create-post-overlay.tsx +82 -0
- package/template/src/draft-post-list.tsx +39 -0
- package/template/src/feedback-cache-invalidation.test.ts +185 -0
- package/template/src/feedback-cache-invalidation.ts +98 -0
- package/template/src/feedback-runtime.ts +105 -0
- package/template/src/feedbax/changelog/index.test.ts +156 -0
- package/template/src/feedbax/changelog/index.ts +206 -0
- package/template/src/feedbax/changelog/notion-changelog.test.ts +395 -0
- package/template/src/feedbax/changelog/notion-changelog.ts +400 -0
- package/template/src/feedbax/config/index.test.ts +139 -0
- package/template/src/feedbax/config/index.ts +364 -0
- package/template/src/feedbax/feedback/connected-feedback.ts +206 -0
- package/template/src/feedbax/feedback/connected.test.ts +272 -0
- package/template/src/feedbax/feedback/connected.ts +215 -0
- package/template/src/feedbax/feedback/email-delivery.test.ts +65 -0
- package/template/src/feedbax/feedback/email-delivery.ts +66 -0
- package/template/src/feedbax/feedback/feedback-storage.ts +43 -0
- package/template/src/feedbax/feedback/identity-handoff.test.ts +81 -0
- package/template/src/feedbax/feedback/identity-handoff.ts +119 -0
- package/template/src/feedbax/feedback/image-feedback.ts +101 -0
- package/template/src/feedbax/feedback/images.test.ts +223 -0
- package/template/src/feedbax/feedback/images.ts +324 -0
- package/template/src/feedbax/feedback/index.test.ts +900 -0
- package/template/src/feedbax/feedback/index.ts +996 -0
- package/template/src/feedbax/feedback/notion-comments.test.ts +171 -0
- package/template/src/feedbax/feedback/notion-comments.ts +231 -0
- package/template/src/feedbax/feedback/notion-data-source.test.ts +364 -0
- package/template/src/feedbax/feedback/notion-data-source.ts +458 -0
- package/template/src/feedbax/feedback/notion-feedback.test.ts +998 -0
- package/template/src/feedbax/feedback/notion-feedback.ts +651 -0
- package/template/src/feedbax/feedback/notion-image-review.ts +55 -0
- package/template/src/feedbax/feedback/notion-request.ts +74 -0
- package/template/src/feedbax/feedback/participation.test.ts +653 -0
- package/template/src/feedbax/feedback/participation.ts +502 -0
- package/template/src/feedbax.test-fixture.ts +64 -0
- package/template/src/feedbax.ts +69 -0
- package/template/src/images-runtime.test.ts +133 -0
- package/template/src/images-runtime.ts +125 -0
- package/template/src/index.css +1795 -0
- package/template/src/lazy-create-post-overlay.tsx +6 -0
- package/template/src/lazy-post-detail-overlay.tsx +21 -0
- package/template/src/masked-post-link.tsx +27 -0
- package/template/src/overlay-post-detail.test.tsx +181 -0
- package/template/src/overlay-post-detail.tsx +43 -0
- package/template/src/participation-client.ts +63 -0
- package/template/src/participation-runtime.test.ts +35 -0
- package/template/src/participation-runtime.ts +255 -0
- package/template/src/portal-comments.test.ts +375 -0
- package/template/src/portal-comments.ts +403 -0
- package/template/src/portal-features.test.tsx +150 -0
- package/template/src/portal-feedback-form.tsx +530 -0
- package/template/src/portal-feedback-runtime.test.ts +32 -0
- package/template/src/portal-feedback-runtime.ts +58 -0
- package/template/src/portal-feedback-server-function.ts +96 -0
- package/template/src/portal-feedback-submission.test.ts +307 -0
- package/template/src/portal-feedback-submission.ts +224 -0
- package/template/src/portal-head.ts +58 -0
- package/template/src/portal-server-entry.ts +68 -0
- package/template/src/portal-voting.test.ts +106 -0
- package/template/src/portal-voting.ts +149 -0
- package/template/src/post-badges.tsx +27 -0
- package/template/src/post-creation-flow.test.tsx +230 -0
- package/template/src/post-creation-flow.tsx +88 -0
- package/template/src/post-detail-content.test.tsx +233 -0
- package/template/src/post-detail-content.tsx +162 -0
- package/template/src/post-detail-overlay.test.tsx +114 -0
- package/template/src/post-detail-overlay.tsx +67 -0
- package/template/src/post-detail-query.ts +34 -0
- package/template/src/post-feed-controls.test.tsx +239 -0
- package/template/src/post-feed-controls.tsx +298 -0
- package/template/src/post-presentation.ts +37 -0
- package/template/src/post-queries.test.ts +158 -0
- package/template/src/post-queries.ts +26 -0
- package/template/src/post-results.tsx +165 -0
- package/template/src/public-cache-policy.test.ts +148 -0
- package/template/src/public-cache-policy.ts +119 -0
- package/template/src/public-cache-tags.ts +7 -0
- package/template/src/public-changelog-page.ts +15 -0
- package/template/src/public-changelog-server-function.ts +27 -0
- package/template/src/public-date.ts +11 -0
- package/template/src/public-failure-state.test.tsx +69 -0
- package/template/src/public-feedback-index.tsx +94 -0
- package/template/src/public-feedback-page.test.tsx +355 -0
- package/template/src/public-feedback-page.ts +86 -0
- package/template/src/public-feedback-server-function.ts +22 -0
- package/template/src/public-portal-error.tsx +27 -0
- package/template/src/public-post-detail-skeleton.tsx +54 -0
- package/template/src/public-post-detail.tsx +772 -0
- package/template/src/public-post-page.test.tsx +173 -0
- package/template/src/public-post-page.ts +15 -0
- package/template/src/public-post-route.test.tsx +250 -0
- package/template/src/public-post-route.tsx +158 -0
- package/template/src/public-post-server-function.ts +48 -0
- package/template/src/public-post-unavailable.tsx +10 -0
- package/template/src/public-roadmap-page.test.tsx +139 -0
- package/template/src/public-roadmap-page.ts +24 -0
- package/template/src/public-roadmap-route.test.tsx +254 -0
- package/template/src/public-roadmap-route.tsx +50 -0
- package/template/src/public-roadmap-server-function.ts +44 -0
- package/template/src/public-roadmap-view.tsx +411 -0
- package/template/src/public-shell.test.tsx +544 -0
- package/template/src/roadmap-query.ts +21 -0
- package/template/src/root-branding.test.ts +53 -0
- package/template/src/routeTree.gen.ts +177 -0
- package/template/src/routed-post-creation-form.tsx +28 -0
- package/template/src/router.tsx +27 -0
- package/template/src/routes/__root.tsx +114 -0
- package/template/src/routes/changelog.tsx +39 -0
- package/template/src/routes/email-preferences.tsx +77 -0
- package/template/src/routes/index.tsx +61 -0
- package/template/src/routes/p.$slug.tsx +16 -0
- package/template/src/routes/roadmap.tsx +11 -0
- package/template/src/routes/submit.tsx +28 -0
- package/template/src/safe-public-failure.ts +47 -0
- package/template/src/server.ts +151 -0
- package/template/src/similar-posts.tsx +45 -0
- package/template/src/submit-route.test.tsx +134 -0
- package/template/src/trusted-feedback-handler.test.ts +425 -0
- package/template/src/trusted-feedback-handler.ts +181 -0
- package/template/src/trusted-feedback-runtime.ts +17 -0
- package/template/src/turnstile-configuration.test.ts +37 -0
- package/template/src/turnstile-configuration.ts +19 -0
- package/template/src/use-media-query.ts +17 -0
- package/template/src/vote-toggle.test.tsx +171 -0
- package/template/src/vote-toggle.tsx +244 -0
- package/template/tsconfig.json +45 -0
- package/template/vite.config.ts +20 -0
- package/template/vitest.config.ts +4 -0
- package/template/vitest.setup.ts +3 -0
- package/template/wrangler.jsonc +35 -0
- package/dist/cli.d.ts +0 -3
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/index.d.ts +0 -21
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/template/.env.example +0 -4
- package/template/apps/portal/components.json +0 -20
- package/template/apps/portal/package.json +0 -31
- package/template/apps/portal/src/lib/utils.ts +0 -6
- package/template/apps/portal/src/routeTree.gen.ts +0 -59
- package/template/apps/portal/src/router.tsx +0 -10
- package/template/apps/portal/src/routes/__root.tsx +0 -31
- package/template/apps/portal/src/routes/index.tsx +0 -35
- package/template/apps/portal/src/styles.css +0 -91
- package/template/apps/portal/tsconfig.json +0 -15
- package/template/apps/portal/vite.config.ts +0 -13
- package/template/feedbax.config.ts +0 -13
- package/template/feedbax.jsonc +0 -11
- package/template/pnpm-workspace.yaml +0 -3
- package/template/turbo.json +0 -8
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
export type ChangelogDate = `${number}-${number}-${number}`;
|
|
2
|
+
|
|
3
|
+
export interface ChangelogImage {
|
|
4
|
+
src: string;
|
|
5
|
+
alt: string;
|
|
6
|
+
expiresAt?: Date;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface StoredChangelogEntry {
|
|
10
|
+
id: string;
|
|
11
|
+
slug: string;
|
|
12
|
+
date: ChangelogDate;
|
|
13
|
+
title: string;
|
|
14
|
+
summary: string;
|
|
15
|
+
body: string;
|
|
16
|
+
labels: string[];
|
|
17
|
+
images: ChangelogImage[];
|
|
18
|
+
published: boolean;
|
|
19
|
+
createdAt: Date;
|
|
20
|
+
updatedAt: Date;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type PublicChangelogEntry = Pick<
|
|
24
|
+
StoredChangelogEntry,
|
|
25
|
+
"slug" | "date" | "title" | "summary" | "body" | "labels" | "updatedAt"
|
|
26
|
+
> & { image?: ChangelogImage };
|
|
27
|
+
|
|
28
|
+
export interface ChangelogPage {
|
|
29
|
+
items: PublicChangelogEntry[];
|
|
30
|
+
nextCursor?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface ChangelogQuery {
|
|
34
|
+
cursor?: string;
|
|
35
|
+
label?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface ChangelogStorage {
|
|
39
|
+
listPublished(query: ChangelogQuery): Promise<ChangelogPage>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface ChangelogModule {
|
|
43
|
+
listPublishedEntries(query?: ChangelogQuery): Promise<ChangelogPage>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export {
|
|
47
|
+
createNotionChangelogDataSource,
|
|
48
|
+
createNotionChangelogStorage,
|
|
49
|
+
validateNotionChangelogDataSource,
|
|
50
|
+
type ChangelogDataSourceConfiguration,
|
|
51
|
+
type ChangelogPropertyIds,
|
|
52
|
+
type NotionChangelogStorageOptions,
|
|
53
|
+
} from "./notion-changelog";
|
|
54
|
+
|
|
55
|
+
export function createChangelogModule({
|
|
56
|
+
storage,
|
|
57
|
+
now = () => new Date(),
|
|
58
|
+
}: {
|
|
59
|
+
storage: ChangelogStorage;
|
|
60
|
+
now?: () => Date;
|
|
61
|
+
}): ChangelogModule {
|
|
62
|
+
const textFallbacks = new Map<
|
|
63
|
+
string,
|
|
64
|
+
{ cachedAt: number; page: ChangelogPage }
|
|
65
|
+
>();
|
|
66
|
+
return {
|
|
67
|
+
async listPublishedEntries(query = {}) {
|
|
68
|
+
const key = fallbackKey(query);
|
|
69
|
+
try {
|
|
70
|
+
const page = await storage.listPublished(query);
|
|
71
|
+
const projected = projectSafeImages(page, now());
|
|
72
|
+
rememberTextFallback(textFallbacks, key, page, now());
|
|
73
|
+
return projected;
|
|
74
|
+
} catch (error) {
|
|
75
|
+
const fallback = textFallbacks.get(key);
|
|
76
|
+
if (fallback && fallback.cachedAt + 86_400_000 > now().getTime()) {
|
|
77
|
+
return fallback.page;
|
|
78
|
+
}
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function projectSafeImages(page: ChangelogPage, now: Date): ChangelogPage {
|
|
86
|
+
return {
|
|
87
|
+
...page,
|
|
88
|
+
items: page.items.map((entry) =>
|
|
89
|
+
entry.image && !isSafeForProjection(entry.image, now)
|
|
90
|
+
? withoutImage(entry)
|
|
91
|
+
: entry,
|
|
92
|
+
),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function rememberTextFallback(
|
|
97
|
+
fallbacks: Map<string, { cachedAt: number; page: ChangelogPage }>,
|
|
98
|
+
key: string,
|
|
99
|
+
page: ChangelogPage,
|
|
100
|
+
now: Date,
|
|
101
|
+
): void {
|
|
102
|
+
if (!fallbacks.has(key) && fallbacks.size >= 100) {
|
|
103
|
+
const oldestKey = fallbacks.keys().next().value as string | undefined;
|
|
104
|
+
if (oldestKey) fallbacks.delete(oldestKey);
|
|
105
|
+
}
|
|
106
|
+
fallbacks.set(key, {
|
|
107
|
+
cachedAt: now.getTime(),
|
|
108
|
+
page: {
|
|
109
|
+
...page,
|
|
110
|
+
items: page.items.map(withoutImage),
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function fallbackKey(query: ChangelogQuery): string {
|
|
116
|
+
return JSON.stringify({
|
|
117
|
+
cursor: query.cursor ?? null,
|
|
118
|
+
label: query.label ?? null,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function isSafeForProjection(image: ChangelogImage, now: Date): boolean {
|
|
123
|
+
if (!image.expiresAt) return true;
|
|
124
|
+
return image.expiresAt.getTime() > now.getTime() + 60_000;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function withoutImage(entry: PublicChangelogEntry): PublicChangelogEntry {
|
|
128
|
+
const textEntry = { ...entry };
|
|
129
|
+
delete textEntry.image;
|
|
130
|
+
return textEntry;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function createInMemoryChangelogStorage(
|
|
134
|
+
initialEntries: StoredChangelogEntry[] = [],
|
|
135
|
+
): ChangelogStorage {
|
|
136
|
+
const entries = structuredClone(initialEntries);
|
|
137
|
+
return {
|
|
138
|
+
async listPublished(query) {
|
|
139
|
+
const offset = decodeCursor(query.cursor, query.label);
|
|
140
|
+
const matching = entries
|
|
141
|
+
.filter(
|
|
142
|
+
(entry) =>
|
|
143
|
+
entry.published &&
|
|
144
|
+
(!query.label || entry.labels.includes(query.label)),
|
|
145
|
+
)
|
|
146
|
+
.sort(compareEntries);
|
|
147
|
+
const page = matching.slice(offset, offset + 20);
|
|
148
|
+
const nextOffset = offset + page.length;
|
|
149
|
+
return {
|
|
150
|
+
items: page.map(toPublicEntry),
|
|
151
|
+
...(nextOffset < matching.length
|
|
152
|
+
? { nextCursor: encodeCursor(nextOffset, query.label) }
|
|
153
|
+
: {}),
|
|
154
|
+
};
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function compareEntries(
|
|
160
|
+
left: StoredChangelogEntry,
|
|
161
|
+
right: StoredChangelogEntry,
|
|
162
|
+
): number {
|
|
163
|
+
return right.date.localeCompare(left.date) || left.id.localeCompare(right.id);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function toPublicEntry(entry: StoredChangelogEntry): PublicChangelogEntry {
|
|
167
|
+
const [image] = entry.images;
|
|
168
|
+
return {
|
|
169
|
+
slug: entry.slug,
|
|
170
|
+
date: entry.date,
|
|
171
|
+
title: entry.title,
|
|
172
|
+
summary: entry.summary,
|
|
173
|
+
body: entry.body,
|
|
174
|
+
labels: [...entry.labels],
|
|
175
|
+
updatedAt: new Date(entry.updatedAt),
|
|
176
|
+
...(image ? { image: structuredClone(image) } : {}),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function encodeCursor(offset: number, label?: string): string {
|
|
181
|
+
return Buffer.from(JSON.stringify({ offset, label: label ?? null })).toString(
|
|
182
|
+
"base64url",
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function decodeCursor(cursor: string | undefined, label?: string): number {
|
|
187
|
+
if (!cursor) return 0;
|
|
188
|
+
try {
|
|
189
|
+
const value: unknown = JSON.parse(
|
|
190
|
+
Buffer.from(cursor, "base64url").toString("utf8"),
|
|
191
|
+
);
|
|
192
|
+
if (!value || typeof value !== "object") throw new Error();
|
|
193
|
+
const offset = Reflect.get(value, "offset");
|
|
194
|
+
const cursorLabel = Reflect.get(value, "label");
|
|
195
|
+
if (
|
|
196
|
+
!Number.isSafeInteger(offset) ||
|
|
197
|
+
offset < 0 ||
|
|
198
|
+
cursorLabel !== (label ?? null)
|
|
199
|
+
) {
|
|
200
|
+
throw new Error();
|
|
201
|
+
}
|
|
202
|
+
return offset as number;
|
|
203
|
+
} catch {
|
|
204
|
+
throw new Error("Changelog cursor does not match this timeline view.");
|
|
205
|
+
}
|
|
206
|
+
}
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createChangelogModule,
|
|
5
|
+
createNotionChangelogDataSource,
|
|
6
|
+
createNotionChangelogStorage,
|
|
7
|
+
validateNotionChangelogDataSource,
|
|
8
|
+
type ChangelogPropertyIds,
|
|
9
|
+
} from ".";
|
|
10
|
+
|
|
11
|
+
const propertyIds: ChangelogPropertyIds = {
|
|
12
|
+
title: "title-id",
|
|
13
|
+
slug: "slug-id",
|
|
14
|
+
date: "date-id",
|
|
15
|
+
summary: "summary-id",
|
|
16
|
+
body: "body-id",
|
|
17
|
+
labels: "labels-id",
|
|
18
|
+
image: "image-id",
|
|
19
|
+
published: "published-id",
|
|
20
|
+
createdAt: "created-id",
|
|
21
|
+
updatedAt: "updated-id",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
describe("Notion Changelog Data Source contract", () => {
|
|
25
|
+
it("creates an empty sibling data source with the canonical schema", async () => {
|
|
26
|
+
const request = vi
|
|
27
|
+
.fn<typeof fetch>()
|
|
28
|
+
.mockResolvedValueOnce(Response.json(notionDataSource()));
|
|
29
|
+
|
|
30
|
+
await expect(
|
|
31
|
+
createNotionChangelogDataSource({
|
|
32
|
+
token: "token",
|
|
33
|
+
databaseId: "feedbax-database",
|
|
34
|
+
request,
|
|
35
|
+
}),
|
|
36
|
+
).resolves.toEqual({
|
|
37
|
+
databaseId: "feedbax-database",
|
|
38
|
+
dataSourceId: "changelog-source",
|
|
39
|
+
propertyIds,
|
|
40
|
+
});
|
|
41
|
+
const body = JSON.parse(String(request.mock.calls[0]?.[1]?.body));
|
|
42
|
+
expect(request.mock.calls[0]?.[0]).toBe(
|
|
43
|
+
"https://api.notion.com/v1/data_sources",
|
|
44
|
+
);
|
|
45
|
+
expect(body.parent).toEqual({ database_id: "feedbax-database" });
|
|
46
|
+
expect(body.properties).toMatchObject({
|
|
47
|
+
Title: { title: {} },
|
|
48
|
+
Slug: { rich_text: {} },
|
|
49
|
+
Date: { date: {} },
|
|
50
|
+
Summary: { rich_text: {} },
|
|
51
|
+
Body: { rich_text: {} },
|
|
52
|
+
Labels: { multi_select: { options: [] } },
|
|
53
|
+
Image: { files: {} },
|
|
54
|
+
Published: { checkbox: {} },
|
|
55
|
+
"Created At": { created_time: {} },
|
|
56
|
+
"Updated At": { last_edited_time: {} },
|
|
57
|
+
});
|
|
58
|
+
expect(request).toHaveBeenCalledTimes(1);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("accepts a compatible data source in another database and reports wrong types", async () => {
|
|
62
|
+
const validRequest = vi
|
|
63
|
+
.fn<typeof fetch>()
|
|
64
|
+
.mockResolvedValueOnce(
|
|
65
|
+
Response.json(notionDataSource({ databaseId: "marketing-database" })),
|
|
66
|
+
);
|
|
67
|
+
await expect(
|
|
68
|
+
validateNotionChangelogDataSource({
|
|
69
|
+
token: "token",
|
|
70
|
+
dataSourceId: "changelog-source",
|
|
71
|
+
propertyIds,
|
|
72
|
+
request: validRequest,
|
|
73
|
+
}),
|
|
74
|
+
).resolves.toMatchObject({ databaseId: "marketing-database" });
|
|
75
|
+
|
|
76
|
+
const invalid = notionDataSource();
|
|
77
|
+
invalid.properties.Summary.type = "number";
|
|
78
|
+
await expect(
|
|
79
|
+
validateNotionChangelogDataSource({
|
|
80
|
+
token: "token",
|
|
81
|
+
dataSourceId: "changelog-source",
|
|
82
|
+
propertyIds,
|
|
83
|
+
request: vi
|
|
84
|
+
.fn<typeof fetch>()
|
|
85
|
+
.mockResolvedValue(Response.json(invalid)),
|
|
86
|
+
}),
|
|
87
|
+
).rejects.toThrow(
|
|
88
|
+
'Change the property configured as "Summary" (ID "summary-id") from "number" to "rich_text"',
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe("Notion Changelog query contract", () => {
|
|
94
|
+
it("maps projected properties when Notion keys them by property name", async () => {
|
|
95
|
+
const page = notionPage();
|
|
96
|
+
page.properties = Object.fromEntries(
|
|
97
|
+
Object.entries(page.properties).map(([id, property]) => [
|
|
98
|
+
id === propertyIds.title
|
|
99
|
+
? "Title"
|
|
100
|
+
: id === propertyIds.slug
|
|
101
|
+
? "Slug"
|
|
102
|
+
: id === propertyIds.date
|
|
103
|
+
? "Date"
|
|
104
|
+
: id === propertyIds.summary
|
|
105
|
+
? "Summary"
|
|
106
|
+
: id === propertyIds.body
|
|
107
|
+
? "Body"
|
|
108
|
+
: id === propertyIds.labels
|
|
109
|
+
? "Labels"
|
|
110
|
+
: "Image",
|
|
111
|
+
{ ...property, id },
|
|
112
|
+
]),
|
|
113
|
+
);
|
|
114
|
+
const storage = createNotionChangelogStorage({
|
|
115
|
+
token: "token",
|
|
116
|
+
dataSourceId: "changelog-source",
|
|
117
|
+
propertyIds,
|
|
118
|
+
request: vi
|
|
119
|
+
.fn<typeof fetch>()
|
|
120
|
+
.mockResolvedValueOnce(
|
|
121
|
+
Response.json({ results: [page], has_more: false }),
|
|
122
|
+
),
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
await expect(storage.listPublished({})).resolves.toMatchObject({
|
|
126
|
+
items: [{ slug: "entry", title: "Entry", body: "Body text" }],
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("queries only Published entries with public properties, ordering, Labels, and cursors", async () => {
|
|
131
|
+
const request = vi.fn<typeof fetch>().mockResolvedValueOnce(
|
|
132
|
+
Response.json({
|
|
133
|
+
results: [notionPage()],
|
|
134
|
+
has_more: true,
|
|
135
|
+
next_cursor: "notion-next",
|
|
136
|
+
}),
|
|
137
|
+
);
|
|
138
|
+
const storage = createNotionChangelogStorage({
|
|
139
|
+
token: "token",
|
|
140
|
+
dataSourceId: "changelog-source",
|
|
141
|
+
propertyIds,
|
|
142
|
+
request,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
await expect(
|
|
146
|
+
storage.listPublished({ cursor: "notion-current", label: "Improved" }),
|
|
147
|
+
).resolves.toMatchObject({
|
|
148
|
+
items: [
|
|
149
|
+
{
|
|
150
|
+
slug: "entry",
|
|
151
|
+
title: "Entry",
|
|
152
|
+
summary: "Summary text",
|
|
153
|
+
body: "Body text",
|
|
154
|
+
labels: ["Improved"],
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
nextCursor: "notion-next",
|
|
158
|
+
});
|
|
159
|
+
const [url, init] = request.mock.calls[0] ?? [];
|
|
160
|
+
const query = new URL(String(url)).searchParams.getAll("filter_properties");
|
|
161
|
+
expect(query).toEqual([
|
|
162
|
+
propertyIds.title,
|
|
163
|
+
propertyIds.slug,
|
|
164
|
+
propertyIds.date,
|
|
165
|
+
propertyIds.summary,
|
|
166
|
+
propertyIds.body,
|
|
167
|
+
propertyIds.labels,
|
|
168
|
+
propertyIds.image,
|
|
169
|
+
propertyIds.updatedAt,
|
|
170
|
+
]);
|
|
171
|
+
expect(query).not.toContain(propertyIds.published);
|
|
172
|
+
expect(JSON.parse(String(init?.body))).toEqual({
|
|
173
|
+
page_size: 20,
|
|
174
|
+
start_cursor: "notion-current",
|
|
175
|
+
filter: {
|
|
176
|
+
and: [
|
|
177
|
+
{ property: propertyIds.published, checkbox: { equals: true } },
|
|
178
|
+
{
|
|
179
|
+
property: propertyIds.labels,
|
|
180
|
+
multi_select: { contains: "Improved" },
|
|
181
|
+
},
|
|
182
|
+
],
|
|
183
|
+
},
|
|
184
|
+
sorts: [
|
|
185
|
+
{ property: propertyIds.date, direction: "descending" },
|
|
186
|
+
{ timestamp: "created_time", direction: "ascending" },
|
|
187
|
+
{ property: propertyIds.slug, direction: "ascending" },
|
|
188
|
+
],
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it("maps one temporary File reference with its expiry and reports additional files", async () => {
|
|
193
|
+
const page = notionPage();
|
|
194
|
+
page.properties[propertyIds.image] = {
|
|
195
|
+
type: "files",
|
|
196
|
+
files: [
|
|
197
|
+
{
|
|
198
|
+
name: "release.png",
|
|
199
|
+
type: "file",
|
|
200
|
+
file: {
|
|
201
|
+
url: "https://files.notion.example/release.png",
|
|
202
|
+
expiry_time: "2026-08-26T14:00:00.000Z",
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
name: "extra.png",
|
|
207
|
+
type: "external",
|
|
208
|
+
external: { url: "https://cdn.example/extra.png" },
|
|
209
|
+
},
|
|
210
|
+
],
|
|
211
|
+
};
|
|
212
|
+
const diagnostics: string[] = [];
|
|
213
|
+
const storage = createNotionChangelogStorage({
|
|
214
|
+
token: "token",
|
|
215
|
+
dataSourceId: "changelog-source",
|
|
216
|
+
propertyIds,
|
|
217
|
+
request: vi
|
|
218
|
+
.fn<typeof fetch>()
|
|
219
|
+
.mockResolvedValueOnce(
|
|
220
|
+
Response.json({ results: [page], has_more: false }),
|
|
221
|
+
),
|
|
222
|
+
onDiagnostic: (message) => diagnostics.push(message),
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
await expect(storage.listPublished({})).resolves.toMatchObject({
|
|
226
|
+
items: [
|
|
227
|
+
{
|
|
228
|
+
title: "Entry",
|
|
229
|
+
image: {
|
|
230
|
+
src: "https://files.notion.example/release.png",
|
|
231
|
+
alt: "Entry image",
|
|
232
|
+
expiresAt: new Date("2026-08-26T14:00:00.000Z"),
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
});
|
|
237
|
+
expect(diagnostics).toEqual([
|
|
238
|
+
'Changelog Entry "entry" has 2 Image files; only the first file is in the public contract.',
|
|
239
|
+
]);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it("maps a temporary File reference's exact expiry while preserving entry text", async () => {
|
|
243
|
+
const page = notionPage();
|
|
244
|
+
page.properties[propertyIds.image] = {
|
|
245
|
+
type: "files",
|
|
246
|
+
files: [
|
|
247
|
+
{
|
|
248
|
+
name: "release.png",
|
|
249
|
+
type: "file",
|
|
250
|
+
file: {
|
|
251
|
+
url: "https://files.notion.example/release.png",
|
|
252
|
+
expiry_time: "2026-08-26T12:00:30.000Z",
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
],
|
|
256
|
+
};
|
|
257
|
+
const storage = createNotionChangelogStorage({
|
|
258
|
+
token: "token",
|
|
259
|
+
dataSourceId: "changelog-source",
|
|
260
|
+
propertyIds,
|
|
261
|
+
request: vi
|
|
262
|
+
.fn<typeof fetch>()
|
|
263
|
+
.mockResolvedValueOnce(
|
|
264
|
+
Response.json({ results: [page], has_more: false }),
|
|
265
|
+
),
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
await expect(storage.listPublished({})).resolves.toMatchObject({
|
|
269
|
+
items: [
|
|
270
|
+
{
|
|
271
|
+
title: "Entry",
|
|
272
|
+
summary: "Summary text",
|
|
273
|
+
body: "Body text",
|
|
274
|
+
image: { expiresAt: new Date("2026-08-26T12:00:30.000Z") },
|
|
275
|
+
},
|
|
276
|
+
],
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it("refreshes a discarded temporary reference and contains malformed Image data", async () => {
|
|
281
|
+
const expiringPage = notionPage();
|
|
282
|
+
expiringPage.properties[propertyIds.image] = {
|
|
283
|
+
type: "files",
|
|
284
|
+
files: [
|
|
285
|
+
{
|
|
286
|
+
type: "file",
|
|
287
|
+
file: {
|
|
288
|
+
url: "https://files.notion.example/release.png",
|
|
289
|
+
expiry_time: "2026-08-26T12:00:30.000Z",
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
],
|
|
293
|
+
};
|
|
294
|
+
const refreshedPage = notionPage();
|
|
295
|
+
refreshedPage.properties[propertyIds.image] = {
|
|
296
|
+
type: "files",
|
|
297
|
+
files: [
|
|
298
|
+
{
|
|
299
|
+
type: "file",
|
|
300
|
+
file: {
|
|
301
|
+
url: "https://files.notion.example/release.png",
|
|
302
|
+
expiry_time: "2026-08-26T14:00:00.000Z",
|
|
303
|
+
},
|
|
304
|
+
},
|
|
305
|
+
],
|
|
306
|
+
};
|
|
307
|
+
const malformedPage = notionPage();
|
|
308
|
+
malformedPage.properties[propertyIds.image] = {
|
|
309
|
+
type: "files",
|
|
310
|
+
files: ["not-a-file"],
|
|
311
|
+
};
|
|
312
|
+
const request = vi
|
|
313
|
+
.fn<typeof fetch>()
|
|
314
|
+
.mockResolvedValueOnce(
|
|
315
|
+
Response.json({ results: [expiringPage], has_more: false }),
|
|
316
|
+
)
|
|
317
|
+
.mockResolvedValueOnce(
|
|
318
|
+
Response.json({ results: [refreshedPage], has_more: false }),
|
|
319
|
+
)
|
|
320
|
+
.mockResolvedValueOnce(
|
|
321
|
+
Response.json({ results: [malformedPage], has_more: false }),
|
|
322
|
+
);
|
|
323
|
+
const storage = createNotionChangelogStorage({
|
|
324
|
+
token: "token",
|
|
325
|
+
dataSourceId: "changelog-source",
|
|
326
|
+
propertyIds,
|
|
327
|
+
request,
|
|
328
|
+
onDiagnostic: vi.fn(),
|
|
329
|
+
});
|
|
330
|
+
const changelog = createChangelogModule({
|
|
331
|
+
storage,
|
|
332
|
+
now: () => new Date("2026-08-26T12:00:00.000Z"),
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
expect(
|
|
336
|
+
(await changelog.listPublishedEntries()).items[0],
|
|
337
|
+
).not.toHaveProperty("image");
|
|
338
|
+
expect((await changelog.listPublishedEntries()).items[0]).toHaveProperty(
|
|
339
|
+
"image.src",
|
|
340
|
+
"https://files.notion.example/release.png",
|
|
341
|
+
);
|
|
342
|
+
await expect(changelog.listPublishedEntries()).resolves.toMatchObject({
|
|
343
|
+
items: [{ title: "Entry", summary: "Summary text", body: "Body text" }],
|
|
344
|
+
});
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
function notionDataSource({ databaseId = "feedbax-database" } = {}) {
|
|
349
|
+
const properties = Object.fromEntries(
|
|
350
|
+
[
|
|
351
|
+
["Title", propertyIds.title, "title"],
|
|
352
|
+
["Slug", propertyIds.slug, "rich_text"],
|
|
353
|
+
["Date", propertyIds.date, "date"],
|
|
354
|
+
["Summary", propertyIds.summary, "rich_text"],
|
|
355
|
+
["Body", propertyIds.body, "rich_text"],
|
|
356
|
+
["Labels", propertyIds.labels, "multi_select"],
|
|
357
|
+
["Image", propertyIds.image, "files"],
|
|
358
|
+
["Published", propertyIds.published, "checkbox"],
|
|
359
|
+
["Created At", propertyIds.createdAt, "created_time"],
|
|
360
|
+
["Updated At", propertyIds.updatedAt, "last_edited_time"],
|
|
361
|
+
].map(([name, id, type]) => [name, { id, name, type }]),
|
|
362
|
+
);
|
|
363
|
+
return {
|
|
364
|
+
id: "changelog-source",
|
|
365
|
+
parent: { type: "database_id", database_id: databaseId },
|
|
366
|
+
properties,
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
function notionPage() {
|
|
371
|
+
return {
|
|
372
|
+
id: "page-id",
|
|
373
|
+
created_time: "2026-08-01T00:00:00.000Z",
|
|
374
|
+
last_edited_time: "2026-08-02T00:00:00.000Z",
|
|
375
|
+
properties: {
|
|
376
|
+
[propertyIds.title]: { type: "title", title: [text("Entry")] },
|
|
377
|
+
[propertyIds.slug]: { type: "rich_text", rich_text: [text("entry")] },
|
|
378
|
+
[propertyIds.date]: { type: "date", date: { start: "2026-08-01" } },
|
|
379
|
+
[propertyIds.summary]: {
|
|
380
|
+
type: "rich_text",
|
|
381
|
+
rich_text: [text("Summary "), text("text")],
|
|
382
|
+
},
|
|
383
|
+
[propertyIds.body]: { type: "rich_text", rich_text: [text("Body text")] },
|
|
384
|
+
[propertyIds.labels]: {
|
|
385
|
+
type: "multi_select",
|
|
386
|
+
multi_select: [{ name: "Improved" }],
|
|
387
|
+
},
|
|
388
|
+
[propertyIds.image]: { type: "files", files: [] as unknown[] },
|
|
389
|
+
},
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
function text(content: string) {
|
|
394
|
+
return { type: "text", plain_text: content, text: { content } };
|
|
395
|
+
}
|