Skip to content

Commit 7334dff

Browse files
hobbescodescoopbri
andauthored
AuthZ for Payment Tiers (#43)
* build(deps): add polar sdk dependency * feature(plugins): add subscription tier to graphql context * refactor(plugins): adjust organization and project RBAC plugins * build(deps): update dependencies * refactor(schema): add tier to user table, remove polar dependency * build(deps): remove ts-pattern * fix: remove unused env variables and exports * chore: add TODOs regarding ownership transfers * refactor(plugins): update members RBAC plugin * refactor(plugins): update members RBAC plugin to disallow adding additional owners * chore: fix typo * refactor(polar): move endpoints to API * chore: format * chore: format * chore: prep merge * refactor: add tags file, remove tier from insert and update mutations * chore: prep merge * chore: update generated artifacts * chore: remove TODO in user RBAC plugin * docs(env): add template comments * docs: add README * docs: add license * chore(plugins): remove TODO in member rbac plugin * refactor(server): add checks to ensure webhook events are scoped to Backfeed products --------- Co-authored-by: Brian Cooper <[email protected]>
1 parent bd74803 commit 7334dff

20 files changed

+18105
-22091
lines changed

.env.development

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
# TODO change once base path changes (https://linear.app/omnidev/issue/OMNI-254/move-apiauth-paths-to-base-path-or-subpath-eg-auth)
22
AUTH_BASE_URL="https://localhost:8000/api/auth"
3+
4+
CHECKOUT_SUCCESS_URL="https://localhost:3000/confirmation"

.env.local.template

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/backfeed?schema=public"
22

3+
# payment processing
4+
# NB: for local development, make sure this token is generated for the Polar sandbox environment (https://docs.polar.sh/integrate/sandbox) in the Polar dashboard. If `NODE_ENV` is `development`, the sandbox will be used, otherwise Polar production will be used
5+
POLAR_ACCESS_TOKEN=""
6+
# a webhook secret can be generated at https://sandbox.polar.sh/dashboard/$ORGANIZATION_NAME/settings/webhooks
7+
POLAR_WEBHOOK_SECRET=""
8+
39
# skip auth check on API (set to SKIP_AUTH="true" to enable skip)
410
SKIP_AUTH=""

.env.production

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
# TODO change once base path changes (https://linear.app/omnidev/issue/OMNI-254/move-apiauth-paths-to-base-path-or-subpath-eg-auth)
22
AUTH_BASE_URL="https://identity.omni.dev/api/auth"
3+
4+
CHECKOUT_SUCCESS_URL="https://backfeed.omni.dev/confirmation"

LICENSE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) Omni LLC
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Backfeed API
2+
3+
Backfeed is an open-source feedback reporting platform.
4+
5+
## Local Development
6+
7+
First, create a Postgres database called `backfeed`. Then, `cp .env.local.template .env.local` and fill in the values.
8+
9+
### Building and Running (Native)
10+
11+
Install dependencies:
12+
13+
```sh
14+
bun install
15+
```
16+
17+
Run database migrations:
18+
19+
```sh
20+
bun db:migrate
21+
```
22+
23+
Run the dev server:
24+
25+
```sh
26+
bun run dev
27+
```
28+
29+
### Webhooks (Payments)
30+
31+
Our Backfeed payment processor, [Polar](https://polar.sh), issues webhooks. Webhooks are used in this project for realtime updates. Webhooks can be managed at https://sandbox.polar.sh/dashboard/$ORGANIZATION_NAME/settings/webhooks.
32+
33+
## License
34+
35+
The code in this repository is licensed under MIT, &copy; Omni LLC. See [LICENSE.md](LICENSE.md) for more information.

bun.lock

Lines changed: 121 additions & 178 deletions
Large diffs are not rendered by default.

graphile.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { PgSimplifyInflectionPreset } from "@graphile/simplify-inflection";
33
import { PostGraphileConnectionFilterPreset } from "postgraphile-plugin-connection-filter";
44
import { makePgService } from "postgraphile/adaptors/pg";
55
import { PostGraphileAmberPreset } from "postgraphile/presets/amber";
6+
import { TagsFilePlugin } from "postgraphile/utils";
67

78
import { DATABASE_URL, isProdEnv } from "./src/lib/config/env.config";
89
import {
@@ -33,6 +34,9 @@ const preset: GraphileConfig.Preset = {
3334
pgForbidSetofFunctionsToReturnNull: false,
3435
jsonScalarAsString: false,
3536
defaultBehavior: "-type:node -interface:node",
37+
// See https://github.com/graphile-contrib/postgraphile-plugin-connection-filter?tab=readme-ov-file#handling-null-and-empty-objects
38+
connectionFilterAllowNullInput: true,
39+
connectionFilterAllowEmptyObjectInput: true,
3640
},
3741
disablePlugins: ["PgIndexBehaviorsPlugin"],
3842
plugins: [
@@ -46,6 +50,7 @@ const preset: GraphileConfig.Preset = {
4650
DownvoteRBACPlugin,
4751
UpvoteRBACPlugin,
4852
CommentRBACPlugin,
53+
TagsFilePlugin,
4954
],
5055
grafserv: {
5156
graphiql: false,

package.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"@types/bun": "^1.2.8",
2727
"@types/node": "^22.13.14",
2828
"@types/pg": "^8.11.11",
29-
"drizzle-kit": "^0.30.6",
29+
"drizzle-kit": "^0.31.0",
3030
"husky": "^9.1.7",
3131
"replace-in-file": "^8.3.0",
3232
"typescript": "^5.8.2"
@@ -36,19 +36,21 @@
3636
"@envelop/parser-cache": "^8.1.3",
3737
"@envelop/validation-cache": "^8.1.3",
3838
"@escape.tech/graphql-armor": "^3.1.2",
39-
"@graphile/pg-aggregates": "0.2.0-beta.7",
40-
"@graphile/simplify-inflection": "8.0.0-beta.5",
39+
"@graphile/pg-aggregates": "0.2.0-beta.8",
40+
"@graphile/simplify-inflection": "8.0.0-beta.6",
41+
"@polar-sh/hono": "^0.3.0",
4142
"dayjs": "^1.11.13",
42-
"drizzle-orm": "^0.41.0",
43+
"drizzle-orm": "^0.42.0",
4344
"drizzle-seed": "^0.3.1",
44-
"graphile-export": "0.0.2-beta.24",
45+
"graphile-export": "0.0.2-beta.26",
4546
"graphql": "^16.10.0",
4647
"graphql-yoga": "^5.13.2",
47-
"hono": "^4.7.5",
48+
"hono": "^4.7.7",
4849
"jose": "^6.0.10",
4950
"pg": "^8.14.1",
50-
"postgraphile": "5.0.0-beta.37",
51-
"postgraphile-plugin-connection-filter": "3.0.0-beta.7"
51+
"postgraphile": "5.0.0-beta.40",
52+
"postgraphile-plugin-connection-filter": "3.0.0-beta.8",
53+
"zod": "^3.24.3"
5254
},
5355
"trustedDependencies": ["@biomejs/biome", "esbuild"]
5456
}

postgraphile.tags.json5

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
version: 1,
3+
config: {
4+
class: {
5+
user: {
6+
attribute: {
7+
tier: {
8+
tags: {
9+
behavior: "-insert -update",
10+
},
11+
},
12+
},
13+
},
14+
},
15+
},
16+
}

0 commit comments

Comments
 (0)