@jamwidgets/astro 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Tim Shedor
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,250 @@
1
+ # @jamwidgets/astro
2
+
3
+ > **Note:** This repo is a read-only mirror. Source lives in a private monorepo.
4
+ > For issues/PRs, please open them here and we'll sync changes back.
5
+
6
+ Astro components and content loader for [JamWidgets](https://jamwidgets.com) - widgets for static sites.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install @jamwidgets/astro
12
+ ```
13
+
14
+ ## Setup
15
+
16
+ Add your JamWidgets site key to your `.env`:
17
+
18
+ ```
19
+ JAMWIDGETS_SITE_KEY=your_site_key_here
20
+ ```
21
+
22
+ ## Content Loader (Posts)
23
+
24
+ Fetch posts from JamWidgets at build time using Astro's content collections:
25
+
26
+ ```ts
27
+ // src/content.config.ts
28
+ import { defineCollection } from "astro:content";
29
+ import { jamwidgetsPostsLoader } from "@jamwidgets/astro/loader";
30
+
31
+ const posts = defineCollection({
32
+ loader: jamwidgetsPostsLoader({
33
+ siteKey: import.meta.env.JAMWIDGETS_SITE_KEY,
34
+ }),
35
+ });
36
+
37
+ export const collections = { posts };
38
+ ```
39
+
40
+ Then use in your pages:
41
+
42
+ ```astro
43
+ ---
44
+ import { getCollection } from "astro:content";
45
+ const posts = await getCollection("posts");
46
+ ---
47
+
48
+ {posts.map((post) => (
49
+ <article>
50
+ <h2>{post.data.title}</h2>
51
+ <p>{post.data.excerpt}</p>
52
+ </article>
53
+ ))}
54
+ ```
55
+
56
+ ### Loader Options
57
+
58
+ ```ts
59
+ jamwidgetsPostsLoader({
60
+ siteKey: string; // Required - your JamWidgets site key
61
+ endpoint?: string; // Default: 'https://jamwidgets.com'
62
+ tag?: string; // Filter posts by tag
63
+ limit?: number; // Max posts to fetch (default: 500)
64
+ onError?: 'throw' | 'warn' | 'ignore'; // Error handling
65
+ })
66
+ ```
67
+
68
+ ## Components
69
+
70
+ ### Form
71
+
72
+ A wrapper component for contact forms with built-in spam protection:
73
+
74
+ ```astro
75
+ ---
76
+ import Form from "@jamwidgets/astro/Form";
77
+ ---
78
+
79
+ <Form siteKey={import.meta.env.JAMWIDGETS_SITE_KEY} formSlug="contact">
80
+ <input name="name" placeholder="Name" required />
81
+ <input name="email" type="email" placeholder="Email" required />
82
+ <textarea name="message" placeholder="Message" required></textarea>
83
+ <button type="submit">Send</button>
84
+ </Form>
85
+ ```
86
+
87
+ **Props:**
88
+ - `siteKey` (required) - Your JamWidgets site key
89
+ - `formSlug` (required) - The form slug as configured in JamWidgets
90
+ - `endpoint` - Base URL (default: `https://jamwidgets.com`)
91
+ - `theme` - `'light'` | `'dark'` | `'auto'` (default: `'light'`)
92
+ - `class` - Additional CSS class
93
+
94
+ **Events:**
95
+ - `jamwidgets:loading` - Form submission started
96
+ - `jamwidgets:success` - Submission successful (detail contains response)
97
+ - `jamwidgets:error` - Submission failed (detail contains error)
98
+
99
+ ### Comments
100
+
101
+ Threaded comments with a submission form:
102
+
103
+ ```astro
104
+ ---
105
+ import Comments from "@jamwidgets/astro/Comments";
106
+ ---
107
+
108
+ <Comments
109
+ siteKey={import.meta.env.JAMWIDGETS_SITE_KEY}
110
+ pageId={Astro.url.pathname}
111
+ />
112
+ ```
113
+
114
+ **Props:**
115
+ - `siteKey` (required) - Your JamWidgets site key
116
+ - `pageId` (required) - Unique page identifier (e.g., URL path)
117
+ - `endpoint` - Base URL (default: `https://jamwidgets.com`)
118
+ - `theme` - `'light'` | `'dark'` | `'auto'` (default: `'light'`)
119
+ - `class` - Additional CSS class
120
+
121
+ **Events:**
122
+ - `jamwidgets:comment-posted` - Comment submitted (detail contains comment)
123
+
124
+ ### Reactions
125
+
126
+ Reaction buttons (like, love, clap, etc.):
127
+
128
+ ```astro
129
+ ---
130
+ import Reactions from "@jamwidgets/astro/Reactions";
131
+ ---
132
+
133
+ <Reactions
134
+ siteKey={import.meta.env.JAMWIDGETS_SITE_KEY}
135
+ pageId={Astro.url.pathname}
136
+ reactions={["like", "love", "clap"]}
137
+ />
138
+ ```
139
+
140
+ **Props:**
141
+ - `siteKey` (required) - Your JamWidgets site key
142
+ - `pageId` (required) - Unique page identifier
143
+ - `reactions` - Array of reaction types (default: `['like']`)
144
+ - `icons` - Custom icons: `{ like: '👍', love: '❤️' }`
145
+ - `endpoint` - Base URL (default: `https://jamwidgets.com`)
146
+ - `theme` - `'light'` | `'dark'` | `'auto'` (default: `'light'`)
147
+ - `class` - Additional CSS class
148
+
149
+ **Built-in icons:** `like`, `love`, `clap`, `fire`, `think`, `sad`, `laugh`
150
+
151
+ **Events:**
152
+ - `jamwidgets:reaction-added` - Reaction added
153
+ - `jamwidgets:reaction-removed` - Reaction removed
154
+
155
+ ### Subscribe
156
+
157
+ Email subscription form with double opt-in:
158
+
159
+ ```astro
160
+ ---
161
+ import Subscribe from "@jamwidgets/astro/Subscribe";
162
+ ---
163
+
164
+ <Subscribe
165
+ siteKey={import.meta.env.JAMWIDGETS_SITE_KEY}
166
+ buttonText="Subscribe"
167
+ placeholder="your@email.com"
168
+ />
169
+ ```
170
+
171
+ **Props:**
172
+ - `siteKey` (required) - Your JamWidgets site key
173
+ - `endpoint` - Base URL (default: `https://jamwidgets.com`)
174
+ - `buttonText` - Submit button text (default: `'Subscribe'`)
175
+ - `placeholder` - Email input placeholder
176
+ - `successMessage` - Custom success message
177
+ - `theme` - `'light'` | `'dark'` | `'auto'` (default: `'light'`)
178
+ - `class` - Additional CSS class
179
+
180
+ **Events:**
181
+ - `jamwidgets:subscribed` - Subscription successful
182
+
183
+ ### SubscribeForm
184
+
185
+ A more flexible subscription form that wraps your own markup:
186
+
187
+ ```astro
188
+ ---
189
+ import SubscribeForm from "@jamwidgets/astro/SubscribeForm";
190
+ ---
191
+
192
+ <SubscribeForm siteKey={import.meta.env.JAMWIDGETS_SITE_KEY}>
193
+ <input name="email" type="email" placeholder="Email" required />
194
+ <button type="submit">Join newsletter</button>
195
+ </SubscribeForm>
196
+ ```
197
+
198
+ ## JavaScript API
199
+
200
+ For advanced use cases, use the JavaScript API directly:
201
+
202
+ ```ts
203
+ import {
204
+ submitForm,
205
+ fetchComments,
206
+ postComment,
207
+ fetchReactions,
208
+ addReaction,
209
+ fetchPosts,
210
+ fetchPost,
211
+ } from "@jamwidgets/astro";
212
+
213
+ // Submit a form
214
+ await submitForm({
215
+ siteKey: "your_key",
216
+ formSlug: "contact",
217
+ data: { name: "John", email: "john@example.com", message: "Hello!" },
218
+ });
219
+
220
+ // Fetch comments
221
+ const comments = await fetchComments({
222
+ siteKey: "your_key",
223
+ pageId: "/blog/my-post",
224
+ });
225
+
226
+ // Add a reaction
227
+ await addReaction({
228
+ siteKey: "your_key",
229
+ pageId: "/blog/my-post",
230
+ reactionType: "like",
231
+ });
232
+ ```
233
+
234
+ ## Styling
235
+
236
+ Components use CSS custom properties for theming. Override them to match your site:
237
+
238
+ ```css
239
+ .jamwidgets-comments {
240
+ --jamwidgets-border-color: #e5e7eb;
241
+ --jamwidgets-bg-color: #f9fafb;
242
+ --jamwidgets-text-color: inherit;
243
+ --jamwidgets-button-bg: #3b82f6;
244
+ /* ... see component source for all variables */
245
+ }
246
+ ```
247
+
248
+ ## License
249
+
250
+ MIT
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @jamwidgets/astro
3
+ *
4
+ * Astro components and content loader for Jamwidgets.
5
+ * Re-exports all types, API functions, and controllers from @jamwidgets/core.
6
+ */
7
+ export { DEFAULT_ENDPOINT, API_PATH, VISITOR_STORAGE_KEY, type JamWidgetsConfig, type SeriphConfig, // deprecated alias
8
+ type Comment, type ReactionCounts, type FormSubmitResponse, type SubscribeResponse, type JamwidgetsPost, type SeriphPost, // deprecated alias
9
+ type Announcement, type AnnouncementType, type Poll, type PollOption, type PollSettings, type PollWithResults, type ShowResultsMode, type FeedbackType, buildUrl, getSiteKey, getVisitorId, setVisitorId, type SubmitFormOptions, submitForm, type FetchCommentsOptions, fetchComments, type PostCommentOptions, postComment, type FetchReactionsOptions, type FetchReactionsResponse, fetchReactions, type AddReactionOptions, addReaction, type RemoveReactionOptions, removeReaction, type SubscribeOptions, subscribe, type JoinWaitlistOptions, type JoinWaitlistResponse, joinWaitlist, type ViewCountsOptions, type ViewCounts, type RecordViewResponse, getViewCounts, recordView, type SubmitFeedbackOptions, type SubmitFeedbackResponse, submitFeedback, type FetchPollOptions, fetchPoll, type VotePollOptions, type VotePollResponse, votePoll, type FetchAnnouncementsOptions, fetchAnnouncements, type DismissAnnouncementOptions, dismissAnnouncement, type FetchPostsOptions, fetchPosts, type FetchPostOptions, fetchPost, type ControllerStatus, type ControllerListener, type SubscribeState, type FormState, type ReactionsState, type CommentsState, type WaitlistState, type ViewCountsState, type FeedbackState, type PollState, type AnnouncementsState, SubscribeController, WaitlistController, FormController, ReactionsController, CommentsController, ViewCountsController, FeedbackController, PollController, AnnouncementsController, } from "@jamwidgets/core";
10
+ export { jamwidgetsPostsLoader, seriphPostsLoader, // deprecated alias
11
+ type JamwidgetsPostsLoaderOptions, type SeriphPostsLoaderOptions, } from "./loader.js";
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @jamwidgets/astro
3
+ *
4
+ * Astro components and content loader for Jamwidgets.
5
+ * Re-exports all types, API functions, and controllers from @jamwidgets/core.
6
+ */
7
+ // Re-export everything from core
8
+ export {
9
+ // Constants
10
+ DEFAULT_ENDPOINT, API_PATH, VISITOR_STORAGE_KEY,
11
+ // Helpers
12
+ buildUrl, getSiteKey, getVisitorId, setVisitorId, submitForm, fetchComments, postComment, fetchReactions, addReaction, removeReaction, subscribe, joinWaitlist, getViewCounts, recordView, submitFeedback, fetchPoll, votePoll, fetchAnnouncements, dismissAnnouncement, fetchPosts, fetchPost, SubscribeController, WaitlistController, FormController, ReactionsController, CommentsController, ViewCountsController, FeedbackController, PollController, AnnouncementsController, } from "@jamwidgets/core";
13
+ // Re-export loader (Astro-specific)
14
+ export { jamwidgetsPostsLoader, seriphPostsLoader, // deprecated alias
15
+ } from "./loader.js";
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Astro Content Loader for Jamwidgets Posts
3
+ *
4
+ * Use this loader to fetch posts from your Jamwidgets instance at build time.
5
+ *
6
+ * @example
7
+ * // In src/content.config.ts
8
+ * import { defineCollection } from 'astro:content';
9
+ * import { jamwidgetsPostsLoader } from '@jamwidgets/astro/loader';
10
+ *
11
+ * const posts = defineCollection({
12
+ * loader: jamwidgetsPostsLoader({
13
+ * siteKey: import.meta.env.JAMWIDGETS_SITE_KEY,
14
+ * }),
15
+ * });
16
+ *
17
+ * export const collections = { posts };
18
+ */
19
+ import { fetchPosts as coreFetchPosts, fetchPost as coreFetchPost, type JamwidgetsPost, type SeriphPost, // deprecated alias
20
+ type FetchPostsOptions, type FetchPostOptions } from "@jamwidgets/core";
21
+ export type { JamwidgetsPost, SeriphPost, FetchPostsOptions, FetchPostOptions };
22
+ export { coreFetchPosts as fetchPosts, coreFetchPost as fetchPost };
23
+ export interface JamwidgetsPostsLoaderOptions {
24
+ /** Your site key (required) */
25
+ siteKey: string;
26
+ /** Base URL of your Jamwidgets instance (default: 'https://jamwidgets.com') */
27
+ endpoint?: string;
28
+ /** Filter posts by tag */
29
+ tag?: string;
30
+ /** Maximum number of posts to fetch (default: 500) */
31
+ limit?: number;
32
+ /** How to handle errors: 'throw' (default), 'warn', or 'ignore' */
33
+ onError?: "throw" | "warn" | "ignore";
34
+ }
35
+ /** @deprecated Use JamwidgetsPostsLoaderOptions instead */
36
+ export type SeriphPostsLoaderOptions = JamwidgetsPostsLoaderOptions;
37
+ interface LoaderContext {
38
+ store: {
39
+ set: (entry: {
40
+ id: string;
41
+ data: JamwidgetsPost;
42
+ }) => void;
43
+ clear: () => void;
44
+ };
45
+ logger: {
46
+ info: (message: string) => void;
47
+ warn: (message: string) => void;
48
+ error: (message: string) => void;
49
+ };
50
+ generateDigest: (data: unknown) => string;
51
+ }
52
+ /**
53
+ * Creates an Astro content loader that fetches posts from Jamwidgets.
54
+ *
55
+ * Posts are fetched at build time and cached by Astro.
56
+ */
57
+ export declare function jamwidgetsPostsLoader(options: JamwidgetsPostsLoaderOptions): {
58
+ name: string;
59
+ load(context: LoaderContext): Promise<void>;
60
+ };
61
+ /** @deprecated Use jamwidgetsPostsLoader instead */
62
+ export declare const seriphPostsLoader: typeof jamwidgetsPostsLoader;
package/dist/loader.js ADDED
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Astro Content Loader for Jamwidgets Posts
3
+ *
4
+ * Use this loader to fetch posts from your Jamwidgets instance at build time.
5
+ *
6
+ * @example
7
+ * // In src/content.config.ts
8
+ * import { defineCollection } from 'astro:content';
9
+ * import { jamwidgetsPostsLoader } from '@jamwidgets/astro/loader';
10
+ *
11
+ * const posts = defineCollection({
12
+ * loader: jamwidgetsPostsLoader({
13
+ * siteKey: import.meta.env.JAMWIDGETS_SITE_KEY,
14
+ * }),
15
+ * });
16
+ *
17
+ * export const collections = { posts };
18
+ */
19
+ import { DEFAULT_ENDPOINT, API_PATH, getSiteKey, fetchPosts as coreFetchPosts, fetchPost as coreFetchPost, } from "@jamwidgets/core";
20
+ export { coreFetchPosts as fetchPosts, coreFetchPost as fetchPost };
21
+ /**
22
+ * Creates an Astro content loader that fetches posts from Jamwidgets.
23
+ *
24
+ * Posts are fetched at build time and cached by Astro.
25
+ */
26
+ export function jamwidgetsPostsLoader(options) {
27
+ const { endpoint = DEFAULT_ENDPOINT, tag, limit = 500, onError = "throw", } = options;
28
+ const siteKey = getSiteKey({ siteKey: options.siteKey });
29
+ const baseUrl = endpoint.replace(/\/+$/, "") + API_PATH;
30
+ return {
31
+ name: "jamwidgets-posts-loader",
32
+ async load(context) {
33
+ const { store, logger } = context;
34
+ try {
35
+ const url = new URL(`${baseUrl}/posts`);
36
+ url.searchParams.set("limit", String(limit));
37
+ if (tag) {
38
+ url.searchParams.set("tag", tag);
39
+ }
40
+ logger.info(`Fetching posts from ${url.toString()}`);
41
+ const response = await fetch(url.toString(), {
42
+ headers: {
43
+ "X-Jamwidgets-Key": siteKey,
44
+ "X-JamWidgets-Key": siteKey, // backward compat
45
+ },
46
+ });
47
+ if (!response.ok) {
48
+ throw new Error(`Failed to fetch posts: ${response.status} ${response.statusText}`);
49
+ }
50
+ const data = await response.json();
51
+ store.clear();
52
+ for (const post of data.posts) {
53
+ store.set({
54
+ id: post.slug,
55
+ data: post,
56
+ });
57
+ }
58
+ logger.info(`Loaded ${data.posts.length} posts from Jamwidgets`);
59
+ }
60
+ catch (error) {
61
+ const message = error instanceof Error ? error.message : String(error);
62
+ if (onError === "throw") {
63
+ logger.error(`Error loading posts: ${message}`);
64
+ throw error;
65
+ }
66
+ else if (onError === "warn") {
67
+ logger.warn(`Error loading posts (continuing anyway): ${message}`);
68
+ }
69
+ }
70
+ },
71
+ };
72
+ }
73
+ /** @deprecated Use jamwidgetsPostsLoader instead */
74
+ export const seriphPostsLoader = jamwidgetsPostsLoader;
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@jamwidgets/astro",
3
+ "version": "0.1.0",
4
+ "description": "Astro components and content loader for Jamwidgets (forms, comments, reactions, posts)",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/jamwidgets/astro.git"
8
+ },
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "homepage": "https://jamwidgets.com",
13
+ "author": "Tim Marks <tim@imothee.xyz>",
14
+ "type": "module",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "import": "./dist/index.js"
19
+ },
20
+ "./loader": {
21
+ "types": "./dist/loader.d.ts",
22
+ "import": "./dist/loader.js"
23
+ },
24
+ "./Form": "./src/Form.astro",
25
+ "./Comments": "./src/Comments.astro",
26
+ "./Reactions": "./src/Reactions.astro",
27
+ "./Views": "./src/Views.astro",
28
+ "./Poll": "./src/Poll.astro",
29
+ "./Subscribe": "./src/Subscribe.astro",
30
+ "./SubscribeForm": "./src/SubscribeForm.astro",
31
+ "./Announcements": "./src/Announcements.astro",
32
+ "./Feedback": "./src/Feedback.astro",
33
+ "./Waitlist": "./src/Waitlist.astro",
34
+ "./Embed": "./src/Embed.astro"
35
+ },
36
+ "files": [
37
+ "src",
38
+ "dist"
39
+ ],
40
+ "keywords": [
41
+ "astro",
42
+ "jamwidgets",
43
+ "forms",
44
+ "comments",
45
+ "reactions",
46
+ "posts",
47
+ "widgets",
48
+ "content-loader",
49
+ "subscribe"
50
+ ],
51
+ "license": "MIT",
52
+ "dependencies": {
53
+ "@jamwidgets/core": "0.1.0"
54
+ },
55
+ "peerDependencies": {
56
+ "astro": "^5.0.0"
57
+ },
58
+ "devDependencies": {
59
+ "typescript": "^5.7.3"
60
+ },
61
+ "scripts": {
62
+ "build": "tsc",
63
+ "dev": "tsc --watch"
64
+ }
65
+ }