G1 TypeScript Common Packages
This monorepo contains common TypeScript packages used across Generation One projects. The repository is public, making it easier to share and collaborate on common utilities.
Repository Structure
g1-ts-common-packages/
├── packages/ # All packages are stored here
│ ├── sse-client/ # Server-Sent Events client package
│ └── [future-packages]/ # Additional packages will be added here
├── scripts/ # Utility scripts for the repository
├── docs/ # Documentation
└── .github/workflows/ # CI/CD workflows
Available Packages
SSE Client (@g1/sse-client
)
A custom Server-Sent Events (SSE) client that supports headers and bypasses certificate issues.
- Supports custom headers for SSE connections
- Handles reconnection with exponential backoff
- Works in both browser and Node.js environments
- Provides connection management utilities
Getting Started
Prerequisites
- Node.js 16+
- pnpm (recommended) or npm
Installation
Clone the repository:
# No authentication required for cloning the public repository
git clone https://git.generation.one/GenerationOne/g1-ts-common-packages.git
cd g1-ts-common-packages
Install dependencies:
pnpm install
Build all packages:
pnpm build
Using the Packages
In Another Project
Add the package to your project:
# If you're a Generation One team member using the private Gitea registry:
# Configure the Gitea registry
echo "@g1:registry=https://git.generation.one/api/packages/GenerationOne/npm/" > .npmrc
echo "//git.generation.one/api/packages/GenerationOne/npm/:_authToken=${GITEA_TOKEN}" >> .npmrc
# Install the package
pnpm add @g1/sse-client
# Alternatively, you can install directly from the public GitHub repository:
pnpm add git+https://git.generation.one/GenerationOne/g1-ts-common-packages.git#packages/sse-client
Example Usage
import { SSEClient } from '@g1/sse-client';
// Create a new SSE client
const client = new SSEClient('https://api.example.com/events', {
headers: {
'Authorization': 'Bearer your-token'
}
});
// Connect to the SSE endpoint
client.connect();
// Add event listeners
client.on('message', (event) => {
console.log('Received message:', event.data);
});
// Close the connection when done
client.close();
Development
Adding a New Package
- Create a new directory in the
packages
folder - Initialize the package with
pnpm init
- Set the package name with the
@g1
scope (e.g.,@g1/your-package-name
) - Set the initial version to
0.2.0
(our standard starting version) - Add your code and build configuration
Building Packages
To build a specific package:
cd packages/package-name
pnpm build
To build all packages:
pnpm -r build
Testing Packages
To run tests for a specific package:
cd packages/package-name
pnpm test
To test all packages:
pnpm -r test
Publishing Packages
Prerequisites
- Gitea access token with
packages:write
permission - Write access to the Generation One Gitea repository
Note: While the repository is public and anyone can clone it, publishing packages to the Gitea registry requires proper authentication and authorization.
Publishing a Package
Use the provided script:
# Set your Gitea token
export GITEA_TOKEN="your-token-here"
# Or create a .gitea-token file in the root directory
# Publish with a patch version bump
./scripts/publish-package.sh packages/sse-client patch
# Publish with a specific version
./scripts/publish-package.sh packages/sse-client version:0.3.0
# Publish without changing the version
./scripts/publish-package.sh packages/sse-client none
For more detailed publishing instructions, see docs/DEPLOY_KEYS.md.
CI/CD
This repository includes GitHub Actions workflows for automated testing and publishing:
- Publish Package: Publishes a package to the Gitea registry
To use the workflows, you need to set up the following secrets in your GitHub repository:
GITEA_TOKEN
: Your Gitea access tokenGITEA_DEPLOY_KEY
: SSH deploy key for the repository
Contributing
Since this repository is public, contributions are welcome! Here's how you can contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Please make sure your code follows the existing style and includes appropriate tests.
License
MIT