A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search
feat: prep for sub tier overrides
Mohamed Bassem5e5692f76f63
diff --git a/apps/web/components/settings/AddApiKey.tsx b/apps/web/components/settings/AddApiKey.tsxindex 9bf49113..c1d11655 100644--- a/apps/web/components/settings/AddApiKey.tsx+++ b/apps/web/components/settings/AddApiKey.tsx@@ -33,6 +33,7 @@ import {import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";import { ScrollArea } from "@/components/ui/scroll-area";import { toast } from "sonner";+import { useClientConfig } from "@/lib/clientConfig";import { useTranslation } from "@/lib/i18n/client";import { zodResolver } from "@hookform/resolvers/zod";import { useMutation } from "@tanstack/react-query";@@ -191,9 +192,17 @@ function AddApiKeyForm({resolver: zodResolver(formSchema),});- const scopeOptions = isAdmin- ? [...API_KEY_SCOPE_OPTIONS, ...API_KEY_ADMIN_SCOPE_OPTIONS]- : API_KEY_SCOPE_OPTIONS;+ const clientConfig = useClientConfig();+ const scopeOptions = (+ isAdmin+ ? [...API_KEY_SCOPE_OPTIONS, ...API_KEY_ADMIN_SCOPE_OPTIONS]+ : API_KEY_SCOPE_OPTIONS+ ).map((option) =>+ // Subscription tiers can only be managed when Stripe is configured+ option.id === "admin:subscriptions" && !clientConfig.stripe.isConfigured+ ? { ...option, hidden: true }+ : option,+ );function selectedScopes(): ZApiKeyScope[] {if (useFullAccess) {diff --git a/apps/web/components/settings/SubscriptionSettings.tsx b/apps/web/components/settings/SubscriptionSettings.tsxindex fa93572a..3ab66593 100644--- a/apps/web/components/settings/SubscriptionSettings.tsx+++ b/apps/web/components/settings/SubscriptionSettings.tsx@@ -91,7 +91,7 @@ export default function SubscriptionSettings() {}).format(date);};- const getStatusBadge = (status: "free" | "paid") => {+ const getStatusBadge = (status: "free" | "custom" | "paid") => {switch (status) {case "paid":return (@@ -99,6 +99,12 @@ export default function SubscriptionSettings() {{t("settings.subscription.paid")}</Badge>);+ case "custom":+ return (+ <Badge variant="secondary">+ {subscriptionStatus?.manualTierName}+ </Badge>+ );case "free":return (<Badge variant="outline">{t("settings.subscription.free")}</Badge>diff --git a/apps/web/components/settings/apiKeyScopes.ts b/apps/web/components/settings/apiKeyScopes.tsindex 76cef8b2..8f85154a 100644--- a/apps/web/components/settings/apiKeyScopes.ts+++ b/apps/web/components/settings/apiKeyScopes.ts@@ -108,6 +108,11 @@ const ADMIN_RESOURCE_TRANSLATION_KEYS = {labelKey: "settings.api_keys.scopes.admin_resources.jobs.label",descriptionKey: "settings.api_keys.scopes.admin_resources.jobs.description",},+ subscriptions: {+ labelKey: "settings.api_keys.scopes.admin_resources.subscriptions.label",+ descriptionKey:+ "settings.api_keys.scopes.admin_resources.subscriptions.description",+ },system: {labelKey: "settings.api_keys.scopes.admin_resources.system.label",descriptionKey:diff --git a/apps/web/lib/clientConfig.tsx b/apps/web/lib/clientConfig.tsxindex 11d7248f..fb12b367 100644--- a/apps/web/lib/clientConfig.tsx+++ b/apps/web/lib/clientConfig.tsx@@ -21,6 +21,9 @@ export const ClientConfigCtx = createContext<ClientConfig>({chat: {enabled: false,},+ stripe: {+ isConfigured: false,+ },legal: {termsOfServiceUrl: undefined,privacyPolicyUrl: undefined,diff --git a/apps/web/lib/i18n/locales/en/translation.json b/apps/web/lib/i18n/locales/en/translation.jsonindex 62ff23d7..cd2518b4 100644--- a/apps/web/lib/i18n/locales/en/translation.json+++ b/apps/web/lib/i18n/locales/en/translation.json@@ -408,6 +408,10 @@"label": "Admin: jobs","description": "Access background job controls."},+ "subscriptions": {+ "label": "Admin: subscriptions",+ "description": "Manage user subscription tiers."+ },"system": {"label": "Admin: system","description": "Access system status and diagnostics."diff --git a/packages/db/drizzle/0089_add_manual_tier_name.sql b/packages/db/drizzle/0089_add_manual_tier_name.sqlnew file mode 100644index 00000000..3e023b5d--- /dev/null+++ b/packages/db/drizzle/0089_add_manual_tier_name.sql@@ -0,0 +1 @@+ALTER TABLE `user` ADD `manualTierName` text;\ No newline at end of filediff --git a/packages/db/drizzle/meta/0089_snapshot.json b/packages/db/drizzle/meta/0089_snapshot.jsonnew file mode 100644index 00000000..015c3954--- /dev/null+++ b/packages/db/drizzle/meta/0089_snapshot.json@@ -0,0 +1,3541 @@+{+ "version": "6",+ "dialect": "sqlite",+ "id": "84cfd70a-83f9-4d49-a1c0-f00bcd8141b6",+ "prevId": "306cbce1-7dfd-4199-8706-0b7f0866093f",+ "tables": {+ "account": {+ "name": "account",+ "columns": {+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "type": {+ "name": "type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "provider": {+ "name": "provider",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "providerAccountId": {+ "name": "providerAccountId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "refresh_token": {+ "name": "refresh_token",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "access_token": {+ "name": "access_token",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "expires_at": {+ "name": "expires_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "token_type": {+ "name": "token_type",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "scope": {+ "name": "scope",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "id_token": {+ "name": "id_token",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "session_state": {+ "name": "session_state",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "account_userId_user_id_fk": {+ "name": "account_userId_user_id_fk",+ "tableFrom": "account",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "account_provider_providerAccountId_pk": {+ "columns": [+ "provider",+ "providerAccountId"+ ],+ "name": "account_provider_providerAccountId_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "apiKey": {+ "name": "apiKey",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "lastUsedAt": {+ "name": "lastUsedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "keyId": {+ "name": "keyId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "keyHash": {+ "name": "keyHash",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "scopes": {+ "name": "scopes",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "apiKey_keyId_unique": {+ "name": "apiKey_keyId_unique",+ "columns": [+ "keyId"+ ],+ "isUnique": true+ },+ "apiKey_name_userId_unique": {+ "name": "apiKey_name_userId_unique",+ "columns": [+ "name",+ "userId"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "apiKey_userId_user_id_fk": {+ "name": "apiKey_userId_user_id_fk",+ "tableFrom": "apiKey",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "assets": {+ "name": "assets",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "assetType": {+ "name": "assetType",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "size": {+ "name": "size",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 0+ },+ "contentType": {+ "name": "contentType",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "fileName": {+ "name": "fileName",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "bookmarkId": {+ "name": "bookmarkId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "assets_bookmarkId_idx": {+ "name": "assets_bookmarkId_idx",+ "columns": [+ "bookmarkId"+ ],+ "isUnique": false+ },+ "assets_assetType_idx": {+ "name": "assets_assetType_idx",+ "columns": [+ "assetType"+ ],+ "isUnique": false+ },+ "assets_userId_idx": {+ "name": "assets_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "assets_bookmarkId_bookmarks_id_fk": {+ "name": "assets_bookmarkId_bookmarks_id_fk",+ "tableFrom": "assets",+ "tableTo": "bookmarks",+ "columnsFrom": [+ "bookmarkId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "assets_userId_user_id_fk": {+ "name": "assets_userId_user_id_fk",+ "tableFrom": "assets",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "backups": {+ "name": "backups",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "assetId": {+ "name": "assetId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "size": {+ "name": "size",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "bookmarkCount": {+ "name": "bookmarkCount",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'pending'"+ },+ "errorMessage": {+ "name": "errorMessage",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "backups_userId_idx": {+ "name": "backups_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ },+ "backups_createdAt_idx": {+ "name": "backups_createdAt_idx",+ "columns": [+ "createdAt"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "backups_userId_user_id_fk": {+ "name": "backups_userId_user_id_fk",+ "tableFrom": "backups",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "backups_assetId_assets_id_fk": {+ "name": "backups_assetId_assets_id_fk",+ "tableFrom": "backups",+ "tableTo": "assets",+ "columnsFrom": [+ "assetId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "bookmarkAssets": {+ "name": "bookmarkAssets",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "assetType": {+ "name": "assetType",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "assetId": {+ "name": "assetId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "content": {+ "name": "content",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "metadata": {+ "name": "metadata",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "fileName": {+ "name": "fileName",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "sourceUrl": {+ "name": "sourceUrl",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "bookmarkAssets_id_bookmarks_id_fk": {+ "name": "bookmarkAssets_id_bookmarks_id_fk",+ "tableFrom": "bookmarkAssets",+ "tableTo": "bookmarks",+ "columnsFrom": [+ "id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "bookmarkLinks": {+ "name": "bookmarkLinks",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "url": {+ "name": "url",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "author": {+ "name": "author",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "publisher": {+ "name": "publisher",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "datePublished": {+ "name": "datePublished",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "dateModified": {+ "name": "dateModified",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "imageUrl": {+ "name": "imageUrl",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "favicon": {+ "name": "favicon",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "htmlContent": {+ "name": "htmlContent",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "contentAssetId": {+ "name": "contentAssetId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "crawledAt": {+ "name": "crawledAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "crawlStatus": {+ "name": "crawlStatus",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "'pending'"+ },+ "crawlStatusCode": {+ "name": "crawlStatusCode",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": 200+ },+ "probeMetadataAt": {+ "name": "probeMetadataAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "bookmarkLinks_url_idx": {+ "name": "bookmarkLinks_url_idx",+ "columns": [+ "url"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "bookmarkLinks_id_bookmarks_id_fk": {+ "name": "bookmarkLinks_id_bookmarks_id_fk",+ "tableFrom": "bookmarkLinks",+ "tableTo": "bookmarks",+ "columnsFrom": [+ "id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "bookmarkLists": {+ "name": "bookmarkLists",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "icon": {+ "name": "icon",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "type": {+ "name": "type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "query": {+ "name": "query",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "parentId": {+ "name": "parentId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "rssToken": {+ "name": "rssToken",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "public": {+ "name": "public",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ }+ },+ "indexes": {+ "bookmarkLists_userId_idx": {+ "name": "bookmarkLists_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ },+ "bookmarkLists_userId_id_idx": {+ "name": "bookmarkLists_userId_id_idx",+ "columns": [+ "userId",+ "id"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "bookmarkLists_userId_user_id_fk": {+ "name": "bookmarkLists_userId_user_id_fk",+ "tableFrom": "bookmarkLists",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "bookmarkLists_parentId_bookmarkLists_id_fk": {+ "name": "bookmarkLists_parentId_bookmarkLists_id_fk",+ "tableFrom": "bookmarkLists",+ "tableTo": "bookmarkLists",+ "columnsFrom": [+ "parentId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "bookmarkTags": {+ "name": "bookmarkTags",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "normalizedName": {+ "name": "normalizedName",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "generated": {+ "as": "(lower(replace(replace(replace(\"name\", ' ', ''), '-', ''), '_', '')))",+ "type": "virtual"+ }+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "bookmarkTags_name_idx": {+ "name": "bookmarkTags_name_idx",+ "columns": [+ "name"+ ],+ "isUnique": false+ },+ "bookmarkTags_userId_idx": {+ "name": "bookmarkTags_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ },+ "bookmarkTags_normalizedName_idx": {+ "name": "bookmarkTags_normalizedName_idx",+ "columns": [+ "normalizedName"+ ],+ "isUnique": false+ },+ "bookmarkTags_userId_name_unique": {+ "name": "bookmarkTags_userId_name_unique",+ "columns": [+ "userId",+ "name"+ ],+ "isUnique": true+ },+ "bookmarkTags_userId_id_idx": {+ "name": "bookmarkTags_userId_id_idx",+ "columns": [+ "userId",+ "id"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "bookmarkTags_userId_user_id_fk": {+ "name": "bookmarkTags_userId_user_id_fk",+ "tableFrom": "bookmarkTags",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "bookmarkTexts": {+ "name": "bookmarkTexts",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "text": {+ "name": "text",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "sourceUrl": {+ "name": "sourceUrl",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "bookmarkTexts_id_bookmarks_id_fk": {+ "name": "bookmarkTexts_id_bookmarks_id_fk",+ "tableFrom": "bookmarkTexts",+ "tableTo": "bookmarks",+ "columnsFrom": [+ "id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "bookmarks": {+ "name": "bookmarks",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "modifiedAt": {+ "name": "modifiedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "archived": {+ "name": "archived",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "favourited": {+ "name": "favourited",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "taggingStatus": {+ "name": "taggingStatus",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "'pending'"+ },+ "summarizationStatus": {+ "name": "summarizationStatus",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "'pending'"+ },+ "embeddingStatus": {+ "name": "embeddingStatus",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "'pending'"+ },+ "summary": {+ "name": "summary",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "note": {+ "name": "note",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "type": {+ "name": "type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "source": {+ "name": "source",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "bookmarks_userId_idx": {+ "name": "bookmarks_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ },+ "bookmarks_createdAt_idx": {+ "name": "bookmarks_createdAt_idx",+ "columns": [+ "createdAt"+ ],+ "isUnique": false+ },+ "bookmarks_userId_createdAt_id_idx": {+ "name": "bookmarks_userId_createdAt_id_idx",+ "columns": [+ "userId",+ "createdAt",+ "id"+ ],+ "isUnique": false+ },+ "bookmarks_userId_archived_createdAt_id_idx": {+ "name": "bookmarks_userId_archived_createdAt_id_idx",+ "columns": [+ "userId",+ "archived",+ "createdAt",+ "id"+ ],+ "isUnique": false+ },+ "bookmarks_userId_favourited_createdAt_id_idx": {+ "name": "bookmarks_userId_favourited_createdAt_id_idx",+ "columns": [+ "userId",+ "favourited",+ "createdAt",+ "id"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "bookmarks_userId_user_id_fk": {+ "name": "bookmarks_userId_user_id_fk",+ "tableFrom": "bookmarks",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "bookmarksInLists": {+ "name": "bookmarksInLists",+ "columns": {+ "bookmarkId": {+ "name": "bookmarkId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "listId": {+ "name": "listId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "addedAt": {+ "name": "addedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "listMembershipId": {+ "name": "listMembershipId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "bookmarksInLists_bookmarkId_idx": {+ "name": "bookmarksInLists_bookmarkId_idx",+ "columns": [+ "bookmarkId"+ ],+ "isUnique": false+ },+ "bookmarksInLists_listId_idx": {+ "name": "bookmarksInLists_listId_idx",+ "columns": [+ "listId"+ ],+ "isUnique": false+ },+ "bookmarksInLists_listId_bookmarkId_idx": {+ "name": "bookmarksInLists_listId_bookmarkId_idx",+ "columns": [+ "listId",+ "bookmarkId"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "bookmarksInLists_bookmarkId_bookmarks_id_fk": {+ "name": "bookmarksInLists_bookmarkId_bookmarks_id_fk",+ "tableFrom": "bookmarksInLists",+ "tableTo": "bookmarks",+ "columnsFrom": [+ "bookmarkId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "bookmarksInLists_listId_bookmarkLists_id_fk": {+ "name": "bookmarksInLists_listId_bookmarkLists_id_fk",+ "tableFrom": "bookmarksInLists",+ "tableTo": "bookmarkLists",+ "columnsFrom": [+ "listId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "bookmarksInLists_listMembershipId_listCollaborators_id_fk": {+ "name": "bookmarksInLists_listMembershipId_listCollaborators_id_fk",+ "tableFrom": "bookmarksInLists",+ "tableTo": "listCollaborators",+ "columnsFrom": [+ "listMembershipId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "bookmarksInLists_bookmarkId_listId_pk": {+ "columns": [+ "bookmarkId",+ "listId"+ ],+ "name": "bookmarksInLists_bookmarkId_listId_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "chatMessages": {+ "name": "chatMessages",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "chatId": {+ "name": "chatId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "role": {+ "name": "role",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "content": {+ "name": "content",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "metadata": {+ "name": "metadata",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "chatMessages_chatId_idx": {+ "name": "chatMessages_chatId_idx",+ "columns": [+ "chatId"+ ],+ "isUnique": false+ },+ "chatMessages_chatId_createdAt_idx": {+ "name": "chatMessages_chatId_createdAt_idx",+ "columns": [+ "chatId",+ "createdAt"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "chatMessages_chatId_chatSessions_id_fk": {+ "name": "chatMessages_chatId_chatSessions_id_fk",+ "tableFrom": "chatMessages",+ "tableTo": "chatSessions",+ "columnsFrom": [+ "chatId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "chatSessions": {+ "name": "chatSessions",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "modifiedAt": {+ "name": "modifiedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "chatSessions_userId_idx": {+ "name": "chatSessions_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ },+ "chatSessions_userId_modifiedAt_idx": {+ "name": "chatSessions_userId_modifiedAt_idx",+ "columns": [+ "userId",+ "modifiedAt"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "chatSessions_userId_user_id_fk": {+ "name": "chatSessions_userId_user_id_fk",+ "tableFrom": "chatSessions",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "config": {+ "name": "config",+ "columns": {+ "key": {+ "name": "key",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "value": {+ "name": "value",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "customPrompts": {+ "name": "customPrompts",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "text": {+ "name": "text",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "enabled": {+ "name": "enabled",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "appliesTo": {+ "name": "appliesTo",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "customPrompts_userId_idx": {+ "name": "customPrompts_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "customPrompts_userId_user_id_fk": {+ "name": "customPrompts_userId_user_id_fk",+ "tableFrom": "customPrompts",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "highlights": {+ "name": "highlights",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "bookmarkId": {+ "name": "bookmarkId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "startOffset": {+ "name": "startOffset",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "endOffset": {+ "name": "endOffset",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "color": {+ "name": "color",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'yellow'"+ },+ "text": {+ "name": "text",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "note": {+ "name": "note",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "highlights_bookmarkId_idx": {+ "name": "highlights_bookmarkId_idx",+ "columns": [+ "bookmarkId"+ ],+ "isUnique": false+ },+ "highlights_userId_idx": {+ "name": "highlights_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "highlights_bookmarkId_bookmarks_id_fk": {+ "name": "highlights_bookmarkId_bookmarks_id_fk",+ "tableFrom": "highlights",+ "tableTo": "bookmarks",+ "columnsFrom": [+ "bookmarkId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "highlights_userId_user_id_fk": {+ "name": "highlights_userId_user_id_fk",+ "tableFrom": "highlights",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "importSessionBookmarks": {+ "name": "importSessionBookmarks",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "importSessionId": {+ "name": "importSessionId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "bookmarkId": {+ "name": "bookmarkId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "importSessionBookmarks_sessionId_idx": {+ "name": "importSessionBookmarks_sessionId_idx",+ "columns": [+ "importSessionId"+ ],+ "isUnique": false+ },+ "importSessionBookmarks_bookmarkId_idx": {+ "name": "importSessionBookmarks_bookmarkId_idx",+ "columns": [+ "bookmarkId"+ ],+ "isUnique": false+ },+ "importSessionBookmarks_importSessionId_bookmarkId_unique": {+ "name": "importSessionBookmarks_importSessionId_bookmarkId_unique",+ "columns": [+ "importSessionId",+ "bookmarkId"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "importSessionBookmarks_importSessionId_importSessions_id_fk": {+ "name": "importSessionBookmarks_importSessionId_importSessions_id_fk",+ "tableFrom": "importSessionBookmarks",+ "tableTo": "importSessions",+ "columnsFrom": [+ "importSessionId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "importSessionBookmarks_bookmarkId_bookmarks_id_fk": {+ "name": "importSessionBookmarks_bookmarkId_bookmarks_id_fk",+ "tableFrom": "importSessionBookmarks",+ "tableTo": "bookmarks",+ "columnsFrom": [+ "bookmarkId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "importSessions": {+ "name": "importSessions",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "message": {+ "name": "message",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "rootListId": {+ "name": "rootListId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'staging'"+ },+ "lastProcessedAt": {+ "name": "lastProcessedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "modifiedAt": {+ "name": "modifiedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "importSessions_userId_idx": {+ "name": "importSessions_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ },+ "importSessions_status_idx": {+ "name": "importSessions_status_idx",+ "columns": [+ "status"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "importSessions_userId_user_id_fk": {+ "name": "importSessions_userId_user_id_fk",+ "tableFrom": "importSessions",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "importSessions_rootListId_bookmarkLists_id_fk": {+ "name": "importSessions_rootListId_bookmarkLists_id_fk",+ "tableFrom": "importSessions",+ "tableTo": "bookmarkLists",+ "columnsFrom": [+ "rootListId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "importStagingBookmarks": {+ "name": "importStagingBookmarks",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "importSessionId": {+ "name": "importSessionId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "type": {+ "name": "type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "url": {+ "name": "url",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "content": {+ "name": "content",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "note": {+ "name": "note",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "tags": {+ "name": "tags",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "listIds": {+ "name": "listIds",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "sourceAddedAt": {+ "name": "sourceAddedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "archived": {+ "name": "archived",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'pending'"+ },+ "processingStartedAt": {+ "name": "processingStartedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "result": {+ "name": "result",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "resultReason": {+ "name": "resultReason",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "resultBookmarkId": {+ "name": "resultBookmarkId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "completedAt": {+ "name": "completedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "importStaging_session_status_idx": {+ "name": "importStaging_session_status_idx",+ "columns": [+ "importSessionId",+ "status"+ ],+ "isUnique": false+ },+ "importStaging_completedAt_idx": {+ "name": "importStaging_completedAt_idx",+ "columns": [+ "completedAt"+ ],+ "isUnique": false+ },+ "importStaging_resultBookmarkId_idx": {+ "name": "importStaging_resultBookmarkId_idx",+ "columns": [+ "resultBookmarkId"+ ],+ "isUnique": false+ },+ "importStaging_status_idx": {+ "name": "importStaging_status_idx",+ "columns": [+ "status"+ ],+ "isUnique": false+ },+ "importStaging_status_processingStartedAt_idx": {+ "name": "importStaging_status_processingStartedAt_idx",+ "columns": [+ "status",+ "processingStartedAt"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "importStagingBookmarks_importSessionId_importSessions_id_fk": {+ "name": "importStagingBookmarks_importSessionId_importSessions_id_fk",+ "tableFrom": "importStagingBookmarks",+ "tableTo": "importSessions",+ "columnsFrom": [+ "importSessionId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "importStagingBookmarks_resultBookmarkId_bookmarks_id_fk": {+ "name": "importStagingBookmarks_resultBookmarkId_bookmarks_id_fk",+ "tableFrom": "importStagingBookmarks",+ "tableTo": "bookmarks",+ "columnsFrom": [+ "resultBookmarkId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "invites": {+ "name": "invites",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "email": {+ "name": "email",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "token": {+ "name": "token",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "usedAt": {+ "name": "usedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "invitedBy": {+ "name": "invitedBy",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "invites_token_unique": {+ "name": "invites_token_unique",+ "columns": [+ "token"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "invites_invitedBy_user_id_fk": {+ "name": "invites_invitedBy_user_id_fk",+ "tableFrom": "invites",+ "tableTo": "user",+ "columnsFrom": [+ "invitedBy"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "listCollaborators": {+ "name": "listCollaborators",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "listId": {+ "name": "listId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "role": {+ "name": "role",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "addedBy": {+ "name": "addedBy",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "listCollaborators_listId_idx": {+ "name": "listCollaborators_listId_idx",+ "columns": [+ "listId"+ ],+ "isUnique": false+ },+ "listCollaborators_userId_idx": {+ "name": "listCollaborators_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ },+ "listCollaborators_listId_userId_unique": {+ "name": "listCollaborators_listId_userId_unique",+ "columns": [+ "listId",+ "userId"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "listCollaborators_listId_bookmarkLists_id_fk": {+ "name": "listCollaborators_listId_bookmarkLists_id_fk",+ "tableFrom": "listCollaborators",+ "tableTo": "bookmarkLists",+ "columnsFrom": [+ "listId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "listCollaborators_userId_user_id_fk": {+ "name": "listCollaborators_userId_user_id_fk",+ "tableFrom": "listCollaborators",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "listCollaborators_addedBy_user_id_fk": {+ "name": "listCollaborators_addedBy_user_id_fk",+ "tableFrom": "listCollaborators",+ "tableTo": "user",+ "columnsFrom": [+ "addedBy"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "listInvitations": {+ "name": "listInvitations",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "listId": {+ "name": "listId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "role": {+ "name": "role",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'pending'"+ },+ "invitedAt": {+ "name": "invitedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "invitedEmail": {+ "name": "invitedEmail",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "invitedBy": {+ "name": "invitedBy",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "listInvitations_listId_idx": {+ "name": "listInvitations_listId_idx",+ "columns": [+ "listId"+ ],+ "isUnique": false+ },+ "listInvitations_userId_idx": {+ "name": "listInvitations_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ },+ "listInvitations_status_idx": {+ "name": "listInvitations_status_idx",+ "columns": [+ "status"+ ],+ "isUnique": false+ },+ "listInvitations_listId_userId_unique": {+ "name": "listInvitations_listId_userId_unique",+ "columns": [+ "listId",+ "userId"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "listInvitations_listId_bookmarkLists_id_fk": {+ "name": "listInvitations_listId_bookmarkLists_id_fk",+ "tableFrom": "listInvitations",+ "tableTo": "bookmarkLists",+ "columnsFrom": [+ "listId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "listInvitations_userId_user_id_fk": {+ "name": "listInvitations_userId_user_id_fk",+ "tableFrom": "listInvitations",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "listInvitations_invitedBy_user_id_fk": {+ "name": "listInvitations_invitedBy_user_id_fk",+ "tableFrom": "listInvitations",+ "tableTo": "user",+ "columnsFrom": [+ "invitedBy"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "passwordResetToken": {+ "name": "passwordResetToken",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "token": {+ "name": "token",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "expires": {+ "name": "expires",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "passwordResetToken_token_unique": {+ "name": "passwordResetToken_token_unique",+ "columns": [+ "token"+ ],+ "isUnique": true+ },+ "passwordResetTokens_userId_idx": {+ "name": "passwordResetTokens_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "passwordResetToken_userId_user_id_fk": {+ "name": "passwordResetToken_userId_user_id_fk",+ "tableFrom": "passwordResetToken",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "rssFeedImports": {+ "name": "rssFeedImports",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "entryId": {+ "name": "entryId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "rssFeedId": {+ "name": "rssFeedId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "bookmarkId": {+ "name": "bookmarkId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "rssFeedImports_feedIdIdx_idx": {+ "name": "rssFeedImports_feedIdIdx_idx",+ "columns": [+ "rssFeedId"+ ],+ "isUnique": false+ },+ "rssFeedImports_entryIdIdx_idx": {+ "name": "rssFeedImports_entryIdIdx_idx",+ "columns": [+ "entryId"+ ],+ "isUnique": false+ },+ "rssFeedImports_bookmarkId_idx": {+ "name": "rssFeedImports_bookmarkId_idx",+ "columns": [+ "bookmarkId"+ ],+ "isUnique": false+ },+ "rssFeedImports_rssFeedId_bookmarkId_idx": {+ "name": "rssFeedImports_rssFeedId_bookmarkId_idx",+ "columns": [+ "rssFeedId",+ "bookmarkId"+ ],+ "isUnique": false+ },+ "rssFeedImports_rssFeedId_entryId_unique": {+ "name": "rssFeedImports_rssFeedId_entryId_unique",+ "columns": [+ "rssFeedId",+ "entryId"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "rssFeedImports_rssFeedId_rssFeeds_id_fk": {+ "name": "rssFeedImports_rssFeedId_rssFeeds_id_fk",+ "tableFrom": "rssFeedImports",+ "tableTo": "rssFeeds",+ "columnsFrom": [+ "rssFeedId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "rssFeedImports_bookmarkId_bookmarks_id_fk": {+ "name": "rssFeedImports_bookmarkId_bookmarks_id_fk",+ "tableFrom": "rssFeedImports",+ "tableTo": "bookmarks",+ "columnsFrom": [+ "bookmarkId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "rssFeeds": {+ "name": "rssFeeds",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "url": {+ "name": "url",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "enabled": {+ "name": "enabled",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": true+ },+ "importTags": {+ "name": "importTags",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "lastFetchedAt": {+ "name": "lastFetchedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "lastSuccessfulFetchAt": {+ "name": "lastSuccessfulFetchAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "lastFetchedStatus": {+ "name": "lastFetchedStatus",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "'pending'"+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "rssFeeds_userId_idx": {+ "name": "rssFeeds_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "rssFeeds_userId_user_id_fk": {+ "name": "rssFeeds_userId_user_id_fk",+ "tableFrom": "rssFeeds",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "ruleEngineActions": {+ "name": "ruleEngineActions",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "ruleId": {+ "name": "ruleId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "action": {+ "name": "action",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "listId": {+ "name": "listId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "tagId": {+ "name": "tagId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "ruleEngineActions_userId_idx": {+ "name": "ruleEngineActions_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ },+ "ruleEngineActions_ruleId_idx": {+ "name": "ruleEngineActions_ruleId_idx",+ "columns": [+ "ruleId"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "ruleEngineActions_userId_user_id_fk": {+ "name": "ruleEngineActions_userId_user_id_fk",+ "tableFrom": "ruleEngineActions",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "ruleEngineActions_ruleId_ruleEngineRules_id_fk": {+ "name": "ruleEngineActions_ruleId_ruleEngineRules_id_fk",+ "tableFrom": "ruleEngineActions",+ "tableTo": "ruleEngineRules",+ "columnsFrom": [+ "ruleId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "ruleEngineActions_userId_tagId_fk": {+ "name": "ruleEngineActions_userId_tagId_fk",+ "tableFrom": "ruleEngineActions",+ "tableTo": "bookmarkTags",+ "columnsFrom": [+ "userId",+ "tagId"+ ],+ "columnsTo": [+ "userId",+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "ruleEngineActions_userId_listId_fk": {+ "name": "ruleEngineActions_userId_listId_fk",+ "tableFrom": "ruleEngineActions",+ "tableTo": "bookmarkLists",+ "columnsFrom": [+ "userId",+ "listId"+ ],+ "columnsTo": [+ "userId",+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "ruleEngineRules": {+ "name": "ruleEngineRules",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "enabled": {+ "name": "enabled",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "event": {+ "name": "event",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "condition": {+ "name": "condition",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "tagId": {+ "name": "tagId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "ruleEngine_userId_idx": {+ "name": "ruleEngine_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "ruleEngineRules_userId_user_id_fk": {+ "name": "ruleEngineRules_userId_user_id_fk",+ "tableFrom": "ruleEngineRules",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "ruleEngineRules_userId_tagId_fk": {+ "name": "ruleEngineRules_userId_tagId_fk",+ "tableFrom": "ruleEngineRules",+ "tableTo": "bookmarkTags",+ "columnsFrom": [+ "userId",+ "tagId"+ ],+ "columnsTo": [+ "userId",+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "session": {+ "name": "session",+ "columns": {+ "sessionToken": {+ "name": "sessionToken",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "expires": {+ "name": "expires",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "session_userId_user_id_fk": {+ "name": "session_userId_user_id_fk",+ "tableFrom": "session",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "subscriptions": {+ "name": "subscriptions",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "stripeCustomerId": {+ "name": "stripeCustomerId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "stripeSubscriptionId": {+ "name": "stripeSubscriptionId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "tier": {+ "name": "tier",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'free'"+ },+ "priceId": {+ "name": "priceId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "cancelAtPeriodEnd": {+ "name": "cancelAtPeriodEnd",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": false+ },+ "startDate": {+ "name": "startDate",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "endDate": {+ "name": "endDate",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "modifiedAt": {+ "name": "modifiedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "subscriptions_userId_unique": {+ "name": "subscriptions_userId_unique",+ "columns": [+ "userId"+ ],+ "isUnique": true+ },+ "subscriptions_userId_idx": {+ "name": "subscriptions_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ },+ "subscriptions_stripeCustomerId_idx": {+ "name": "subscriptions_stripeCustomerId_idx",+ "columns": [+ "stripeCustomerId"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "subscriptions_userId_user_id_fk": {+ "name": "subscriptions_userId_user_id_fk",+ "tableFrom": "subscriptions",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "tagsOnBookmarks": {+ "name": "tagsOnBookmarks",+ "columns": {+ "bookmarkId": {+ "name": "bookmarkId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "tagId": {+ "name": "tagId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "attachedAt": {+ "name": "attachedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "attachedBy": {+ "name": "attachedBy",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "tagsOnBookmarks_tagId_idx": {+ "name": "tagsOnBookmarks_tagId_idx",+ "columns": [+ "tagId"+ ],+ "isUnique": false+ },+ "tagsOnBookmarks_bookmarkId_idx": {+ "name": "tagsOnBookmarks_bookmarkId_idx",+ "columns": [+ "bookmarkId"+ ],+ "isUnique": false+ },+ "tagsOnBookmarks_tagId_bookmarkId_idx": {+ "name": "tagsOnBookmarks_tagId_bookmarkId_idx",+ "columns": [+ "tagId",+ "bookmarkId"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "tagsOnBookmarks_bookmarkId_bookmarks_id_fk": {+ "name": "tagsOnBookmarks_bookmarkId_bookmarks_id_fk",+ "tableFrom": "tagsOnBookmarks",+ "tableTo": "bookmarks",+ "columnsFrom": [+ "bookmarkId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "tagsOnBookmarks_tagId_bookmarkTags_id_fk": {+ "name": "tagsOnBookmarks_tagId_bookmarkTags_id_fk",+ "tableFrom": "tagsOnBookmarks",+ "tableTo": "bookmarkTags",+ "columnsFrom": [+ "tagId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "tagsOnBookmarks_bookmarkId_tagId_pk": {+ "columns": [+ "bookmarkId",+ "tagId"+ ],+ "name": "tagsOnBookmarks_bookmarkId_tagId_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "userReadingProgress": {+ "name": "userReadingProgress",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "bookmarkId": {+ "name": "bookmarkId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "readingProgressOffset": {+ "name": "readingProgressOffset",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "readingProgressAnchor": {+ "name": "readingProgressAnchor",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "readingProgressPercent": {+ "name": "readingProgressPercent",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "modifiedAt": {+ "name": "modifiedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "userReadingProgress_bookmarkId_idx": {+ "name": "userReadingProgress_bookmarkId_idx",+ "columns": [+ "bookmarkId"+ ],+ "isUnique": false+ },+ "userReadingProgress_userId_idx": {+ "name": "userReadingProgress_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ },+ "userReadingProgress_bookmarkId_userId_unique": {+ "name": "userReadingProgress_bookmarkId_userId_unique",+ "columns": [+ "bookmarkId",+ "userId"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "userReadingProgress_bookmarkId_bookmarks_id_fk": {+ "name": "userReadingProgress_bookmarkId_bookmarks_id_fk",+ "tableFrom": "userReadingProgress",+ "tableTo": "bookmarks",+ "columnsFrom": [+ "bookmarkId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "userReadingProgress_userId_user_id_fk": {+ "name": "userReadingProgress_userId_user_id_fk",+ "tableFrom": "userReadingProgress",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "user": {+ "name": "user",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "email": {+ "name": "email",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "emailVerified": {+ "name": "emailVerified",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "image": {+ "name": "image",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "password": {+ "name": "password",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "salt": {+ "name": "salt",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "''"+ },+ "role": {+ "name": "role",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "'user'"+ },+ "bookmarkQuota": {+ "name": "bookmarkQuota",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "storageQuota": {+ "name": "storageQuota",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "browserCrawlingEnabled": {+ "name": "browserCrawlingEnabled",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "manualTierName": {+ "name": "manualTierName",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "bookmarkClickAction": {+ "name": "bookmarkClickAction",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'open_original_link'"+ },+ "archiveDisplayBehaviour": {+ "name": "archiveDisplayBehaviour",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'show'"+ },+ "timezone": {+ "name": "timezone",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "'UTC'"+ },+ "backupsEnabled": {+ "name": "backupsEnabled",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "backupsFrequency": {+ "name": "backupsFrequency",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'weekly'"+ },+ "backupsRetentionDays": {+ "name": "backupsRetentionDays",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 30+ },+ "readerFontSize": {+ "name": "readerFontSize",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "readerLineHeight": {+ "name": "readerLineHeight",+ "type": "real",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "readerFontFamily": {+ "name": "readerFontFamily",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "autoTaggingEnabled": {+ "name": "autoTaggingEnabled",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "autoSummarizationEnabled": {+ "name": "autoSummarizationEnabled",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "tagStyle": {+ "name": "tagStyle",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "'titlecase-spaces'"+ },+ "curatedTagIds": {+ "name": "curatedTagIds",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "inferredTagLang": {+ "name": "inferredTagLang",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "user_email_unique": {+ "name": "user_email_unique",+ "columns": [+ "email"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "verificationToken": {+ "name": "verificationToken",+ "columns": {+ "identifier": {+ "name": "identifier",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "token": {+ "name": "token",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "expires": {+ "name": "expires",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {+ "verificationToken_identifier_token_pk": {+ "columns": [+ "identifier",+ "token"+ ],+ "name": "verificationToken_identifier_token_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "webhooks": {+ "name": "webhooks",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "url": {+ "name": "url",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "events": {+ "name": "events",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "token": {+ "name": "token",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "webhooks_userId_idx": {+ "name": "webhooks_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "webhooks_userId_user_id_fk": {+ "name": "webhooks_userId_user_id_fk",+ "tableFrom": "webhooks",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ }+ },+ "views": {},+ "enums": {},+ "_meta": {+ "schemas": {},+ "tables": {},+ "columns": {}+ },+ "internal": {+ "indexes": {}+ }+}\ No newline at end of filediff --git a/packages/db/drizzle/meta/_journal.json b/packages/db/drizzle/meta/_journal.jsonindex 4bf77d88..64f74b15 100644--- a/packages/db/drizzle/meta/_journal.json+++ b/packages/db/drizzle/meta/_journal.json@@ -624,6 +624,13 @@"when": 1783874446162,"tag": "0088_add_chat_tables","breakpoints": true+ },+ {+ "idx": 89,+ "version": "6",+ "when": 1784178098346,+ "tag": "0089_add_manual_tier_name",+ "breakpoints": true}]}\ No newline at end of filediff --git a/packages/db/schema.ts b/packages/db/schema.tsindex 81379166..9b5531cc 100644--- a/packages/db/schema.ts+++ b/packages/db/schema.ts@@ -60,6 +60,10 @@ export const users = sqliteTable("user", {browserCrawlingEnabled: integer("browserCrawlingEnabled", {mode: "boolean",}),+ // Admin-granted plan label (e.g. a collaborator name). While set, Stripe+ // sync doesn't downgrade the user's entitlements; it's cleared when the+ // user gets an active Stripe subscription.+ manualTierName: text("manualTierName"),// User SettingsbookmarkClickAction: text("bookmarkClickAction", {diff --git a/packages/shared-server/src/eventLogTypes.ts b/packages/shared-server/src/eventLogTypes.tsindex c9df5847..21a15f5e 100644--- a/packages/shared-server/src/eventLogTypes.ts+++ b/packages/shared-server/src/eventLogTypes.ts@@ -187,7 +187,7 @@ type EventLogInternal ="subscription.status"?: string;"subscription.prev_tier"?: string;"subscription.prev_status"?: string;- "subscription.sync_skipped_reason"?: "unknown_customer";+ "subscription.sync_skipped_reason"?: "unknown_customer" | "manual_tier";"subscription.cancel_at_period_end"?: boolean;"subscription.transition"?:| "upgrade"diff --git a/packages/shared/config.ts b/packages/shared/config.tsindex 11853ee6..9bbcc2d5 100644--- a/packages/shared/config.ts+++ b/packages/shared/config.ts@@ -552,6 +552,9 @@ export const clientConfig = {chat: {enabled: serverConfig.chat.enabled,},+ stripe: {+ isConfigured: serverConfig.stripe.isConfigured,+ },legal: {termsOfServiceUrl: serverConfig.legal.termsOfServiceUrl,privacyPolicyUrl: serverConfig.legal.privacyPolicyUrl,diff --git a/packages/shared/types/apiKeys.ts b/packages/shared/types/apiKeys.tsindex 8277b630..9e1a6abd 100644--- a/packages/shared/types/apiKeys.ts+++ b/packages/shared/types/apiKeys.ts@@ -21,6 +21,7 @@ export const API_KEY_SCOPE_RESOURCES = [export const API_KEY_ADMIN_SCOPE_RESOURCES = ["bookmarks","jobs",+ "subscriptions","system","users",] as const;diff --git a/packages/trpc/routers/subscriptions.test.ts b/packages/trpc/routers/subscriptions.test.tsindex 33ce99dd..e62c00c0 100644--- a/packages/trpc/routers/subscriptions.test.ts+++ b/packages/trpc/routers/subscriptions.test.ts@@ -4,8 +4,14 @@ import { beforeEach, describe, expect, test, vi } from "vitest";import { assets, AssetTypes, subscriptions, users } from "@karakeep/db/schema";import { BookmarkTypes } from "@karakeep/shared/types/bookmarks";+import serverConfig from "@karakeep/shared/config";+import type { CustomTestContext } from "../testUtils";-import { defaultBeforeEach, getApiCaller } from "../testUtils";+import {+ defaultBeforeEach,+ getApiCaller,+ getApiKeyCallerForPlainKey,+} from "../testUtils";// Mock Stripe using vi.hoisted to ensure it's available during module initializationconst mockStripeInstance = vi.hoisted(() => ({@@ -60,10 +66,12 @@ vi.mock("@karakeep/shared/config", async (original) => {free: {bookmarkLimit: 100,assetSizeBytes: 1000000, // 1MB+ browserCrawlingEnabled: false,},paid: {bookmarkLimit: null,assetSizeBytes: null,+ browserCrawlingEnabled: true,},},},@@ -110,6 +118,7 @@ describe("Subscription Routes", () => {expect(status).toEqual({tier: "free",+ manualTierName: null,status: null,startDate: null,endDate: null,@@ -149,6 +158,7 @@ describe("Subscription Routes", () => {expect(status).toEqual({tier: "paid",+ manualTierName: null,status: "active",startDate,endDate,@@ -158,6 +168,511 @@ describe("Subscription Routes", () => {});});+ describe("manual tier", () => {+ test<CustomTestContext>("getSubscriptionStatus returns custom tier when manualTierName is set", async ({+ db,+ unauthedAPICaller,+ }) => {+ const user = await unauthedAPICaller.users.create({+ name: "Test User",+ email: "[email protected]",+ password: "pass1234",+ confirmPassword: "pass1234",+ });+ const caller = getApiCaller(db, user.id);++ await db+ .update(users)+ .set({ manualTierName: "Acme" })+ .where(eq(users.id, user.id));++ const status = await caller.subscriptions.getSubscriptionStatus();++ expect(status).toEqual({+ tier: "custom",+ manualTierName: "Acme",+ status: null,+ startDate: null,+ endDate: null,+ hasActiveSubscription: false,+ cancelAtPeriodEnd: false,+ });+ });++ test<CustomTestContext>("getSubscriptionStatus returns custom tier over an inactive subscription", async ({+ db,+ unauthedAPICaller,+ }) => {+ const user = await unauthedAPICaller.users.create({+ name: "Test User",+ email: "[email protected]",+ password: "pass1234",+ confirmPassword: "pass1234",+ });+ const caller = getApiCaller(db, user.id);++ await db+ .update(users)+ .set({ manualTierName: "Acme" })+ .where(eq(users.id, user.id));++ // e.g. an abandoned checkout created a Stripe customer earlier+ await db.insert(subscriptions).values({+ userId: user.id,+ stripeCustomerId: "cus_123",+ status: "unpaid",+ tier: "free",+ });++ const status = await caller.subscriptions.getSubscriptionStatus();++ expect(status.tier).toBe("custom");+ expect(status.manualTierName).toBe("Acme");+ expect(status.hasActiveSubscription).toBe(false);+ });++ test<CustomTestContext>("sync doesn't downgrade a manual tier user with no Stripe subscriptions", async ({+ db,+ unauthedAPICaller,+ }) => {+ const user = await unauthedAPICaller.users.create({+ name: "Test User",+ email: "[email protected]",+ password: "pass1234",+ confirmPassword: "pass1234",+ });++ // Manually granted tier with custom quotas+ await db+ .update(users)+ .set({+ manualTierName: "Acme",+ bookmarkQuota: 500,+ storageQuota: 5000000,+ })+ .where(eq(users.id, user.id));++ // An abandoned checkout created a Stripe customer with no subscriptions+ await db.insert(subscriptions).values({+ userId: user.id,+ stripeCustomerId: "cus_123",+ status: "unpaid",+ tier: "free",+ });++ mockSubscriptionsList.mockResolvedValue({+ data: [],+ });++ mockWebhooksConstructEvent.mockReturnValue({+ type: "customer.subscription.deleted",+ data: {+ object: {+ id: "sub_123",+ customer: "cus_123",+ },+ },+ });++ const result = await unauthedAPICaller.subscriptions.handleWebhook({+ body: "webhook-body",+ signature: "webhook-signature",+ });++ expect(result).toEqual({ received: true });++ const subscription = await db.query.subscriptions.findFirst({+ where: eq(subscriptions.userId, user.id),+ });+ expect(subscription?.status).toBe("unpaid");++ const updatedUser = await db.query.users.findFirst({+ where: eq(users.id, user.id),+ columns: {+ bookmarkQuota: true,+ storageQuota: true,+ manualTierName: true,+ },+ });+ expect(updatedUser?.manualTierName).toBe("Acme");+ expect(updatedUser?.bookmarkQuota).toBe(500);+ expect(updatedUser?.storageQuota).toBe(5000000);+ });++ test<CustomTestContext>("sync doesn't downgrade a manual tier user with only inactive Stripe subscriptions", async ({+ db,+ unauthedAPICaller,+ }) => {+ const user = await unauthedAPICaller.users.create({+ name: "Test User",+ email: "[email protected]",+ password: "pass1234",+ confirmPassword: "pass1234",+ });++ await db+ .update(users)+ .set({+ manualTierName: "Acme",+ bookmarkQuota: 500,+ storageQuota: 5000000,+ })+ .where(eq(users.id, user.id));++ await db.insert(subscriptions).values({+ userId: user.id,+ stripeCustomerId: "cus_123",+ status: "unpaid",+ tier: "free",+ });++ mockSubscriptionsList.mockResolvedValue({+ data: [+ {+ id: "sub_123",+ status: "canceled",+ cancel_at_period_end: false,+ items: {+ data: [+ {+ price: { id: "price_123" },+ current_period_start: 1640995200,+ current_period_end: 1643673600,+ },+ ],+ },+ },+ ],+ });++ mockWebhooksConstructEvent.mockReturnValue({+ type: "customer.subscription.updated",+ data: {+ object: {+ id: "sub_123",+ customer: "cus_123",+ },+ },+ });++ const result = await unauthedAPICaller.subscriptions.handleWebhook({+ body: "webhook-body",+ signature: "webhook-signature",+ });++ expect(result).toEqual({ received: true });++ const subscription = await db.query.subscriptions.findFirst({+ where: eq(subscriptions.userId, user.id),+ });+ expect(subscription?.status).toBe("unpaid");+ expect(subscription?.stripeSubscriptionId).toBeNull();++ const updatedUser = await db.query.users.findFirst({+ where: eq(users.id, user.id),+ columns: {+ bookmarkQuota: true,+ storageQuota: true,+ manualTierName: true,+ },+ });+ expect(updatedUser?.manualTierName).toBe("Acme");+ expect(updatedUser?.bookmarkQuota).toBe(500);+ expect(updatedUser?.storageQuota).toBe(5000000);+ });++ test<CustomTestContext>("an active Stripe subscription supersedes and clears the manual tier", async ({+ db,+ unauthedAPICaller,+ }) => {+ const user = await unauthedAPICaller.users.create({+ name: "Test User",+ email: "[email protected]",+ password: "pass1234",+ confirmPassword: "pass1234",+ });++ await db+ .update(users)+ .set({+ manualTierName: "Acme",+ bookmarkQuota: 500,+ storageQuota: 5000000,+ })+ .where(eq(users.id, user.id));++ await db.insert(subscriptions).values({+ userId: user.id,+ stripeCustomerId: "cus_123",+ status: "unpaid",+ tier: "free",+ });++ mockSubscriptionsList.mockResolvedValue({+ data: [+ {+ id: "sub_123",+ status: "active",+ cancel_at_period_end: false,+ items: {+ data: [+ {+ price: { id: "price_123" },+ current_period_start: 1640995200,+ current_period_end: 1643673600,+ },+ ],+ },+ },+ ],+ });++ mockWebhooksConstructEvent.mockReturnValue({+ type: "customer.subscription.created",+ data: {+ object: {+ id: "sub_123",+ customer: "cus_123",+ },+ },+ });++ const result = await unauthedAPICaller.subscriptions.handleWebhook({+ body: "webhook-body",+ signature: "webhook-signature",+ });++ expect(result).toEqual({ received: true });++ const subscription = await db.query.subscriptions.findFirst({+ where: eq(subscriptions.userId, user.id),+ });+ expect(subscription?.status).toBe("active");+ expect(subscription?.tier).toBe("paid");+ expect(subscription?.stripeSubscriptionId).toBe("sub_123");++ const updatedUser = await db.query.users.findFirst({+ where: eq(users.id, user.id),+ columns: {+ bookmarkQuota: true,+ storageQuota: true,+ manualTierName: true,+ },+ });+ expect(updatedUser?.manualTierName).toBeNull();+ expect(updatedUser?.bookmarkQuota).toBeNull(); // unlimited for paid+ expect(updatedUser?.storageQuota).toBeNull(); // unlimited for paid+ });+ });++ describe("updateSubscriptionTier", () => {+ async function createAdminCaller(db: CustomTestContext["db"]) {+ const [adminUser] = await db+ .insert(users)+ .values({+ name: "Admin User",+ email: "[email protected]",+ role: "admin",+ })+ .returning();+ return getApiCaller(db, adminUser.id, adminUser.email, "admin");+ }++ test<CustomTestContext>("admin can grant and revoke a manual tier by email", async ({+ db,+ unauthedAPICaller,+ }) => {+ const adminApi = await createAdminCaller(db);+ const targetUser = await unauthedAPICaller.users.create({+ name: "Target User",+ email: "[email protected]",+ password: "pass1234",+ confirmPassword: "pass1234",+ });++ await adminApi.subscriptions.updateSubscriptionTier({+ email: "[email protected]",+ manualTierName: "Acme",+ bookmarkQuota: 500,+ storageQuota: 5000000,+ browserCrawlingEnabled: true,+ });++ let user = await db.query.users.findFirst({+ where: eq(users.id, targetUser.id),+ columns: {+ manualTierName: true,+ bookmarkQuota: true,+ storageQuota: true,+ browserCrawlingEnabled: true,+ },+ });+ expect(user?.manualTierName).toBe("Acme");+ expect(user?.bookmarkQuota).toBe(500);+ expect(user?.storageQuota).toBe(5000000);+ expect(user?.browserCrawlingEnabled).toBe(true);++ await adminApi.subscriptions.updateSubscriptionTier({+ email: "[email protected]",+ manualTierName: null,+ });++ user = await db.query.users.findFirst({+ where: eq(users.id, targetUser.id),+ columns: {+ manualTierName: true,+ bookmarkQuota: true,+ storageQuota: true,+ browserCrawlingEnabled: true,+ },+ });+ expect(user?.manualTierName).toBeNull();+ expect(user?.bookmarkQuota).toBe(100);+ expect(user?.storageQuota).toBe(1000000);+ expect(user?.browserCrawlingEnabled).toBe(false);++ const nonAdminCaller = getApiCaller(db, targetUser.id);+ await expect(+ nonAdminCaller.subscriptions.updateSubscriptionTier({+ email: "[email protected]",+ manualTierName: "Acme",+ }),+ ).rejects.toThrow(/FORBIDDEN/);+ });++ test<CustomTestContext>("fails for unknown emails and actively subscribed users", async ({+ db,+ unauthedAPICaller,+ }) => {+ const adminApi = await createAdminCaller(db);++ await expect(+ adminApi.subscriptions.updateSubscriptionTier({+ email: "[email protected]",+ manualTierName: "Acme",+ }),+ ).rejects.toThrow(/User not found/);++ const subscribedUser = await unauthedAPICaller.users.create({+ name: "Subscribed User",+ email: "[email protected]",+ password: "pass1234",+ confirmPassword: "pass1234",+ });+ await db.insert(subscriptions).values({+ userId: subscribedUser.id,+ stripeCustomerId: "cus_123",+ stripeSubscriptionId: "sub_123",+ status: "active",+ tier: "paid",+ });++ await expect(+ adminApi.subscriptions.updateSubscriptionTier({+ email: "[email protected]",+ manualTierName: "Acme",+ }),+ ).rejects.toThrow(/User already has an active Stripe subscription/);++ // Revoking is still allowed for actively subscribed users.+ await adminApi.subscriptions.updateSubscriptionTier({+ email: "[email protected]",+ manualTierName: null,+ });+ });++ test<CustomTestContext>("requires a verified email when verification is enabled", async ({+ db,+ unauthedAPICaller,+ }) => {+ const adminApi = await createAdminCaller(db);+ const targetUser = await unauthedAPICaller.users.create({+ name: "Target User",+ email: "[email protected]",+ password: "pass1234",+ confirmPassword: "pass1234",+ });++ const originalValue = serverConfig.auth.emailVerificationRequired;+ serverConfig.auth.emailVerificationRequired = true;+ try {+ await expect(+ adminApi.subscriptions.updateSubscriptionTier({+ email: "[email protected]",+ manualTierName: "Acme",+ }),+ ).rejects.toThrow(/User email is not verified/);++ // Revoking doesn't require a verified email.+ await adminApi.subscriptions.updateSubscriptionTier({+ email: "[email protected]",+ manualTierName: null,+ });++ await db+ .update(users)+ .set({ emailVerified: new Date() })+ .where(eq(users.id, targetUser.id));++ await adminApi.subscriptions.updateSubscriptionTier({+ email: "[email protected]",+ manualTierName: "Acme",+ });+ } finally {+ serverConfig.auth.emailVerificationRequired = originalValue;+ }++ const user = await db.query.users.findFirst({+ where: eq(users.id, targetUser.id),+ columns: {+ manualTierName: true,+ },+ });+ expect(user?.manualTierName).toBe("Acme");+ });++ test<CustomTestContext>("requires the admin:subscriptions scope for API keys", async ({+ db,+ unauthedAPICaller,+ }) => {+ const adminApi = await createAdminCaller(db);+ await unauthedAPICaller.users.create({+ name: "Target User",+ email: "[email protected]",+ password: "pass1234",+ confirmPassword: "pass1234",+ });++ const usersScopedKey = await adminApi.apiKeys.create({+ name: "Admin Users Key",+ scopes: ["admin:users:readwrite"],+ });+ const usersScopedCaller = await getApiKeyCallerForPlainKey(+ db,+ usersScopedKey.key,+ );+ await expect(+ usersScopedCaller.subscriptions.updateSubscriptionTier({+ email: "[email protected]",+ manualTierName: "Acme",+ }),+ ).rejects.toThrow(/admin:subscriptions:readwrite/);++ const subscriptionsScopedKey = await adminApi.apiKeys.create({+ name: "Admin Subscriptions Key",+ scopes: ["admin:subscriptions:readwrite"],+ });+ const subscriptionsScopedCaller = await getApiKeyCallerForPlainKey(+ db,+ subscriptionsScopedKey.key,+ );+ await subscriptionsScopedCaller.subscriptions.updateSubscriptionTier({+ email: "[email protected]",+ manualTierName: "Acme",+ });+ });+ });+describe("getSubscriptionPrice", () => {test<CustomTestContext>("returns monthly and yearly prices", async ({db,diff --git a/packages/trpc/routers/subscriptions.ts b/packages/trpc/routers/subscriptions.tsindex 7f74a9c4..473a0fea 100644--- a/packages/trpc/routers/subscriptions.ts+++ b/packages/trpc/routers/subscriptions.ts@@ -11,6 +11,7 @@ import serverConfig from "@karakeep/shared/config";import {Context,+ createAdminScopedProcedure,createEventLogMiddleware,publicProcedure,router,@@ -130,6 +131,14 @@ export async function syncStripeDataToDatabase("subscription.prev_status": prevStatus ?? undefined,});+ const user = await db.query.users.findFirst({+ where: eq(users.id, existingSubscription.userId),+ columns: {+ manualTierName: true,+ },+ });+ const manualTierName = user?.manualTierName ?? null;+try {const subscriptionsList = await stripe.subscriptions.list({customer: customerId,@@ -138,6 +147,14 @@ export async function syncStripeDataToDatabase(});if (subscriptionsList.data.length === 0) {+ if (manualTierName) {+ // The user's entitlements were granted manually (e.g. through a+ // collaboration); don't downgrade them to the free tier.+ addLogFields<"subscription.synced">({+ "subscription.sync_skipped_reason": "manual_tier",+ });+ return;+ }await db.transaction(async (trx) => {await trx.update(subscriptions)@@ -219,6 +236,15 @@ export async function syncStripeDataToDatabase(: null,};+ if (subData.tier === "free" && manualTierName) {+ // The user's entitlements were granted manually (e.g. through a+ // collaboration); don't downgrade them to the free tier.+ addLogFields<"subscription.synced">({+ "subscription.sync_skipped_reason": "manual_tier",+ });+ return;+ }+await db.transaction(async (trx) => {await trx.update(subscriptions)@@ -226,7 +252,8 @@ export async function syncStripeDataToDatabase(.where(eq(subscriptions.stripeCustomerId, customerId));if (subData.status === "active" || subData.status === "trialing") {- // Enable paid tier quotas and browser crawling+ // Enable paid tier quotas and browser crawling. A real subscription+ // supersedes a manually granted tier, so clear it.await trx.update(users).set({@@ -234,6 +261,7 @@ export async function syncStripeDataToDatabase(storageQuota: serverConfig.quotas.paid.assetSizeBytes,browserCrawlingEnabled:serverConfig.quotas.paid.browserCrawlingEnabled,+ manualTierName: null,}).where(eq(users.id, existingSubscription.userId));} else {@@ -299,16 +327,27 @@ async function processEvent(event: Stripe.Event, db: Context["db"]) {}const subscriptionsProcedure = createScopedAuthedProcedure("subscriptions");+const adminSubscriptionsProcedure = createAdminScopedProcedure("subscriptions");export const subscriptionsRouter = router({getSubscriptionStatus: subscriptionsProcedure.query(async ({ ctx }) => {- const subscription = await ctx.db.query.subscriptions.findFirst({- where: eq(subscriptions.userId, ctx.user.id),- });+ const [user, subscription] = await Promise.all([+ ctx.db.query.users.findFirst({+ where: eq(users.id, ctx.user.id),+ columns: {+ manualTierName: true,+ },+ }),+ ctx.db.query.subscriptions.findFirst({+ where: eq(subscriptions.userId, ctx.user.id),+ }),+ ]);+ const manualTierName = user?.manualTierName ?? null;if (!subscription) {return {- tier: "free" as const,+ tier: manualTierName ? ("custom" as const) : ("free" as const),+ manualTierName,status: null,startDate: null,endDate: null,@@ -318,7 +357,8 @@ export const subscriptionsRouter = router({}return {- tier: subscription.tier,+ tier: manualTierName ? ("custom" as const) : subscription.tier,+ manualTierName,status: subscription.status,startDate: subscription.startDate,endDate: subscription.endDate,@@ -551,6 +591,90 @@ export const subscriptionsRouter = router({};}),+ // Grants a manually-managed tier (e.g. a collaboration with another+ // company). While set, Stripe sync won't downgrade the user's entitlements;+ // it's cleared automatically when the user gets an active Stripe+ // subscription. Pass manualTierName: null to revoke the grant and restore+ // the configured free-tier entitlements.+ updateSubscriptionTier: adminSubscriptionsProcedure+ .input(+ z.object({+ email: z.string().email(),+ manualTierName: z.string().trim().min(1).max(100).nullable(),+ bookmarkQuota: z.number().int().min(0).nullable().optional(),+ storageQuota: z.number().int().min(0).nullable().optional(),+ browserCrawlingEnabled: z.boolean().nullable().optional(),+ }),+ )+ .mutation(async ({ input, ctx }) => {+ const user = await ctx.db.query.users.findFirst({+ where: eq(users.email, input.email),+ columns: {+ id: true,+ emailVerified: true,+ },+ with: {+ subscription: true,+ },+ });++ if (!user) {+ throw new TRPCError({+ code: "NOT_FOUND",+ message: "User not found",+ });+ }++ if (+ input.manualTierName &&+ serverConfig.auth.emailVerificationRequired &&+ !user.emailVerified+ ) {+ throw new TRPCError({+ code: "PRECONDITION_FAILED",+ message: "User email is not verified",+ });+ }++ if (+ input.manualTierName &&+ (user.subscription?.status === "active" ||+ user.subscription?.status === "trialing")+ ) {+ throw new TRPCError({+ code: "BAD_REQUEST",+ message: "User already has an active Stripe subscription",+ });+ }++ const updateData: Partial<typeof users.$inferInsert> =+ input.manualTierName === null+ ? {+ manualTierName: null,+ bookmarkQuota: serverConfig.quotas.free.bookmarkLimit,+ storageQuota: serverConfig.quotas.free.assetSizeBytes,+ browserCrawlingEnabled:+ serverConfig.quotas.free.browserCrawlingEnabled,+ }+ : { manualTierName: input.manualTierName };++ if (input.manualTierName !== null) {+ if (input.bookmarkQuota !== undefined) {+ updateData.bookmarkQuota = input.bookmarkQuota;+ }++ if (input.storageQuota !== undefined) {+ updateData.storageQuota = input.storageQuota;+ }++ if (input.browserCrawlingEnabled !== undefined) {+ updateData.browserCrawlingEnabled = input.browserCrawlingEnabled;+ }+ }++ await ctx.db.update(users).set(updateData).where(eq(users.id, user.id));+ }),+handleWebhook: publicProcedure.use(createEventLogMiddleware("subscription.webhook_received")).input(diff --git a/packages/trpc/stats.ts b/packages/trpc/stats.tsindex 1c24ded4..05c5f7e7 100644--- a/packages/trpc/stats.ts+++ b/packages/trpc/stats.ts@@ -1,4 +1,4 @@-import { count, sum } from "drizzle-orm";+import { count, eq, isNotNull, or, sql, sum } from "drizzle-orm";import { Counter, Gauge, Histogram, register } from "prom-client";import type { Metric } from "prom-client";@@ -104,27 +104,44 @@ const totalUsersGauge = getOrCreateMetric();if (serverConfig.stripe.isConfigured) {+ const subscriptionStatus = sql<string>`coalesce(${subscriptions.status}, 'none')`;+ const subscriptionTier = sql<string>`+ case+ when ${users.manualTierName} is not null then ${users.manualTierName}+ else coalesce(${subscriptions.tier}, 'free')+ end+ `;getOrCreateMetric("karakeep_subscription_status",() =>new Gauge({name: "karakeep_subscription_status",- help: "Total number of subscriptions per status",+ help: "Total number of users per subscription status and tier",labelNames: ["status", "tier"],async collect() {this.reset();try {const results = await db.select({- status: subscriptions.status,- tier: subscriptions.tier,+ status: subscriptionStatus,+ tier: subscriptionTier,count: count(),})- .from(subscriptions)- .groupBy(subscriptions.status, subscriptions.tier);+ .from(users)+ .leftJoin(subscriptions, eq(subscriptions.userId, users.id))+ .where(+ or(+ isNotNull(subscriptions.id),+ isNotNull(users.manualTierName),+ ),+ )+ .groupBy(subscriptionStatus, subscriptionTier);for (const result of results) {this.set(- { status: result.status, tier: result.tier },+ {+ status: result.status,+ tier: result.tier,+ },result.count,);}