@0x0501/mystack 0.0.0-stage → 0.1.0-bootstrap.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/README.md +68 -2
- package/assets/auth.sqlite.schema.ts +479 -0
- package/assets/bun-sqlite.test.ts +46 -0
- package/assets/d1.test.ts +41 -0
- package/assets/drizzle.config.ts +2 -0
- package/assets/generate-auth-schema.mjs +25 -0
- package/assets/platform.sqlite.schema.ts +46 -0
- package/assets/polar-checkout.ts +10 -0
- package/assets/polar-route.ts +19 -0
- package/assets/polar.test.ts +30 -0
- package/assets/polar.ts +12 -0
- package/assets/purchase.bun-sqlite.ts +38 -0
- package/assets/purchase.sqlite.ts +39 -0
- package/assets/sqlite-migrations/0000_thin_phalanx.sql +295 -0
- package/assets/sqlite-migrations/meta/0000_snapshot.json +2058 -0
- package/assets/sqlite-migrations/meta/_journal.json +13 -0
- package/assets/turso.test.ts +40 -0
- package/package.json +44 -5
- package/src/adapters/database.mjs +448 -0
- package/src/adapters/deployment.mjs +101 -0
- package/src/adapters/email.mjs +75 -0
- package/src/adapters/payments.mjs +270 -0
- package/src/catalog.mjs +128 -0
- package/src/cli.mjs +294 -0
- package/src/generate.mjs +183 -0
- package/src/template.mjs +93 -0
- package/template/.env.docker +16 -0
- package/template/.env.example +67 -0
- package/template/DESIGN.md +58 -0
- package/template/LICENSE +21 -0
- package/template/biome.json +46 -0
- package/template/docker-compose.yml +47 -0
- package/template/docs/project-guide.md +61 -0
- package/template/drizzle/0000_create-app-role.sql +54 -0
- package/template/drizzle/0001_add-rls-context.sql +21 -0
- package/template/drizzle/0002_platform_tables.sql +320 -0
- package/template/drizzle/meta/0002_snapshot.json +2125 -0
- package/template/drizzle/meta/_journal.json +27 -0
- package/template/drizzle.config.ts +25 -0
- package/template/e2e/authenticated-ui.spec.ts +40 -0
- package/template/e2e/headless-design.spec.ts +66 -0
- package/template/e2e/navigation-loading.spec.ts +70 -0
- package/template/e2e/theme-responsive.spec.ts +260 -0
- package/template/gitignore +24 -0
- package/template/messages/de.json +212 -0
- package/template/messages/en.json +212 -0
- package/template/package.json +101 -0
- package/template/paraglide.config.ts +49 -0
- package/template/playwright.config.ts +58 -0
- package/template/project.inlang/settings.json +12 -0
- package/template/public/drizzle.svg +1 -0
- package/template/public/favicon.ico +0 -0
- package/template/public/logo192.png +0 -0
- package/template/public/logo512.png +0 -0
- package/template/public/manifest.json +25 -0
- package/template/public/robots.txt +3 -0
- package/template/scripts/check-client-bundle.ts +150 -0
- package/template/scripts/check-server-fns.ts +290 -0
- package/template/scripts/check-sql-raw.ts +50 -0
- package/template/scripts/compile-paraglide.ts +12 -0
- package/template/scripts/postgres/README.md +76 -0
- package/template/scripts/postgres/create-app-role.sh +60 -0
- package/template/scripts/seed-local.ts +331 -0
- package/template/scripts/validate-prod-env.ts +53 -0
- package/template/src/__tests__/README.md +9 -0
- package/template/src/__tests__/account-security.test.ts +664 -0
- package/template/src/__tests__/admin-http-surface.test.ts +311 -0
- package/template/src/__tests__/admin-peer-protection.test.ts +178 -0
- package/template/src/__tests__/auth-harness.ts +104 -0
- package/template/src/__tests__/auth-rate-limit.test.ts +43 -0
- package/template/src/__tests__/auth-redirect.test.ts +120 -0
- package/template/src/__tests__/body-limit.test.ts +47 -0
- package/template/src/__tests__/creem.test.ts +62 -0
- package/template/src/__tests__/demo-checkout.test.ts +141 -0
- package/template/src/__tests__/email-locale.test.ts +110 -0
- package/template/src/__tests__/global-setup.ts +80 -0
- package/template/src/__tests__/input-rules.test.ts +0 -0
- package/template/src/__tests__/message-parity.test.ts +38 -0
- package/template/src/__tests__/navigation-loading.test.tsx +252 -0
- package/template/src/__tests__/nowpayments.test.ts +106 -0
- package/template/src/__tests__/paraglide-url-contract.test.ts +87 -0
- package/template/src/__tests__/purchase-fulfillment.test.ts +204 -0
- package/template/src/__tests__/query-unauthorized-redirect.test.ts +95 -0
- package/template/src/__tests__/rls-policy.test.ts +120 -0
- package/template/src/__tests__/same-page-locale-href.test.ts +47 -0
- package/template/src/__tests__/search-params-oauth.test.ts +57 -0
- package/template/src/__tests__/security-headers.test.ts +12 -0
- package/template/src/__tests__/server-fn-error-contract.test.ts +173 -0
- package/template/src/__tests__/stripe.test.ts +84 -0
- package/template/src/__tests__/test-db.ts +32 -0
- package/template/src/__tests__/test-rls-db.ts +23 -0
- package/template/src/__tests__/user-update-guard.test.ts +109 -0
- package/template/src/components/LocaleSwitcher.tsx +79 -0
- package/template/src/components/ThemeToggle.tsx +47 -0
- package/template/src/components/auth/social.tsx +90 -0
- package/template/src/components/auth/turnstile.tsx +67 -0
- package/template/src/components/root/navigation-progress.tsx +32 -0
- package/template/src/components/root/not-found.tsx +20 -0
- package/template/src/components/root/pending.tsx +9 -0
- package/template/src/components/root/root-document.tsx +37 -0
- package/template/src/components/root/root-error.tsx +34 -0
- package/template/src/components/shells.tsx +201 -0
- package/template/src/components/ui/styles.ts +9 -0
- package/template/src/db/auth.schema.ts +455 -0
- package/template/src/db/helper.ts +38 -0
- package/template/src/db/index.ts +15 -0
- package/template/src/db/platform.schema.ts +122 -0
- package/template/src/db/schema.ts +2 -0
- package/template/src/env.ts +65 -0
- package/template/src/hooks/use-theme.ts +32 -0
- package/template/src/integrations/better-auth/header-user.tsx +36 -0
- package/template/src/integrations/better-auth/session-query.ts +11 -0
- package/template/src/integrations/react-email/PasswordOtpEmail.tsx +62 -0
- package/template/src/integrations/react-email/ResetPasswordEmail.tsx +64 -0
- package/template/src/integrations/react-email/VerifyEmail.tsx +72 -0
- package/template/src/integrations/react-email/theme.ts +75 -0
- package/template/src/integrations/tanstack-query/devtools.tsx +6 -0
- package/template/src/integrations/tanstack-query/root-provider.tsx +60 -0
- package/template/src/lib/auth-client.ts +27 -0
- package/template/src/lib/auth-paths.ts +94 -0
- package/template/src/lib/auth-plugins/existing-email-signup.ts +86 -0
- package/template/src/lib/auth-plugins/field-rules.ts +84 -0
- package/template/src/lib/auth-plugins/social-two-factor.ts +194 -0
- package/template/src/lib/auth-timing.ts +9 -0
- package/template/src/lib/auth.ts +279 -0
- package/template/src/lib/captcha.ts +11 -0
- package/template/src/lib/email.tsx +162 -0
- package/template/src/lib/github.ts +18 -0
- package/template/src/lib/locale-cookie.ts +12 -0
- package/template/src/lib/localized-pages.ts +25 -0
- package/template/src/lib/oauth-metadata.ts +19 -0
- package/template/src/lib/permissions.ts +29 -0
- package/template/src/lib/security-headers.ts +20 -0
- package/template/src/lib/site.ts +59 -0
- package/template/src/lib/theme.ts +42 -0
- package/template/src/lib/user-update-guard.ts +35 -0
- package/template/src/middlewares/admin.ts +46 -0
- package/template/src/middlewares/auth-rate-limit.ts +37 -0
- package/template/src/middlewares/better-auth.ts +15 -0
- package/template/src/middlewares/body-limit.ts +62 -0
- package/template/src/middlewares/database.ts +13 -0
- package/template/src/middlewares/protected.ts +45 -0
- package/template/src/routeTree.gen.ts +536 -0
- package/template/src/router.tsx +53 -0
- package/template/src/routes/[.]well-known/oauth-authorization-server/api/auth.ts +18 -0
- package/template/src/routes/[.]well-known/oauth-protected-resource/index.ts +32 -0
- package/template/src/routes/__root.tsx +175 -0
- package/template/src/routes/admin/audit.tsx +74 -0
- package/template/src/routes/admin/index.tsx +7 -0
- package/template/src/routes/admin/oauth-apps.tsx +164 -0
- package/template/src/routes/admin/route.tsx +27 -0
- package/template/src/routes/admin/users.tsx +215 -0
- package/template/src/routes/api/auth/$.ts +14 -0
- package/template/src/routes/api/auth/[.]well-known/openid-configuration.ts +15 -0
- package/template/src/routes/api/webhooks/creem.ts +69 -0
- package/template/src/routes/api/webhooks/nowpayments.ts +62 -0
- package/template/src/routes/api/webhooks/stripe.ts +74 -0
- package/template/src/routes/dashboard/account.tsx +430 -0
- package/template/src/routes/dashboard/index.tsx +128 -0
- package/template/src/routes/dashboard/route.tsx +17 -0
- package/template/src/routes/forgot-password.tsx +65 -0
- package/template/src/routes/index.tsx +85 -0
- package/template/src/routes/oauth/consent.tsx +77 -0
- package/template/src/routes/reset-password.tsx +78 -0
- package/template/src/routes/sign-in.tsx +174 -0
- package/template/src/routes/sign-up.tsx +135 -0
- package/template/src/routes/two-factor.tsx +74 -0
- package/template/src/server/README.md +3 -0
- package/template/src/server/account-security.ts +163 -0
- package/template/src/server/admin-audit.ts +37 -0
- package/template/src/server/admin-users.ts +112 -0
- package/template/src/server/auth.ts +44 -0
- package/template/src/server/demo-checkout.ts +67 -0
- package/template/src/server/oauth-clients.ts +83 -0
- package/template/src/server/payment-toggles.ts +39 -0
- package/template/src/server.ts +20 -0
- package/template/src/services/README.md +3 -0
- package/template/src/services/account-security.ts +893 -0
- package/template/src/services/admin-security.ts +164 -0
- package/template/src/services/admin-users.ts +181 -0
- package/template/src/services/auth-rate-limit.ts +32 -0
- package/template/src/services/creem.ts +83 -0
- package/template/src/services/demo-checkout.ts +100 -0
- package/template/src/services/nowpayments.ts +154 -0
- package/template/src/services/oauth-client.ts +85 -0
- package/template/src/services/oauth-clients.ts +15 -0
- package/template/src/services/payment-providers.ts +157 -0
- package/template/src/services/payment-toggles.ts +48 -0
- package/template/src/services/purchase.ts +233 -0
- package/template/src/services/stripe.ts +106 -0
- package/template/src/start.ts +35 -0
- package/template/src/styles/layout.css +93 -0
- package/template/src/styles/theme.css +84 -0
- package/template/src/styles/ui.css +233 -0
- package/template/src/styles.css +90 -0
- package/template/src/utils/api-error.ts +129 -0
- package/template/src/utils/auth-errors.ts +157 -0
- package/template/src/utils/auth-redirect.ts +61 -0
- package/template/src/utils/body-limit.ts +84 -0
- package/template/src/utils/cn.ts +6 -0
- package/template/src/utils/input-rules.ts +172 -0
- package/template/src/utils/locale-paths.ts +18 -0
- package/template/src/utils/same-page-locale-href.ts +20 -0
- package/template/src/utils/search-params.ts +71 -0
- package/template/tsconfig.json +30 -0
- package/template/tsr.config.json +6 -0
- package/template/vite.config.ts +24 -0
- package/template/vitest.config.ts +26 -0
- package/template/worker-configuration.d.ts +14660 -0
- package/template/wrangler.jsonc +39 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { createServerFn } from "@tanstack/react-start";
|
|
2
|
+
import { getRequestHeaders } from "@tanstack/react-start/server";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { adminMiddleware } from "@/middlewares/admin";
|
|
5
|
+
import { logAdminAction } from "@/services/admin-security";
|
|
6
|
+
import {
|
|
7
|
+
createOAuthClientInputSchema,
|
|
8
|
+
oauthClientRegistrationBody,
|
|
9
|
+
} from "@/services/oauth-client";
|
|
10
|
+
import { deleteOAuthClientById } from "@/services/oauth-clients";
|
|
11
|
+
import { validated } from "@/utils/api-error";
|
|
12
|
+
|
|
13
|
+
type OAuthClientSummary = {
|
|
14
|
+
clientId: string;
|
|
15
|
+
name: string | null;
|
|
16
|
+
redirectUris: string[];
|
|
17
|
+
grantTypes: string[];
|
|
18
|
+
responseTypes: string[];
|
|
19
|
+
tokenEndpointAuthMethod: string | null;
|
|
20
|
+
scope: string | null;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const stringArray = (value: unknown) =>
|
|
24
|
+
Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
25
|
+
|
|
26
|
+
export const getOAuthClients = createServerFn({ method: "GET" })
|
|
27
|
+
.middleware([adminMiddleware])
|
|
28
|
+
.handler(async ({ context }) => {
|
|
29
|
+
const clients = await context.auth.api.getOAuthClients({
|
|
30
|
+
headers: getRequestHeaders(),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return (clients ?? []).map(
|
|
34
|
+
(client): OAuthClientSummary => ({
|
|
35
|
+
clientId: client.client_id,
|
|
36
|
+
name: client.client_name ?? null,
|
|
37
|
+
redirectUris: stringArray(client.redirect_uris),
|
|
38
|
+
grantTypes: stringArray(client.grant_types),
|
|
39
|
+
responseTypes: stringArray(client.response_types),
|
|
40
|
+
tokenEndpointAuthMethod: client.token_endpoint_auth_method ?? null,
|
|
41
|
+
scope: client.scope ?? null,
|
|
42
|
+
}),
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export const createOAuthClient = createServerFn({ method: "POST" })
|
|
47
|
+
.middleware([adminMiddleware])
|
|
48
|
+
.validator(validated(createOAuthClientInputSchema))
|
|
49
|
+
.handler(async ({ context, data }) => {
|
|
50
|
+
const client = await context.auth.api.adminCreateOAuthClient({
|
|
51
|
+
body: oauthClientRegistrationBody(data),
|
|
52
|
+
headers: getRequestHeaders(),
|
|
53
|
+
});
|
|
54
|
+
await logAdminAction(context.db, {
|
|
55
|
+
actorId: context.session.user.id,
|
|
56
|
+
action: "oauth_client.create",
|
|
57
|
+
targetType: "oauth_client",
|
|
58
|
+
targetId: client.client_id,
|
|
59
|
+
detail: { name: client.client_name ?? null },
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
clientId: client.client_id,
|
|
63
|
+
clientSecret: client.client_secret ?? null,
|
|
64
|
+
name: client.client_name ?? null,
|
|
65
|
+
redirectUris: client.redirect_uris ?? [],
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
export const deleteOAuthClient = createServerFn({ method: "POST" })
|
|
70
|
+
.middleware([adminMiddleware])
|
|
71
|
+
.validator(validated(z.object({ clientId: z.string().trim().min(1) })))
|
|
72
|
+
.handler(async ({ context, data }) => {
|
|
73
|
+
const deleted = await deleteOAuthClientById(context.db, data.clientId);
|
|
74
|
+
if (deleted) {
|
|
75
|
+
await logAdminAction(context.db, {
|
|
76
|
+
actorId: context.session.user.id,
|
|
77
|
+
action: "oauth_client.delete",
|
|
78
|
+
targetType: "oauth_client",
|
|
79
|
+
targetId: data.clientId,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return { ok: deleted };
|
|
83
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createServerFn } from "@tanstack/react-start";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { adminMiddleware } from "@/middlewares/admin";
|
|
4
|
+
import { databaseMiddleware } from "@/middlewares/database";
|
|
5
|
+
import { logAdminAction } from "@/services/admin-security";
|
|
6
|
+
import {
|
|
7
|
+
getPaymentToggles,
|
|
8
|
+
type PaymentToggles,
|
|
9
|
+
setPaymentToggles,
|
|
10
|
+
} from "@/services/payment-toggles";
|
|
11
|
+
import { validated } from "@/utils/api-error";
|
|
12
|
+
|
|
13
|
+
export const getPaymentMethodToggles = createServerFn({ method: "GET" })
|
|
14
|
+
.middleware([databaseMiddleware, adminMiddleware])
|
|
15
|
+
.handler(({ context }) => getPaymentToggles(context.db));
|
|
16
|
+
|
|
17
|
+
export const updatePaymentMethodToggles = createServerFn({ method: "POST" })
|
|
18
|
+
.middleware([databaseMiddleware, adminMiddleware])
|
|
19
|
+
.validator(
|
|
20
|
+
validated(
|
|
21
|
+
z.object({
|
|
22
|
+
stripe: z.boolean(),
|
|
23
|
+
creem: z.boolean(),
|
|
24
|
+
nowpayments: z.boolean(),
|
|
25
|
+
}),
|
|
26
|
+
),
|
|
27
|
+
)
|
|
28
|
+
.handler(async ({ context, data }) => {
|
|
29
|
+
const next = data as PaymentToggles;
|
|
30
|
+
await setPaymentToggles(context.db, next);
|
|
31
|
+
await logAdminAction(context.db, {
|
|
32
|
+
actorId: context.session.user.id,
|
|
33
|
+
action: "payment_toggle.change",
|
|
34
|
+
targetType: "system_config",
|
|
35
|
+
targetId: "payment_toggles",
|
|
36
|
+
detail: next,
|
|
37
|
+
});
|
|
38
|
+
return { ok: true as const, toggles: next };
|
|
39
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worker / SSR entry — Paraglide ambient locale + original Request handoff.
|
|
3
|
+
*
|
|
4
|
+
* Pass the ORIGINAL localized request into Start. Router `rewrite` does
|
|
5
|
+
* de-/re-localization; handing it an already-de-localized URL causes a 307 loop.
|
|
6
|
+
* paraglideMiddleware still sets ambient getLocale() for SSR messages.
|
|
7
|
+
*/
|
|
8
|
+
import handler, { createServerEntry } from "@tanstack/react-start/server-entry";
|
|
9
|
+
import { withSecurityHeaders } from "@/lib/security-headers";
|
|
10
|
+
import { paraglideMiddleware } from "./paraglide/server.js";
|
|
11
|
+
|
|
12
|
+
export default createServerEntry({
|
|
13
|
+
fetch: async (request) => {
|
|
14
|
+
return paraglideMiddleware(request, async () => {
|
|
15
|
+
// Original request — not the middleware-delocalized one.
|
|
16
|
+
const res = await handler.fetch(request);
|
|
17
|
+
return withSecurityHeaders(res);
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
});
|