-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: initial spike on referrals service #1
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4231a44
feat: initial spike on referrals service
travis 79e1f2e
fix: add tests
travis ce1f446
feat: initial pass at credits and conversions script
travis 959fce7
fix: convert tabs to spaces
travis c1bf2e2
chore: add TODO
travis d4905cb
feat: add error handling and add docs
travis 1da3e82
feat: add deployment and CI
travis 103291c
fix: fix run command
travis d87dfad
fix: keep trying to fix CI
travis 0ce1729
fix: add missing dependency
travis 0ebe45a
fix: skip c&c test for now
travis c3538d2
feat: configure databases in staging and prod
travis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this work - is there some external process that's updating it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep exactly - I have the beginnings of a cronjob in this PR that will go look at Stripe and update these referrals after we've granted the referrer credits.