@jamwidgets/astro 0.3.1 → 0.3.2
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/README.md +6 -0
- package/dist/loader.d.ts +2 -0
- package/dist/loader.js +2 -3
- package/package.json +5 -3
- package/src/loader.ts +4 -2
package/README.md
CHANGED
|
@@ -17,6 +17,7 @@ Add your JamWidgets site key to your `.env`:
|
|
|
17
17
|
|
|
18
18
|
```
|
|
19
19
|
JAMWIDGETS_SITE_KEY=your_site_key_here
|
|
20
|
+
SITE_URL=https://example.com
|
|
20
21
|
```
|
|
21
22
|
|
|
22
23
|
## Content Loader (Posts)
|
|
@@ -31,12 +32,16 @@ import { jamwidgetsPostsLoader } from "@jamwidgets/astro/loader";
|
|
|
31
32
|
const posts = defineCollection({
|
|
32
33
|
loader: jamwidgetsPostsLoader({
|
|
33
34
|
siteKey: import.meta.env.JAMWIDGETS_SITE_KEY,
|
|
35
|
+
origin: import.meta.env.SITE_URL,
|
|
34
36
|
}),
|
|
35
37
|
});
|
|
36
38
|
|
|
37
39
|
export const collections = { posts };
|
|
38
40
|
```
|
|
39
41
|
|
|
42
|
+
Set `origin` to an allowed origin for production builds. JamWidgets rejects the
|
|
43
|
+
request when the site restricts origins and the loader omits it.
|
|
44
|
+
|
|
40
45
|
Then use in your pages:
|
|
41
46
|
|
|
42
47
|
```astro
|
|
@@ -59,6 +64,7 @@ const posts = await getCollection("posts");
|
|
|
59
64
|
jamwidgetsPostsLoader({
|
|
60
65
|
siteKey: string; // Required - your JamWidgets site key
|
|
61
66
|
endpoint?: string; // Default: 'https://jamwidgets.com'
|
|
67
|
+
origin?: string; // Site URL used for allowed-origin validation
|
|
62
68
|
tag?: string; // Filter posts by tag
|
|
63
69
|
limit?: number; // Max posts to fetch (default: 500)
|
|
64
70
|
onError?: 'throw' | 'warn' | 'ignore'; // Error handling
|
package/dist/loader.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ export interface JamwidgetsPostsLoaderOptions {
|
|
|
26
26
|
siteKey: string;
|
|
27
27
|
/** Base URL of your Jamwidgets instance (default: 'https://jamwidgets.com') */
|
|
28
28
|
endpoint?: string;
|
|
29
|
+
/** Site origin sent for allowed-origin validation */
|
|
30
|
+
origin?: string;
|
|
29
31
|
/** Filter posts by tag */
|
|
30
32
|
tag?: string;
|
|
31
33
|
/** Maximum number of posts to fetch (default: 500) */
|
package/dist/loader.js
CHANGED
|
@@ -24,7 +24,7 @@ export { coreFetchPosts as fetchPosts, coreFetchPost as fetchPost };
|
|
|
24
24
|
* Posts are fetched at build time and cached by Astro.
|
|
25
25
|
*/
|
|
26
26
|
export function jamwidgetsPostsLoader(options) {
|
|
27
|
-
const { endpoint = DEFAULT_ENDPOINT, tag, limit = 500, onError = "throw", } = options;
|
|
27
|
+
const { endpoint = DEFAULT_ENDPOINT, origin, tag, limit = 500, onError = "throw", } = options;
|
|
28
28
|
const siteKey = getSiteKey({ siteKey: options.siteKey });
|
|
29
29
|
const baseUrl = endpoint.replace(/\/+$/, "") + API_PATH;
|
|
30
30
|
return {
|
|
@@ -41,10 +41,9 @@ export function jamwidgetsPostsLoader(options) {
|
|
|
41
41
|
const response = await fetch(url.toString(), {
|
|
42
42
|
headers: {
|
|
43
43
|
"X-Jamwidgets-Key": siteKey,
|
|
44
|
-
// Legacy headers for backward compatibility
|
|
45
44
|
"X-Seriph-Key": siteKey,
|
|
46
|
-
// User-Agent to avoid bot detection (Cloudflare, etc.)
|
|
47
45
|
"User-Agent": "JamwidgetsAstroLoader/1.0",
|
|
46
|
+
...(origin ? { Origin: origin } : {}),
|
|
48
47
|
},
|
|
49
48
|
});
|
|
50
49
|
if (!response.ok) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jamwidgets/astro",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Astro components and content loader for Jamwidgets (forms, comments, reactions, posts)",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -41,7 +41,8 @@
|
|
|
41
41
|
],
|
|
42
42
|
"scripts": {
|
|
43
43
|
"build": "tsc",
|
|
44
|
-
"dev": "tsc --watch"
|
|
44
|
+
"dev": "tsc --watch",
|
|
45
|
+
"test": "vitest run test/loader.test.ts"
|
|
45
46
|
},
|
|
46
47
|
"keywords": [
|
|
47
48
|
"astro",
|
|
@@ -63,6 +64,7 @@
|
|
|
63
64
|
},
|
|
64
65
|
"devDependencies": {
|
|
65
66
|
"astro": "^7.1.3",
|
|
66
|
-
"typescript": "^5.9.3"
|
|
67
|
+
"typescript": "^5.9.3",
|
|
68
|
+
"vitest": "^4.1.10"
|
|
67
69
|
}
|
|
68
70
|
}
|
package/src/loader.ts
CHANGED
|
@@ -39,6 +39,8 @@ export interface JamwidgetsPostsLoaderOptions {
|
|
|
39
39
|
siteKey: string;
|
|
40
40
|
/** Base URL of your Jamwidgets instance (default: 'https://jamwidgets.com') */
|
|
41
41
|
endpoint?: string;
|
|
42
|
+
/** Site origin sent for allowed-origin validation */
|
|
43
|
+
origin?: string;
|
|
42
44
|
/** Filter posts by tag */
|
|
43
45
|
tag?: string;
|
|
44
46
|
/** Maximum number of posts to fetch (default: 500) */
|
|
@@ -63,6 +65,7 @@ interface ApiResponse {
|
|
|
63
65
|
export function jamwidgetsPostsLoader(options: JamwidgetsPostsLoaderOptions): Loader {
|
|
64
66
|
const {
|
|
65
67
|
endpoint = DEFAULT_ENDPOINT,
|
|
68
|
+
origin,
|
|
66
69
|
tag,
|
|
67
70
|
limit = 500,
|
|
68
71
|
onError = "throw",
|
|
@@ -89,10 +92,9 @@ export function jamwidgetsPostsLoader(options: JamwidgetsPostsLoaderOptions): Lo
|
|
|
89
92
|
const response = await fetch(url.toString(), {
|
|
90
93
|
headers: {
|
|
91
94
|
"X-Jamwidgets-Key": siteKey,
|
|
92
|
-
// Legacy headers for backward compatibility
|
|
93
95
|
"X-Seriph-Key": siteKey,
|
|
94
|
-
// User-Agent to avoid bot detection (Cloudflare, etc.)
|
|
95
96
|
"User-Agent": "JamwidgetsAstroLoader/1.0",
|
|
97
|
+
...(origin ? { Origin: origin } : {}),
|
|
96
98
|
},
|
|
97
99
|
});
|
|
98
100
|
|