@orbclub/create-app 0.0.0 → 0.1.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.
Files changed (36) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +30 -0
  3. package/bin/create-orb-app.js +410 -0
  4. package/bin/node-version.js +6 -0
  5. package/bin/package-manager.js +87 -0
  6. package/bin/sdk-version.js +3 -0
  7. package/package.json +35 -1
  8. package/template/.env.local.example +10 -0
  9. package/template/AGENTS.md +105 -0
  10. package/template/README.md +56 -0
  11. package/template/eslint.config.mjs +11 -0
  12. package/template/gitignore +26 -0
  13. package/template/next.config.ts +25 -0
  14. package/template/package.json +29 -0
  15. package/template/pnpm-workspace.yaml +15 -0
  16. package/template/src/app/.well-known/orb-siwo.json/route.ts +23 -0
  17. package/template/src/app/api/local-sign-in/init/route.ts +12 -0
  18. package/template/src/app/api/local-sign-in/local-sign-in.ts +50 -0
  19. package/template/src/app/api/local-sign-in/status/route.ts +12 -0
  20. package/template/src/app/api/orb/route-validation.ts +123 -0
  21. package/template/src/app/api/orb/user/route.ts +44 -0
  22. package/template/src/app/api/route-security.ts +105 -0
  23. package/template/src/app/api/site-session/bind/route.ts +82 -0
  24. package/template/src/app/api/site-session/binding/route.ts +35 -0
  25. package/template/src/app/api/site-session/end/route.ts +30 -0
  26. package/template/src/app/api/site-session/renew/route.ts +71 -0
  27. package/template/src/app/api/site-session/site-session.ts +152 -0
  28. package/template/src/app/globals.css +196 -0
  29. package/template/src/app/home.tsx +115 -0
  30. package/template/src/app/layout.tsx +24 -0
  31. package/template/src/app/page.tsx +12 -0
  32. package/template/src/lib/orb-session.ts +703 -0
  33. package/template/src/lib/sign-in.ts +61 -0
  34. package/template/src/lib/site-origin.ts +35 -0
  35. package/template/src/lib/use-orb-session.ts +26 -0
  36. package/template/tsconfig.json +30 -0
@@ -0,0 +1,61 @@
1
+ import { isLoopbackOrigin } from "@orbclub/apps-sdk/site";
2
+
3
+ import { getSiteSignInOrigin } from "./site-origin";
4
+
5
+ type Environment = Readonly<Record<string, string | undefined>>;
6
+
7
+ /**
8
+ * How a browser outside the Orb app signs in, derived from server
9
+ * configuration only (never from NODE_ENV or request input):
10
+ *
11
+ * - `site`: browser-site Sign in with Orb, for the deployed HTTPS origin.
12
+ * - `local`: local development sign-in through this app's
13
+ * `/api/local-sign-in/*` routes, on any `http://` loopback origin, so the
14
+ * dev server's port does not matter.
15
+ * - `none`: sign-in outside Orb is not configured; `message` says why.
16
+ */
17
+ export type SignInSetup =
18
+ | { flow: "site"; origin: string }
19
+ | { flow: "local" }
20
+ | { flow: "none"; message: string };
21
+
22
+ const SESSION_SECRET = /^[A-Za-z0-9_-]{43}$/;
23
+
24
+ /**
25
+ * Whether a value is a canonical `http://` loopback origin: `localhost`,
26
+ * `127.0.0.1` or `[::1]` with an optional non-default port.
27
+ */
28
+ export { isLoopbackOrigin };
29
+
30
+ /** The local sign-in session key when it is a 32-byte base64url value. */
31
+ export function getLocalSessionSecret(
32
+ environment: Environment = process.env,
33
+ ): string | null {
34
+ const secret = environment.ORB_LOCAL_SIWO_SESSION_SECRET?.trim();
35
+ return secret && SESSION_SECRET.test(secret) ? secret : null;
36
+ }
37
+
38
+ export function getSignInSetup(
39
+ environment: Environment = process.env,
40
+ ): SignInSetup {
41
+ const siteOrigin = getSiteSignInOrigin(environment);
42
+ if (siteOrigin) return { flow: "site", origin: siteOrigin };
43
+
44
+ const configured = environment.ORB_APP_ORIGIN?.trim().replace(/\/$/, "");
45
+ if (configured && !isLoopbackOrigin(configured)) {
46
+ return {
47
+ flow: "none",
48
+ message:
49
+ "ORB_APP_ORIGIN must be an https:// origin, or http://localhost for local development.",
50
+ };
51
+ }
52
+
53
+ return getLocalSessionSecret(environment)
54
+ ? { flow: "local" }
55
+ : {
56
+ flow: "none",
57
+ message: configured
58
+ ? "Local sign-in needs ORB_LOCAL_SIWO_SESSION_SECRET. See .env.local.example."
59
+ : "Set ORB_APP_ORIGIN to your https:// origin, or ORB_LOCAL_SIWO_SESSION_SECRET for local development. See .env.local.example.",
60
+ };
61
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The origin this deployment signs in as with browser-site Sign in with Orb.
3
+ *
4
+ * `ORB_APP_ORIGIN` must be the exact public HTTPS origin the site is served
5
+ * from (scheme and host, plus any non-default port; no path). The Orb backend
6
+ * compares it with the signing-in page's `Origin`, so preview deployments on
7
+ * other origins cannot sign in. Returns null when it is unset or not an HTTPS
8
+ * origin; the manifest route then answers 503 and sign-in is unavailable.
9
+ */
10
+ export function getSiteSignInOrigin(
11
+ environment: Readonly<Record<string, string | undefined>> = process.env,
12
+ ): string | null {
13
+ const configured = environment.ORB_APP_ORIGIN?.trim();
14
+ if (!configured) return null;
15
+
16
+ let parsed: URL;
17
+ try {
18
+ parsed = new URL(configured);
19
+ } catch {
20
+ return null;
21
+ }
22
+
23
+ if (
24
+ parsed.protocol !== "https:" ||
25
+ parsed.username ||
26
+ parsed.password ||
27
+ parsed.pathname !== "/" ||
28
+ parsed.search ||
29
+ parsed.hash
30
+ ) {
31
+ return null;
32
+ }
33
+
34
+ return parsed.origin;
35
+ }
@@ -0,0 +1,26 @@
1
+ import { useEffect, useState, useSyncExternalStore } from "react";
2
+
3
+ import { OrbSession } from "./orb-session";
4
+ import type { SignInSetup } from "./sign-in";
5
+
6
+ export function useOrbSession(setup: SignInSetup) {
7
+ const [session] = useState(() => new OrbSession(setup));
8
+
9
+ useEffect(() => {
10
+ session.start();
11
+ return () => session.stop();
12
+ }, [session]);
13
+
14
+ const state = useSyncExternalStore(
15
+ session.subscribe,
16
+ session.getSnapshot,
17
+ session.getServerSnapshot,
18
+ );
19
+
20
+ return {
21
+ ...state,
22
+ signIn: session.signIn,
23
+ cancel: session.cancel,
24
+ signOut: session.signOut,
25
+ };
26
+ }
@@ -0,0 +1,30 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2017",
4
+ "lib": ["dom", "dom.iterable", "esnext"],
5
+ "allowJs": true,
6
+ "skipLibCheck": true,
7
+ "strict": true,
8
+ "noEmit": true,
9
+ "esModuleInterop": true,
10
+ "module": "esnext",
11
+ "moduleResolution": "bundler",
12
+ "resolveJsonModule": true,
13
+ "isolatedModules": true,
14
+ "jsx": "react-jsx",
15
+ "incremental": true,
16
+ "plugins": [{ "name": "next" }],
17
+ "paths": {
18
+ "@/*": ["./src/*"]
19
+ }
20
+ },
21
+ "include": [
22
+ "next-env.d.ts",
23
+ "**/*.ts",
24
+ "**/*.tsx",
25
+ ".next/types/**/*.ts",
26
+ ".next/dev/types/**/*.ts",
27
+ "**/*.mts"
28
+ ],
29
+ "exclude": ["node_modules"]
30
+ }