Skip to content

Commit 279f54e

Browse files
authored
docs: Improve and expand project documentation (#398)
1 parent 86336bc commit 279f54e

File tree

5 files changed

+143
-42
lines changed

5 files changed

+143
-42
lines changed

api/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Publisher Tools - API
2+
3+
This package contains the Hono-based API server that powers the Publisher Tools. It runs on Cloudflare Workers and is responsible for fetching tool configurations, handling Open Payments, and managing probabilistic revenue sharing.
4+
5+
## Endpoints
6+
7+
The API exposes endpoints related to the following functionalities:
8+
9+
- **Tool Configuration:** Handles fetching the configuration for the monetization tools (see `src/routes/get-config.ts`).
10+
- **Payments:** Manages the Open Payments flow (see `src/routes/payment.ts`).
11+
- **Probabilistic Revshare:** Handles logic related to probabilistic revenue sharing (see `src/routes/probabilistic-revshare.ts`).
12+
13+
## Development
14+
15+
To run the API server for local development, you can use the `dev` script from the project root:
16+
17+
```sh
18+
pnpm -C api dev
19+
```
20+
21+
This will start the Cloudflare Wrangler development server, which automatically reloads on file changes.

cdn/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Publisher Tools - CDN
2+
3+
This package is responsible for building and delivering the final, browser-ready JavaScript assets (the banner and widget scripts) that publishers embed on their websites.
4+
5+
It takes the raw source code from the `@tools/components` package, bundles it using `esbuild`, and prepares it for delivery via the Cloudflare CDN.
6+
7+
## Build Process
8+
9+
The core of this package is the custom build script located at `build.js`. This script uses `esbuild` to compile the TypeScript source from `src/` and the components from the `components` package into distributable files.
10+
11+
The main entry points for the build are:
12+
13+
- `src/banner.ts`
14+
- `src/widget.ts`
15+
16+
The output is placed in the `dist/` directory.
17+
18+
## Assets
19+
20+
This package also manages static assets required by the components, such as fonts. The build process ensures that these assets are correctly referenced and made available through the CDN. Fonts are located in the `src/assets/fonts` directory.
21+
22+
## Development
23+
24+
To build the assets and run a local development server that simulates the CDN, use the `dev` script from the project root. This will watch for file changes in both the `cdn` and `components` packages and automatically rebuild.
25+
26+
```sh
27+
pnpm -C cdn dev
28+
```

components/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Publisher Tools - Components
2+
3+
This package contains the core, embeddable web components for the Publisher Tools, built using the [Lit](https://lit.dev/) library. These components are intended to be placed on publishers' websites.
4+
5+
## Core Components
6+
7+
- **Banner:** A notification banner that can be displayed on a publisher's site. The source is located in `src/banner.ts`.
8+
- **Widget:** The interactive monetization widget. Its source code is in the `src/widget/` directory.
9+
10+
## Build Process
11+
12+
This package contains the raw source code for the web components but does not have its own build process.
13+
14+
The components are imported and bundled by the **`cdn`** package, which is responsible for compiling them into a browser-ready format. They are also used by the **`frontend`** package for demonstration purposes.
15+
16+
Please see the `cdn` package for more details on the build and delivery process.
17+
18+
## Development
19+
20+
The only available script is for type checking, which can be run from the project root:
21+
22+
```sh
23+
pnpm -C components typecheck
24+
```

docs/env-vars.md

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,105 @@
11
# Environment Variables Setup
22

3-
This guide provides detailed instructions for setting up your `.dev.vars` file for local development.\
4-
Follow the sections below to configure each variable.
3+
This guide provides detailed instructions for setting up your `.dev.vars` file for local development.
54

6-
## Environment Variables
5+
First, copy the sample environment file:
76

8-
### Open Payments Configuration
7+
```sh
8+
cp .env.sample .dev.vars
9+
```
10+
11+
Then, edit the `.dev.vars` file to set the required values as described below.
12+
13+
## Variables Summary
914

10-
These variables are required to enable Open Payments functionality:
15+
| Variable | Description | Example Value |
16+
| ----------------------- | ------------------------------------------------ | -------------------------------------------- |
17+
| `OP_KEY_ID` | UUID v4 identifier for your Open Payments key. | `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` |
18+
| `OP_PRIVATE_KEY` | Base64-encoded private key for signing requests. | (See conversion script below) |
19+
| `OP_WALLET_ADDRESS` | The URL of your Open Payments wallet address. | `https://ilp.interledger-test.dev/my-wallet` |
20+
| `AWS_ACCESS_KEY_ID` | AWS access key for S3. Not used in local dev. | `ABCDEFGHIJKLMN12OPQR` |
21+
| `AWS_SECRET_ACCESS_KEY` | AWS secret key for S3. Not used in local dev. | `ab1cD/2e/fGhIJ11kL13mN0pQrS45tu6V7w8X9yZ` |
22+
| `AWS_S3_ENDPOINT` | The endpoint for the S3-compatible storage. | `http://localhost:8081` |
1123

12-
The following are instructions for development setup. For production use, please follow the setup instructions provided by your chosen wallet.
24+
## Detailed Configuration
25+
26+
### Open Payments Configuration
27+
28+
These variables are required to connect to an Interledger wallet for handling payments. For development, you can use the Interledger Testnet.
1329

1430
#### `OP_KEY_ID`
1531

16-
UUID v4 identifier for your Open Payments key
32+
This is the unique identifier for your API key.
1733

18-
1. Sign up for [Interledger Testnet wallet](https://wallet.interledger-test.dev)
19-
2. Navigate to the developers/API keys section
20-
3. Generate a new key pair
21-
4. Copy the Key ID (UUID format)
34+
1. Sign up for an [Interledger Testnet wallet](https://wallet.interledger-test.dev).
35+
2. In your wallet dashboard, navigate to the **Settings** section from the side menu and access developer keys.
36+
3. Generate a new key pair.
37+
4. Copy the **Key ID** (which is in UUID format) and paste it into your `.dev.vars` file.
2238

2339
#### `OP_PRIVATE_KEY`
2440

25-
Base64-encoded private key for signing Open Payments requests
41+
This is the secret key used to sign payment requests, proving you own the wallet.
2642

27-
1. When generating your key pair in your wallet's developer section
28-
2. Download or copy the private key
29-
3. **Important**: The private key must be converted to the format expected by the tools using the script below
43+
1. When you generate a key pair, your wallet will provide a private key.
44+
2. **Important**: This key needs to be converted to a specific format. Use the script below to do this.
3045

31-
**Security Note**: Never commit this value to version control
46+
**Security Note**: Never commit this value to version control.
3247

3348
<details>
34-
<summary><b>Private Key Conversion Script</b></summary>
49+
<summary><b>Click to see Private Key Conversion Script</b></summary>
3550

3651
After copying your private key, run this script to convert it to the correct format.\
3752
Replace `currentKey` value string with your copied private key, then use the output as your `OP_PRIVATE_KEY` value:
3853

3954
```javascript
40-
// Extract base64-encoded part and decode to get DER bytes
55+
// paste your private key from the wallet here
4156
const currentKey = ''
57+
4258
const derBytes = atob(
4359
currentKey
4460
.replace('-----BEGIN PRIVATE KEY-----', '')
4561
.replace('-----END PRIVATE KEY-----', '')
4662
.replace(/\s/g, '')
4763
)
48-
49-
// Convert to Uint8Array
5064
const bytes = new Uint8Array(derBytes.length)
5165
for (let i = 0; i < derBytes.length; i++) {
5266
bytes[i] = derBytes.charCodeAt(i)
5367
}
54-
55-
// Extract just the 32-byte key
5668
const privateKey = bytes.slice(-32)
57-
58-
// Convert back to base64 for storage
5969
const keyBase64 = btoa(String.fromCharCode(...privateKey))
6070

61-
console.log('New key format for direct use:')
71+
console.log('Your new OP_PRIVATE_KEY is:')
6272
console.log(keyBase64)
6373
```
6474

6575
</details>
6676

6777
#### `OP_WALLET_ADDRESS`
6878

69-
Your wallet address URL
79+
This is the public address of your wallet where you can receive payments.
7080

71-
1. In your Interledger testnet wallet dashboard
72-
2. Find your wallet address
73-
3. Copy the payment pointer and convert it to `https://` format.
81+
1. In your Interledger wallet dashboard, find your payment pointer. It will look something like `$ilp.interledger-test.dev/my-wallet`.
82+
2. To get the wallet address, simply replace the `$` with `https://`.
7483

75-
### AWS Configuration
76-
77-
These variables configure S3 storage for configuration data:
84+
For example, if your payment pointer is `$ilp.interledger-test.dev/alice`, your `OP_WALLET_ADDRESS` would be `https://ilp.interledger-test.dev/alice`.
7885

79-
#### `AWS_ACCESS_KEY_ID`
86+
### AWS Configuration
8087

81-
AWS access key for S3 operations\
82-
**Development Note**: This key is ignored when using the local S3 simulator, so it's not required for development
88+
These variables are for connecting to an S3 bucket, which is used to store the configuration for the publisher tools. For local development, a simulated S3 service is used, so you don't need real AWS credentials.
8389

84-
#### `AWS_SECRET_ACCESS_KEY`
90+
#### `AWS_ACCESS_KEY_ID` & `AWS_SECRET_ACCESS_KEY`
8591

86-
AWS secret key corresponding to the access key ID\
87-
**Development Note**: This key is ignored when using the local S3 simulator, so it's not required for development
92+
For local development, these values are ignored by the local S3 simulator. You can leave the default values from `.env.sample` as they are.
8893

8994
#### `AWS_S3_ENDPOINT`
9095

91-
**For Development**: Use the local S3 simulator
96+
**For Development**: Use the local S3 simulator, which runs on `http://localhost:8081`. This should be the default value in your `.dev.vars`.
9297

9398
```
9499
AWS_S3_ENDPOINT="http://localhost:8081"
95100
```
96101

97-
**For Production**: Use your actual S3 bucket endpoint
102+
**For Production**: Use your actual S3 bucket endpoint, this would be the URL of your actual S3 bucket endpoint.
98103

99104
```
100105
AWS_S3_ENDPOINT="https://your-bucket-name.s3.your-region.amazonaws.com"
@@ -111,8 +116,7 @@ AWS_S3_ENDPOINT="https://your-bucket-name.s3.your-region.amazonaws.com"
111116
6. Scroll down to "Access keys" and click "Create access key"
112117
7. Choose "Application running outside AWS"
113118
8. Copy the Access key ID
114-
115-
Make sure to save both the Access Key ID and Secret Access Key when they are displayed, as AWS will not show the secret key again.
119+
Make sure to save both the Access Key ID and Secret Access Key when they are displayed, as AWS will not show the secret key again.
116120

117121
**Required Permissions**: S3 read/write access\
118122
**Security Note**: Never commit this value to version control

frontend/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Publisher Tools - Frontend
2+
3+
This package contains the Remix frontend application for the Publisher Tools, providing a user-friendly dashboard for publishers to configure and manage monetization on their websites.
4+
5+
## Core Features
6+
7+
The dashboard allows users to customize and generate code for the following tools:
8+
9+
- **Index (`/`):** The main landing page that offers an overview of the available monetization tools.
10+
- **Banner (`/banner`):** A tool to create a customizable notification banner that can be displayed on a publisher's website, often used to inform users about monetization or request consent.
11+
- **Widget (`/widget`):** A configuration page for the monetization widget, which provides users with a clear and interactive way to make payments or donations.
12+
- **Link Tag (`/link-tag`):** A simple tool for generating a monetized `<link>` tag, which can be embedded in a website to enable Web Monetization.
13+
- **Probabilistic Revshare (`/prob-revshare`):** A UI for setting up probabilistic revenue sharing, allowing publishers to distribute incoming payments among multiple recipients based on assigned weights.
14+
- **Payment Confirmation (`/payment-confirmation`):** A dedicated page to display the status of a payment to the user. Embedded tools may redirect users to this page after a payment is completed or fails.
15+
16+
The application also includes API routes (e.g., `api.config.$type.ts`) that are handled by the Remix server to manage configuration and other backend tasks.
17+
18+
## Development
19+
20+
To run the frontend application for local development, use the `dev` script from the project root:
21+
22+
```sh
23+
pnpm -C frontend dev
24+
```

0 commit comments

Comments
 (0)