Skip to content
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

DEV2-5322 initial release #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module.exports = {
env: {
es2021: true,
node: true
},
extends: [
'airbnb-typescript/base',
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:import/errors',
'plugin:import/typescript',
'prettier'
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname
},
plugins: ['@typescript-eslint', 'import'],
ignorePatterns: ['**/*.raw.js'],
rules: {
'no-void': 'off',
'no-console': 'off',
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/camelcase': 'off',
'class-methods-use-this': 'off',
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: [
'**/*.test.[t|j]s',
'**/*.spec.[t|j]s',
'./src/app/tests/**/*.[t|j]s'
]
}
]
}
};
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# The following github team will be considered code-owners for all account repositories
# code-owners will be later applied as merge approvers for all pull requests in order to comply with our SOC2 Policy.
* @codota/merge-approvers
39 changes: 39 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: 'CI'

on:
push:
branches: ['main']
pull_request:

jobs:
build:
name: 'Build'
runs-on: ubuntu-latest
steps:
- name: Checkout project
uses: actions/checkout@v2

- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: '18.16'

- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: .yarn/cache
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

- name: Install
run: yarn --immutable

- name: Prettier
run: yarn prettier:check

- name: Lint
run: yarn lint

- name: Test
run: yarn test
21 changes: 21 additions & 0 deletions .github/workflows/enforce-pr-jira-association.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Enforce PR-Jira association

on:
pull_request:
types:
- opened
- reopened
- edited
- synchronize

jobs:
enforce-issue:
runs-on: ubuntu-latest
name: JIRA Association
steps:
- name: Check for JIRA ISSUE
id: check
uses: usehaystack/jira-pr-link-action@v4
with:
ignore-author: dependabot[bot]
project: 'DEV2'
18 changes: 18 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Release

on: workflow_dispatch

jobs:
publish:
name: Publish to GitBook
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18.x
- run: npm ci
- run: npm install -g @gitbook/cli
- run: gitbook publish .
env:
GITBOOK_TOKEN: ${{ secrets.GITBOOK_TOKEN }}
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn prettier
yarn lint:fix
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.16.0
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# @gitbook/integration-segment

## 1.0.0

### Major Changes

### Minor Changes

### Patch Changes
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# gitbook-integration-rudderstack

A Gitbook plugin for sending events to RudderStack
Binary file added assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = { presets: ['@babel/preset-env'] };
33 changes: 33 additions & 0 deletions gitbook-manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: hubspot
title: HubSpot
icon: ./assets/icon.png
organization: tabnine
description: Plug your GitBook site to your Google Tag Manager installation.
visibility: private
script: ./src/index.ts
scopes:
- space:script:inject
contentSecurityPolicy:
script-src: hsadspixel.net hs-banner.com hs-analytics.net hs-scripts.com;
summary: |
# Overview
This integration allows to add the Hotjar tracker on your published GitBook site.

# How it works
The integration injects the Hotjar Analytics script on your page, using the configured environment ID,
so that you can get analytics information from your GitBook site directly inside of Heap.

# Configure
Install the integration on the GitBook space of your choice.
Locate the Hotjar site ID you want to use, which is available in Hotjar's Organization & sites section
categories:
- analytics
configurations:
space:
properties:
tracking_id:
type: string
title: Hotjar Site ID
description: Available in Hotjar's Organization & sites section
required:
- tracking_id
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
preset: 'ts-jest',
transform: {
'^.+\\.(ts|tsx)?$': 'ts-jest',
'^.+\\.(js|jsx)$': 'babel-jest'
}
};
52 changes: 52 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "integration-rudderstack",
"version": "1.0.2",
"private": true,
"dependencies": {
"@gitbook/api": "*",
"@gitbook/runtime": "*"
},
"devDependencies": {
"@babel/preset-env": "^7.23.9",
"@gitbook/cli": "*",
"@gitbook/eslint-config": "*",
"@gitbook/tsconfig": "*",
"@types/crypto-js": "^4.2.2",
"@types/jest": "^29.5.12",
"@types/node": "^18.16.0",
"assert": "^2.0.0",
"babel-jest": "^29.7.0",
"esbuild-register": "^3.5.0",
"eslint": "^8.57.0",
"eslint-config-airbnb-typescript": "7",
"eslint-config-standard-with-typescript": "^43.0.1",
"eslint-plugin-import": "2",
"eslint-plugin-json": "^3.1.0",
"husky": "^9.0.11",
"jest": "^29.7.0",
"test": "^3.2.1",
"ts-jest": "^29.1.2",
"typescript": "^5.3.3"
},
"scripts": {
"typecheck": "tsc --noEmit",
"publish-integration": "gitbook publish .",
"test": "jest --passWithNoTests",
"lint": "eslint . --max-warnings 0",
"lint:fix": "eslint --fix .",
"prepare": "husky install",
"prettier": "prettier --write .",
"prettier:check": "prettier --check ."
},
"prettier": {
"useTabs": false,
"trailingComma": "none",
"singleQuote": true,
"jsxBracketSameLine": false,
"arrowParens": "avoid"
},
"eslintIgnore": [
"*.test.ts",
".eslintrc.js"
]
}
47 changes: 47 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {
createIntegration,
FetchPublishScriptEventCallback,
RuntimeContext,
RuntimeEnvironment
} from '@gitbook/runtime';

// eslint-disable-next-line import/extensions
import script from './script.raw.js';

type HubSpotRuntimeContext = RuntimeContext<
RuntimeEnvironment<
// eslint-disable-next-line @typescript-eslint/ban-types
{},
{
script_loader_url?: string;
}
>
>;

export const handleFetchEvent: FetchPublishScriptEventCallback = (
event,
{ environment }: HubSpotRuntimeContext
) => {
const scriptLoaderURL =
environment.spaceInstallation.configuration.script_loader_url;
if (!scriptLoaderURL) {
throw new Error(
`The HubSpot Script Loader URL is missing from the configuration (ID: ${event.spaceId}).`
);
}

return new Response(
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument
script.replace('<TO_REPLACE_SCRIPT_LOADER_URL>', scriptLoaderURL),
{
headers: {
'Content-Type': 'application/javascript',
'Cache-Control': 'max-age=604800'
}
}
);
};

export default createIntegration<HubSpotRuntimeContext>({
fetch_published_script: handleFetchEvent
});
15 changes: 15 additions & 0 deletions src/script.raw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(function (h, u, b, s, p, o, t) {
if (!u.getElementById(b)) {
const scriptLoaderURL = '<TO_REPLACE_SCRIPT_LOADER_URL>';
s = u.getElementsByTagName('head')[0];
p = u.createElement('script');
p.src = scriptLoaderURL;
p.type = 'text/javascript';
p.id = b;
p.async = 1;
p.defer = 1;
s.appendChild(p);
o = h._hsp = h._hsp || [];
o.push(['setContentType', 'knowledge-article']);
}
})(window, document, 'hs-script-loader');
5 changes: 5 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe("currently doesn't test anything as this file is highly integrated into the gitbook runtime", () => {
it("life's beauty without logical conflict", () => {
expect(true).toBeTruthy();
});
});
13 changes: 13 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Integration",
"compilerOptions": {
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"lib": ["ES2021"],
"jsx": "react-jsx",
"jsxImportSource": "@gitbook/runtime"
},
"exclude": ["node_modules", ".eslintrc.js"]
}
Loading
Loading