@magicpages/ghost-typesense-webhook 1.1.0 → 1.1.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/README.md +47 -71
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,99 +1,75 @@
|
|
|
1
1
|
# @magicpages/ghost-typesense-webhook
|
|
2
2
|
|
|
3
|
-
A Netlify Function that
|
|
3
|
+
A Netlify Function that keeps your Typesense search index in sync with your Ghost content.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Quick Setup
|
|
6
|
+
|
|
7
|
+
1. Deploy to Netlify:
|
|
8
|
+
|
|
9
|
+
[](https://app.netlify.com/start/deploy?repository=https://github.com/magicpages/ghost-typesense)
|
|
10
|
+
|
|
11
|
+
2. Set environment variables in Netlify:
|
|
6
12
|
|
|
7
13
|
```bash
|
|
8
|
-
|
|
14
|
+
GHOST_URL=https://your-ghost-blog.com
|
|
15
|
+
GHOST_CONTENT_API_KEY=your-content-api-key
|
|
16
|
+
TYPESENSE_HOST=your-typesense-host
|
|
17
|
+
TYPESENSE_API_KEY=your-admin-api-key
|
|
18
|
+
COLLECTION_NAME=ghost
|
|
19
|
+
WEBHOOK_SECRET=your-secret-key # Create a secure random string
|
|
9
20
|
```
|
|
10
21
|
|
|
11
|
-
|
|
22
|
+
3. Add webhooks in Ghost Admin:
|
|
23
|
+
- Go to Settings → Integrations
|
|
24
|
+
- Create/select a Custom Integration
|
|
25
|
+
- Add the following four webhooks:
|
|
26
|
+
| Name | Event | Target URL |
|
|
27
|
+
|------|-------|------------|
|
|
28
|
+
| Post published | Post published | `https://your-site.netlify.app/.netlify/functions/handler?secret=your-secret-key` |
|
|
29
|
+
| Post updated | Post updated | `https://your-site.netlify.app/.netlify/functions/handler?secret=your-secret-key` |
|
|
30
|
+
| Post deleted | Post deleted | `https://your-site.netlify.app/.netlify/functions/handler?secret=your-secret-key` |
|
|
31
|
+
| Post unpublished | Post unpublished | `https://your-site.netlify.app/.netlify/functions/handler?secret=your-secret-key` |
|
|
12
32
|
|
|
13
|
-
|
|
14
|
-
2. Create a `netlify.toml` configuration:
|
|
33
|
+
## Manual Setup
|
|
15
34
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
node_bundler = "esbuild"
|
|
20
|
-
|
|
21
|
-
[functions.ghost-typesense]
|
|
22
|
-
external_node_modules = ["@netlify/functions"]
|
|
35
|
+
1. Install the package:
|
|
36
|
+
```bash
|
|
37
|
+
npm install @magicpages/ghost-typesense-webhook
|
|
23
38
|
```
|
|
24
39
|
|
|
25
|
-
|
|
26
|
-
|
|
40
|
+
2. Create the function:
|
|
27
41
|
```typescript
|
|
28
|
-
// netlify/functions/
|
|
42
|
+
// netlify/functions/handler.ts
|
|
29
43
|
import { handler } from '@magicpages/ghost-typesense-webhook';
|
|
30
44
|
export { handler };
|
|
31
45
|
```
|
|
32
46
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
GHOST_WEBHOOK_SECRET=your-webhook-secret
|
|
39
|
-
TYPESENSE_HOST=your-typesense-host
|
|
40
|
-
TYPESENSE_PORT=443
|
|
41
|
-
TYPESENSE_PROTOCOL=https
|
|
42
|
-
TYPESENSE_API_KEY=your-typesense-api-key
|
|
43
|
-
TYPESENSE_COLLECTION_NAME=posts
|
|
47
|
+
3. Configure `netlify.toml`:
|
|
48
|
+
```toml
|
|
49
|
+
[functions]
|
|
50
|
+
directory = "netlify/functions"
|
|
51
|
+
node_bundler = "esbuild"
|
|
44
52
|
```
|
|
45
53
|
|
|
46
|
-
5. Configure the webhook in Ghost Admin:
|
|
47
|
-
- Go to Settings > Integrations
|
|
48
|
-
- Create a new Custom Integration
|
|
49
|
-
- Add a webhook with the following settings:
|
|
50
|
-
- Event: Post published/updated/unpublished
|
|
51
|
-
- Target URL: Your Netlify function URL (e.g., `https://your-site.netlify.app/.netlify/functions/ghost-typesense`)
|
|
52
|
-
|
|
53
54
|
## Environment Variables
|
|
54
55
|
|
|
55
56
|
| Variable | Description |
|
|
56
57
|
|----------|-------------|
|
|
57
|
-
| `GHOST_URL` |
|
|
58
|
-
| `
|
|
59
|
-
| `
|
|
60
|
-
| `
|
|
61
|
-
| `
|
|
62
|
-
| `
|
|
63
|
-
| `TYPESENSE_API_KEY` | Typesense API key |
|
|
64
|
-
| `TYPESENSE_COLLECTION_NAME` | Name of the Typesense collection |
|
|
65
|
-
|
|
66
|
-
## Webhook Events
|
|
67
|
-
|
|
68
|
-
The handler processes the following Ghost webhook events:
|
|
69
|
-
|
|
70
|
-
- `post.published`: Adds or updates the post in Typesense
|
|
71
|
-
- `post.updated`: Updates the post in Typesense
|
|
72
|
-
- `post.unpublished`: Removes the post from Typesense
|
|
73
|
-
- `post.deleted`: Removes the post from Typesense
|
|
74
|
-
|
|
75
|
-
## Security
|
|
76
|
-
|
|
77
|
-
The webhook handler validates incoming requests using the `GHOST_WEBHOOK_SECRET`. Make sure to:
|
|
78
|
-
|
|
79
|
-
1. Generate a secure random string for your webhook secret
|
|
80
|
-
2. Configure the same secret in both Ghost and your environment variables
|
|
81
|
-
3. Keep your secret secure and never commit it to version control
|
|
82
|
-
|
|
83
|
-
## Error Handling
|
|
84
|
-
|
|
85
|
-
The handler includes comprehensive error handling:
|
|
58
|
+
| `GHOST_URL` | Your Ghost blog URL |
|
|
59
|
+
| `GHOST_CONTENT_API_KEY` | Content API key from Ghost |
|
|
60
|
+
| `TYPESENSE_HOST` | Typesense host |
|
|
61
|
+
| `TYPESENSE_API_KEY` | Typesense admin API key |
|
|
62
|
+
| `COLLECTION_NAME` | Collection name (default: 'ghost') |
|
|
63
|
+
| `WEBHOOK_SECRET` | Secret key for webhook security |
|
|
86
64
|
|
|
87
|
-
|
|
88
|
-
- Validates request payloads
|
|
89
|
-
- Handles Ghost API errors
|
|
90
|
-
- Handles Typesense errors
|
|
91
|
-
- Returns appropriate HTTP status codes
|
|
65
|
+
## How It Works
|
|
92
66
|
|
|
93
|
-
|
|
67
|
+
The webhook handler:
|
|
68
|
+
1. Validates the secret in the URL query parameter
|
|
69
|
+
2. Processes post status changes (publish/unpublish/update)
|
|
70
|
+
3. Updates the Typesense index accordingly
|
|
94
71
|
|
|
95
|
-
This package is written in TypeScript and includes full type definitions. It uses strict type checking and provides comprehensive type safety for all APIs.
|
|
96
72
|
|
|
97
73
|
## License
|
|
98
74
|
|
|
99
|
-
MIT
|
|
75
|
+
MIT © [MagicPages](https://www.magicpages.co)
|