-
Notifications
You must be signed in to change notification settings - Fork 83
Vaultrice voting integration #971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
adrai
wants to merge
4
commits into
GitbookIO:main
Choose a base branch
from
vaultrice:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # @gitbook/integration-vaultrice-voting | ||
|
|
||
| ## 0.1.0 | ||
|
|
||
| ### Minor Changes | ||
|
|
||
| - initial version | ||
|
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| name: vaultrice-voting-widget | ||
| title: Vaultrice Voting Integration | ||
| description: Add interactive voting widgets to your GitBook documentation with real-time results. | ||
| visibility: public | ||
| organization: lTQNmOvSMj7VuZMuxuG8 | ||
| icon: ./assets/icon.png | ||
| previewImages: | ||
| - ./assets/voting-preview.png | ||
| - ./assets/install-config.png | ||
| - ./assets/widget-config.png | ||
| summary: | | ||
| # Overview | ||
|
|
||
| The Vaultrice Voting Integration allows you to embed interactive voting widgets directly into your GitBook pages. Users can vote on options and see real-time results without requiring any backend infrastructure. | ||
|
|
||
| # Features | ||
|
|
||
| - **Real-time voting**: Vote counts update instantly across all clients | ||
| - **No backend required**: Powered by Vaultrice's encrypted key-value storage | ||
| - **Persistent results**: Vote data is stored securely and persists across sessions | ||
| - **Customizable**: Configure titles, descriptions, and voting options | ||
|
|
||
| # How it works | ||
|
|
||
| Once installed, you can insert voting widgets into any page. Configure the voting options, title, and description through the block editor. Results are displayed in real-time as users vote. | ||
|
|
||
| # Integration script (we'll return this from fetch_published_script) | ||
| script: ./src/index.ts | ||
|
|
||
| blocks: | ||
| - id: vote-block | ||
| title: Vaultrice Voting Widget | ||
| description: Insert a Vaultrice voting widget. | ||
| categories: | ||
| - content | ||
| - other | ||
|
|
||
| # Integration user-configurable settings | ||
| configurations: | ||
| account: | ||
| properties: | ||
| projectId: | ||
| type: string | ||
| title: Vaultrice Project ID | ||
| description: 'Create an account and paste your Project ID. (like here: https://www.vaultrice.com/docs/quickstart)' | ||
| apiKey: | ||
| type: string | ||
| title: Vaultrice API Key | ||
| description: 'Create an account and paste your API Key. (like here: https://www.vaultrice.com/docs/quickstart)' | ||
| apiSecret: | ||
| type: string | ||
| title: Vaultrice API Secret | ||
| description: 'Create an account and paste your API Secret. (like here: https://www.vaultrice.com/docs/quickstart)' | ||
| required: | ||
| - projectId | ||
| - apiKey | ||
| - apiSecret | ||
|
|
||
| # Scopes your integration needs | ||
| scopes: [] | ||
|
|
||
| externalLinks: | ||
| - label: Vaultrice Website | ||
| url: https://www.vaultrice.com | ||
| - label: Vaultrice App | ||
| url: https://www.vaultrice.app | ||
|
|
||
| target: space |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| { | ||
| "name": "@gitbook/integration-vaultrice-voting", | ||
| "version": "0.1.0", | ||
| "private": true, | ||
| "dependencies": { | ||
| "@gitbook/api": "*", | ||
| "@gitbook/runtime": "*" | ||
| }, | ||
| "devDependencies": { | ||
| "@gitbook/cli": "workspace:*", | ||
| "@gitbook/tsconfig": "workspace:*", | ||
| "@types/react": "^19.1.13", | ||
| "@types/react-dom": "^19.1.9", | ||
| "@vaultrice/react-components": "^1.2.1", | ||
| "@vitejs/plugin-react": "5.0.2", | ||
| "react": "19.1.1", | ||
| "react-dom": "19.1.1", | ||
| "vite": "7.1.5" | ||
| }, | ||
| "scripts": { | ||
| "typecheck": "tsc --noEmit", | ||
| "build:widget": "vite build --config vite.widget.config.ts && mv dist/voting.mjs src/script.raw.js", | ||
| "build": "bun run build:widget", | ||
| "publish-integrations-staging": "bun run build && gitbook publish .", | ||
| "check": "gitbook check", | ||
| "publish-integrations": "bun run build && gitbook publish ." | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import { | ||
| createIntegration, | ||
| FetchEventCallback, | ||
| FetchPublishScriptEventCallback, | ||
| RuntimeContext, | ||
| RuntimeEnvironment, | ||
| } from '@gitbook/runtime'; | ||
| import { VoteBlock } from './vote-block'; | ||
|
|
||
| // @ts-ignore | ||
| // eslint-disable-next-line import/no-unresolved | ||
| import script from './script.raw.js?raw'; // the generated string module | ||
|
|
||
| type VaultriceContext = RuntimeContext< | ||
| RuntimeEnvironment< | ||
| {}, | ||
| { | ||
| projectId?: string; | ||
| apiKey?: string; | ||
| apiSecret?: string; | ||
| } | ||
| > | ||
| >; | ||
|
|
||
| /** | ||
| * serve the published script: return JS string with placeholders replaced | ||
| */ | ||
| export const handleFetchPublishedScript: FetchPublishScriptEventCallback = async ( | ||
| event, | ||
| { environment }: VaultriceContext, | ||
| ) => { | ||
| return new Response(script as string, { | ||
| headers: { | ||
| 'Content-Type': 'application/javascript', | ||
| 'Cache-Control': 'public, max-age=3600', | ||
| }, | ||
| }); | ||
| }; | ||
|
|
||
| /** | ||
| * Generic HTTP handler (GitBook calls /integration) | ||
| */ | ||
| export const handleFetch: FetchEventCallback = async (request, context) => { | ||
| const url = new URL(request.url); | ||
| const path = url.pathname; | ||
|
|
||
| if (path.endsWith('voting.js') && url.searchParams.get('script') === 'true') { | ||
| return handleFetchPublishedScript(request as any, context as any) as any; | ||
| } | ||
|
|
||
| return new Response( | ||
| `<!doctype html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <meta name="color-scheme" content="light dark" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
| <title>Vaultrice Voting iframe</title> | ||
| <style> | ||
| * { margin: 0; padding: 0; box-sizing: border-box; } | ||
| html,body { width: 100%; height: 100%; } | ||
| #root { padding: 12px; } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <div id="root"><div class="loading">Loading voting widget...</div></div> | ||
| <script type="module"> | ||
| // Import the ES module served by the integration (same path with script param) | ||
| import init from '${url.origin}${url.pathname}/voting.js?script=true&v=${context.environment.integration.version}'; | ||
| // call the exported init() to setup message listeners and rendering | ||
| (async () => { | ||
| try { | ||
| const api = await init(); | ||
| // optional: keep reference (api) to call later if needed | ||
| } catch (err) { | ||
| console.error('Widget init failed', err); | ||
| } | ||
| })(); | ||
| </script> | ||
| </body> | ||
| </html>`, | ||
| { | ||
| headers: { | ||
| 'Content-Type': 'text/html', | ||
| 'Cache-Control': 'public, max-age=86400', | ||
| }, | ||
| }, | ||
| ); | ||
| }; | ||
|
|
||
| export default createIntegration({ | ||
| fetch: handleFetch, | ||
| fetch_published_script: handleFetchPublishedScript, | ||
| components: [VoteBlock], | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.