mirror of https://github.com/TZGyn/shortener
Compare commits
No commits in common. '5400c123bd78097024449b55d381d8364dd42eba' and '186a06b3a928205f40aac4dee40cc510cfbf2d64' have entirely different histories.
5400c123bd
...
186a06b3a9
@ -1,20 +0,0 @@
|
|||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
name: migrate-db
|
|
||||||
jobs:
|
|
||||||
migrate-db:
|
|
||||||
name: migrate-db
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: oven-sh/setup-bun@v2
|
|
||||||
- name: bun install
|
|
||||||
working-directory: ./frontend
|
|
||||||
run: bun install
|
|
||||||
- name: migrate-db
|
|
||||||
working-directory: ./frontend
|
|
||||||
env: # Or as an environment variable
|
|
||||||
DATABASE_URL: ${{ secrets.DATABASE_URL }}
|
|
||||||
run: bun run db:migrate
|
|
||||||
@ -1,17 +1,24 @@
|
|||||||
FROM oven/bun
|
FROM node:22
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
RUN npm install -g bun
|
||||||
|
|
||||||
COPY ./package.json ./
|
COPY ./package.json ./
|
||||||
COPY ./bun.lock ./
|
COPY ./bun.lockb ./
|
||||||
|
|
||||||
RUN bun install
|
RUN bun install
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
# COPY ./.env.example ./.env
|
# COPY ./.env.example ./.env
|
||||||
|
|
||||||
RUN bun run build
|
ARG DATABASE_URL
|
||||||
|
|
||||||
|
RUN DATABASE_URL=$DATABASE_URL npm run db:migrate
|
||||||
|
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
ENTRYPOINT ["bun", "build/index.js"]
|
ENTRYPOINT ["node", "build"]
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@ -1 +0,0 @@
|
|||||||
ALTER TABLE "user" ADD COLUMN "polar_customer_id" varchar(255);
|
|
||||||
@ -1,548 +0,0 @@
|
|||||||
{
|
|
||||||
"id": "f7c94100-ab5e-40a0-82b6-b4f93b459a6c",
|
|
||||||
"prevId": "ce042384-c48f-4a7b-b067-8808e73834d6",
|
|
||||||
"version": "7",
|
|
||||||
"dialect": "postgresql",
|
|
||||||
"tables": {
|
|
||||||
"public.email_verification_token": {
|
|
||||||
"name": "email_verification_token",
|
|
||||||
"schema": "",
|
|
||||||
"columns": {
|
|
||||||
"id": {
|
|
||||||
"name": "id",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"primaryKey": true,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"user_id": {
|
|
||||||
"name": "user_id",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"email": {
|
|
||||||
"name": "email",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"expires_at": {
|
|
||||||
"name": "expires_at",
|
|
||||||
"type": "timestamp with time zone",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"indexes": {},
|
|
||||||
"foreignKeys": {},
|
|
||||||
"compositePrimaryKeys": {},
|
|
||||||
"uniqueConstraints": {}
|
|
||||||
},
|
|
||||||
"public.file": {
|
|
||||||
"name": "file",
|
|
||||||
"schema": "",
|
|
||||||
"columns": {
|
|
||||||
"id": {
|
|
||||||
"name": "id",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": true,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"user_id": {
|
|
||||||
"name": "user_id",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"project_id": {
|
|
||||||
"name": "project_id",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
"key": {
|
|
||||||
"name": "key",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"name": {
|
|
||||||
"name": "name",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"size": {
|
|
||||||
"name": "size",
|
|
||||||
"type": "bigint",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": 0
|
|
||||||
},
|
|
||||||
"etag": {
|
|
||||||
"name": "etag",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"created_at_epoch": {
|
|
||||||
"name": "created_at_epoch",
|
|
||||||
"type": "bigint",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"updated_at_epoch": {
|
|
||||||
"name": "updated_at_epoch",
|
|
||||||
"type": "bigint",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"indexes": {},
|
|
||||||
"foreignKeys": {},
|
|
||||||
"compositePrimaryKeys": {},
|
|
||||||
"uniqueConstraints": {}
|
|
||||||
},
|
|
||||||
"public.project": {
|
|
||||||
"name": "project",
|
|
||||||
"schema": "",
|
|
||||||
"columns": {
|
|
||||||
"id": {
|
|
||||||
"name": "id",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": true,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"uuid": {
|
|
||||||
"name": "uuid",
|
|
||||||
"type": "uuid",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": false,
|
|
||||||
"default": "gen_random_uuid()"
|
|
||||||
},
|
|
||||||
"name": {
|
|
||||||
"name": "name",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"user_id": {
|
|
||||||
"name": "user_id",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"qr_background": {
|
|
||||||
"name": "qr_background",
|
|
||||||
"type": "varchar(7)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": "'#ffffff'"
|
|
||||||
},
|
|
||||||
"qr_foreground": {
|
|
||||||
"name": "qr_foreground",
|
|
||||||
"type": "varchar(7)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": "'#000000'"
|
|
||||||
},
|
|
||||||
"domain_status": {
|
|
||||||
"name": "domain_status",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": "'verified'"
|
|
||||||
},
|
|
||||||
"enable_custom_domain": {
|
|
||||||
"name": "enable_custom_domain",
|
|
||||||
"type": "boolean",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": false
|
|
||||||
},
|
|
||||||
"custom_ip": {
|
|
||||||
"name": "custom_ip",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
"custom_domain_id": {
|
|
||||||
"name": "custom_domain_id",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
"custom_domain": {
|
|
||||||
"name": "custom_domain",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
"qr_corner_square_style": {
|
|
||||||
"name": "qr_corner_square_style",
|
|
||||||
"type": "varchar",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": "'square'"
|
|
||||||
},
|
|
||||||
"qr_dot_style": {
|
|
||||||
"name": "qr_dot_style",
|
|
||||||
"type": "varchar",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": "'square'"
|
|
||||||
},
|
|
||||||
"qr_image_base64": {
|
|
||||||
"name": "qr_image_base64",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"indexes": {},
|
|
||||||
"foreignKeys": {},
|
|
||||||
"compositePrimaryKeys": {},
|
|
||||||
"uniqueConstraints": {}
|
|
||||||
},
|
|
||||||
"public.session": {
|
|
||||||
"name": "session",
|
|
||||||
"schema": "",
|
|
||||||
"columns": {
|
|
||||||
"id": {
|
|
||||||
"name": "id",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"primaryKey": true,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"user_id": {
|
|
||||||
"name": "user_id",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"expires_at": {
|
|
||||||
"name": "expires_at",
|
|
||||||
"type": "timestamp with time zone",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"indexes": {},
|
|
||||||
"foreignKeys": {},
|
|
||||||
"compositePrimaryKeys": {},
|
|
||||||
"uniqueConstraints": {}
|
|
||||||
},
|
|
||||||
"public.shortener": {
|
|
||||||
"name": "shortener",
|
|
||||||
"schema": "",
|
|
||||||
"columns": {
|
|
||||||
"id": {
|
|
||||||
"name": "id",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": true,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"link": {
|
|
||||||
"name": "link",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"ios": {
|
|
||||||
"name": "ios",
|
|
||||||
"type": "boolean",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": false
|
|
||||||
},
|
|
||||||
"ios_link": {
|
|
||||||
"name": "ios_link",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
"android": {
|
|
||||||
"name": "android",
|
|
||||||
"type": "boolean",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": false
|
|
||||||
},
|
|
||||||
"android_link": {
|
|
||||||
"name": "android_link",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
"code": {
|
|
||||||
"name": "code",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"created_at": {
|
|
||||||
"name": "created_at",
|
|
||||||
"type": "timestamp",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": "now()"
|
|
||||||
},
|
|
||||||
"user_id": {
|
|
||||||
"name": "user_id",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"active": {
|
|
||||||
"name": "active",
|
|
||||||
"type": "boolean",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": true
|
|
||||||
},
|
|
||||||
"project_id": {
|
|
||||||
"name": "project_id",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
"is_file_upload": {
|
|
||||||
"name": "is_file_upload",
|
|
||||||
"type": "boolean",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": false
|
|
||||||
},
|
|
||||||
"file_path": {
|
|
||||||
"name": "file_path",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"indexes": {},
|
|
||||||
"foreignKeys": {},
|
|
||||||
"compositePrimaryKeys": {},
|
|
||||||
"uniqueConstraints": {}
|
|
||||||
},
|
|
||||||
"public.user": {
|
|
||||||
"name": "user",
|
|
||||||
"schema": "",
|
|
||||||
"columns": {
|
|
||||||
"id": {
|
|
||||||
"name": "id",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": true,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"uuid": {
|
|
||||||
"name": "uuid",
|
|
||||||
"type": "uuid",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": false,
|
|
||||||
"default": "gen_random_uuid()"
|
|
||||||
},
|
|
||||||
"email_verified": {
|
|
||||||
"name": "email_verified",
|
|
||||||
"type": "boolean",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": false
|
|
||||||
},
|
|
||||||
"email": {
|
|
||||||
"name": "email",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"google_id": {
|
|
||||||
"name": "google_id",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
"username": {
|
|
||||||
"name": "username",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
"password": {
|
|
||||||
"name": "password",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
"created_at": {
|
|
||||||
"name": "created_at",
|
|
||||||
"type": "timestamp",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": "now()"
|
|
||||||
},
|
|
||||||
"plan": {
|
|
||||||
"name": "plan",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": "'free'"
|
|
||||||
},
|
|
||||||
"stripe_customer_id": {
|
|
||||||
"name": "stripe_customer_id",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
"polar_customer_id": {
|
|
||||||
"name": "polar_customer_id",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
"qr_background": {
|
|
||||||
"name": "qr_background",
|
|
||||||
"type": "varchar(7)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": "'#fff'"
|
|
||||||
},
|
|
||||||
"qr_foreground": {
|
|
||||||
"name": "qr_foreground",
|
|
||||||
"type": "varchar(7)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": "'#000'"
|
|
||||||
},
|
|
||||||
"qr_corner_square_style": {
|
|
||||||
"name": "qr_corner_square_style",
|
|
||||||
"type": "varchar",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": "'square'"
|
|
||||||
},
|
|
||||||
"qr_dot_style": {
|
|
||||||
"name": "qr_dot_style",
|
|
||||||
"type": "varchar",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": "'square'"
|
|
||||||
},
|
|
||||||
"qr_image_base64": {
|
|
||||||
"name": "qr_image_base64",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
"file_storage_usage_in_byte": {
|
|
||||||
"name": "file_storage_usage_in_byte",
|
|
||||||
"type": "bigint",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"indexes": {},
|
|
||||||
"foreignKeys": {},
|
|
||||||
"compositePrimaryKeys": {},
|
|
||||||
"uniqueConstraints": {
|
|
||||||
"user_email_unique": {
|
|
||||||
"name": "user_email_unique",
|
|
||||||
"nullsNotDistinct": false,
|
|
||||||
"columns": [
|
|
||||||
"email"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"public.visitor": {
|
|
||||||
"name": "visitor",
|
|
||||||
"schema": "",
|
|
||||||
"columns": {
|
|
||||||
"id": {
|
|
||||||
"name": "id",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": true,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"shortener_id": {
|
|
||||||
"name": "shortener_id",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"created_at": {
|
|
||||||
"name": "created_at",
|
|
||||||
"type": "timestamp",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": "now()"
|
|
||||||
},
|
|
||||||
"country_code": {
|
|
||||||
"name": "country_code",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"country": {
|
|
||||||
"name": "country",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"city": {
|
|
||||||
"name": "city",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"device_type": {
|
|
||||||
"name": "device_type",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": "''"
|
|
||||||
},
|
|
||||||
"device_vendor": {
|
|
||||||
"name": "device_vendor",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": "''"
|
|
||||||
},
|
|
||||||
"os": {
|
|
||||||
"name": "os",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": "''"
|
|
||||||
},
|
|
||||||
"browser": {
|
|
||||||
"name": "browser",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": "''"
|
|
||||||
},
|
|
||||||
"referer": {
|
|
||||||
"name": "referer",
|
|
||||||
"type": "varchar(255)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": "''"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"indexes": {},
|
|
||||||
"foreignKeys": {},
|
|
||||||
"compositePrimaryKeys": {},
|
|
||||||
"uniqueConstraints": {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"enums": {},
|
|
||||||
"schemas": {},
|
|
||||||
"sequences": {},
|
|
||||||
"_meta": {
|
|
||||||
"columns": {},
|
|
||||||
"schemas": {},
|
|
||||||
"tables": {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
import { env } from '$env/dynamic/private'
|
|
||||||
import { Checkout } from '@polar-sh/sveltekit'
|
|
||||||
|
|
||||||
export const GET = Checkout({
|
|
||||||
accessToken: env.PRIVATE_POLAR_ACCESS_KEY,
|
|
||||||
successUrl: env.APP_URL + '/dashboard/',
|
|
||||||
server: env.APP_ENV === 'prod' ? 'production' : 'sandbox',
|
|
||||||
})
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
import { env } from '$env/dynamic/private'
|
|
||||||
import { CustomerPortal } from '@polar-sh/sveltekit'
|
|
||||||
|
|
||||||
export const GET = CustomerPortal({
|
|
||||||
accessToken: env.PRIVATE_POLAR_ACCESS_KEY,
|
|
||||||
getCustomerId: async (event) =>
|
|
||||||
event.locals.user.polarCustomerId || '', // Fuction to resolve a Polar Customer ID
|
|
||||||
server: env.APP_ENV === 'prod' ? 'production' : 'sandbox',
|
|
||||||
})
|
|
||||||
@ -1,45 +0,0 @@
|
|||||||
import { env } from '$env/dynamic/private'
|
|
||||||
import { db } from '$lib/db'
|
|
||||||
import { user } from '$lib/db/schema'
|
|
||||||
import { Webhooks } from '@polar-sh/sveltekit'
|
|
||||||
import { eq } from 'drizzle-orm'
|
|
||||||
|
|
||||||
export const POST = Webhooks({
|
|
||||||
webhookSecret: env.PRIVATE_POLAR_WEBHOOK_SECRET,
|
|
||||||
onSubscriptionRevoked: async (payload) => {
|
|
||||||
if (
|
|
||||||
payload.data.priceId === env.PRIVATE_POLAR_PRO_PLAN_PRICE_ID
|
|
||||||
) {
|
|
||||||
const customerId = payload.data.customerId
|
|
||||||
|
|
||||||
if (!customerId) return
|
|
||||||
|
|
||||||
await db
|
|
||||||
.update(user)
|
|
||||||
.set({
|
|
||||||
plan: 'free',
|
|
||||||
})
|
|
||||||
.where(eq(user.polarCustomerId, customerId))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onOrderCreated: async (payload) => {
|
|
||||||
if (
|
|
||||||
payload.data.billingReason === 'subscription_cycle' ||
|
|
||||||
payload.data.billingReason === 'subscription_create'
|
|
||||||
) {
|
|
||||||
const priceId = payload.data.productPriceId
|
|
||||||
if (priceId === env.PRIVATE_POLAR_PRO_PLAN_PRICE_ID) {
|
|
||||||
const customerId = payload.data.customerId
|
|
||||||
|
|
||||||
if (!customerId) return
|
|
||||||
|
|
||||||
await db
|
|
||||||
.update(user)
|
|
||||||
.set({
|
|
||||||
plan: 'pro',
|
|
||||||
})
|
|
||||||
.where(eq(user.polarCustomerId, customerId))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
})
|
|
||||||
Loading…
Reference in New Issue