create-signet-app 0.2.2 → 0.4.1
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/README.md +128 -7
- package/package.json +4 -3
- package/src/index.ts +338 -66
- package/template-api/_github/workflows/ci.yml +0 -3
- package/template-api/_mcp/test/mcp-off.test.ts +13 -0
- package/template-api/_mcp/test/mcp.test.ts +49 -0
- package/template-api/_targets/bun/Dockerfile +13 -0
- package/template-api/_targets/bun/_dockerignore +10 -0
- package/template-api/_targets/bun/src/server.ts +32 -0
- package/template-api/_targets/cloudflare/_github/workflows/ci.yml +24 -0
- package/template-api/_targets/cloudflare/src/index.ts +17 -0
- package/template-api/_targets/node/src/server.ts +55 -0
- package/template-api/_targets/vercel/index.ts +16 -0
- package/template-api/_targets/vercel/vercel.json +4 -0
- package/template-api/src/app.ts +77 -0
- package/template-api/src/env.ts +4 -0
- package/template-api/tsconfig.json +2 -1
- package/template-api/tsconfig.test.json +1 -1
- package/template-full/README.md +155 -0
- package/template-full/_github/workflows/ci.yml +22 -0
- package/template-full/_gitignore +9 -0
- package/template-full/_mcp/test/mcp.test.ts +55 -0
- package/template-full/api/app.ts +132 -0
- package/template-full/api/db/index.ts +10 -0
- package/template-full/api/db/kv.ts +54 -0
- package/template-full/api/db/open.ts +33 -0
- package/template-full/api/db/schema.ts +57 -0
- package/template-full/api/env.ts +44 -0
- package/template-full/api/plans.ts +23 -0
- package/template-full/api/routes/account.ts +63 -0
- package/template-full/api/routes/auth.ts +134 -0
- package/template-full/api/routes/billing.ts +44 -0
- package/template-full/api/routes/notifications.ts +59 -0
- package/template-full/api/routes/privacy.ts +52 -0
- package/template-full/api/server.ts +44 -0
- package/template-full/api/services.ts +185 -0
- package/template-full/biome.json +50 -0
- package/template-full/drizzle/0000_init.sql +155 -0
- package/template-full/drizzle/0001_orgs.sql +47 -0
- package/template-full/drizzle/meta/0000_snapshot.json +974 -0
- package/template-full/drizzle/meta/0001_snapshot.json +1270 -0
- package/template-full/drizzle/meta/_journal.json +20 -0
- package/template-full/drizzle.config.ts +9 -0
- package/template-full/e2e/smoke.spec.ts +152 -0
- package/template-full/index.html +17 -0
- package/template-full/playwright.config.ts +10 -0
- package/template-full/scripts/dev.ts +17 -0
- package/template-full/src/app.css +9 -0
- package/template-full/src/components/toaster.tsx +13 -0
- package/template-full/src/lib/api.ts +40 -0
- package/template-full/src/main.tsx +36 -0
- package/template-full/src/routeTree.gen.ts +297 -0
- package/template-full/src/router.test.ts +23 -0
- package/template-full/src/router.ts +17 -0
- package/template-full/src/routes/__root.tsx +9 -0
- package/template-full/src/routes/_app/account.tsx +64 -0
- package/template-full/src/routes/_app/admin.tsx +38 -0
- package/template-full/src/routes/_app/billing.tsx +40 -0
- package/template-full/src/routes/_app/index.tsx +33 -0
- package/template-full/src/routes/_app/notifications.tsx +72 -0
- package/template-full/src/routes/_app/org/index.tsx +38 -0
- package/template-full/src/routes/_app/org/members.tsx +86 -0
- package/template-full/src/routes/_app/org/new.tsx +45 -0
- package/template-full/src/routes/_app/privacy.tsx +48 -0
- package/template-full/src/routes/_app.tsx +88 -0
- package/template-full/src/routes/invite.$token.tsx +55 -0
- package/template-full/src/routes/login.tsx +36 -0
- package/template-full/test/api.test.ts +189 -0
- package/template-full/tsconfig.api.json +19 -0
- package/template-full/tsconfig.app.json +26 -0
- package/template-full/tsconfig.json +9 -0
- package/template-full/tsconfig.node.json +16 -0
- package/template-full/tsconfig.test.json +8 -0
- package/template-full/vite.config.ts +24 -0
- package/template-api/src/index.ts +0 -55
- /package/template-api/{wrangler.jsonc → _targets/cloudflare/wrangler.jsonc} +0 -0
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { type AdminContext, type Authorize, defineAdmin, roles } from "@dapplelight/signet-db/admin"
|
|
2
|
+
import { createEntitlements } from "@dapplelight/signet-db/entitlements"
|
|
3
|
+
import { createGrowth } from "@dapplelight/signet-db/growth"
|
|
4
|
+
import { createOrgs } from "@dapplelight/signet-db/orgs"
|
|
5
|
+
import { createPrivacy } from "@dapplelight/signet-db/privacy"
|
|
6
|
+
import { createPayments, sqlStore } from "@dapplelight/signet-payments"
|
|
7
|
+
import { razorpay } from "@dapplelight/signet-payments/razorpay"
|
|
8
|
+
import type { KeyValue } from "@dapplelight/signet-server/adapters"
|
|
9
|
+
import { kvRateLimitStore } from "@dapplelight/signet-server/adapters"
|
|
10
|
+
import { kvApiKeyStore } from "@dapplelight/signet-server/auth/api-keys"
|
|
11
|
+
import { devSmsSender, type SmsSender } from "@dapplelight/signet-server/auth/otp"
|
|
12
|
+
import { kvSessionStore } from "@dapplelight/signet-server/auth/sessions"
|
|
13
|
+
import {
|
|
14
|
+
createNotifier,
|
|
15
|
+
defineTemplates,
|
|
16
|
+
kvNotifyStore,
|
|
17
|
+
} from "@dapplelight/signet-server/notify/notifier"
|
|
18
|
+
import { eq } from "drizzle-orm"
|
|
19
|
+
import { z } from "zod"
|
|
20
|
+
import type { Db } from "./db/index.ts"
|
|
21
|
+
import * as schema from "./db/schema.ts"
|
|
22
|
+
import { env } from "./env.ts"
|
|
23
|
+
import { plans } from "./plans.ts"
|
|
24
|
+
|
|
25
|
+
export { PLAN_DISPLAY, type PlanId, plans } from "./plans.ts"
|
|
26
|
+
|
|
27
|
+
/** DPDP consent purposes the privacy screen lists. Bump NOTICE_VERSION when the notice text changes. */
|
|
28
|
+
export const PURPOSES = [
|
|
29
|
+
{
|
|
30
|
+
id: "product-email",
|
|
31
|
+
label: "Product updates by email",
|
|
32
|
+
description: "New features, once a month",
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
id: "analytics",
|
|
36
|
+
label: "Usage analytics",
|
|
37
|
+
description: "Which screens you use, to improve them",
|
|
38
|
+
},
|
|
39
|
+
] as const
|
|
40
|
+
export const NOTICE_VERSION = "2026-01-01"
|
|
41
|
+
|
|
42
|
+
/** In-app notification templates. Add email, SMS or WhatsApp variants per event as you need them. */
|
|
43
|
+
export const templates = defineTemplates({
|
|
44
|
+
"account.welcome": {
|
|
45
|
+
category: "account",
|
|
46
|
+
data: z.object({ name: z.string() }),
|
|
47
|
+
en: {
|
|
48
|
+
inApp: {
|
|
49
|
+
title: () => "Welcome",
|
|
50
|
+
body: (d) => `Hi ${d.name}, your account is ready. Add your name in Account.`,
|
|
51
|
+
link: () => "/account",
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
"billing.plan_changed": {
|
|
56
|
+
category: "billing",
|
|
57
|
+
data: z.object({ plan: z.string() }),
|
|
58
|
+
en: {
|
|
59
|
+
inApp: {
|
|
60
|
+
title: () => "Plan changed",
|
|
61
|
+
body: (d) => `You are now on ${d.plan}.`,
|
|
62
|
+
link: () => "/billing",
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Where the client IP comes from: server.ts overwrites x-forwarded-for with the
|
|
70
|
+
* socket's address, so one hop. Behind your own proxy, see server.ts.
|
|
71
|
+
*/
|
|
72
|
+
export const TRUST = { forwardedHops: 1 } as const
|
|
73
|
+
|
|
74
|
+
/** Users' columns only an admin may set: who someone is, and what they may do. */
|
|
75
|
+
const ADMIN_ONLY_USER_COLUMNS = ["role", "phone"]
|
|
76
|
+
const byRole = roles()
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* signet-db's DEFAULT_ROLES (admin: all; staff: all but delete; readonly:
|
|
80
|
+
* look), except that only an admin writes a user's role or phone, so staff
|
|
81
|
+
* cannot promote themselves or take over an account.
|
|
82
|
+
*/
|
|
83
|
+
const adminAuthorize: Authorize<AdminContext> = (ctx, check) =>
|
|
84
|
+
check.table === "users" &&
|
|
85
|
+
ctx.role !== "admin" &&
|
|
86
|
+
Object.keys(check.input ?? {}).some((k) => ADMIN_ONLY_USER_COLUMNS.includes(k))
|
|
87
|
+
? false
|
|
88
|
+
: byRole(ctx, check)
|
|
89
|
+
|
|
90
|
+
export type Deps = {
|
|
91
|
+
db: Db
|
|
92
|
+
/** Raw SQL with `?` placeholders, for signet-payments' store. */
|
|
93
|
+
query: (sql: string, params: unknown[]) => Record<string, unknown>[]
|
|
94
|
+
kv: KeyValue
|
|
95
|
+
/** Sends one-time codes. Default: printed to the console, development only. */
|
|
96
|
+
sms?: SmsSender
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Everything the routes use, built once per process. */
|
|
100
|
+
export function createServices({ db, query, kv, sms }: Deps) {
|
|
101
|
+
const orm = db.orm
|
|
102
|
+
const sessions = {
|
|
103
|
+
cookieName: "session",
|
|
104
|
+
secret: env.SESSION_SECRET,
|
|
105
|
+
store: kvSessionStore(kv),
|
|
106
|
+
}
|
|
107
|
+
const rateLimit = kvRateLimitStore(kv)
|
|
108
|
+
const otp = {
|
|
109
|
+
kv,
|
|
110
|
+
secret: env.OTP_SECRET,
|
|
111
|
+
// devSmsSender throws in staging and production: plug in a real sender
|
|
112
|
+
// there, e.g. smsSenderFor(msg91Sms({ ... }), { ... }) from notify/channels.
|
|
113
|
+
sender: sms ?? devSmsSender({ appEnv: env.APP_ENV }),
|
|
114
|
+
rateLimit,
|
|
115
|
+
}
|
|
116
|
+
const notifier = createNotifier({
|
|
117
|
+
channels: {},
|
|
118
|
+
templates,
|
|
119
|
+
store: kvNotifyStore(kv),
|
|
120
|
+
recipients: async (id) => {
|
|
121
|
+
const u = orm.select().from(schema.users).where(eq(schema.users.id, id)).get()
|
|
122
|
+
return u ? { phone: u.phone, ...(u.email ? { email: u.email } : {}) } : null
|
|
123
|
+
},
|
|
124
|
+
})
|
|
125
|
+
const entitlements = createEntitlements(db, {
|
|
126
|
+
plans,
|
|
127
|
+
default: "free",
|
|
128
|
+
tables: schema,
|
|
129
|
+
// Gateway plan ids → your plans, e.g. a Razorpay plan_id.
|
|
130
|
+
billing: { plans: { plan_pro_monthly: "pro" } },
|
|
131
|
+
})
|
|
132
|
+
if (env.BILLING === "fake" && (env.APP_ENV === "production" || env.APP_ENV === "staging"))
|
|
133
|
+
throw new Error(`BILLING=fake switches plans for free; not allowed in ${env.APP_ENV}.`)
|
|
134
|
+
const payments = createPayments({
|
|
135
|
+
gateways:
|
|
136
|
+
env.BILLING === "razorpay" && env.RAZORPAY_KEY_ID && env.RAZORPAY_KEY_SECRET
|
|
137
|
+
? [
|
|
138
|
+
razorpay({
|
|
139
|
+
keyId: env.RAZORPAY_KEY_ID,
|
|
140
|
+
keySecret: env.RAZORPAY_KEY_SECRET,
|
|
141
|
+
...(env.RAZORPAY_WEBHOOK_SECRET
|
|
142
|
+
? { webhookSecret: env.RAZORPAY_WEBHOOK_SECRET }
|
|
143
|
+
: {}),
|
|
144
|
+
}),
|
|
145
|
+
]
|
|
146
|
+
: [],
|
|
147
|
+
db: sqlStore({ query: async (s, p) => query(s, p) }, { dialect: "sqlite" }),
|
|
148
|
+
// Each subscription event moves the subject's plan; link the subject at
|
|
149
|
+
// checkout with the gateway's notes (see README, "Taking real payments").
|
|
150
|
+
onEvent: async (event) => {
|
|
151
|
+
await entitlements.applyBillingEvent(event)
|
|
152
|
+
},
|
|
153
|
+
})
|
|
154
|
+
return {
|
|
155
|
+
db,
|
|
156
|
+
orm,
|
|
157
|
+
kv,
|
|
158
|
+
sessions,
|
|
159
|
+
rateLimit,
|
|
160
|
+
otp,
|
|
161
|
+
apiKeys: kvApiKeyStore(kv),
|
|
162
|
+
notifier,
|
|
163
|
+
entitlements,
|
|
164
|
+
payments,
|
|
165
|
+
privacy: createPrivacy(db, {
|
|
166
|
+
tables: schema,
|
|
167
|
+
// What export covers and erasure deletes, children before parents.
|
|
168
|
+
userTables: [schema.feedback, [schema.users, schema.users.id]],
|
|
169
|
+
respondWithinMs: 30 * 86_400_000,
|
|
170
|
+
}),
|
|
171
|
+
growth: createGrowth(db, { tables: schema }),
|
|
172
|
+
// Orgs, roles (owner, admin, member) and invites. Add roles with
|
|
173
|
+
// `roles: defineRoles({ ...DEFAULT_ORG_ROLES, ... })`.
|
|
174
|
+
orgs: createOrgs(db, { tables: schema }),
|
|
175
|
+
/** The org switch cookie: Secure everywhere but local http. */
|
|
176
|
+
orgCookie: { secure: env.APP_ENV !== "development" },
|
|
177
|
+
admin: defineAdmin(schema, {
|
|
178
|
+
authorize: adminAuthorize,
|
|
179
|
+
// Per table by SQL name: search, readonly, hidden columns, row actions.
|
|
180
|
+
tables: { kv: false, idempotency_keys: false },
|
|
181
|
+
}),
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export type Services = ReturnType<typeof createServices>
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://biomejs.dev/schemas/2.5.14/schema.json",
|
|
3
|
+
"vcs": {
|
|
4
|
+
"enabled": true,
|
|
5
|
+
"clientKind": "git",
|
|
6
|
+
"useIgnoreFile": true
|
|
7
|
+
},
|
|
8
|
+
"files": {
|
|
9
|
+
"ignoreUnknown": true,
|
|
10
|
+
"includes": ["**", "!**/routeTree.gen.ts", "!drizzle", "!**/*.md"]
|
|
11
|
+
},
|
|
12
|
+
"formatter": {
|
|
13
|
+
"enabled": true,
|
|
14
|
+
"indentStyle": "space",
|
|
15
|
+
"indentWidth": 2,
|
|
16
|
+
"lineWidth": 100
|
|
17
|
+
},
|
|
18
|
+
"javascript": {
|
|
19
|
+
"formatter": {
|
|
20
|
+
"quoteStyle": "double",
|
|
21
|
+
"semicolons": "asNeeded"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"linter": {
|
|
25
|
+
"enabled": true,
|
|
26
|
+
"rules": {
|
|
27
|
+
"correctness": {
|
|
28
|
+
"useExhaustiveDependencies": "warn",
|
|
29
|
+
"useHookAtTopLevel": "error"
|
|
30
|
+
},
|
|
31
|
+
"suspicious": {
|
|
32
|
+
"noExplicitAny": "warn"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"assist": {
|
|
37
|
+
"actions": {
|
|
38
|
+
"source": {
|
|
39
|
+
"organizeImports": "on"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"css": {
|
|
44
|
+
"parser": {
|
|
45
|
+
"cssModules": false,
|
|
46
|
+
"allowWrongLineComments": false,
|
|
47
|
+
"tailwindDirectives": true
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
CREATE TABLE `audit_log` (
|
|
2
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
3
|
+
`at` integer DEFAULT (cast((julianday('now') - 2440587.5) * 86400000 as integer)) NOT NULL,
|
|
4
|
+
`actor_type` text NOT NULL,
|
|
5
|
+
`actor_id` text NOT NULL,
|
|
6
|
+
`action` text NOT NULL,
|
|
7
|
+
`table_name` text NOT NULL,
|
|
8
|
+
`row_id` text,
|
|
9
|
+
`before` text,
|
|
10
|
+
`after` text
|
|
11
|
+
);
|
|
12
|
+
--> statement-breakpoint
|
|
13
|
+
CREATE TABLE `consents` (
|
|
14
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
15
|
+
`subject` text NOT NULL,
|
|
16
|
+
`purpose` text NOT NULL,
|
|
17
|
+
`notice_version` text NOT NULL,
|
|
18
|
+
`source` text,
|
|
19
|
+
`given_at` integer NOT NULL,
|
|
20
|
+
`withdrawn_at` integer
|
|
21
|
+
);
|
|
22
|
+
--> statement-breakpoint
|
|
23
|
+
CREATE INDEX `consents_subject` ON `consents` (`subject`,`purpose`);--> statement-breakpoint
|
|
24
|
+
CREATE TABLE `data_requests` (
|
|
25
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
26
|
+
`subject` text NOT NULL,
|
|
27
|
+
`kind` text NOT NULL,
|
|
28
|
+
`status` text DEFAULT 'pending' NOT NULL,
|
|
29
|
+
`requested_at` integer NOT NULL,
|
|
30
|
+
`due_at` integer,
|
|
31
|
+
`closed_at` integer,
|
|
32
|
+
`closed_by` text,
|
|
33
|
+
`note` text,
|
|
34
|
+
`result` text
|
|
35
|
+
);
|
|
36
|
+
--> statement-breakpoint
|
|
37
|
+
CREATE INDEX `data_requests_subject` ON `data_requests` (`subject`);--> statement-breakpoint
|
|
38
|
+
CREATE TABLE `entitlement_overrides` (
|
|
39
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
40
|
+
`subject` text NOT NULL,
|
|
41
|
+
`kind` text NOT NULL,
|
|
42
|
+
`key` text NOT NULL,
|
|
43
|
+
`value` integer,
|
|
44
|
+
`expires_at` integer,
|
|
45
|
+
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5) * 86400000 as integer)) NOT NULL
|
|
46
|
+
);
|
|
47
|
+
--> statement-breakpoint
|
|
48
|
+
CREATE INDEX `entitlement_overrides_subject` ON `entitlement_overrides` (`subject`);--> statement-breakpoint
|
|
49
|
+
CREATE TABLE `feedback` (
|
|
50
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
51
|
+
`subject` text,
|
|
52
|
+
`kind` text NOT NULL,
|
|
53
|
+
`message` text NOT NULL,
|
|
54
|
+
`rating` integer,
|
|
55
|
+
`page` text,
|
|
56
|
+
`meta` text,
|
|
57
|
+
`status` text DEFAULT 'new' NOT NULL,
|
|
58
|
+
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5) * 86400000 as integer)) NOT NULL
|
|
59
|
+
);
|
|
60
|
+
--> statement-breakpoint
|
|
61
|
+
CREATE TABLE `idempotency_keys` (
|
|
62
|
+
`scope` text NOT NULL,
|
|
63
|
+
`key` text NOT NULL,
|
|
64
|
+
`status` text NOT NULL,
|
|
65
|
+
`result` text,
|
|
66
|
+
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5) * 86400000 as integer)) NOT NULL,
|
|
67
|
+
`expires_at` integer NOT NULL,
|
|
68
|
+
PRIMARY KEY(`scope`, `key`)
|
|
69
|
+
);
|
|
70
|
+
--> statement-breakpoint
|
|
71
|
+
CREATE TABLE `invites` (
|
|
72
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
73
|
+
`token_hash` text NOT NULL,
|
|
74
|
+
`email` text,
|
|
75
|
+
`invited_by` text NOT NULL,
|
|
76
|
+
`scope` text,
|
|
77
|
+
`role` text,
|
|
78
|
+
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5) * 86400000 as integer)) NOT NULL,
|
|
79
|
+
`expires_at` integer NOT NULL,
|
|
80
|
+
`accepted_at` integer,
|
|
81
|
+
`accepted_by` text,
|
|
82
|
+
`revoked_at` integer
|
|
83
|
+
);
|
|
84
|
+
--> statement-breakpoint
|
|
85
|
+
CREATE UNIQUE INDEX `invites_token` ON `invites` (`token_hash`);--> statement-breakpoint
|
|
86
|
+
CREATE TABLE `kv` (
|
|
87
|
+
`key` text PRIMARY KEY NOT NULL,
|
|
88
|
+
`value` text NOT NULL,
|
|
89
|
+
`expires_at` integer
|
|
90
|
+
);
|
|
91
|
+
--> statement-breakpoint
|
|
92
|
+
CREATE TABLE `marks` (
|
|
93
|
+
`subject` text NOT NULL,
|
|
94
|
+
`key` text NOT NULL,
|
|
95
|
+
`at` integer DEFAULT (cast((julianday('now') - 2440587.5) * 86400000 as integer)) NOT NULL,
|
|
96
|
+
PRIMARY KEY(`subject`, `key`)
|
|
97
|
+
);
|
|
98
|
+
--> statement-breakpoint
|
|
99
|
+
CREATE TABLE `referral_codes` (
|
|
100
|
+
`subject` text PRIMARY KEY NOT NULL,
|
|
101
|
+
`code` text NOT NULL,
|
|
102
|
+
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5) * 86400000 as integer)) NOT NULL
|
|
103
|
+
);
|
|
104
|
+
--> statement-breakpoint
|
|
105
|
+
CREATE UNIQUE INDEX `referral_codes_code` ON `referral_codes` (`code`);--> statement-breakpoint
|
|
106
|
+
CREATE TABLE `referrals` (
|
|
107
|
+
`referee` text PRIMARY KEY NOT NULL,
|
|
108
|
+
`referrer` text NOT NULL,
|
|
109
|
+
`code` text NOT NULL,
|
|
110
|
+
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5) * 86400000 as integer)) NOT NULL,
|
|
111
|
+
`converted_at` integer,
|
|
112
|
+
`rewarded_at` integer
|
|
113
|
+
);
|
|
114
|
+
--> statement-breakpoint
|
|
115
|
+
CREATE INDEX `referrals_referrer` ON `referrals` (`referrer`);--> statement-breakpoint
|
|
116
|
+
CREATE TABLE `subject_plans` (
|
|
117
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
118
|
+
`subject` text NOT NULL,
|
|
119
|
+
`plan` text NOT NULL,
|
|
120
|
+
`status` text NOT NULL,
|
|
121
|
+
`gateway` text NOT NULL,
|
|
122
|
+
`subscription_id` text NOT NULL,
|
|
123
|
+
`current_period_end` integer,
|
|
124
|
+
`grace_until` integer,
|
|
125
|
+
`event_at` integer NOT NULL,
|
|
126
|
+
`updated_at` integer DEFAULT (cast((julianday('now') - 2440587.5) * 86400000 as integer)) NOT NULL
|
|
127
|
+
);
|
|
128
|
+
--> statement-breakpoint
|
|
129
|
+
CREATE INDEX `subject_plans_subject` ON `subject_plans` (`subject`);--> statement-breakpoint
|
|
130
|
+
CREATE TABLE `usage_counters` (
|
|
131
|
+
`subject` text NOT NULL,
|
|
132
|
+
`key` text NOT NULL,
|
|
133
|
+
`period` text NOT NULL,
|
|
134
|
+
`used` integer DEFAULT 0 NOT NULL,
|
|
135
|
+
PRIMARY KEY(`subject`, `key`, `period`)
|
|
136
|
+
);
|
|
137
|
+
--> statement-breakpoint
|
|
138
|
+
CREATE TABLE `users` (
|
|
139
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
140
|
+
`phone` text NOT NULL,
|
|
141
|
+
`name` text,
|
|
142
|
+
`email` text,
|
|
143
|
+
`role` text DEFAULT 'user' NOT NULL,
|
|
144
|
+
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5) * 86400000 as integer)) NOT NULL,
|
|
145
|
+
`updated_at` integer DEFAULT (cast((julianday('now') - 2440587.5) * 86400000 as integer)) NOT NULL
|
|
146
|
+
);
|
|
147
|
+
--> statement-breakpoint
|
|
148
|
+
CREATE UNIQUE INDEX `users_phone_unique` ON `users` (`phone`);--> statement-breakpoint
|
|
149
|
+
CREATE TABLE `waitlist` (
|
|
150
|
+
`email` text PRIMARY KEY NOT NULL,
|
|
151
|
+
`source` text,
|
|
152
|
+
`referral_code` text,
|
|
153
|
+
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5) * 86400000 as integer)) NOT NULL,
|
|
154
|
+
`invited_at` integer
|
|
155
|
+
);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
CREATE TABLE `invitations` (
|
|
2
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
3
|
+
`org_id` text NOT NULL,
|
|
4
|
+
`token_hash` text NOT NULL,
|
|
5
|
+
`email` text,
|
|
6
|
+
`role` text NOT NULL,
|
|
7
|
+
`invited_by` text NOT NULL,
|
|
8
|
+
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5) * 86400000 as integer)) NOT NULL,
|
|
9
|
+
`expires_at` integer NOT NULL,
|
|
10
|
+
`accepted_at` integer,
|
|
11
|
+
`accepted_by` text,
|
|
12
|
+
`revoked_at` integer
|
|
13
|
+
);
|
|
14
|
+
--> statement-breakpoint
|
|
15
|
+
CREATE UNIQUE INDEX `invitations_token` ON `invitations` (`token_hash`);--> statement-breakpoint
|
|
16
|
+
CREATE INDEX `invitations_org` ON `invitations` (`org_id`);--> statement-breakpoint
|
|
17
|
+
CREATE TABLE `memberships` (
|
|
18
|
+
`org_id` text NOT NULL,
|
|
19
|
+
`user_id` text NOT NULL,
|
|
20
|
+
`role` text NOT NULL,
|
|
21
|
+
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5) * 86400000 as integer)) NOT NULL,
|
|
22
|
+
PRIMARY KEY(`org_id`, `user_id`)
|
|
23
|
+
);
|
|
24
|
+
--> statement-breakpoint
|
|
25
|
+
CREATE INDEX `memberships_user` ON `memberships` (`user_id`);--> statement-breakpoint
|
|
26
|
+
CREATE TABLE `org_roles` (
|
|
27
|
+
`org_id` text NOT NULL,
|
|
28
|
+
`name` text NOT NULL,
|
|
29
|
+
`permissions` text NOT NULL,
|
|
30
|
+
`updated_at` integer DEFAULT (cast((julianday('now') - 2440587.5) * 86400000 as integer)) NOT NULL,
|
|
31
|
+
PRIMARY KEY(`org_id`, `name`)
|
|
32
|
+
);
|
|
33
|
+
--> statement-breakpoint
|
|
34
|
+
CREATE TABLE `organizations` (
|
|
35
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
36
|
+
`name` text NOT NULL,
|
|
37
|
+
`slug` text NOT NULL,
|
|
38
|
+
`domain` text,
|
|
39
|
+
`theme` text,
|
|
40
|
+
`brand_color` text,
|
|
41
|
+
`personal` integer DEFAULT false NOT NULL,
|
|
42
|
+
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5) * 86400000 as integer)) NOT NULL,
|
|
43
|
+
`updated_at` integer DEFAULT (cast((julianday('now') - 2440587.5) * 86400000 as integer)) NOT NULL
|
|
44
|
+
);
|
|
45
|
+
--> statement-breakpoint
|
|
46
|
+
CREATE UNIQUE INDEX `organizations_slug` ON `organizations` (`slug`);--> statement-breakpoint
|
|
47
|
+
CREATE UNIQUE INDEX `organizations_domain` ON `organizations` (`domain`);
|