@codelitdev/platform-cli 0.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +43 -0
- package/dist/codemod-readme-title.d.ts +5 -0
- package/dist/codemod-readme-title.js +21 -0
- package/dist/create.d.ts +6 -0
- package/dist/create.js +124 -0
- package/dist/doctor.d.ts +12 -0
- package/dist/doctor.js +111 -0
- package/dist/fs.d.ts +5 -0
- package/dist/fs.js +42 -0
- package/dist/git.d.ts +1 -0
- package/dist/git.js +19 -0
- package/dist/hash.d.ts +2 -0
- package/dist/hash.js +8 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/manifest.d.ts +12 -0
- package/dist/manifest.js +31 -0
- package/dist/template.d.ts +2 -0
- package/dist/template.js +23 -0
- package/dist/upgrade.d.ts +13 -0
- package/dist/upgrade.js +97 -0
- package/package.json +41 -0
- package/template/.github/workflows/platform-conformance.yml +28 -0
- package/template/README.md +5 -0
- package/template/apps/api/.env.example +18 -0
- package/template/apps/api/README.md +3 -0
- package/template/apps/api/billing.config.ts +25 -0
- package/template/apps/api/drizzle.config.ts +7 -0
- package/template/apps/api/package.json +53 -0
- package/template/apps/api/scripts/generate-auth-schema.mjs +173 -0
- package/template/apps/api/scripts/migrate.mjs +15 -0
- package/template/apps/api/src/app.test.ts +479 -0
- package/template/apps/api/src/auth/api-keys.ts +131 -0
- package/template/apps/api/src/auth/authenticate.ts +166 -0
- package/template/apps/api/src/auth/better-auth.ts +38 -0
- package/template/apps/api/src/auth/oauth.ts +9 -0
- package/template/apps/api/src/auth/options.ts +69 -0
- package/template/apps/api/src/billing.ts +58 -0
- package/template/apps/api/src/conformance-adapter.ts +335 -0
- package/template/apps/api/src/db/migrate.ts +26 -0
- package/template/apps/api/src/db/migrations/0000_application.sql +72 -0
- package/template/apps/api/src/db/migrations/0000_auth.sql +178 -0
- package/template/apps/api/src/db/migrations/0001_billing.sql +234 -0
- package/template/apps/api/src/db/schema/auth.generated.ts +185 -0
- package/template/apps/api/src/db/schema/billing.generated.ts +447 -0
- package/template/apps/api/src/db/schema/index.ts +3 -0
- package/template/apps/api/src/db/schema/notes.ts +31 -0
- package/template/apps/api/src/db/schema/tenants.ts +83 -0
- package/template/apps/api/src/deps.ts +12 -0
- package/template/apps/api/src/dispatch.ts +476 -0
- package/template/apps/api/src/express-app.ts +161 -0
- package/template/apps/api/src/invitations.ts +217 -0
- package/template/apps/api/src/logger.ts +26 -0
- package/template/apps/api/src/main.ts +98 -0
- package/template/apps/api/src/mcp.ts +127 -0
- package/template/apps/api/src/notes.ts +251 -0
- package/template/apps/api/src/openapi.ts +12 -0
- package/template/apps/api/src/permissions.ts +35 -0
- package/template/apps/api/src/runtime.ts +167 -0
- package/template/apps/api/src/seed.ts +340 -0
- package/template/apps/api/src/tenancy.ts +116 -0
- package/template/apps/api/src/types.ts +20 -0
- package/template/apps/api/src/worker.ts +57 -0
- package/template/apps/api/tsconfig.json +14 -0
- package/template/apps/web/.env.example +7 -0
- package/template/apps/web/app/api/[...path]/route.ts +51 -0
- package/template/apps/web/app/globals.css +156 -0
- package/template/apps/web/app/layout.tsx +34 -0
- package/template/apps/web/app/login/page.tsx +127 -0
- package/template/apps/web/app/notes/page.tsx +93 -0
- package/template/apps/web/app/page.tsx +80 -0
- package/template/apps/web/components/auth-gate.tsx +34 -0
- package/template/apps/web/components/browser-observability.tsx +53 -0
- package/template/apps/web/components/tenant-switcher.tsx +51 -0
- package/template/apps/web/lib/observability-config.ts +15 -0
- package/template/apps/web/next-env.d.ts +2 -0
- package/template/apps/web/next.config.ts +7 -0
- package/template/apps/web/package.json +26 -0
- package/template/apps/web/tsconfig.json +21 -0
- package/template/biome.template.json +50 -0
- package/template/docker-compose.yml +14 -0
- package/template/package.json +40 -0
- package/template/packages/api-contract/package.json +23 -0
- package/template/packages/api-contract/src/index.ts +256 -0
- package/template/packages/api-contract/src/mcp-parity.ts +158 -0
- package/template/packages/api-contract/tsconfig.json +11 -0
- package/template/patches/@anatine__zod-openapi@1.14.2.patch +14 -0
- package/template/tooling/platform/config.ts +2 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
CREATE TABLE IF NOT EXISTS "tenants" (
|
|
2
|
+
id uuid PRIMARY KEY,
|
|
3
|
+
public_id text NOT NULL UNIQUE,
|
|
4
|
+
name text NOT NULL,
|
|
5
|
+
created_at timestamptz NOT NULL
|
|
6
|
+
);
|
|
7
|
+
--> statement-breakpoint
|
|
8
|
+
CREATE TABLE IF NOT EXISTS "memberships" (
|
|
9
|
+
id uuid PRIMARY KEY,
|
|
10
|
+
tenant_id uuid NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,
|
|
11
|
+
user_id text NOT NULL REFERENCES "user"(id) ON DELETE CASCADE,
|
|
12
|
+
role text NOT NULL,
|
|
13
|
+
is_owner boolean NOT NULL DEFAULT false,
|
|
14
|
+
permissions text NOT NULL,
|
|
15
|
+
created_at timestamptz NOT NULL
|
|
16
|
+
);
|
|
17
|
+
--> statement-breakpoint
|
|
18
|
+
CREATE UNIQUE INDEX IF NOT EXISTS memberships_tenant_user_uidx ON memberships (tenant_id, user_id);
|
|
19
|
+
--> statement-breakpoint
|
|
20
|
+
CREATE TABLE IF NOT EXISTS "selected_tenants" (
|
|
21
|
+
user_id text PRIMARY KEY REFERENCES "user"(id) ON DELETE CASCADE,
|
|
22
|
+
tenant_id uuid NOT NULL REFERENCES tenants(id) ON DELETE CASCADE
|
|
23
|
+
);
|
|
24
|
+
--> statement-breakpoint
|
|
25
|
+
CREATE TABLE IF NOT EXISTS "invitations" (
|
|
26
|
+
id uuid PRIMARY KEY,
|
|
27
|
+
tenant_id uuid NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,
|
|
28
|
+
email text NOT NULL,
|
|
29
|
+
role text NOT NULL,
|
|
30
|
+
permissions text NOT NULL,
|
|
31
|
+
token_digest text NOT NULL,
|
|
32
|
+
inviter_id text NOT NULL REFERENCES "user"(id),
|
|
33
|
+
expires_at timestamptz NOT NULL,
|
|
34
|
+
accepted_at timestamptz,
|
|
35
|
+
revoked_at timestamptz,
|
|
36
|
+
created_at timestamptz NOT NULL
|
|
37
|
+
);
|
|
38
|
+
--> statement-breakpoint
|
|
39
|
+
CREATE TABLE IF NOT EXISTS "api_keys" (
|
|
40
|
+
id uuid PRIMARY KEY,
|
|
41
|
+
public_id text NOT NULL UNIQUE,
|
|
42
|
+
tenant_id uuid NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,
|
|
43
|
+
user_id text NOT NULL REFERENCES "user"(id) ON DELETE CASCADE,
|
|
44
|
+
digest text NOT NULL,
|
|
45
|
+
permissions text NOT NULL,
|
|
46
|
+
expires_at timestamptz,
|
|
47
|
+
revoked_at timestamptz,
|
|
48
|
+
last_used_at timestamptz,
|
|
49
|
+
created_at timestamptz NOT NULL
|
|
50
|
+
);
|
|
51
|
+
--> statement-breakpoint
|
|
52
|
+
CREATE TABLE IF NOT EXISTS "notes" (
|
|
53
|
+
id uuid PRIMARY KEY,
|
|
54
|
+
public_id text NOT NULL UNIQUE,
|
|
55
|
+
tenant_id uuid NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,
|
|
56
|
+
title text NOT NULL,
|
|
57
|
+
body text NOT NULL,
|
|
58
|
+
created_by text NOT NULL REFERENCES "user"(id),
|
|
59
|
+
created_at timestamptz NOT NULL,
|
|
60
|
+
updated_at timestamptz NOT NULL
|
|
61
|
+
);
|
|
62
|
+
--> statement-breakpoint
|
|
63
|
+
CREATE TABLE IF NOT EXISTS "audit_events" (
|
|
64
|
+
id uuid PRIMARY KEY,
|
|
65
|
+
tenant_id uuid REFERENCES tenants(id) ON DELETE CASCADE,
|
|
66
|
+
actor_id text NOT NULL,
|
|
67
|
+
action text NOT NULL,
|
|
68
|
+
resource_type text NOT NULL,
|
|
69
|
+
resource_id text NOT NULL,
|
|
70
|
+
request_id text NOT NULL,
|
|
71
|
+
created_at timestamptz NOT NULL
|
|
72
|
+
);
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
-- AUTO-GENERATED by scripts/generate-auth-schema.mjs. DO NOT EDIT.
|
|
2
|
+
CREATE TABLE IF NOT EXISTS "user" (
|
|
3
|
+
id text PRIMARY KEY,
|
|
4
|
+
"name" text NOT NULL,
|
|
5
|
+
"email" text NOT NULL UNIQUE,
|
|
6
|
+
"email_verified" boolean NOT NULL,
|
|
7
|
+
"image" text,
|
|
8
|
+
"created_at" timestamptz NOT NULL,
|
|
9
|
+
"updated_at" timestamptz NOT NULL
|
|
10
|
+
);
|
|
11
|
+
--> statement-breakpoint
|
|
12
|
+
CREATE TABLE IF NOT EXISTS "session" (
|
|
13
|
+
id text PRIMARY KEY,
|
|
14
|
+
"expires_at" timestamptz NOT NULL,
|
|
15
|
+
"token" text NOT NULL UNIQUE,
|
|
16
|
+
"created_at" timestamptz NOT NULL,
|
|
17
|
+
"updated_at" timestamptz NOT NULL,
|
|
18
|
+
"ip_address" text,
|
|
19
|
+
"user_agent" text,
|
|
20
|
+
"user_id" text NOT NULL REFERENCES "user"("id") ON DELETE CASCADE
|
|
21
|
+
);
|
|
22
|
+
--> statement-breakpoint
|
|
23
|
+
CREATE TABLE IF NOT EXISTS "account" (
|
|
24
|
+
id text PRIMARY KEY,
|
|
25
|
+
"issuer" text NOT NULL,
|
|
26
|
+
"account_id" text NOT NULL,
|
|
27
|
+
"provider_id" text NOT NULL,
|
|
28
|
+
"user_id" text NOT NULL REFERENCES "user"("id") ON DELETE CASCADE,
|
|
29
|
+
"access_token" text,
|
|
30
|
+
"refresh_token" text,
|
|
31
|
+
"id_token" text,
|
|
32
|
+
"access_token_expires_at" timestamptz,
|
|
33
|
+
"refresh_token_expires_at" timestamptz,
|
|
34
|
+
"scope" text,
|
|
35
|
+
"password" text,
|
|
36
|
+
"created_at" timestamptz NOT NULL,
|
|
37
|
+
"updated_at" timestamptz NOT NULL
|
|
38
|
+
);
|
|
39
|
+
--> statement-breakpoint
|
|
40
|
+
CREATE TABLE IF NOT EXISTS "verification" (
|
|
41
|
+
id text PRIMARY KEY,
|
|
42
|
+
"identifier" text NOT NULL,
|
|
43
|
+
"value" text NOT NULL,
|
|
44
|
+
"expires_at" timestamptz NOT NULL,
|
|
45
|
+
"created_at" timestamptz NOT NULL,
|
|
46
|
+
"updated_at" timestamptz NOT NULL
|
|
47
|
+
);
|
|
48
|
+
--> statement-breakpoint
|
|
49
|
+
CREATE TABLE IF NOT EXISTS "jwks" (
|
|
50
|
+
id text PRIMARY KEY,
|
|
51
|
+
"public_key" text NOT NULL,
|
|
52
|
+
"private_key" text NOT NULL,
|
|
53
|
+
"created_at" timestamptz NOT NULL,
|
|
54
|
+
"expires_at" timestamptz,
|
|
55
|
+
"alg" text,
|
|
56
|
+
"crv" text
|
|
57
|
+
);
|
|
58
|
+
--> statement-breakpoint
|
|
59
|
+
CREATE TABLE IF NOT EXISTS "oauth_client" (
|
|
60
|
+
id text PRIMARY KEY,
|
|
61
|
+
"client_id" text NOT NULL UNIQUE,
|
|
62
|
+
"client_secret" text,
|
|
63
|
+
"client_discovery_id" text,
|
|
64
|
+
"disabled" boolean,
|
|
65
|
+
"skip_consent" boolean,
|
|
66
|
+
"enable_end_session" boolean,
|
|
67
|
+
"subject_type" text,
|
|
68
|
+
"scopes" text[],
|
|
69
|
+
"client_credentials_scopes" text[],
|
|
70
|
+
"user_id" text REFERENCES "user"("id") ON DELETE CASCADE,
|
|
71
|
+
"created_at" timestamptz,
|
|
72
|
+
"updated_at" timestamptz,
|
|
73
|
+
"name" text,
|
|
74
|
+
"uri" text,
|
|
75
|
+
"icon" text,
|
|
76
|
+
"contacts" text[],
|
|
77
|
+
"tos" text,
|
|
78
|
+
"policy" text,
|
|
79
|
+
"software_id" text,
|
|
80
|
+
"software_version" text,
|
|
81
|
+
"software_statement" text,
|
|
82
|
+
"redirect_uris" text[] NOT NULL,
|
|
83
|
+
"post_logout_redirect_uris" text[],
|
|
84
|
+
"backchannel_logout_uri" text,
|
|
85
|
+
"backchannel_logout_session_required" boolean,
|
|
86
|
+
"token_endpoint_auth_method" text,
|
|
87
|
+
"application_type" text,
|
|
88
|
+
"jwks" text,
|
|
89
|
+
"jwks_uri" text,
|
|
90
|
+
"grant_types" text[],
|
|
91
|
+
"response_types" text[],
|
|
92
|
+
"require_pkce" boolean,
|
|
93
|
+
"dpop_bound_access_tokens" boolean,
|
|
94
|
+
"reference_id" text,
|
|
95
|
+
"metadata" jsonb
|
|
96
|
+
);
|
|
97
|
+
--> statement-breakpoint
|
|
98
|
+
CREATE TABLE IF NOT EXISTS "oauth_resource" (
|
|
99
|
+
id text PRIMARY KEY,
|
|
100
|
+
"identifier" text NOT NULL UNIQUE,
|
|
101
|
+
"name" text NOT NULL,
|
|
102
|
+
"access_token_ttl" integer,
|
|
103
|
+
"refresh_token_ttl" integer,
|
|
104
|
+
"signing_algorithm" text,
|
|
105
|
+
"signing_key_id" text,
|
|
106
|
+
"allowed_scopes" text[],
|
|
107
|
+
"custom_claims" jsonb,
|
|
108
|
+
"dpop_bound_access_tokens_required" boolean,
|
|
109
|
+
"disabled" boolean,
|
|
110
|
+
"created_at" timestamptz,
|
|
111
|
+
"updated_at" timestamptz,
|
|
112
|
+
"policy_version" integer,
|
|
113
|
+
"metadata" jsonb
|
|
114
|
+
);
|
|
115
|
+
--> statement-breakpoint
|
|
116
|
+
CREATE TABLE IF NOT EXISTS "oauth_client_resource" (
|
|
117
|
+
id text PRIMARY KEY,
|
|
118
|
+
"client_id" text NOT NULL REFERENCES "oauth_client"("client_id") ON DELETE CASCADE,
|
|
119
|
+
"resource_id" text NOT NULL REFERENCES "oauth_resource"("identifier") ON DELETE CASCADE,
|
|
120
|
+
"metadata" jsonb,
|
|
121
|
+
"created_at" timestamptz
|
|
122
|
+
);
|
|
123
|
+
--> statement-breakpoint
|
|
124
|
+
CREATE TABLE IF NOT EXISTS "oauth_refresh_token" (
|
|
125
|
+
id text PRIMARY KEY,
|
|
126
|
+
"token" text NOT NULL UNIQUE,
|
|
127
|
+
"client_id" text NOT NULL REFERENCES "oauth_client"("client_id") ON DELETE CASCADE,
|
|
128
|
+
"session_id" text REFERENCES "session"("id") ON DELETE SET NULL,
|
|
129
|
+
"user_id" text NOT NULL REFERENCES "user"("id") ON DELETE CASCADE,
|
|
130
|
+
"reference_id" text,
|
|
131
|
+
"authorization_code_id" text,
|
|
132
|
+
"resources" text[],
|
|
133
|
+
"requested_user_info_claims" text[],
|
|
134
|
+
"expires_at" timestamptz,
|
|
135
|
+
"created_at" timestamptz,
|
|
136
|
+
"revoked" timestamptz,
|
|
137
|
+
"rotated_at" timestamptz,
|
|
138
|
+
"rotation_replay_response" text,
|
|
139
|
+
"rotation_replay_expires_at" timestamptz,
|
|
140
|
+
"auth_time" timestamptz,
|
|
141
|
+
"confirmation" jsonb,
|
|
142
|
+
"scopes" text[] NOT NULL
|
|
143
|
+
);
|
|
144
|
+
--> statement-breakpoint
|
|
145
|
+
CREATE TABLE IF NOT EXISTS "oauth_access_token" (
|
|
146
|
+
id text PRIMARY KEY,
|
|
147
|
+
"token" text UNIQUE,
|
|
148
|
+
"client_id" text NOT NULL REFERENCES "oauth_client"("client_id") ON DELETE CASCADE,
|
|
149
|
+
"session_id" text REFERENCES "session"("id") ON DELETE SET NULL,
|
|
150
|
+
"user_id" text REFERENCES "user"("id") ON DELETE CASCADE,
|
|
151
|
+
"reference_id" text,
|
|
152
|
+
"authorization_code_id" text,
|
|
153
|
+
"resources" text[],
|
|
154
|
+
"requested_user_info_claims" text[],
|
|
155
|
+
"refresh_id" text REFERENCES "oauth_refresh_token"("id") ON DELETE CASCADE,
|
|
156
|
+
"expires_at" timestamptz,
|
|
157
|
+
"created_at" timestamptz,
|
|
158
|
+
"revoked" timestamptz,
|
|
159
|
+
"confirmation" jsonb,
|
|
160
|
+
"scopes" text[] NOT NULL
|
|
161
|
+
);
|
|
162
|
+
--> statement-breakpoint
|
|
163
|
+
CREATE TABLE IF NOT EXISTS "oauth_consent" (
|
|
164
|
+
id text PRIMARY KEY,
|
|
165
|
+
"client_id" text NOT NULL REFERENCES "oauth_client"("client_id") ON DELETE CASCADE,
|
|
166
|
+
"user_id" text REFERENCES "user"("id") ON DELETE CASCADE,
|
|
167
|
+
"reference_id" text,
|
|
168
|
+
"resources" text[],
|
|
169
|
+
"requested_user_info_claims" text[],
|
|
170
|
+
"scopes" text[] NOT NULL,
|
|
171
|
+
"created_at" timestamptz,
|
|
172
|
+
"updated_at" timestamptz
|
|
173
|
+
);
|
|
174
|
+
--> statement-breakpoint
|
|
175
|
+
CREATE TABLE IF NOT EXISTS "oauth_client_assertion" (
|
|
176
|
+
id text PRIMARY KEY,
|
|
177
|
+
"expires_at" timestamptz NOT NULL
|
|
178
|
+
);
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
CREATE TABLE IF NOT EXISTS billing_price_entries (
|
|
2
|
+
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
3
|
+
offer_key text NOT NULL,
|
|
4
|
+
plan text NOT NULL,
|
|
5
|
+
billing_interval text NOT NULL,
|
|
6
|
+
currency text NOT NULL,
|
|
7
|
+
amount_minor integer NOT NULL,
|
|
8
|
+
provider_trial_days integer NOT NULL DEFAULT 0,
|
|
9
|
+
provider text NOT NULL,
|
|
10
|
+
provider_product_id text NOT NULL,
|
|
11
|
+
verified_at timestamptz,
|
|
12
|
+
created_at timestamptz NOT NULL DEFAULT now(),
|
|
13
|
+
updated_at timestamptz NOT NULL DEFAULT now(),
|
|
14
|
+
CONSTRAINT billing_price_entries_amount_check CHECK (amount_minor > 0),
|
|
15
|
+
CONSTRAINT billing_price_entries_trial_days_check CHECK (provider_trial_days >= 0),
|
|
16
|
+
CONSTRAINT billing_price_entries_currency_check CHECK (currency ~ '^[A-Z]{3}$'),
|
|
17
|
+
CONSTRAINT billing_price_entries_plan_check CHECK (plan IN ('pro', 'business')),
|
|
18
|
+
CONSTRAINT billing_price_entries_interval_check CHECK (billing_interval IN ('month', 'year'))
|
|
19
|
+
);
|
|
20
|
+
--> statement-breakpoint
|
|
21
|
+
CREATE UNIQUE INDEX IF NOT EXISTS billing_price_entries_provider_product_uidx
|
|
22
|
+
ON billing_price_entries (provider, provider_product_id);
|
|
23
|
+
--> statement-breakpoint
|
|
24
|
+
CREATE INDEX IF NOT EXISTS billing_price_entries_offer_key_idx ON billing_price_entries (offer_key);
|
|
25
|
+
--> statement-breakpoint
|
|
26
|
+
CREATE TABLE IF NOT EXISTS billing_catalog_revisions (
|
|
27
|
+
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
28
|
+
revision integer NOT NULL UNIQUE,
|
|
29
|
+
checkout_provider text NOT NULL,
|
|
30
|
+
status text NOT NULL DEFAULT 'pending_verification',
|
|
31
|
+
verified_at timestamptz,
|
|
32
|
+
activated_at timestamptz,
|
|
33
|
+
retired_at timestamptz,
|
|
34
|
+
created_at timestamptz NOT NULL DEFAULT now(),
|
|
35
|
+
updated_at timestamptz NOT NULL DEFAULT now(),
|
|
36
|
+
CONSTRAINT billing_catalog_revisions_status_check CHECK (status IN ('pending_verification', 'active', 'retired', 'invalid', 'abandoned')),
|
|
37
|
+
CONSTRAINT billing_catalog_revisions_revision_check CHECK (revision > 0)
|
|
38
|
+
);
|
|
39
|
+
--> statement-breakpoint
|
|
40
|
+
CREATE UNIQUE INDEX IF NOT EXISTS billing_catalog_revisions_active_provider_uidx
|
|
41
|
+
ON billing_catalog_revisions (checkout_provider) WHERE status = 'active';
|
|
42
|
+
--> statement-breakpoint
|
|
43
|
+
CREATE TABLE IF NOT EXISTS billing_catalog_revision_items (
|
|
44
|
+
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
45
|
+
catalog_revision_id uuid NOT NULL REFERENCES billing_catalog_revisions(id) ON DELETE CASCADE,
|
|
46
|
+
offer_key text NOT NULL,
|
|
47
|
+
billing_price_entry_id uuid NOT NULL REFERENCES billing_price_entries(id) ON DELETE RESTRICT
|
|
48
|
+
);
|
|
49
|
+
--> statement-breakpoint
|
|
50
|
+
CREATE UNIQUE INDEX IF NOT EXISTS billing_catalog_revision_items_revision_key_uidx
|
|
51
|
+
ON billing_catalog_revision_items (catalog_revision_id, offer_key);
|
|
52
|
+
--> statement-breakpoint
|
|
53
|
+
CREATE UNIQUE INDEX IF NOT EXISTS billing_catalog_revision_items_revision_price_uidx
|
|
54
|
+
ON billing_catalog_revision_items (catalog_revision_id, billing_price_entry_id);
|
|
55
|
+
--> statement-breakpoint
|
|
56
|
+
CREATE TABLE IF NOT EXISTS billing_provider_customers (
|
|
57
|
+
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
58
|
+
provider text NOT NULL,
|
|
59
|
+
payer_id text NOT NULL REFERENCES "user"(id) ON DELETE RESTRICT,
|
|
60
|
+
payer_email text NOT NULL DEFAULT '',
|
|
61
|
+
provider_customer_id text,
|
|
62
|
+
idempotency_key text NOT NULL,
|
|
63
|
+
status text NOT NULL DEFAULT 'creating',
|
|
64
|
+
last_error text,
|
|
65
|
+
created_at timestamptz NOT NULL DEFAULT now(),
|
|
66
|
+
updated_at timestamptz NOT NULL DEFAULT now(),
|
|
67
|
+
CONSTRAINT billing_provider_customers_status_check CHECK (status IN ('creating', 'active', 'conflicted'))
|
|
68
|
+
);
|
|
69
|
+
--> statement-breakpoint
|
|
70
|
+
CREATE UNIQUE INDEX IF NOT EXISTS billing_provider_customers_provider_payer_uidx
|
|
71
|
+
ON billing_provider_customers (provider, payer_id);
|
|
72
|
+
--> statement-breakpoint
|
|
73
|
+
CREATE UNIQUE INDEX IF NOT EXISTS billing_provider_customers_idempotency_uidx
|
|
74
|
+
ON billing_provider_customers (idempotency_key);
|
|
75
|
+
--> statement-breakpoint
|
|
76
|
+
CREATE TABLE IF NOT EXISTS billing_checkout_attempts (
|
|
77
|
+
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
78
|
+
attempt_id text NOT NULL UNIQUE,
|
|
79
|
+
billable_entity_id uuid NOT NULL REFERENCES tenants(id) ON DELETE RESTRICT,
|
|
80
|
+
payer_id text NOT NULL REFERENCES "user"(id) ON DELETE RESTRICT,
|
|
81
|
+
payer_email text NOT NULL DEFAULT '',
|
|
82
|
+
return_url text NOT NULL DEFAULT '',
|
|
83
|
+
provider text NOT NULL,
|
|
84
|
+
catalog_revision integer NOT NULL,
|
|
85
|
+
offer_key text NOT NULL,
|
|
86
|
+
requested_plan text NOT NULL,
|
|
87
|
+
requested_interval text NOT NULL,
|
|
88
|
+
billing_price_entry_id uuid NOT NULL REFERENCES billing_price_entries(id) ON DELETE RESTRICT,
|
|
89
|
+
quoted_amount_minor integer NOT NULL,
|
|
90
|
+
quoted_currency text NOT NULL,
|
|
91
|
+
billing_customer_id uuid REFERENCES billing_provider_customers(id) ON DELETE RESTRICT,
|
|
92
|
+
provider_checkout_session_id text,
|
|
93
|
+
checkout_url_encrypted text,
|
|
94
|
+
idempotency_key text NOT NULL,
|
|
95
|
+
status text NOT NULL DEFAULT 'creating',
|
|
96
|
+
expires_at timestamptz NOT NULL,
|
|
97
|
+
last_error text,
|
|
98
|
+
completed_at timestamptz,
|
|
99
|
+
created_at timestamptz NOT NULL DEFAULT now(),
|
|
100
|
+
updated_at timestamptz NOT NULL DEFAULT now(),
|
|
101
|
+
consumer_reference text,
|
|
102
|
+
CONSTRAINT billing_checkout_attempts_status_check CHECK (status IN ('creating', 'open', 'completed', 'expired', 'abandoned', 'conflicted')),
|
|
103
|
+
CONSTRAINT billing_checkout_attempts_amount_check CHECK (quoted_amount_minor > 0)
|
|
104
|
+
);
|
|
105
|
+
--> statement-breakpoint
|
|
106
|
+
CREATE UNIQUE INDEX IF NOT EXISTS billing_checkout_attempts_idempotency_uidx
|
|
107
|
+
ON billing_checkout_attempts (idempotency_key);
|
|
108
|
+
--> statement-breakpoint
|
|
109
|
+
CREATE TABLE IF NOT EXISTS billing_webhook_events (
|
|
110
|
+
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
111
|
+
provider text NOT NULL,
|
|
112
|
+
provider_event_id text NOT NULL,
|
|
113
|
+
event_type text NOT NULL,
|
|
114
|
+
occurred_at timestamptz NOT NULL,
|
|
115
|
+
subscription_id text,
|
|
116
|
+
checkout_attempt_id text,
|
|
117
|
+
payload_encrypted text,
|
|
118
|
+
payload_key_version text,
|
|
119
|
+
verified_key_version text,
|
|
120
|
+
status text NOT NULL DEFAULT 'pending',
|
|
121
|
+
processing_attempts integer NOT NULL DEFAULT 0,
|
|
122
|
+
last_error text,
|
|
123
|
+
available_at timestamptz NOT NULL DEFAULT now(),
|
|
124
|
+
locked_at timestamptz,
|
|
125
|
+
lease_expires_at timestamptz,
|
|
126
|
+
worker_id text,
|
|
127
|
+
received_at timestamptz NOT NULL DEFAULT now(),
|
|
128
|
+
processed_at timestamptz,
|
|
129
|
+
CONSTRAINT billing_webhook_events_status_check CHECK (status IN ('pending', 'processing', 'processed', 'ignored', 'quarantined', 'failed'))
|
|
130
|
+
);
|
|
131
|
+
--> statement-breakpoint
|
|
132
|
+
CREATE UNIQUE INDEX IF NOT EXISTS billing_webhook_events_provider_event_uidx
|
|
133
|
+
ON billing_webhook_events (provider, provider_event_id);
|
|
134
|
+
--> statement-breakpoint
|
|
135
|
+
CREATE TABLE IF NOT EXISTS billing_subscriptions (
|
|
136
|
+
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
137
|
+
billable_entity_id uuid NOT NULL REFERENCES tenants(id) ON DELETE RESTRICT,
|
|
138
|
+
billing_customer_id uuid NOT NULL REFERENCES billing_provider_customers(id) ON DELETE RESTRICT,
|
|
139
|
+
payer_id text NOT NULL REFERENCES "user"(id) ON DELETE RESTRICT,
|
|
140
|
+
origin_checkout_attempt_id uuid REFERENCES billing_checkout_attempts(id) ON DELETE RESTRICT,
|
|
141
|
+
provider text NOT NULL,
|
|
142
|
+
provider_subscription_id text NOT NULL,
|
|
143
|
+
provider_product_id text NOT NULL,
|
|
144
|
+
billing_price_entry_id uuid NOT NULL REFERENCES billing_price_entries(id) ON DELETE RESTRICT,
|
|
145
|
+
catalog_revision integer NOT NULL,
|
|
146
|
+
offer_key text NOT NULL,
|
|
147
|
+
plan text NOT NULL,
|
|
148
|
+
billing_interval text NOT NULL,
|
|
149
|
+
status text NOT NULL DEFAULT 'pending',
|
|
150
|
+
current_period_starts_at timestamptz,
|
|
151
|
+
current_period_ends_at timestamptz,
|
|
152
|
+
paid_through_at timestamptz,
|
|
153
|
+
trial_ends_at timestamptz,
|
|
154
|
+
cancel_at_period_end boolean NOT NULL DEFAULT false,
|
|
155
|
+
is_entitlement_source boolean NOT NULL DEFAULT false,
|
|
156
|
+
provider_occurred_at timestamptz,
|
|
157
|
+
provider_version text,
|
|
158
|
+
last_observed_at timestamptz,
|
|
159
|
+
last_reconciled_at timestamptz,
|
|
160
|
+
created_at timestamptz NOT NULL DEFAULT now(),
|
|
161
|
+
updated_at timestamptz NOT NULL DEFAULT now()
|
|
162
|
+
);
|
|
163
|
+
--> statement-breakpoint
|
|
164
|
+
CREATE UNIQUE INDEX IF NOT EXISTS billing_subscriptions_provider_subscription_uidx
|
|
165
|
+
ON billing_subscriptions (provider, provider_subscription_id);
|
|
166
|
+
--> statement-breakpoint
|
|
167
|
+
CREATE UNIQUE INDEX IF NOT EXISTS billing_subscriptions_entity_source_uidx
|
|
168
|
+
ON billing_subscriptions (billable_entity_id) WHERE is_entitlement_source = true;
|
|
169
|
+
--> statement-breakpoint
|
|
170
|
+
CREATE TABLE IF NOT EXISTS billing_plan_states (
|
|
171
|
+
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
172
|
+
billable_entity_id uuid NOT NULL UNIQUE REFERENCES tenants(id) ON DELETE RESTRICT,
|
|
173
|
+
active_subscription_id uuid REFERENCES billing_subscriptions(id) ON DELETE RESTRICT,
|
|
174
|
+
projection_version integer NOT NULL DEFAULT 0,
|
|
175
|
+
created_at timestamptz NOT NULL DEFAULT now(),
|
|
176
|
+
updated_at timestamptz NOT NULL DEFAULT now()
|
|
177
|
+
);
|
|
178
|
+
--> statement-breakpoint
|
|
179
|
+
CREATE TABLE IF NOT EXISTS billing_plan_change_attempts (
|
|
180
|
+
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
181
|
+
change_id text NOT NULL UNIQUE,
|
|
182
|
+
billable_entity_id uuid NOT NULL REFERENCES tenants(id) ON DELETE RESTRICT,
|
|
183
|
+
subscription_id uuid NOT NULL REFERENCES billing_subscriptions(id) ON DELETE RESTRICT,
|
|
184
|
+
actor_id text NOT NULL,
|
|
185
|
+
payer_id text NOT NULL REFERENCES "user"(id) ON DELETE RESTRICT,
|
|
186
|
+
provider text NOT NULL,
|
|
187
|
+
idempotency_key text NOT NULL,
|
|
188
|
+
current_catalog_revision integer NOT NULL,
|
|
189
|
+
current_billing_price_entry_id uuid NOT NULL REFERENCES billing_price_entries(id) ON DELETE RESTRICT,
|
|
190
|
+
current_plan text NOT NULL,
|
|
191
|
+
current_interval text NOT NULL,
|
|
192
|
+
target_catalog_revision integer NOT NULL,
|
|
193
|
+
target_billing_price_entry_id uuid NOT NULL REFERENCES billing_price_entries(id) ON DELETE RESTRICT,
|
|
194
|
+
target_plan text NOT NULL,
|
|
195
|
+
target_interval text NOT NULL,
|
|
196
|
+
target_offer_key text NOT NULL,
|
|
197
|
+
effective_at text NOT NULL,
|
|
198
|
+
proration_mode text NOT NULL,
|
|
199
|
+
provider_payment_id text,
|
|
200
|
+
payment_url_encrypted text,
|
|
201
|
+
status text NOT NULL DEFAULT 'creating',
|
|
202
|
+
last_error text,
|
|
203
|
+
completed_at timestamptz,
|
|
204
|
+
created_at timestamptz NOT NULL DEFAULT now(),
|
|
205
|
+
updated_at timestamptz NOT NULL DEFAULT now()
|
|
206
|
+
);
|
|
207
|
+
--> statement-breakpoint
|
|
208
|
+
CREATE UNIQUE INDEX IF NOT EXISTS billing_plan_change_attempts_idempotency_uidx
|
|
209
|
+
ON billing_plan_change_attempts (idempotency_key);
|
|
210
|
+
--> statement-breakpoint
|
|
211
|
+
CREATE TABLE IF NOT EXISTS billing_reconciliation_jobs (
|
|
212
|
+
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
213
|
+
provider text NOT NULL,
|
|
214
|
+
checkout_attempt_id uuid REFERENCES billing_checkout_attempts(id) ON DELETE RESTRICT,
|
|
215
|
+
plan_change_attempt_id uuid REFERENCES billing_plan_change_attempts(id) ON DELETE RESTRICT,
|
|
216
|
+
subscription_id uuid REFERENCES billing_subscriptions(id) ON DELETE RESTRICT,
|
|
217
|
+
provider_customer_id uuid REFERENCES billing_provider_customers(id) ON DELETE RESTRICT,
|
|
218
|
+
operation text NOT NULL DEFAULT 'reconcile',
|
|
219
|
+
status text NOT NULL DEFAULT 'pending',
|
|
220
|
+
attempt_count integer NOT NULL DEFAULT 0,
|
|
221
|
+
available_at timestamptz NOT NULL DEFAULT now(),
|
|
222
|
+
locked_at timestamptz,
|
|
223
|
+
lease_expires_at timestamptz,
|
|
224
|
+
worker_id text,
|
|
225
|
+
last_error text,
|
|
226
|
+
created_at timestamptz NOT NULL DEFAULT now(),
|
|
227
|
+
updated_at timestamptz NOT NULL DEFAULT now(),
|
|
228
|
+
CONSTRAINT billing_reconciliation_jobs_exactly_one_subject CHECK (
|
|
229
|
+
((CASE WHEN checkout_attempt_id IS NOT NULL THEN 1 ELSE 0 END)
|
|
230
|
+
+ (CASE WHEN plan_change_attempt_id IS NOT NULL THEN 1 ELSE 0 END)
|
|
231
|
+
+ (CASE WHEN subscription_id IS NOT NULL THEN 1 ELSE 0 END)
|
|
232
|
+
+ (CASE WHEN provider_customer_id IS NOT NULL THEN 1 ELSE 0 END)) = 1
|
|
233
|
+
)
|
|
234
|
+
);
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AUTO-GENERATED FILE. DO NOT EDIT.
|
|
3
|
+
* Generated by Better Auth getSchema (better-auth/db) from the reference
|
|
4
|
+
* Better Auth options (jwt + oauth-server-kit oauthProvider).
|
|
5
|
+
* Importing this module performs no DDL.
|
|
6
|
+
*/
|
|
7
|
+
import { boolean, integer, jsonb, pgTable, text, timestamp } from "drizzle-orm/pg-core";
|
|
8
|
+
|
|
9
|
+
export const user = pgTable("user", {
|
|
10
|
+
id: text("id").primaryKey(),
|
|
11
|
+
name: text("name").notNull(),
|
|
12
|
+
email: text("email").notNull().unique(),
|
|
13
|
+
emailVerified: boolean("email_verified").notNull(),
|
|
14
|
+
image: text("image"),
|
|
15
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
|
|
16
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export const session = pgTable("session", {
|
|
20
|
+
id: text("id").primaryKey(),
|
|
21
|
+
expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
|
|
22
|
+
token: text("token").notNull().unique(),
|
|
23
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
|
|
24
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
|
|
25
|
+
ipAddress: text("ip_address"),
|
|
26
|
+
userAgent: text("user_agent"),
|
|
27
|
+
userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export const account = pgTable("account", {
|
|
31
|
+
id: text("id").primaryKey(),
|
|
32
|
+
issuer: text("issuer").notNull(),
|
|
33
|
+
accountId: text("account_id").notNull(),
|
|
34
|
+
providerId: text("provider_id").notNull(),
|
|
35
|
+
userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
|
36
|
+
accessToken: text("access_token"),
|
|
37
|
+
refreshToken: text("refresh_token"),
|
|
38
|
+
idToken: text("id_token"),
|
|
39
|
+
accessTokenExpiresAt: timestamp("access_token_expires_at", { withTimezone: true }),
|
|
40
|
+
refreshTokenExpiresAt: timestamp("refresh_token_expires_at", { withTimezone: true }),
|
|
41
|
+
scope: text("scope"),
|
|
42
|
+
password: text("password"),
|
|
43
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
|
|
44
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export const verification = pgTable("verification", {
|
|
48
|
+
id: text("id").primaryKey(),
|
|
49
|
+
identifier: text("identifier").notNull(),
|
|
50
|
+
value: text("value").notNull(),
|
|
51
|
+
expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
|
|
52
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
|
|
53
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export const jwks = pgTable("jwks", {
|
|
57
|
+
id: text("id").primaryKey(),
|
|
58
|
+
publicKey: text("public_key").notNull(),
|
|
59
|
+
privateKey: text("private_key").notNull(),
|
|
60
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
|
|
61
|
+
expiresAt: timestamp("expires_at", { withTimezone: true }),
|
|
62
|
+
alg: text("alg"),
|
|
63
|
+
crv: text("crv"),
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
export const oauthClient = pgTable("oauth_client", {
|
|
67
|
+
id: text("id").primaryKey(),
|
|
68
|
+
clientId: text("client_id").notNull().unique(),
|
|
69
|
+
clientSecret: text("client_secret"),
|
|
70
|
+
clientDiscoveryId: text("client_discovery_id"),
|
|
71
|
+
disabled: boolean("disabled"),
|
|
72
|
+
skipConsent: boolean("skip_consent"),
|
|
73
|
+
enableEndSession: boolean("enable_end_session"),
|
|
74
|
+
subjectType: text("subject_type"),
|
|
75
|
+
scopes: text("scopes").array(),
|
|
76
|
+
clientCredentialsScopes: text("client_credentials_scopes").array(),
|
|
77
|
+
userId: text("user_id").references(() => user.id, { onDelete: "cascade" }),
|
|
78
|
+
createdAt: timestamp("created_at", { withTimezone: true }),
|
|
79
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }),
|
|
80
|
+
name: text("name"),
|
|
81
|
+
uri: text("uri"),
|
|
82
|
+
icon: text("icon"),
|
|
83
|
+
contacts: text("contacts").array(),
|
|
84
|
+
tos: text("tos"),
|
|
85
|
+
policy: text("policy"),
|
|
86
|
+
softwareId: text("software_id"),
|
|
87
|
+
softwareVersion: text("software_version"),
|
|
88
|
+
softwareStatement: text("software_statement"),
|
|
89
|
+
redirectUris: text("redirect_uris").array().notNull(),
|
|
90
|
+
postLogoutRedirectUris: text("post_logout_redirect_uris").array(),
|
|
91
|
+
backchannelLogoutUri: text("backchannel_logout_uri"),
|
|
92
|
+
backchannelLogoutSessionRequired: boolean("backchannel_logout_session_required"),
|
|
93
|
+
tokenEndpointAuthMethod: text("token_endpoint_auth_method"),
|
|
94
|
+
applicationType: text("application_type"),
|
|
95
|
+
jwks: text("jwks"),
|
|
96
|
+
jwksUri: text("jwks_uri"),
|
|
97
|
+
grantTypes: text("grant_types").array(),
|
|
98
|
+
responseTypes: text("response_types").array(),
|
|
99
|
+
requirePKCE: boolean("require_pkce"),
|
|
100
|
+
dpopBoundAccessTokens: boolean("dpop_bound_access_tokens"),
|
|
101
|
+
referenceId: text("reference_id"),
|
|
102
|
+
metadata: jsonb("metadata"),
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
export const oauthResource = pgTable("oauth_resource", {
|
|
106
|
+
id: text("id").primaryKey(),
|
|
107
|
+
identifier: text("identifier").notNull().unique(),
|
|
108
|
+
name: text("name").notNull(),
|
|
109
|
+
accessTokenTtl: integer("access_token_ttl"),
|
|
110
|
+
refreshTokenTtl: integer("refresh_token_ttl"),
|
|
111
|
+
signingAlgorithm: text("signing_algorithm"),
|
|
112
|
+
signingKeyId: text("signing_key_id"),
|
|
113
|
+
allowedScopes: text("allowed_scopes").array(),
|
|
114
|
+
customClaims: jsonb("custom_claims"),
|
|
115
|
+
dpopBoundAccessTokensRequired: boolean("dpop_bound_access_tokens_required"),
|
|
116
|
+
disabled: boolean("disabled"),
|
|
117
|
+
createdAt: timestamp("created_at", { withTimezone: true }),
|
|
118
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }),
|
|
119
|
+
policyVersion: integer("policy_version"),
|
|
120
|
+
metadata: jsonb("metadata"),
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
export const oauthClientResource = pgTable("oauth_client_resource", {
|
|
124
|
+
id: text("id").primaryKey(),
|
|
125
|
+
clientId: text("client_id").notNull().references(() => oauthClient.clientId, { onDelete: "cascade" }),
|
|
126
|
+
resourceId: text("resource_id").notNull().references(() => oauthResource.identifier, { onDelete: "cascade" }),
|
|
127
|
+
metadata: jsonb("metadata"),
|
|
128
|
+
createdAt: timestamp("created_at", { withTimezone: true }),
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
export const oauthRefreshToken = pgTable("oauth_refresh_token", {
|
|
132
|
+
id: text("id").primaryKey(),
|
|
133
|
+
token: text("token").notNull().unique(),
|
|
134
|
+
clientId: text("client_id").notNull().references(() => oauthClient.clientId, { onDelete: "cascade" }),
|
|
135
|
+
sessionId: text("session_id").references(() => session.id, { onDelete: "set null" }),
|
|
136
|
+
userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
|
137
|
+
referenceId: text("reference_id"),
|
|
138
|
+
authorizationCodeId: text("authorization_code_id"),
|
|
139
|
+
resources: text("resources").array(),
|
|
140
|
+
requestedUserInfoClaims: text("requested_user_info_claims").array(),
|
|
141
|
+
expiresAt: timestamp("expires_at", { withTimezone: true }),
|
|
142
|
+
createdAt: timestamp("created_at", { withTimezone: true }),
|
|
143
|
+
revoked: timestamp("revoked", { withTimezone: true }),
|
|
144
|
+
rotatedAt: timestamp("rotated_at", { withTimezone: true }),
|
|
145
|
+
rotationReplayResponse: text("rotation_replay_response"),
|
|
146
|
+
rotationReplayExpiresAt: timestamp("rotation_replay_expires_at", { withTimezone: true }),
|
|
147
|
+
authTime: timestamp("auth_time", { withTimezone: true }),
|
|
148
|
+
confirmation: jsonb("confirmation"),
|
|
149
|
+
scopes: text("scopes").array().notNull(),
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
export const oauthAccessToken = pgTable("oauth_access_token", {
|
|
153
|
+
id: text("id").primaryKey(),
|
|
154
|
+
token: text("token").unique(),
|
|
155
|
+
clientId: text("client_id").notNull().references(() => oauthClient.clientId, { onDelete: "cascade" }),
|
|
156
|
+
sessionId: text("session_id").references(() => session.id, { onDelete: "set null" }),
|
|
157
|
+
userId: text("user_id").references(() => user.id, { onDelete: "cascade" }),
|
|
158
|
+
referenceId: text("reference_id"),
|
|
159
|
+
authorizationCodeId: text("authorization_code_id"),
|
|
160
|
+
resources: text("resources").array(),
|
|
161
|
+
requestedUserInfoClaims: text("requested_user_info_claims").array(),
|
|
162
|
+
refreshId: text("refresh_id").references(() => oauthRefreshToken.id, { onDelete: "cascade" }),
|
|
163
|
+
expiresAt: timestamp("expires_at", { withTimezone: true }),
|
|
164
|
+
createdAt: timestamp("created_at", { withTimezone: true }),
|
|
165
|
+
revoked: timestamp("revoked", { withTimezone: true }),
|
|
166
|
+
confirmation: jsonb("confirmation"),
|
|
167
|
+
scopes: text("scopes").array().notNull(),
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
export const oauthConsent = pgTable("oauth_consent", {
|
|
171
|
+
id: text("id").primaryKey(),
|
|
172
|
+
clientId: text("client_id").notNull().references(() => oauthClient.clientId, { onDelete: "cascade" }),
|
|
173
|
+
userId: text("user_id").references(() => user.id, { onDelete: "cascade" }),
|
|
174
|
+
referenceId: text("reference_id"),
|
|
175
|
+
resources: text("resources").array(),
|
|
176
|
+
requestedUserInfoClaims: text("requested_user_info_claims").array(),
|
|
177
|
+
scopes: text("scopes").array().notNull(),
|
|
178
|
+
createdAt: timestamp("created_at", { withTimezone: true }),
|
|
179
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }),
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
export const oauthClientAssertion = pgTable("oauth_client_assertion", {
|
|
183
|
+
id: text("id").primaryKey(),
|
|
184
|
+
expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
|
|
185
|
+
});
|