NPM Installation Guide
This guide covers NPM installation for React applications. For non-React applications or simple script tag integration, see the CDN Installation Guide.Installation Methods
The Moss SDK offers two installation methods:| Method | Best For | Setup Complexity |
|---|---|---|
| CDN Installation | Non-React apps, simple integration | ⭐ Simple |
| NPM Installation (this guide) | React apps, full TypeScript support | ⭐⭐ Moderate |
Prerequisites
- A React application (v17 or higher)
- An active Node.js environment (v16 or higher recommended)
1. Authenticating to GitHub Packages
The Moss SDK is hosted as a private package on GitHub. To install it, you must first authenticate your package manager (npm, pnpm, or yarn) to the GitHub Packages registry.Creating a Personal Access Token (PAT)
- Navigate to Personal access tokens in your GitHub developer settings.
- Click Generate new token and select Generate new token (classic).
- Give your token a descriptive name (e.g.,
moss-sdk-access). - Set the Expiration for the token. For security, avoid “No expiration” in production environments.
- Under Select scopes, check the
read:packagesscope. This grants permission to download packages from the GitHub Packages registry. - Click Generate token.
- Important: Copy the generated token immediately. You will not be able to see it again.
Configuring Your Package Manager
You need to create or update a.npmrc file in the root of your project. This file tells your package manager how to handle packages from the @principles-first scope.
Create a file named .npmrc in your project’s root directory and add the following line:
.npmrc
.npmrc file to keep your token secure.
- For macOS/Linux: The file is located at
~/.npmrc. - For Windows: The file is located at
C:\Users\YOUR_USERNAME\.npmrc.
YOUR_PAT with the Personal Access Token you just created:
2. Installing the SDK
Once your environment is authenticated, you can install the Moss SDK using your preferred package manager.3. Integration
After installation, you can integrate the SDK into your application as described in the Quickstart Guide. If you encounter any issues, double-check that your Personal Access Token is not expired and has the correctread:packages scope.