@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.
Files changed (2) hide show
  1. package/README.md +47 -71
  2. 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 handles Ghost webhooks to keep your Typesense search index in sync with your Ghost content in real-time.
3
+ A Netlify Function that keeps your Typesense search index in sync with your Ghost content.
4
4
 
5
- ## Installation
5
+ ## Quick Setup
6
+
7
+ 1. Deploy to Netlify:
8
+
9
+ [![Deploy to Netlify](https://www.netlify.com/img/deploy/button.svg)](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
- npm install @magicpages/ghost-typesense-webhook
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
- ## Usage with Netlify
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
- 1. Install the package in your Netlify project
14
- 2. Create a `netlify.toml` configuration:
33
+ ## Manual Setup
15
34
 
16
- ```toml
17
- [functions]
18
- directory = "netlify/functions"
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
- 3. Create the function in your Netlify functions directory:
26
-
40
+ 2. Create the function:
27
41
  ```typescript
28
- // netlify/functions/ghost-typesense.ts
42
+ // netlify/functions/handler.ts
29
43
  import { handler } from '@magicpages/ghost-typesense-webhook';
30
44
  export { handler };
31
45
  ```
32
46
 
33
- 4. Configure environment variables in your Netlify dashboard:
34
-
35
- ```env
36
- GHOST_URL=https://your-ghost-blog.com
37
- GHOST_ADMIN_API_KEY=your-admin-api-key
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` | URL of your Ghost blog |
58
- | `GHOST_ADMIN_API_KEY` | Ghost Admin API key |
59
- | `GHOST_WEBHOOK_SECRET` | Secret for validating webhook requests |
60
- | `TYPESENSE_HOST` | Typesense server host |
61
- | `TYPESENSE_PORT` | Typesense server port |
62
- | `TYPESENSE_PROTOCOL` | Typesense server protocol (http/https) |
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
- - Validates webhook signatures
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
- ## TypeScript Support
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 - see the [LICENSE](../../LICENSE) file for details.
75
+ MIT © [MagicPages](https://www.magicpages.co)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magicpages/ghost-typesense-webhook",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Webhook handler for real-time Ghost content synchronization with Typesense",
5
5
  "author": "MagicPages",
6
6
  "license": "MIT",