mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-12 05:48:57 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d9b5a898ab | |||
| f127d28675 | |||
| 65c1bdc455 | |||
| 0711a171d4 | |||
| c58c551f9e | |||
| f574858b9b | |||
| 3e1592e16b |
@@ -1,6 +1,12 @@
|
|||||||
name: 'Deploy cloudflare'
|
name: 'Deploy cloudflare'
|
||||||
description: 'Deploy GitBook to Cloudflare'
|
description: 'Deploy GitBook to Cloudflare'
|
||||||
inputs:
|
inputs:
|
||||||
|
opItem:
|
||||||
|
description: '1Password item to load secrets from'
|
||||||
|
required: true
|
||||||
|
opServiceAccount:
|
||||||
|
description: '1Password service account token'
|
||||||
|
required: true
|
||||||
apiToken:
|
apiToken:
|
||||||
description: 'Cloudflare API token'
|
description: 'Cloudflare API token'
|
||||||
required: true
|
required: true
|
||||||
@@ -8,44 +14,11 @@ inputs:
|
|||||||
description: 'Cloudflare account ID'
|
description: 'Cloudflare account ID'
|
||||||
required: true
|
required: true
|
||||||
environment:
|
environment:
|
||||||
description: 'Environment to deploy to'
|
description: 'Cloudflare environment to deploy to (staging, production, preview)'
|
||||||
required: true
|
required: true
|
||||||
deploy:
|
deploy:
|
||||||
description: 'Deploy as main version for all traffic instead of uploading versions'
|
description: 'Deploy as main version for all traffic instead of uploading versions'
|
||||||
required: true
|
required: true
|
||||||
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY:
|
|
||||||
description: 'Next server actions encryption key'
|
|
||||||
required: true
|
|
||||||
GITBOOK_URL:
|
|
||||||
description: 'GitBook URL'
|
|
||||||
required: true
|
|
||||||
GITBOOK_SECRET:
|
|
||||||
description: 'GitBook secret'
|
|
||||||
required: true
|
|
||||||
GITBOOK_APP_URL:
|
|
||||||
description: 'GitBook app URL'
|
|
||||||
required: false
|
|
||||||
GITBOOK_API_URL:
|
|
||||||
description: 'GitBook API URL'
|
|
||||||
required: false
|
|
||||||
GITBOOK_INTEGRATIONS_HOST:
|
|
||||||
description: 'GitBook integrations host'
|
|
||||||
required: false
|
|
||||||
GITBOOK_IMAGE_RESIZE_SIGNING_KEY:
|
|
||||||
description: 'GitBook image resize signing key'
|
|
||||||
required: true
|
|
||||||
GITBOOK_IMAGE_RESIZE_URL:
|
|
||||||
description: 'GitBook image resize URL'
|
|
||||||
required: true
|
|
||||||
GITBOOK_ICONS_URL:
|
|
||||||
description: 'GitBook icons URL'
|
|
||||||
required: true
|
|
||||||
GITBOOK_ICONS_TOKEN:
|
|
||||||
description: 'GitBook icons token'
|
|
||||||
required: true
|
|
||||||
GITBOOK_ASSETS_PREFIX:
|
|
||||||
description: 'GitBook assets prefix'
|
|
||||||
required: false
|
|
||||||
outputs:
|
outputs:
|
||||||
deployment-url:
|
deployment-url:
|
||||||
description: "Deployment URL"
|
description: "Deployment URL"
|
||||||
@@ -60,21 +33,25 @@ runs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
env:
|
env:
|
||||||
PUPPETEER_SKIP_DOWNLOAD: 1
|
PUPPETEER_SKIP_DOWNLOAD: 1
|
||||||
|
- name: Load secret
|
||||||
|
uses: 1password/load-secrets-action@v2
|
||||||
|
env:
|
||||||
|
OP_SERVICE_ACCOUNT_TOKEN: ${{ inputs.opServiceAccount }}
|
||||||
|
GITBOOK_URL: ${{ inputs.opItem }}/GITBOOK_URL
|
||||||
|
GITBOOK_ICONS_URL: ${{ inputs.opItem }}/GITBOOK_ICONS_URL
|
||||||
|
GITBOOK_ICONS_TOKEN: ${{ inputs.opItem }}/GITBOOK_ICONS_TOKEN
|
||||||
|
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: ${{ inputs.opItem }}/NEXT_SERVER_ACTIONS_ENCRYPTION_KEY
|
||||||
|
GITBOOK_SECRET: ${{ inputs.opItem }}/GITBOOK_SECRET
|
||||||
|
GITBOOK_APP_URL: ${{ inputs.opItem }}/GITBOOK_APP_URL
|
||||||
|
GITBOOK_API_URL: ${{ inputs.opItem }}/GITBOOK_API_URL
|
||||||
|
GITBOOK_API_TOKEN: ${{ inputs.opItem }}/GITBOOK_API_TOKEN
|
||||||
|
GITBOOK_INTEGRATIONS_HOST: ${{ inputs.opItem }}/GITBOOK_INTEGRATIONS_HOST
|
||||||
|
GITBOOK_IMAGE_RESIZE_SIGNING_KEY: ${{ inputs.opItem }}/GITBOOK_IMAGE_RESIZE_SIGNING_KEY
|
||||||
|
GITBOOK_IMAGE_RESIZE_URL: ${{ inputs.opItem }}/GITBOOK_IMAGE_RESIZE_URL
|
||||||
|
GITBOOK_ASSETS_PREFIX: ${{ inputs.opItem }}/GITBOOK_ASSETS_PREFIX
|
||||||
- name: Build worker
|
- name: Build worker
|
||||||
run: bun run turbo build:v2:cloudflare
|
run: bun run turbo build:v2:cloudflare
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
|
||||||
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: ${{ inputs.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY }}
|
|
||||||
GITBOOK_URL: ${{ inputs.GITBOOK_URL }}
|
|
||||||
GITBOOK_SECRET: ${{ inputs.GITBOOK_SECRET }}
|
|
||||||
GITBOOK_APP_URL: ${{ inputs.GITBOOK_APP_URL }}
|
|
||||||
GITBOOK_API_URL: ${{ inputs.GITBOOK_API_URL }}
|
|
||||||
GITBOOK_INTEGRATIONS_HOST: ${{ inputs.GITBOOK_INTEGRATIONS_HOST }}
|
|
||||||
GITBOOK_IMAGE_RESIZE_SIGNING_KEY: ${{ inputs.GITBOOK_IMAGE_RESIZE_SIGNING_KEY }}
|
|
||||||
GITBOOK_IMAGE_RESIZE_URL: ${{ inputs.GITBOOK_IMAGE_RESIZE_URL }}
|
|
||||||
GITBOOK_ICONS_URL: ${{ inputs.GITBOOK_ICONS_URL }}
|
|
||||||
GITBOOK_ICONS_TOKEN: ${{ inputs.GITBOOK_ICONS_TOKEN }}
|
|
||||||
GITBOOK_ASSETS_PREFIX: ${{ inputs.GITBOOK_ASSETS_PREFIX }}
|
|
||||||
- id: deploy
|
- id: deploy
|
||||||
name: Deploy to Cloudflare
|
name: Deploy to Cloudflare
|
||||||
uses: cloudflare/wrangler-action@v3.14.0
|
uses: cloudflare/wrangler-action@v3.14.0
|
||||||
@@ -84,7 +61,7 @@ runs:
|
|||||||
workingDirectory: ./
|
workingDirectory: ./
|
||||||
wranglerVersion: '3.112.0'
|
wranglerVersion: '3.112.0'
|
||||||
environment: ${{ inputs.environment }}
|
environment: ${{ inputs.environment }}
|
||||||
command: ${{ inputs.deploy && 'deploy' || 'versions upload' }} --config ./packages/gitbook-v2/wrangler.toml
|
command: ${{ fromJSON(inputs.deploy) == true && 'deploy' || 'versions upload' }} --config ./packages/gitbook-v2/wrangler.toml
|
||||||
- name: Outputs
|
- name: Outputs
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
env:
|
||||||
|
|||||||
@@ -1,15 +1,21 @@
|
|||||||
name: 'Deploy vercel'
|
name: 'Deploy vercel'
|
||||||
description: 'Deploy GitBook to Vercel'
|
description: 'Deploy GitBook to Vercel'
|
||||||
inputs:
|
inputs:
|
||||||
vercel-org:
|
vercelOrg:
|
||||||
description: 'Vercel organization'
|
description: 'Vercel organization'
|
||||||
required: true
|
required: true
|
||||||
vercel-project:
|
vercelProject:
|
||||||
description: 'Vercel project'
|
description: 'Vercel project'
|
||||||
required: true
|
required: true
|
||||||
vercel-token:
|
vercelToken:
|
||||||
description: 'Vercel token'
|
description: 'Vercel token'
|
||||||
required: true
|
required: true
|
||||||
|
opItem:
|
||||||
|
description: '1Password item to load secrets from'
|
||||||
|
required: true
|
||||||
|
opServiceAccount:
|
||||||
|
description: '1Password service account token'
|
||||||
|
required: true
|
||||||
environment:
|
environment:
|
||||||
description: 'Environment to deploy to'
|
description: 'Environment to deploy to'
|
||||||
required: true
|
required: true
|
||||||
@@ -27,31 +33,42 @@ runs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
env:
|
env:
|
||||||
PUPPETEER_SKIP_DOWNLOAD: 1
|
PUPPETEER_SKIP_DOWNLOAD: 1
|
||||||
- name: Sets env vars for environment
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
echo "VERCEL_ENVIRONMENT=${{ inputs.environment }}" >> $GITHUB_ENV
|
|
||||||
- name: Pull Vercel Environment Information
|
- name: Pull Vercel Environment Information
|
||||||
run: bun run vercel pull --yes --environment=$VERCEL_ENVIRONMENT --token=${{ inputs.vercel-token }}
|
run: bun run vercel pull --yes --environment=${{ inputs.environment }} --token=${{ inputs.vercelToken }}
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
env:
|
||||||
VERCEL_ORG_ID: ${{ inputs.vercel-org }}
|
VERCEL_ORG_ID: ${{ inputs.vercelOrg }}
|
||||||
VERCEL_PROJECT_ID: ${{ inputs.vercel-project }}
|
VERCEL_PROJECT_ID: ${{ inputs.vercelProject }}
|
||||||
|
- name: Load secret
|
||||||
|
uses: 1password/load-secrets-action@v2
|
||||||
|
env:
|
||||||
|
OP_SERVICE_ACCOUNT_TOKEN: ${{ inputs.opServiceAccount }}
|
||||||
|
GITBOOK_URL: ${{ inputs.opItem }}/GITBOOK_URL
|
||||||
|
GITBOOK_ICONS_URL: ${{ inputs.opItem }}/GITBOOK_ICONS_URL
|
||||||
|
GITBOOK_ICONS_TOKEN: ${{ inputs.opItem }}/GITBOOK_ICONS_TOKEN
|
||||||
|
GITBOOK_SECRET: ${{ inputs.opItem }}/GITBOOK_SECRET
|
||||||
|
GITBOOK_APP_URL: ${{ inputs.opItem }}/GITBOOK_APP_URL
|
||||||
|
GITBOOK_API_URL: ${{ inputs.opItem }}/GITBOOK_API_URL
|
||||||
|
GITBOOK_API_TOKEN: ${{ inputs.opItem }}/GITBOOK_API_TOKEN
|
||||||
|
GITBOOK_INTEGRATIONS_HOST: ${{ inputs.opItem }}/GITBOOK_INTEGRATIONS_HOST
|
||||||
|
GITBOOK_IMAGE_RESIZE_SIGNING_KEY: ${{ inputs.opItem }}/GITBOOK_IMAGE_RESIZE_SIGNING_KEY
|
||||||
|
GITBOOK_IMAGE_RESIZE_URL: ${{ inputs.opItem }}/GITBOOK_IMAGE_RESIZE_URL
|
||||||
|
GITBOOK_ASSETS_PREFIX: ${{ inputs.opItem }}/GITBOOK_ASSETS_PREFIX
|
||||||
- name: Build Project Artifacts
|
- name: Build Project Artifacts
|
||||||
run: bun run vercel build --target=$VERCEL_ENVIRONMENT --token=${{ inputs.vercel-token }}
|
run: bun run vercel build --target=${{ inputs.environment }} --token=${{ inputs.vercelToken }}
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
env:
|
||||||
VERCEL_ORG_ID: ${{ inputs.vercel-org }}
|
VERCEL_ORG_ID: ${{ inputs.vercelOrg }}
|
||||||
VERCEL_PROJECT_ID: ${{ inputs.vercel-project }}
|
VERCEL_PROJECT_ID: ${{ inputs.vercelProject }}
|
||||||
- name: Deploy Project Artifacts to Vercel
|
- name: Deploy Project Artifacts to Vercel
|
||||||
id: deploy
|
id: deploy
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
DEPLOYMENT_URL=$(bun run vercel deploy --prebuilt --target=$VERCEL_ENVIRONMENT --token=${{ inputs.vercel-token }})
|
DEPLOYMENT_URL=$(bun run vercel deploy --prebuilt --target=${{ inputs.environment }} --token=${{ inputs.vercelToken }})
|
||||||
echo "deployment-url=$DEPLOYMENT_URL" >> "$GITHUB_OUTPUT"
|
echo "deployment-url=$DEPLOYMENT_URL" >> "$GITHUB_OUTPUT"
|
||||||
env:
|
env:
|
||||||
VERCEL_ORG_ID: ${{ inputs.vercel-org }}
|
VERCEL_ORG_ID: ${{ inputs.vercelOrg }}
|
||||||
VERCEL_PROJECT_ID: ${{ inputs.vercel-project }}
|
VERCEL_PROJECT_ID: ${{ inputs.vercelProject }}
|
||||||
- name: Outputs
|
- name: Outputs
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ jobs:
|
|||||||
deploy-v1-cloudflare:
|
deploy-v1-cloudflare:
|
||||||
name: Deploy v1 to Cloudflare Pages
|
name: Deploy v1 to Cloudflare Pages
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
environment:
|
||||||
|
name: ${{ github.ref == 'refs/heads/main' && '1c-production' || '1c-preview' }}
|
||||||
|
url: ${{ steps.deploy.outputs.deployment-url }}
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
deployments: write
|
deployments: write
|
||||||
@@ -63,56 +66,45 @@ jobs:
|
|||||||
deploy-v2-vercel:
|
deploy-v2-vercel:
|
||||||
name: Deploy v2 to Vercel (preview)
|
name: Deploy v2 to Vercel (preview)
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
environment:
|
||||||
contents: read
|
name: 2v-preview
|
||||||
deployments: write
|
url: ${{ steps.deploy.outputs.deployment-url }}
|
||||||
issues: write
|
|
||||||
pull-requests: write
|
|
||||||
checks: write
|
|
||||||
statuses: write
|
|
||||||
outputs:
|
outputs:
|
||||||
deployment-url: ${{ steps.deploy.outputs.deployment-url }}
|
deployment-url: ${{ steps.deploy.outputs.deployment-url }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: Deploy ${{ github.ref == 'refs/heads/main' && 'production' || 'preview' }}
|
- name: Deploy to Vercel
|
||||||
id: deploy
|
id: deploy
|
||||||
uses: ./.github/composite/deploy-vercel
|
uses: ./.github/composite/deploy-vercel
|
||||||
with:
|
with:
|
||||||
environment: ${{ github.ref == 'refs/heads/main' && 'production' || 'preview' }}
|
environment: preview
|
||||||
vercel-org: ${{ secrets.VERCEL_ORG_ID }}
|
vercelOrg: ${{ secrets.VERCEL_ORG_ID }}
|
||||||
vercel-project: ${{ secrets.VERCEL_PROJECT_ID }}
|
vercelProject: ${{ secrets.VERCEL_PROJECT_ID }}
|
||||||
vercel-token: ${{ secrets.VERCEL_TOKEN }}
|
vercelToken: ${{ secrets.VERCEL_TOKEN }}
|
||||||
|
opItem: op://gitbook-open/2v-preview
|
||||||
|
opServiceAccount: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
|
||||||
deploy-v2-cloudflare:
|
deploy-v2-cloudflare:
|
||||||
name: Deploy v2 to Cloudflare Worker (preview)
|
name: Deploy v2 to Cloudflare Worker (preview)
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
environment:
|
||||||
contents: read
|
name: 2c-preview
|
||||||
deployments: write
|
url: ${{ steps.deploy.outputs.deployment-url }}
|
||||||
issues: write
|
|
||||||
pull-requests: write
|
|
||||||
checks: write
|
|
||||||
statuses: write
|
|
||||||
outputs:
|
outputs:
|
||||||
deployment-url: ${{ steps.deploy.outputs.deployment-url }}
|
deployment-url: ${{ steps.deploy.outputs.deployment-url }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: Deploy ${{ github.ref == 'refs/heads/main' && 'production' || 'preview' }}
|
- name: Deploy to Cloudflare
|
||||||
id: deploy
|
id: deploy
|
||||||
uses: ./.github/composite/deploy-cloudflare
|
uses: ./.github/composite/deploy-cloudflare
|
||||||
with:
|
with:
|
||||||
environment: ${{ github.ref == 'refs/heads/main' && 'production' || 'preview' }}
|
environment: preview
|
||||||
deploy: ${{ github.ref == 'refs/heads/main' }}
|
deploy: ${{ github.ref == 'refs/heads/main' }}
|
||||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: ${{ secrets.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY }}
|
opItem: op://gitbook-open/2c-preview
|
||||||
GITBOOK_URL: ${{ github.ref == 'refs/heads/main' && vars.PRODUCTION_2C_GITBOOK_URL || vars.PREVIEW_2C_GITBOOK_URL }}
|
opServiceAccount: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
|
||||||
GITBOOK_IMAGE_RESIZE_SIGNING_KEY: ${{ secrets.PREVIEW_GITBOOK_IMAGE_RESIZE_SIGNING_KEY }}
|
|
||||||
GITBOOK_IMAGE_RESIZE_URL: ${{ vars.GITBOOK_IMAGE_RESIZE_URL }}
|
|
||||||
GITBOOK_ICONS_URL: ${{ vars.GITBOOK_ICONS_URL }}
|
|
||||||
GITBOOK_ICONS_TOKEN: ${{ vars.GITBOOK_ICONS_TOKEN }}
|
|
||||||
GITBOOK_SECRET: ${{ github.ref == 'refs/heads/main' && secrets.PRODUCTION_GITBOOK_SECRET|| '' }}
|
|
||||||
- name: Outputs
|
- name: Outputs
|
||||||
run: |
|
run: |
|
||||||
echo "URL: ${{ steps.deploy.outputs.deployment-url }}"
|
echo "URL: ${{ steps.deploy.outputs.deployment-url }}"
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ jobs:
|
|||||||
deploy-v2-vercel:
|
deploy-v2-vercel:
|
||||||
name: Deploy v2 to Vercel (production)
|
name: Deploy v2 to Vercel (production)
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
environment:
|
||||||
|
name: 2v-production
|
||||||
|
url: ${{ steps.deploy.outputs.deployment-url }}
|
||||||
outputs:
|
outputs:
|
||||||
deployment-url: ${{ steps.deploy.outputs.deployment-url }}
|
deployment-url: ${{ steps.deploy.outputs.deployment-url }}
|
||||||
steps:
|
steps:
|
||||||
@@ -18,13 +21,18 @@ jobs:
|
|||||||
id: deploy
|
id: deploy
|
||||||
uses: ./.github/composite/deploy-vercel
|
uses: ./.github/composite/deploy-vercel
|
||||||
with:
|
with:
|
||||||
environment: production
|
environment: production
|
||||||
vercel-org: ${{ secrets.VERCEL_ORG_ID }}
|
vercelOrg: ${{ secrets.VERCEL_ORG_ID }}
|
||||||
vercel-project: ${{ secrets.VERCEL_PROJECT_ID }}
|
vercelProject: ${{ secrets.VERCEL_PROJECT_ID }}
|
||||||
vercel-token: ${{ secrets.VERCEL_TOKEN }}
|
vercelToken: ${{ secrets.VERCEL_TOKEN }}
|
||||||
|
opItem: op://gitbook-open/2v-production
|
||||||
|
opServiceAccount: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
|
||||||
deploy-v2-cloudflare:
|
deploy-v2-cloudflare:
|
||||||
name: Deploy v2 to Cloudflare Worker (production)
|
name: Deploy v2 to Cloudflare Worker (production)
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
environment:
|
||||||
|
name: 2c-production
|
||||||
|
url: ${{ steps.deploy.outputs.deployment-url }}
|
||||||
outputs:
|
outputs:
|
||||||
deployment-url: ${{ steps.deploy.outputs.deployment-url }}
|
deployment-url: ${{ steps.deploy.outputs.deployment-url }}
|
||||||
steps:
|
steps:
|
||||||
@@ -34,16 +42,12 @@ jobs:
|
|||||||
id: deploy
|
id: deploy
|
||||||
uses: ./.github/composite/deploy-cloudflare
|
uses: ./.github/composite/deploy-cloudflare
|
||||||
with:
|
with:
|
||||||
environment: staging
|
environment: production
|
||||||
|
deploy: true
|
||||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: ${{ secrets.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY }}
|
opItem: op://gitbook-open/2c-production
|
||||||
GITBOOK_URL: ${{ vars.STAGING_2C_GITBOOK_URL }}
|
opServiceAccount: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
|
||||||
GITBOOK_IMAGE_RESIZE_SIGNING_KEY: ${{ secrets.STAGING_GITBOOK_IMAGE_RESIZE_SIGNING_KEY }}
|
|
||||||
GITBOOK_IMAGE_RESIZE_URL: ${{ vars.GITBOOK_IMAGE_RESIZE_URL }}
|
|
||||||
GITBOOK_ICONS_URL: ${{ vars.GITBOOK_ICONS_URL }}
|
|
||||||
GITBOOK_ICONS_TOKEN: ${{ vars.GITBOOK_ICONS_TOKEN }}
|
|
||||||
GITBOOK_ASSETS_PREFIX: ${{ vars.STAGING_2C_GITBOOK_ASSETS_PREFIX }}
|
|
||||||
- name: Outputs
|
- name: Outputs
|
||||||
run: |
|
run: |
|
||||||
echo "URL: ${{ steps.deploy.outputs.deployment-url }}"
|
echo "URL: ${{ steps.deploy.outputs.deployment-url }}"
|
||||||
@@ -9,6 +9,9 @@ jobs:
|
|||||||
deploy-v2-vercel:
|
deploy-v2-vercel:
|
||||||
name: Deploy v2 to Vercel (staging)
|
name: Deploy v2 to Vercel (staging)
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
environment:
|
||||||
|
name: 2v-staging
|
||||||
|
url: ${{ steps.deploy.outputs.deployment-url }}
|
||||||
outputs:
|
outputs:
|
||||||
deployment-url: ${{ steps.deploy.outputs.deployment-url }}
|
deployment-url: ${{ steps.deploy.outputs.deployment-url }}
|
||||||
steps:
|
steps:
|
||||||
@@ -18,13 +21,18 @@ jobs:
|
|||||||
id: deploy
|
id: deploy
|
||||||
uses: ./.github/composite/deploy-vercel
|
uses: ./.github/composite/deploy-vercel
|
||||||
with:
|
with:
|
||||||
environment: staging
|
environment: staging
|
||||||
vercel-org: ${{ secrets.VERCEL_ORG_ID }}
|
vercelOrg: ${{ secrets.VERCEL_ORG_ID }}
|
||||||
vercel-project: ${{ secrets.VERCEL_PROJECT_ID }}
|
vercelProject: ${{ secrets.VERCEL_PROJECT_ID }}
|
||||||
vercel-token: ${{ secrets.VERCEL_TOKEN }}
|
vercelToken: ${{ secrets.VERCEL_TOKEN }}
|
||||||
|
opItem: op://gitbook-open/2v-staging
|
||||||
|
opServiceAccount: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
|
||||||
deploy-v2-cloudflare:
|
deploy-v2-cloudflare:
|
||||||
name: Deploy v2 to Cloudflare Worker (staging)
|
name: Deploy v2 to Cloudflare Worker (staging)
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
environment:
|
||||||
|
name: 2c-staging
|
||||||
|
url: ${{ steps.deploy.outputs.deployment-url }}
|
||||||
outputs:
|
outputs:
|
||||||
deployment-url: ${{ steps.deploy.outputs.deployment-url }}
|
deployment-url: ${{ steps.deploy.outputs.deployment-url }}
|
||||||
steps:
|
steps:
|
||||||
@@ -38,17 +46,8 @@ jobs:
|
|||||||
deploy: true
|
deploy: true
|
||||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: ${{ secrets.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY }}
|
opItem: op://gitbook-open/2c-staging
|
||||||
GITBOOK_URL: ${{ vars.STAGING_2C_GITBOOK_URL }}
|
opServiceAccount: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
|
||||||
GITBOOK_SECRET: ${{ secrets.STAGING_GITBOOK_SECRET }}
|
|
||||||
GITBOOK_APP_URL: https://app.gitbook-staging.com
|
|
||||||
GITBOOK_API_URL: https://api.gitbook-staging.com
|
|
||||||
GITBOOK_INTEGRATIONS_HOST: https://integrations.gitbook-staging.com
|
|
||||||
GITBOOK_IMAGE_RESIZE_SIGNING_KEY: ${{ secrets.STAGING_GITBOOK_IMAGE_RESIZE_SIGNING_KEY }}
|
|
||||||
GITBOOK_IMAGE_RESIZE_URL: ${{ vars.GITBOOK_IMAGE_RESIZE_URL }}
|
|
||||||
GITBOOK_ICONS_URL: ${{ vars.GITBOOK_ICONS_URL }}
|
|
||||||
GITBOOK_ICONS_TOKEN: ${{ vars.GITBOOK_ICONS_TOKEN }}
|
|
||||||
GITBOOK_ASSETS_PREFIX: ${{ vars.STAGING_2C_GITBOOK_ASSETS_PREFIX }}
|
|
||||||
- name: Outputs
|
- name: Outputs
|
||||||
run: |
|
run: |
|
||||||
echo "URL: ${{ steps.deploy.outputs.deployment-url }}"
|
echo "URL: ${{ steps.deploy.outputs.deployment-url }}"
|
||||||
@@ -10,16 +10,21 @@ const nextConfig = {
|
|||||||
|
|
||||||
env: {
|
env: {
|
||||||
BUILD_VERSION: (process.env.GITHUB_SHA ?? '').slice(0, 7),
|
BUILD_VERSION: (process.env.GITHUB_SHA ?? '').slice(0, 7),
|
||||||
GITBOOK_URL: process.env.GITBOOK_URL,
|
|
||||||
GITBOOK_SECRET: process.env.GITBOOK_SECRET,
|
// GitBook envs
|
||||||
GITBOOK_API_URL: process.env.GITBOOK_API_URL,
|
GITBOOK_API_URL: process.env.GITBOOK_API_URL,
|
||||||
GITBOOK_APP_URL: process.env.GITBOOK_APP_URL,
|
GITBOOK_APP_URL: process.env.GITBOOK_APP_URL,
|
||||||
GITBOOK_INTEGRATIONS_HOST: process.env.GITBOOK_INTEGRATIONS_HOST,
|
GITBOOK_INTEGRATIONS_HOST: process.env.GITBOOK_INTEGRATIONS_HOST,
|
||||||
GITBOOK_IMAGE_RESIZE_SIGNING_KEY: process.env.GITBOOK_IMAGE_RESIZE_SIGNING_KEY,
|
|
||||||
GITBOOK_IMAGE_RESIZE_URL: process.env.GITBOOK_IMAGE_RESIZE_URL,
|
GITBOOK_IMAGE_RESIZE_URL: process.env.GITBOOK_IMAGE_RESIZE_URL,
|
||||||
GITBOOK_ASSETS_PREFIX: process.env.GITBOOK_ASSETS_PREFIX,
|
|
||||||
GITBOOK_ICONS_URL: process.env.GITBOOK_ICONS_URL,
|
GITBOOK_ICONS_URL: process.env.GITBOOK_ICONS_URL,
|
||||||
GITBOOK_ICONS_TOKEN: process.env.GITBOOK_ICONS_TOKEN,
|
GITBOOK_ICONS_TOKEN: process.env.GITBOOK_ICONS_TOKEN,
|
||||||
|
GITBOOK_URL: process.env.GITBOOK_URL,
|
||||||
|
GITBOOK_API_TOKEN: process.env.GITBOOK_API_TOKEN,
|
||||||
|
GITBOOK_ASSETS_PREFIX: process.env.GITBOOK_ASSETS_PREFIX,
|
||||||
|
GITBOOK_SECRET: process.env.GITBOOK_SECRET,
|
||||||
|
GITBOOK_IMAGE_RESIZE_SIGNING_KEY: process.env.GITBOOK_IMAGE_RESIZE_SIGNING_KEY,
|
||||||
|
|
||||||
|
// Next.js envs
|
||||||
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: process.env.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY,
|
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: process.env.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY,
|
||||||
|
|
||||||
// Used to detect if the app is running in V2 mode
|
// Used to detect if the app is running in V2 mode
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
import { type NextRequest, NextResponse } from 'next/server';
|
import { type NextRequest, NextResponse } from 'next/server';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
GITBOOK_API_TOKEN,
|
||||||
GITBOOK_API_URL,
|
GITBOOK_API_URL,
|
||||||
GITBOOK_APP_URL,
|
GITBOOK_APP_URL,
|
||||||
GITBOOK_ASSETS_URL,
|
GITBOOK_ASSETS_URL,
|
||||||
GITBOOK_DISABLE_TRACKING,
|
GITBOOK_DISABLE_TRACKING,
|
||||||
|
GITBOOK_ICONS_URL,
|
||||||
|
GITBOOK_IMAGE_RESIZE_SIGNING_KEY,
|
||||||
GITBOOK_INTEGRATIONS_HOST,
|
GITBOOK_INTEGRATIONS_HOST,
|
||||||
|
GITBOOK_SECRET,
|
||||||
GITBOOK_URL,
|
GITBOOK_URL,
|
||||||
GITBOOK_USER_AGENT,
|
GITBOOK_USER_AGENT,
|
||||||
} from '@v2/lib/env';
|
} from '@v2/lib/env';
|
||||||
@@ -19,8 +23,14 @@ export async function GET(_req: NextRequest) {
|
|||||||
GITBOOK_APP_URL,
|
GITBOOK_APP_URL,
|
||||||
GITBOOK_API_URL,
|
GITBOOK_API_URL,
|
||||||
GITBOOK_ASSETS_URL,
|
GITBOOK_ASSETS_URL,
|
||||||
|
GITBOOK_ICONS_URL,
|
||||||
GITBOOK_USER_AGENT,
|
GITBOOK_USER_AGENT,
|
||||||
GITBOOK_INTEGRATIONS_HOST,
|
GITBOOK_INTEGRATIONS_HOST,
|
||||||
GITBOOK_DISABLE_TRACKING,
|
GITBOOK_DISABLE_TRACKING,
|
||||||
|
|
||||||
|
// Secret envs
|
||||||
|
GITBOOK_SECRET: !!GITBOOK_SECRET,
|
||||||
|
GITBOOK_API_TOKEN: !!GITBOOK_API_TOKEN,
|
||||||
|
GITBOOK_IMAGE_RESIZE_SIGNING_KEY: !!GITBOOK_IMAGE_RESIZE_SIGNING_KEY,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,3 +3,4 @@ export * from './types';
|
|||||||
export * from './pages';
|
export * from './pages';
|
||||||
export * from './urls';
|
export * from './urls';
|
||||||
export * from './errors';
|
export * from './errors';
|
||||||
|
export * from './lookup';
|
||||||
|
|||||||
@@ -0,0 +1,118 @@
|
|||||||
|
import { race, tryCatch } from '@/lib/async';
|
||||||
|
import { joinPath } from '@/lib/paths';
|
||||||
|
import { GitBookAPI, type GitBookAPIError, type PublishedSiteContentLookup } from '@gitbook/api';
|
||||||
|
import { GITBOOK_API_TOKEN, GITBOOK_API_URL, GITBOOK_USER_AGENT } from '@v2/lib/env';
|
||||||
|
import { getURLLookupAlternatives, stripURLSearch } from './urls';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lookup a content by its URL using the GitBook API.
|
||||||
|
* To optimize caching, we try multiple lookup alternatives and return the first one that matches.
|
||||||
|
*/
|
||||||
|
export async function getPublishedContentByURL(input: {
|
||||||
|
url: string;
|
||||||
|
visitorAuthToken: string | null;
|
||||||
|
redirectOnError: boolean;
|
||||||
|
}): Promise<
|
||||||
|
| { data: PublishedSiteContentLookup; error?: undefined }
|
||||||
|
| { data?: undefined; error: Error | GitBookAPIError }
|
||||||
|
> {
|
||||||
|
const lookupURL = new URL(input.url);
|
||||||
|
const url = stripURLSearch(lookupURL);
|
||||||
|
const lookup = getURLLookupAlternatives(url);
|
||||||
|
|
||||||
|
const result = await race(lookup.urls, async (alternative, { signal }) => {
|
||||||
|
const api = new GitBookAPI({
|
||||||
|
authToken: GITBOOK_API_TOKEN ?? undefined,
|
||||||
|
endpoint: GITBOOK_API_URL,
|
||||||
|
userAgent: GITBOOK_USER_AGENT,
|
||||||
|
});
|
||||||
|
|
||||||
|
const callResult = await tryCatch(
|
||||||
|
api.urls.getPublishedContentByUrl(
|
||||||
|
{
|
||||||
|
url: alternative.url,
|
||||||
|
visitorAuthToken: input.visitorAuthToken ?? undefined,
|
||||||
|
redirectOnError: input.redirectOnError,
|
||||||
|
cache: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
signal,
|
||||||
|
headers: {
|
||||||
|
'x-gitbook-force-cache': 'true',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (callResult.error) {
|
||||||
|
if (alternative.primary) {
|
||||||
|
// We only return an error for the primary alternative (full URL),
|
||||||
|
// as other parts could result in errors due to the URL being incomplete (share links, etc).
|
||||||
|
return { error: callResult.error };
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: { data },
|
||||||
|
} = callResult;
|
||||||
|
|
||||||
|
if ('redirect' in data) {
|
||||||
|
if (alternative.primary) {
|
||||||
|
// Append the path to the redirect URL
|
||||||
|
// because we might have matched a shorter path and the redirect is relative to it
|
||||||
|
if (alternative.extraPath) {
|
||||||
|
if (data.target === 'content') {
|
||||||
|
const redirect = new URL(data.redirect);
|
||||||
|
redirect.pathname = joinPath(redirect.pathname, alternative.extraPath);
|
||||||
|
data.redirect = redirect.toString();
|
||||||
|
} else {
|
||||||
|
const redirect = new URL(data.redirect);
|
||||||
|
if (redirect.searchParams.has('location')) {
|
||||||
|
redirect.searchParams.set(
|
||||||
|
'location',
|
||||||
|
joinPath(
|
||||||
|
redirect.searchParams.get('location') ?? '',
|
||||||
|
alternative.extraPath
|
||||||
|
)
|
||||||
|
);
|
||||||
|
data.redirect = redirect.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { data };
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We use the following criteria to determine if the lookup result is the right one:
|
||||||
|
* - the primary alternative was resolved (because that's the longest or most inclusive path)
|
||||||
|
* - the resolution of the site URL is complete (because we want to resolve the deepest path possible)
|
||||||
|
*
|
||||||
|
* In both cases, the idea is to use the deepest/longest/most inclusive path to resolve the content.
|
||||||
|
*/
|
||||||
|
if (alternative.primary || ('site' in data && data.complete)) {
|
||||||
|
const siteResult: PublishedSiteContentLookup = {
|
||||||
|
...data,
|
||||||
|
changeRequest: data.changeRequest ?? lookup.changeRequest,
|
||||||
|
revision: data.revision ?? lookup.revision,
|
||||||
|
basePath: joinPath(data.basePath, lookup.basePath ?? ''),
|
||||||
|
pathname: joinPath(data.pathname, alternative.extraPath),
|
||||||
|
};
|
||||||
|
return { data: siteResult };
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
return {
|
||||||
|
error: new Error('No content found'),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -1,121 +1,3 @@
|
|||||||
import { race, tryCatch } from '@/lib/async';
|
|
||||||
import { joinPath } from '@/lib/paths';
|
|
||||||
import { GitBookAPI, type GitBookAPIError, type PublishedSiteContentLookup } from '@gitbook/api';
|
|
||||||
import { GITBOOK_API_TOKEN, GITBOOK_API_URL, GITBOOK_USER_AGENT } from '@v2/lib/env';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Lookup a content by its URL using the GitBook API.
|
|
||||||
* To optimize caching, we try multiple lookup alternatives and return the first one that matches.
|
|
||||||
*/
|
|
||||||
export async function getPublishedContentByURL(input: {
|
|
||||||
url: string;
|
|
||||||
visitorAuthToken: string | null;
|
|
||||||
redirectOnError: boolean;
|
|
||||||
}): Promise<
|
|
||||||
| { data: PublishedSiteContentLookup; error?: undefined }
|
|
||||||
| { data?: undefined; error: Error | GitBookAPIError }
|
|
||||||
> {
|
|
||||||
const lookupURL = new URL(input.url);
|
|
||||||
const url = stripURLSearch(lookupURL);
|
|
||||||
const lookup = getURLLookupAlternatives(url);
|
|
||||||
|
|
||||||
const result = await race(lookup.urls, async (alternative, { signal }) => {
|
|
||||||
const api = new GitBookAPI({
|
|
||||||
authToken: GITBOOK_API_TOKEN ?? undefined,
|
|
||||||
endpoint: GITBOOK_API_URL,
|
|
||||||
userAgent: GITBOOK_USER_AGENT,
|
|
||||||
});
|
|
||||||
|
|
||||||
const callResult = await tryCatch(
|
|
||||||
api.urls.getPublishedContentByUrl(
|
|
||||||
{
|
|
||||||
url: alternative.url,
|
|
||||||
visitorAuthToken: input.visitorAuthToken ?? undefined,
|
|
||||||
redirectOnError: input.redirectOnError,
|
|
||||||
cache: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
signal,
|
|
||||||
headers: {
|
|
||||||
'x-gitbook-force-cache': 'true',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (callResult.error) {
|
|
||||||
if (alternative.primary) {
|
|
||||||
// We only return an error for the primary alternative (full URL),
|
|
||||||
// as other parts could result in errors due to the URL being incomplete (share links, etc).
|
|
||||||
return { error: callResult.error };
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const {
|
|
||||||
data: { data },
|
|
||||||
} = callResult;
|
|
||||||
|
|
||||||
if ('redirect' in data) {
|
|
||||||
if (alternative.primary) {
|
|
||||||
// Append the path to the redirect URL
|
|
||||||
// because we might have matched a shorter path and the redirect is relative to it
|
|
||||||
if (alternative.extraPath) {
|
|
||||||
if (data.target === 'content') {
|
|
||||||
const redirect = new URL(data.redirect);
|
|
||||||
redirect.pathname = joinPath(redirect.pathname, alternative.extraPath);
|
|
||||||
data.redirect = redirect.toString();
|
|
||||||
} else {
|
|
||||||
const redirect = new URL(data.redirect);
|
|
||||||
if (redirect.searchParams.has('location')) {
|
|
||||||
redirect.searchParams.set(
|
|
||||||
'location',
|
|
||||||
joinPath(
|
|
||||||
redirect.searchParams.get('location') ?? '',
|
|
||||||
alternative.extraPath
|
|
||||||
)
|
|
||||||
);
|
|
||||||
data.redirect = redirect.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return { data };
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* We use the following criteria to determine if the lookup result is the right one:
|
|
||||||
* - the primary alternative was resolved (because that's the longest or most inclusive path)
|
|
||||||
* - the resolution of the site URL is complete (because we want to resolve the deepest path possible)
|
|
||||||
*
|
|
||||||
* In both cases, the idea is to use the deepest/longest/most inclusive path to resolve the content.
|
|
||||||
*/
|
|
||||||
if (alternative.primary || ('site' in data && data.complete)) {
|
|
||||||
const siteResult: PublishedSiteContentLookup = {
|
|
||||||
...data,
|
|
||||||
changeRequest: data.changeRequest ?? lookup.changeRequest,
|
|
||||||
revision: data.revision ?? lookup.revision,
|
|
||||||
basePath: joinPath(data.basePath, lookup.basePath ?? ''),
|
|
||||||
pathname: joinPath(data.pathname, alternative.extraPath),
|
|
||||||
};
|
|
||||||
return { data: siteResult };
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return {
|
|
||||||
error: new Error('No content found'),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For a given GitBook URL, return a list of alternative URLs that could be matched against to lookup the content.
|
* For a given GitBook URL, return a list of alternative URLs that could be matched against to lookup the content.
|
||||||
* The approach is optimized to aim at reusing cached lookup results as much as possible.
|
* The approach is optimized to aim at reusing cached lookup results as much as possible.
|
||||||
|
|||||||
+22
-3
@@ -1,3 +1,11 @@
|
|||||||
|
import 'server-only';
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Support both Cloudflare and Vercel, environment variables can be bundled.
|
||||||
|
* To avoid leaking them on the client-side, they should be accessed from this file
|
||||||
|
* and not from the `process.env` object.
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main host on which GitBook is running.
|
* Main host on which GitBook is running.
|
||||||
*/
|
*/
|
||||||
@@ -14,12 +22,12 @@ export const GITBOOK_URL =
|
|||||||
export const GITBOOK_ASSETS_URL =
|
export const GITBOOK_ASSETS_URL =
|
||||||
process.env.NODE_ENV === 'development'
|
process.env.NODE_ENV === 'development'
|
||||||
? 'http://localhost:3000'
|
? 'http://localhost:3000'
|
||||||
: process.env.GITBOOK_ASSETS_PREFIX || GITBOOK_URL;
|
: process.env.GITBOOK_ASSETS_PREFIX;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GitBook app URL.
|
* GitBook app URL.
|
||||||
*/
|
*/
|
||||||
export const GITBOOK_APP_URL = process.env.NEXT_PUBLIC_GITBOOK_APP_URL || 'https://app.gitbook.com';
|
export const GITBOOK_APP_URL = process.env.GITBOOK_APP_URL || 'https://app.gitbook.com';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default GitBook API URL endpoint.
|
* Default GitBook API URL endpoint.
|
||||||
@@ -30,7 +38,7 @@ export const GITBOOK_API_URL = process.env.GITBOOK_API_URL || 'https://api.gitbo
|
|||||||
* Default GitBook API token.
|
* Default GitBook API token.
|
||||||
* It can be use to avoid rate-limiting.
|
* It can be use to avoid rate-limiting.
|
||||||
*/
|
*/
|
||||||
export const GITBOOK_API_TOKEN = process.env.GITBOOK_API_TOKEN ?? null;
|
export const GITBOOK_API_TOKEN = process.env.GITBOOK_API_TOKEN || null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User agent to use for API requests.
|
* User agent to use for API requests.
|
||||||
@@ -59,6 +67,17 @@ export const GITBOOK_IMAGE_RESIZE_URL = process.env.GITBOOK_IMAGE_RESIZE_URL ??
|
|||||||
export const GITBOOK_IMAGE_RESIZE_SIGNING_KEY =
|
export const GITBOOK_IMAGE_RESIZE_SIGNING_KEY =
|
||||||
process.env.GITBOOK_IMAGE_RESIZE_SIGNING_KEY ?? null;
|
process.env.GITBOOK_IMAGE_RESIZE_SIGNING_KEY ?? null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Endpoint where icons are served.
|
||||||
|
*/
|
||||||
|
export const GITBOOK_ICONS_URL =
|
||||||
|
process.env.GITBOOK_ICONS_URL || `${GITBOOK_ASSETS_URL || ''}/~gitbook/static/icons`;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Token passed to the icons endpoint.
|
||||||
|
*/
|
||||||
|
export const GITBOOK_ICONS_TOKEN = process.env.GITBOOK_ICONS_TOKEN;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Secret used to validate requests from the GitBook app.
|
* Secret used to validate requests from the GitBook app.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,5 +1,20 @@
|
|||||||
# gitbook
|
# gitbook
|
||||||
|
|
||||||
|
## 0.7.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- f127d28: Rename OpenAPIModels to OpenAPISchemas
|
||||||
|
- Updated dependencies [f127d28]
|
||||||
|
- @gitbook/react-openapi@1.1.2
|
||||||
|
|
||||||
|
## 0.7.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [f574858]
|
||||||
|
- @gitbook/react-openapi@1.1.1
|
||||||
|
|
||||||
## 0.7.0
|
## 0.7.0
|
||||||
|
|
||||||
### Minor Changes
|
### Minor Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "gitbook",
|
"name": "gitbook",
|
||||||
"version": "0.7.0",
|
"version": "0.7.2",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "env-cmd --silent -f ../../.env.local next dev",
|
"dev": "env-cmd --silent -f ../../.env.local next dev",
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
@apply flex-1 flex flex-col gap-4 mb-14;
|
@apply flex-1 flex flex-col gap-4 mb-14;
|
||||||
}
|
}
|
||||||
|
|
||||||
.openapi-models {
|
.openapi-schemas {
|
||||||
@apply flex flex-col mb-14 flex-1;
|
@apply flex flex-col mb-14 flex-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -620,10 +620,10 @@
|
|||||||
@apply space-y-2.5;
|
@apply space-y-2.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
.openapi-section-models {
|
.openapi-section-schemas {
|
||||||
@apply border border-tint-subtle rounded-lg;
|
@apply border border-tint-subtle rounded-lg;
|
||||||
}
|
}
|
||||||
|
|
||||||
.openapi-section-models > .openapi-section-body > .openapi-schema-properties > .openapi-schema {
|
.openapi-section-schemas > .openapi-section-body > .openapi-schema-properties > .openapi-schema {
|
||||||
@apply p-2.5;
|
@apply p-2.5;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ const InsightsContext = React.createContext<TrackEventCallback>(() => {});
|
|||||||
|
|
||||||
interface InsightsProviderProps extends InsightsEventContext {
|
interface InsightsProviderProps extends InsightsEventContext {
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
|
appURL: string;
|
||||||
apiHost: string;
|
apiHost: string;
|
||||||
visitorAuthToken: string | null;
|
visitorAuthToken: string | null;
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
@@ -72,7 +73,7 @@ interface InsightsProviderProps extends InsightsEventContext {
|
|||||||
* Wrap the content of the app with the InsightsProvider to track events.
|
* Wrap the content of the app with the InsightsProvider to track events.
|
||||||
*/
|
*/
|
||||||
export function InsightsProvider(props: InsightsProviderProps) {
|
export function InsightsProvider(props: InsightsProviderProps) {
|
||||||
const { enabled, apiHost, visitorAuthToken, children, ...context } = props;
|
const { enabled, appURL, apiHost, visitorAuthToken, children, ...context } = props;
|
||||||
|
|
||||||
const visitorIdRef = React.useRef<string | null>(null);
|
const visitorIdRef = React.useRef<string | null>(null);
|
||||||
const eventsRef = React.useRef<{
|
const eventsRef = React.useRef<{
|
||||||
@@ -140,7 +141,7 @@ export function InsightsProvider(props: InsightsProviderProps) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const flushBatchedEvents = useDebounceCallback(async () => {
|
const flushBatchedEvents = useDebounceCallback(async () => {
|
||||||
const visitorId = visitorIdRef.current ?? (await getVisitorId());
|
const visitorId = visitorIdRef.current ?? (await getVisitorId(appURL));
|
||||||
visitorIdRef.current = visitorId;
|
visitorIdRef.current = visitorId;
|
||||||
|
|
||||||
flushEventsSync();
|
flushEventsSync();
|
||||||
@@ -184,7 +185,7 @@ export function InsightsProvider(props: InsightsProviderProps) {
|
|||||||
* Get the visitor ID and store it in a ref.
|
* Get the visitor ID and store it in a ref.
|
||||||
*/
|
*/
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
getVisitorId().then((visitorId) => {
|
getVisitorId(appURL).then((visitorId) => {
|
||||||
visitorIdRef.current = visitorId;
|
visitorIdRef.current = visitorId;
|
||||||
// When the page is unloaded, flush all events, but only if the visitor ID is set
|
// When the page is unloaded, flush all events, but only if the visitor ID is set
|
||||||
window.addEventListener('beforeunload', flushEventsSync);
|
window.addEventListener('beforeunload', flushEventsSync);
|
||||||
@@ -192,7 +193,7 @@ export function InsightsProvider(props: InsightsProviderProps) {
|
|||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener('beforeunload', flushEventsSync);
|
window.removeEventListener('beforeunload', flushEventsSync);
|
||||||
};
|
};
|
||||||
}, [flushEventsSync]);
|
}, [flushEventsSync, appURL]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<InsightsContext.Provider value={trackEvent}>
|
<InsightsContext.Provider value={trackEvent}>
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ let pendingVisitorId: Promise<string> | null = null;
|
|||||||
/**
|
/**
|
||||||
* Return the current visitor identifier.
|
* Return the current visitor identifier.
|
||||||
*/
|
*/
|
||||||
export async function getVisitorId(): Promise<string> {
|
export async function getVisitorId(appURL: string): Promise<string> {
|
||||||
if (!visitorId) {
|
if (!visitorId) {
|
||||||
if (!pendingVisitorId) {
|
if (!pendingVisitorId) {
|
||||||
pendingVisitorId = fetchVisitorID().finally(() => {
|
pendingVisitorId = fetchVisitorID(appURL).finally(() => {
|
||||||
pendingVisitorId = null;
|
pendingVisitorId = null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,7 @@ export async function getVisitorId(): Promise<string> {
|
|||||||
/**
|
/**
|
||||||
* Propose a visitor identifier to the GitBook.com server and get the devideId back.
|
* Propose a visitor identifier to the GitBook.com server and get the devideId back.
|
||||||
*/
|
*/
|
||||||
async function fetchVisitorID(): Promise<string> {
|
async function fetchVisitorID(appURL: string): Promise<string> {
|
||||||
const withoutCookies = isCookiesTrackingDisabled();
|
const withoutCookies = isCookiesTrackingDisabled();
|
||||||
|
|
||||||
if (withoutCookies) {
|
if (withoutCookies) {
|
||||||
@@ -46,7 +46,7 @@ async function fetchVisitorID(): Promise<string> {
|
|||||||
// No tracking deviceId set, we'll need to consolidate with the server.
|
// No tracking deviceId set, we'll need to consolidate with the server.
|
||||||
const proposed = generateRandomId();
|
const proposed = generateRandomId();
|
||||||
|
|
||||||
const url = new URL(process.env.NEXT_PUBLIC_GITBOOK_APP_URL ?? 'https://app.gitbook.com');
|
const url = new URL(appURL);
|
||||||
url.pathname = '/__session';
|
url.pathname = '/__session';
|
||||||
url.searchParams.set('proposed', proposed);
|
url.searchParams.set('proposed', proposed);
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import { ClientContexts } from './ClientContexts';
|
|||||||
|
|
||||||
import '@gitbook/icons/style.css';
|
import '@gitbook/icons/style.css';
|
||||||
import './globals.css';
|
import './globals.css';
|
||||||
|
import { GITBOOK_ICONS_TOKEN, GITBOOK_ICONS_URL } from '@v2/lib/env';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Layout shared between the content and the PDF renderer.
|
* Layout shared between the content and the PDF renderer.
|
||||||
@@ -127,8 +128,8 @@ export async function CustomizationRootLayout(props: {
|
|||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<IconsProvider
|
<IconsProvider
|
||||||
assetsURL={process.env.GITBOOK_ICONS_URL ?? getAssetURL('icons')}
|
assetsURL={GITBOOK_ICONS_URL}
|
||||||
assetsURLToken={process.env.GITBOOK_ICONS_TOKEN}
|
assetsURLToken={GITBOOK_ICONS_TOKEN}
|
||||||
assetsByStyles={{
|
assetsByStyles={{
|
||||||
'custom-icons': {
|
'custom-icons': {
|
||||||
assetsURL: getAssetURL('icons'),
|
assetsURL: getAssetURL('icons'),
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { getSpaceLanguage } from '@/intl/server';
|
|||||||
import { t } from '@/intl/translate';
|
import { t } from '@/intl/translate';
|
||||||
import { tcls } from '@/lib/tailwind';
|
import { tcls } from '@/lib/tailwind';
|
||||||
|
|
||||||
|
import { GITBOOK_APP_URL } from '@v2/lib/env';
|
||||||
import { SpacesDropdown } from '../Header/SpacesDropdown';
|
import { SpacesDropdown } from '../Header/SpacesDropdown';
|
||||||
import { InsightsProvider } from '../Insights';
|
import { InsightsProvider } from '../Insights';
|
||||||
import { SiteSectionList, encodeClientSiteSections } from '../SiteSections';
|
import { SiteSectionList, encodeClientSiteSections } from '../SiteSections';
|
||||||
@@ -47,6 +48,7 @@ export function SpaceLayout(props: {
|
|||||||
return (
|
return (
|
||||||
<InsightsProvider
|
<InsightsProvider
|
||||||
enabled={withTracking}
|
enabled={withTracking}
|
||||||
|
appURL={GITBOOK_APP_URL}
|
||||||
apiHost={context.dataFetcher.apiEndpoint}
|
apiHost={context.dataFetcher.apiEndpoint}
|
||||||
visitorAuthToken={visitorAuthToken}
|
visitorAuthToken={visitorAuthToken}
|
||||||
organizationId={context.organizationId}
|
organizationId={context.organizationId}
|
||||||
|
|||||||
@@ -4,5 +4,5 @@ import { GITBOOK_ASSETS_URL } from '@v2/lib/env';
|
|||||||
* Create a public URL for an asset.
|
* Create a public URL for an asset.
|
||||||
*/
|
*/
|
||||||
export function getAssetURL(path: string): string {
|
export function getAssetURL(path: string): string {
|
||||||
return `${GITBOOK_ASSETS_URL}/~gitbook/static/${path}`;
|
return `${GITBOOK_ASSETS_URL || ''}/~gitbook/static/${path}`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
} from '@gitbook/api';
|
} from '@gitbook/api';
|
||||||
import { headers } from 'next/headers';
|
import { headers } from 'next/headers';
|
||||||
|
|
||||||
|
import { GITBOOK_APP_URL } from '@v2/lib/env';
|
||||||
import { getPagePath } from './pages';
|
import { getPagePath } from './pages';
|
||||||
import { assertIsNotV2 } from './v2';
|
import { assertIsNotV2 } from './v2';
|
||||||
|
|
||||||
@@ -100,7 +101,7 @@ export async function getAbsoluteHref(href: string, withHost = false): Promise<s
|
|||||||
* Create an absolute href in the GitBook application.
|
* Create an absolute href in the GitBook application.
|
||||||
*/
|
*/
|
||||||
export function getGitbookAppHref(pathname: string): string {
|
export function getGitbookAppHref(pathname: string): string {
|
||||||
const appUrl = new URL(process.env.NEXT_PUBLIC_GITBOOK_APP_URL ?? 'https://app.gitbook.com');
|
const appUrl = new URL(GITBOOK_APP_URL);
|
||||||
appUrl.pathname = pathname;
|
appUrl.pathname = pathname;
|
||||||
|
|
||||||
return appUrl.toString();
|
return appUrl.toString();
|
||||||
|
|||||||
+10
-10
@@ -1,35 +1,35 @@
|
|||||||
import { fetchOpenAPIFilesystem } from '@/lib/openapi/fetch';
|
import { fetchOpenAPIFilesystem } from '@/lib/openapi/fetch';
|
||||||
import type { ResolveOpenAPIBlockResult } from '@/lib/openapi/types';
|
import type { ResolveOpenAPIBlockResult } from '@/lib/openapi/types';
|
||||||
import { OpenAPIParseError } from '@gitbook/openapi-parser';
|
import { OpenAPIParseError } from '@gitbook/openapi-parser';
|
||||||
import { type OpenAPIModelsData, resolveOpenAPIModels } from '@gitbook/react-openapi';
|
import { type OpenAPISchemasData, resolveOpenAPISchemas } from '@gitbook/react-openapi';
|
||||||
import type { AnyOpenAPIBlock, ResolveOpenAPIBlockArgs } from './types';
|
import type { AnyOpenAPIBlock, ResolveOpenAPIBlockArgs } from './types';
|
||||||
|
|
||||||
type ResolveOpenAPIModelsBlockResult = ResolveOpenAPIBlockResult<OpenAPIModelsData>;
|
type ResolveOpenAPISchemasBlockResult = ResolveOpenAPIBlockResult<OpenAPISchemasData>;
|
||||||
|
|
||||||
const weakmap = new WeakMap<AnyOpenAPIBlock, Promise<ResolveOpenAPIModelsBlockResult>>();
|
const weakmap = new WeakMap<AnyOpenAPIBlock, Promise<ResolveOpenAPISchemasBlockResult>>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cache the result of resolving an OpenAPI block.
|
* Cache the result of resolving an OpenAPI block.
|
||||||
* It is important because the resolve is called in sections and in the block itself.
|
* It is important because the resolve is called in sections and in the block itself.
|
||||||
*/
|
*/
|
||||||
export function resolveOpenAPIModelsBlock(
|
export function resolveOpenAPISchemasBlock(
|
||||||
args: ResolveOpenAPIBlockArgs
|
args: ResolveOpenAPIBlockArgs
|
||||||
): Promise<ResolveOpenAPIModelsBlockResult> {
|
): Promise<ResolveOpenAPISchemasBlockResult> {
|
||||||
if (weakmap.has(args.block)) {
|
if (weakmap.has(args.block)) {
|
||||||
return weakmap.get(args.block)!;
|
return weakmap.get(args.block)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = baseResolveOpenAPIModelsBlock(args);
|
const result = baseResolveOpenAPISchemasBlock(args);
|
||||||
weakmap.set(args.block, result);
|
weakmap.set(args.block, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve OpenAPI models block.
|
* Resolve OpenAPI schemas block.
|
||||||
*/
|
*/
|
||||||
async function baseResolveOpenAPIModelsBlock(
|
async function baseResolveOpenAPISchemasBlock(
|
||||||
args: ResolveOpenAPIBlockArgs
|
args: ResolveOpenAPIBlockArgs
|
||||||
): Promise<ResolveOpenAPIModelsBlockResult> {
|
): Promise<ResolveOpenAPISchemasBlockResult> {
|
||||||
const { context, block } = args;
|
const { context, block } = args;
|
||||||
if (!block.data.path || !block.data.method) {
|
if (!block.data.path || !block.data.method) {
|
||||||
return { data: null, specUrl: null };
|
return { data: null, specUrl: null };
|
||||||
@@ -42,7 +42,7 @@ async function baseResolveOpenAPIModelsBlock(
|
|||||||
return { data: null, specUrl: null };
|
return { data: null, specUrl: null };
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await resolveOpenAPIModels(filesystem);
|
const data = await resolveOpenAPISchemas(filesystem);
|
||||||
|
|
||||||
return { data, specUrl };
|
return { data, specUrl };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -2,7 +2,7 @@ import type { DocumentBlockOpenAPI, DocumentBlockOpenAPIOperation } from '@gitbo
|
|||||||
import type { Filesystem, OpenAPIParseError, OpenAPIV3xDocument } from '@gitbook/openapi-parser';
|
import type { Filesystem, OpenAPIParseError, OpenAPIV3xDocument } from '@gitbook/openapi-parser';
|
||||||
import type { GitBookAnyContext } from '@v2/lib/context';
|
import type { GitBookAnyContext } from '@v2/lib/context';
|
||||||
|
|
||||||
//!!TODO: Add DocumentBlockOpenAPIModels when available in @gitbook/api
|
//!!TODO: Add DocumentBlockOpenAPISchemas when available in @gitbook/api
|
||||||
export type AnyOpenAPIBlock = DocumentBlockOpenAPI | DocumentBlockOpenAPIOperation;
|
export type AnyOpenAPIBlock = DocumentBlockOpenAPI | DocumentBlockOpenAPIOperation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,17 @@
|
|||||||
# @gitbook/react-openapi
|
# @gitbook/react-openapi
|
||||||
|
|
||||||
|
## 1.1.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- f127d28: Rename OpenAPIModels to OpenAPISchemas
|
||||||
|
|
||||||
|
## 1.1.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- f574858: Fix OpenAPI example display error
|
||||||
|
|
||||||
## 1.1.0
|
## 1.1.0
|
||||||
|
|
||||||
### Minor Changes
|
### Minor Changes
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
"default": "./dist/index.js"
|
"default": "./dist/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"version": "1.1.0",
|
"version": "1.1.2",
|
||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@gitbook/openapi-parser": "workspace:*",
|
"@gitbook/openapi-parser": "workspace:*",
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ function OpenAPISchemaPresentation(props: { property: OpenAPISchemaPropertyEntry
|
|||||||
propertyName={propertyName}
|
propertyName={propertyName}
|
||||||
required={required}
|
required={required}
|
||||||
/>
|
/>
|
||||||
{schema['x-deprecated-sunset'] ? (
|
{typeof schema['x-deprecated-sunset'] === 'string' ? (
|
||||||
<div className="openapi-deprecated-sunset openapi-schema-description openapi-markdown">
|
<div className="openapi-deprecated-sunset openapi-schema-description openapi-markdown">
|
||||||
Sunset date:{' '}
|
Sunset date:{' '}
|
||||||
<span className="openapi-deprecated-sunset-date">
|
<span className="openapi-deprecated-sunset-date">
|
||||||
@@ -228,7 +228,7 @@ function OpenAPISchemaPresentation(props: { property: OpenAPISchemaPropertyEntry
|
|||||||
{description ? (
|
{description ? (
|
||||||
<Markdown source={description} className="openapi-schema-description" />
|
<Markdown source={description} className="openapi-schema-description" />
|
||||||
) : null}
|
) : null}
|
||||||
{example ? (
|
{typeof example === 'string' ? (
|
||||||
<div className="openapi-schema-example">
|
<div className="openapi-schema-example">
|
||||||
Example: <code>{example}</code>
|
Example: <code>{example}</code>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
export * from './models';
|
export * from './schemas';
|
||||||
export * from './OpenAPIOperation';
|
export * from './OpenAPIOperation';
|
||||||
export * from './OpenAPIOperationContext';
|
export * from './OpenAPIOperationContext';
|
||||||
export * from './resolveOpenAPIOperation';
|
export * from './resolveOpenAPIOperation';
|
||||||
export type { OpenAPIModelsData, OpenAPIOperationData } from './types';
|
export type { OpenAPISchemasData, OpenAPIOperationData } from './types';
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
export * from './OpenAPIModels';
|
|
||||||
export * from './resolveOpenAPIModels';
|
|
||||||
+18
-18
@@ -2,18 +2,18 @@ import clsx from 'clsx';
|
|||||||
import { OpenAPIDisclosureGroup } from '../OpenAPIDisclosureGroup';
|
import { OpenAPIDisclosureGroup } from '../OpenAPIDisclosureGroup';
|
||||||
import { OpenAPIRootSchema } from '../OpenAPISchema';
|
import { OpenAPIRootSchema } from '../OpenAPISchema';
|
||||||
import { Section, SectionBody } from '../StaticSection';
|
import { Section, SectionBody } from '../StaticSection';
|
||||||
import type { OpenAPIClientContext, OpenAPIContextProps, OpenAPIModelsData } from '../types';
|
import type { OpenAPIClientContext, OpenAPIContextProps, OpenAPISchemasData } from '../types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display OpenAPI Models.
|
* Display OpenAPI Schemas.
|
||||||
*/
|
*/
|
||||||
export function OpenAPIModels(props: {
|
export function OpenAPISchemas(props: {
|
||||||
className?: string;
|
className?: string;
|
||||||
data: OpenAPIModelsData;
|
data: OpenAPISchemasData;
|
||||||
context: OpenAPIContextProps;
|
context: OpenAPIContextProps;
|
||||||
}) {
|
}) {
|
||||||
const { className, data, context } = props;
|
const { className, data, context } = props;
|
||||||
const { models } = data;
|
const { schemas } = data;
|
||||||
|
|
||||||
const clientContext: OpenAPIClientContext = {
|
const clientContext: OpenAPIClientContext = {
|
||||||
defaultInteractiveOpened: context.defaultInteractiveOpened,
|
defaultInteractiveOpened: context.defaultInteractiveOpened,
|
||||||
@@ -21,30 +21,30 @@ export function OpenAPIModels(props: {
|
|||||||
blockKey: context.blockKey,
|
blockKey: context.blockKey,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!models.length) {
|
if (!schemas.length) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={clsx('openapi-models', className)}>
|
<div className={clsx('openapi-schemas', className)}>
|
||||||
<OpenAPIRootModelsSchema models={models} context={clientContext} />
|
<OpenAPIRootSchemasSchema schemas={schemas} context={clientContext} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Root schema for OpenAPI models.
|
* Root schema for OpenAPI schemas.
|
||||||
* It displays a single model or a disclosure group for multiple models.
|
* It displays a single model or a disclosure group for multiple schemas.
|
||||||
*/
|
*/
|
||||||
function OpenAPIRootModelsSchema(props: {
|
function OpenAPIRootSchemasSchema(props: {
|
||||||
models: OpenAPIModelsData['models'];
|
schemas: OpenAPISchemasData['schemas'];
|
||||||
context: OpenAPIClientContext;
|
context: OpenAPIClientContext;
|
||||||
}) {
|
}) {
|
||||||
const { models, context } = props;
|
const { schemas, context } = props;
|
||||||
|
|
||||||
// If there is only one model, we show it directly.
|
// If there is only one model, we show it directly.
|
||||||
if (models.length === 1) {
|
if (schemas.length === 1) {
|
||||||
const schema = models?.[0]?.schema;
|
const schema = schemas?.[0]?.schema;
|
||||||
|
|
||||||
if (!schema) {
|
if (!schema) {
|
||||||
return null;
|
return null;
|
||||||
@@ -59,12 +59,12 @@ function OpenAPIRootModelsSchema(props: {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there are multiple models, we use a disclosure group to show them all.
|
// If there are multiple schemas, we use a disclosure group to show them all.
|
||||||
return (
|
return (
|
||||||
<OpenAPIDisclosureGroup
|
<OpenAPIDisclosureGroup
|
||||||
allowsMultipleExpanded
|
allowsMultipleExpanded
|
||||||
icon={context.icons.chevronRight}
|
icon={context.icons.chevronRight}
|
||||||
groups={models.map(({ name, schema }) => ({
|
groups={schemas.map(({ name, schema }) => ({
|
||||||
id: name,
|
id: name,
|
||||||
label: (
|
label: (
|
||||||
<div className="openapi-response-tab-content" key={`model-${name}`}>
|
<div className="openapi-response-tab-content" key={`model-${name}`}>
|
||||||
@@ -75,7 +75,7 @@ function OpenAPIRootModelsSchema(props: {
|
|||||||
{
|
{
|
||||||
id: 'model',
|
id: 'model',
|
||||||
body: (
|
body: (
|
||||||
<Section className="openapi-section-models">
|
<Section className="openapi-section-schemas">
|
||||||
<SectionBody>
|
<SectionBody>
|
||||||
<OpenAPIRootSchema schema={schema} context={context} />
|
<OpenAPIRootSchema schema={schema} context={context} />
|
||||||
</SectionBody>
|
</SectionBody>
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export * from './OpenAPISchemas';
|
||||||
|
export * from './resolveOpenAPISchemas';
|
||||||
+9
-9
@@ -6,28 +6,28 @@ import {
|
|||||||
shouldIgnoreEntity,
|
shouldIgnoreEntity,
|
||||||
} from '@gitbook/openapi-parser';
|
} from '@gitbook/openapi-parser';
|
||||||
import { dereferenceFilesystem } from '../dereference';
|
import { dereferenceFilesystem } from '../dereference';
|
||||||
import type { OpenAPIModel, OpenAPIModelsData } from '../types';
|
import type { OpenAPISchema, OpenAPISchemasData } from '../types';
|
||||||
|
|
||||||
//!!TODO: We should return only the models that are used in the block. Still a WIP awaiting future work.
|
//!!TODO: We should return only the schemas that are used in the block. Still a WIP awaiting future work.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve an OpenAPI models from a file and compile it to a more usable format.
|
* Resolve an OpenAPI schemas from a file and compile it to a more usable format.
|
||||||
* Models are extracted from the OpenAPI components.schemas
|
* Schemas are extracted from the OpenAPI components.schemas
|
||||||
*/
|
*/
|
||||||
export async function resolveOpenAPIModels(
|
export async function resolveOpenAPISchemas(
|
||||||
filesystem: Filesystem<OpenAPIV3xDocument>
|
filesystem: Filesystem<OpenAPIV3xDocument>
|
||||||
): Promise<OpenAPIModelsData | null> {
|
): Promise<OpenAPISchemasData | null> {
|
||||||
const schema = await dereferenceFilesystem(filesystem);
|
const schema = await dereferenceFilesystem(filesystem);
|
||||||
|
|
||||||
const models = getOpenAPIComponents(schema);
|
const schemas = getOpenAPIComponents(schema);
|
||||||
|
|
||||||
return { models };
|
return { schemas };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get OpenAPI components.schemas that are not ignored.
|
* Get OpenAPI components.schemas that are not ignored.
|
||||||
*/
|
*/
|
||||||
function getOpenAPIComponents(schema: OpenAPIV3.Document | OpenAPIV3_1.Document): OpenAPIModel[] {
|
function getOpenAPIComponents(schema: OpenAPIV3.Document | OpenAPIV3_1.Document): OpenAPISchema[] {
|
||||||
const schemas = schema.components?.schemas ?? {};
|
const schemas = schema.components?.schemas ?? {};
|
||||||
return Object.entries(schemas)
|
return Object.entries(schemas)
|
||||||
.filter(([, schema]) => !shouldIgnoreEntity(schema))
|
.filter(([, schema]) => !shouldIgnoreEntity(schema))
|
||||||
@@ -56,12 +56,12 @@ export interface OpenAPIOperationData extends OpenAPICustomSpecProperties {
|
|||||||
securities: [string, OpenAPIV3.SecuritySchemeObject][];
|
securities: [string, OpenAPIV3.SecuritySchemeObject][];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type OpenAPIModel = {
|
export type OpenAPISchema = {
|
||||||
name: string;
|
name: string;
|
||||||
schema: OpenAPIV3.SchemaObject;
|
schema: OpenAPIV3.SchemaObject;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface OpenAPIModelsData {
|
export interface OpenAPISchemasData {
|
||||||
/** Components schemas to be used for models */
|
/** Components schemas to be used for schemas */
|
||||||
models: OpenAPIModel[];
|
schemas: OpenAPISchema[];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,12 +51,12 @@ export function extractDescriptions(object: AnyObject) {
|
|||||||
/**
|
/**
|
||||||
* Resolve the first example from an object.
|
* Resolve the first example from an object.
|
||||||
*/
|
*/
|
||||||
export function resolveFirstExample(object: AnyObject) {
|
export function resolveFirstExample(object: AnyObject): string | undefined {
|
||||||
if ('examples' in object && typeof object.examples === 'object' && object.examples) {
|
if ('examples' in object && typeof object.examples === 'object' && object.examples) {
|
||||||
const keys = Object.keys(object.examples);
|
const keys = Object.keys(object.examples);
|
||||||
const firstKey = keys[0];
|
const firstKey = keys[0];
|
||||||
if (firstKey && object.examples[firstKey]) {
|
if (firstKey && object.examples[firstKey]) {
|
||||||
return object.examples[firstKey];
|
return formatExample(object.examples[firstKey]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+10
-3
@@ -1,7 +1,15 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://turbo.build/schema.json",
|
"$schema": "https://turbo.build/schema.json",
|
||||||
"ui": "stream",
|
"ui": "stream",
|
||||||
"globalEnv": ["NODE_ENV", "CI", "ARGOS_*", "GITHUB_*", "GITBOOK_*", "SENTRY_*"],
|
"globalEnv": [
|
||||||
|
"NODE_ENV",
|
||||||
|
"CI",
|
||||||
|
"ARGOS_*",
|
||||||
|
"GITHUB_*",
|
||||||
|
"GITBOOK_*",
|
||||||
|
"SENTRY_*",
|
||||||
|
"NEXT_SERVER_ACTIONS_ENCRYPTION_KEY"
|
||||||
|
],
|
||||||
"tasks": {
|
"tasks": {
|
||||||
// Prepare the package for all other tasks
|
// Prepare the package for all other tasks
|
||||||
"generate": {
|
"generate": {
|
||||||
@@ -25,8 +33,7 @@
|
|||||||
},
|
},
|
||||||
// Build the package for Cloudflare Pages
|
// Build the package for Cloudflare Pages
|
||||||
"build:cloudflare": {
|
"build:cloudflare": {
|
||||||
"dependsOn": ["^build", "generate"],
|
"dependsOn": ["^build", "generate"]
|
||||||
"env": ["NEXT_SERVER_ACTIONS_ENCRYPTION_KEY"]
|
|
||||||
},
|
},
|
||||||
// Check the package for type errors
|
// Check the package for type errors
|
||||||
"typecheck": {
|
"typecheck": {
|
||||||
|
|||||||
Reference in New Issue
Block a user