-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from storacha/feat/prototype
feat: initial spike on referrals service
- Loading branch information
Showing
15 changed files
with
2,573 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: Test | ||
description: 'Setup and test' | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Install pnpm | ||
uses: pnpm/action-setup@v4 | ||
with: | ||
version: 9 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
registry-url: 'https://registry.npmjs.org' | ||
node-version: 20 | ||
cache: 'pnpm' | ||
- run: pnpm install | ||
shell: bash | ||
- run: pnpm test | ||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
on: | ||
push: | ||
branches: | ||
- main | ||
name: Release | ||
jobs: | ||
release-staging: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
pull-requests: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: ./.github/actions/test | ||
- name: Deploy to Staging | ||
uses: cloudflare/wrangler-action@2.0.0 | ||
with: | ||
apiToken: ${{secrets.CF_TOKEN }} | ||
environment: 'staging' | ||
release-production: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
pull-requests: write | ||
steps: | ||
- uses: google-github-actions/release-please-action@v3 | ||
id: release | ||
with: | ||
release-type: node | ||
package-name: referrals-service | ||
- uses: actions/checkout@v4 | ||
- uses: ./.github/actions/test | ||
- name: Deploy to Production | ||
uses: cloudflare/wrangler-action@2.0.0 | ||
with: | ||
apiToken: ${{ secrets.CF_TOKEN }} | ||
environment: 'production' | ||
if: ${{ steps.release.outputs.release_created }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: Test | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: ./.github/actions/test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Storacha Referrals Service | ||
|
||
Simple RESTful service for tracking Storacha referrals. | ||
|
||
## Run | ||
|
||
To get started, clone this repo and run: | ||
|
||
``` | ||
pnpm install | ||
pnpm dev | ||
``` | ||
|
||
## Domain Model | ||
|
||
A `refcode` is a 16 character string drawn from | ||
the [`nolookalikesSafe` nanoid dictionary](https://github.com/CyberAP/nanoid-dictionary). | ||
It is associated with an email address. | ||
|
||
A `referral` is a record of a different email address using a refcode to sign up. It | ||
records an email, a refcode and referral time. | ||
|
||
## API | ||
|
||
The API does not use any sort of authorization at the moment as it needs to be usable by | ||
users who have not yet established an identity relationship with us. As a result it's important | ||
that it not return sensitive information like email addresses in any responses. | ||
|
||
### `POST /refcode/create'` | ||
|
||
Create a refcode by posting form data with `email` set to the email the refcode will | ||
be attached to. | ||
|
||
### `GET /refcode/:email'` | ||
|
||
Get the refcode associated with an email. Returns a JSON object like: | ||
|
||
``` | ||
{ | ||
refcode: 'abc123' | ||
} | ||
``` | ||
|
||
### `POST /referrals/create'` | ||
|
||
Create a referral by posting form data with `email` set to the email of the referred | ||
user and `refcode` set to the refcode they used to sign up. | ||
|
||
### `GET /referredby/:email'` | ||
|
||
Get the refcode used when an email address signed up. Returns a JSON object like: | ||
|
||
``` | ||
{ | ||
refcode: 'abc123' | ||
} | ||
``` | ||
|
||
### `GET /referrals/:refcode'` | ||
|
||
Get the referrals associated with a refcode. Returns a list of JSON objects like: | ||
|
||
|
||
``` | ||
[ | ||
{ referredAt: '2024-11-21 00:45:12', rewarded: false } | ||
] | ||
``` | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
-- Migration number: 0001 2024-10-21T15:14:46.268Z | ||
|
||
-- users identified by email. each user has a refcode they can use to invite other users | ||
CREATE TABLE IF NOT EXISTS users ( | ||
email TEXT PRIMARY KEY, | ||
refcode TEXT UNIQUE | ||
); | ||
|
||
-- referrals identified by email. each referral tracks the refcode it was referred by. | ||
-- "reward" tracks whether the referee has paid long enough for the referrer to be rewarded | ||
CREATE TABLE IF NOT EXISTS referrals ( | ||
email TEXT PRIMARY KEY, | ||
refcode TEXT UNIQUE, | ||
referred_at DATETIME DEFAULT CURRENT_TIMESTAMP, | ||
selected_plan TEXT, | ||
rewarded BOOLEAN DEFAULT false, | ||
FOREIGN KEY(refcode) REFERENCES users(refcode) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.