flypod 0.6.0 → 0.7.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.
@@ -1,6 +1,6 @@
1
1
  // src/cli.ts
2
- import { readdir, readFile, stat } from "node:fs/promises";
3
- import { join, relative } from "node:path";
2
+ import { readdir, readFile as readFile2, stat } from "node:fs/promises";
3
+ import { join as join2, relative } from "node:path";
4
4
 
5
5
  // ../../node_modules/.bun/fflate@0.8.3/node_modules/fflate/esm/index.mjs
6
6
  import { createRequire } from "module";
@@ -645,6 +645,130 @@ function zipSync(data, opts) {
645
645
  return out;
646
646
  }
647
647
 
648
+ // src/cli/session.ts
649
+ import { readFile, unlink } from "node:fs/promises";
650
+
651
+ // src/cli/paths.ts
652
+ import { mkdir, rename, writeFile } from "node:fs/promises";
653
+ import { homedir, platform } from "node:os";
654
+ import { dirname, join } from "node:path";
655
+ function configDir(env = process.env) {
656
+ if (env.FLYPOD_CONFIG_DIR)
657
+ return env.FLYPOD_CONFIG_DIR;
658
+ const os = platform();
659
+ if (os === "darwin") {
660
+ return join(homedir(), "Library", "Application Support", "flypod");
661
+ }
662
+ if (os === "win32") {
663
+ const appData = env.APPDATA ?? join(homedir(), "AppData", "Roaming");
664
+ return join(appData, "flypod");
665
+ }
666
+ const xdg = env.XDG_CONFIG_HOME ?? join(homedir(), ".config");
667
+ return join(xdg, "flypod");
668
+ }
669
+ function sessionFilePath(env = process.env) {
670
+ return join(configDir(env), "session.json");
671
+ }
672
+ function projectsFilePath(env = process.env) {
673
+ return join(configDir(env), "projects.json");
674
+ }
675
+ async function atomicWriteFile(path, content) {
676
+ await mkdir(dirname(path), { recursive: true });
677
+ const tmp = `${path}.tmp`;
678
+ await writeFile(tmp, content, { mode: 384 });
679
+ await rename(tmp, path);
680
+ }
681
+
682
+ // src/cli/session.ts
683
+ async function loadSession(env) {
684
+ try {
685
+ const path = sessionFilePath(env);
686
+ const text = await readFile(path, "utf8");
687
+ const parsed = JSON.parse(text);
688
+ if (typeof parsed?.session_token === "string" && typeof parsed?.base_url === "string" && typeof parsed?.created_at === "number") {
689
+ return parsed;
690
+ }
691
+ return null;
692
+ } catch {
693
+ return null;
694
+ }
695
+ }
696
+ async function saveSession(session, env) {
697
+ const path = sessionFilePath(env);
698
+ await atomicWriteFile(path, `${JSON.stringify(session, null, 2)}
699
+ `);
700
+ return path;
701
+ }
702
+ async function clearSession(env) {
703
+ try {
704
+ await unlink(sessionFilePath(env));
705
+ return true;
706
+ } catch {
707
+ return false;
708
+ }
709
+ }
710
+
711
+ // src/cli/client.ts
712
+ var DEVICE_CLIENT_ID = "flypod-cli";
713
+ var DEVICE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
714
+ function resolveCredentials(env, session, overrides) {
715
+ const token = overrides?.token ?? overrides?.manageToken ?? env.FLYPOD_TOKEN ?? session?.session_token ?? env.FLYPOD_API_KEY;
716
+ const baseUrl = overrides?.baseUrl ?? session?.base_url ?? env.DEPLOY_URL ?? "https://flypod.dev";
717
+ return { token, baseUrl };
718
+ }
719
+ function buildClient(token, baseUrl, fetchImpl) {
720
+ async function request(method, path, init = {}) {
721
+ const url = new URL(path, baseUrl);
722
+ if (init.query) {
723
+ for (const [key, value] of Object.entries(init.query)) {
724
+ if (value !== undefined)
725
+ url.searchParams.set(key, value);
726
+ }
727
+ }
728
+ const headers = {};
729
+ if (token)
730
+ headers.authorization = `Bearer ${token}`;
731
+ if (init.json !== undefined)
732
+ headers["content-type"] = "application/json";
733
+ else if (init.zip !== undefined)
734
+ headers["content-type"] = "application/zip";
735
+ const body = init.json !== undefined ? JSON.stringify(init.json) : init.zip;
736
+ return fetchImpl(url.toString(), { method, headers, body });
737
+ }
738
+ return {
739
+ baseUrl,
740
+ token,
741
+ request,
742
+ deviceCode: () => request("POST", "/api/auth/device/code", { json: { client_id: DEVICE_CLIENT_ID } }),
743
+ deviceToken: (deviceCode) => request("POST", "/api/auth/device/token", {
744
+ json: {
745
+ grant_type: DEVICE_GRANT_TYPE,
746
+ device_code: deviceCode,
747
+ client_id: DEVICE_CLIENT_ID
748
+ }
749
+ }),
750
+ listSites: () => request("GET", "/account/sites"),
751
+ claimSite: (siteId, claimToken) => request("POST", `/sites/${siteId}/claim`, { json: { claim_token: claimToken } }),
752
+ bulkAttach: (sites) => request("POST", "/account/bulk-attach", { json: { sites } }),
753
+ getSite: (siteId) => request("GET", `/sites/${siteId}`),
754
+ createSite: (zip) => request("POST", "/sites", { zip }),
755
+ redeploy: (siteId, zip) => request("POST", `/sites/${siteId}/deploys`, { zip }),
756
+ rollback: (siteId, versionId) => request("POST", `/sites/${siteId}/rollback`, { json: { version_id: versionId } }),
757
+ setCommentsMode: (siteId, body) => request("POST", `/api/sites/${siteId}/comments-mode`, { json: body }),
758
+ listComments: (siteId, query) => request("GET", `/api/sites/${siteId}/comments`, { query }),
759
+ getThread: (siteId, threadId) => request("GET", `/api/sites/${siteId}/comments/${threadId}`),
760
+ postComment: (siteId, body) => request("POST", `/api/sites/${siteId}/comments`, { json: body }),
761
+ setThreadStatus: (siteId, threadId, status) => request("POST", `/api/sites/${siteId}/comments/${threadId}/${status}`)
762
+ };
763
+ }
764
+ async function createClient(opts) {
765
+ const env = opts.env ?? process.env;
766
+ const fetchImpl = opts.fetch ?? fetch;
767
+ const session = await loadSession(env);
768
+ const { token, baseUrl } = resolveCredentials(env, session, opts.overrides);
769
+ return buildClient(token, baseUrl, fetchImpl);
770
+ }
771
+
648
772
  // src/cli.ts
649
773
  var BUILD_DIR_CANDIDATES = [
650
774
  "dist",
@@ -660,11 +784,11 @@ async function resolveDeployDir(opts = {}) {
660
784
  return opts.explicit;
661
785
  const cwd = opts.cwd ?? process.cwd();
662
786
  for (const candidate of BUILD_DIR_CANDIDATES) {
663
- const dir = join(cwd, candidate);
787
+ const dir = join2(cwd, candidate);
664
788
  try {
665
789
  if (!(await stat(dir)).isDirectory())
666
790
  continue;
667
- if ((await stat(join(dir, "index.html"))).isFile())
791
+ if ((await stat(join2(dir, "index.html"))).isFile())
668
792
  return dir;
669
793
  } catch {}
670
794
  }
@@ -674,16 +798,16 @@ async function collectDist(path) {
674
798
  const info = await stat(path);
675
799
  if (info.isFile()) {
676
800
  const name = path.split("/").pop() ?? "index.html";
677
- return { [name]: await readFile(path) };
801
+ return { [name]: await readFile2(path) };
678
802
  }
679
803
  const files = {};
680
804
  async function walk(current) {
681
805
  for (const entry of await readdir(current, { withFileTypes: true })) {
682
- const full = join(current, entry.name);
806
+ const full = join2(current, entry.name);
683
807
  if (entry.isDirectory())
684
808
  await walk(full);
685
809
  else
686
- files[relative(path, full).split("\\").join("/")] = await readFile(full);
810
+ files[relative(path, full).split("\\").join("/")] = await readFile2(full);
687
811
  }
688
812
  }
689
813
  await walk(path);
@@ -693,17 +817,12 @@ async function deploySite(opts) {
693
817
  const handle = opts.handle ?? ((request) => fetch(request));
694
818
  const baseUrl = opts.baseUrl ?? "https://flypod.dev";
695
819
  const zip = zipSync(opts.files);
696
- const headers = { "content-type": "application/zip" };
697
- if (opts.apiKey)
698
- headers.authorization = `Bearer ${opts.apiKey}`;
699
- const res = await handle(new Request(`${baseUrl}/sites`, {
700
- method: "POST",
701
- headers,
702
- body: zip
703
- }));
820
+ const bridgeFetch = async (input, init) => handle(new Request(typeof input === "string" ? input : input.url, init));
821
+ const client = buildClient(opts.apiKey, baseUrl, bridgeFetch);
822
+ const res = await client.createSite(zip);
704
823
  if (!res.ok)
705
824
  throw new Error(`deploy failed: ${res.status}`);
706
825
  return await res.json();
707
826
  }
708
827
 
709
- export { zipSync, BUILD_DIR_CANDIDATES, resolveDeployDir, collectDist, deploySite };
828
+ export { zipSync, projectsFilePath, atomicWriteFile, saveSession, clearSession, resolveCredentials, createClient, BUILD_DIR_CANDIDATES, resolveDeployDir, collectDist, deploySite };
@@ -0,0 +1,87 @@
1
+ import type { CliSession } from "./session";
2
+ type FetchLike = typeof fetch;
3
+ /** Per-call-site credential overrides — `--token`/`--site` flags, or a
4
+ * project record's stashed `manage_token`/`base_url`. */
5
+ export interface ClientOverrides {
6
+ /** An explicit `--token` flag. */
7
+ token?: string;
8
+ /** A site's own `manage_token`, from `projects.json` (anonymous sites). */
9
+ manageToken?: string;
10
+ /** A site's own `base_url`, from `projects.json`. */
11
+ baseUrl?: string;
12
+ }
13
+ interface RequestInit {
14
+ json?: unknown;
15
+ zip?: Uint8Array;
16
+ query?: Record<string, string | undefined>;
17
+ }
18
+ export interface FlypodClient {
19
+ readonly baseUrl: string;
20
+ readonly token: string | undefined;
21
+ /** Low-level escape hatch: `path` is resolved against `baseUrl`; the auth
22
+ * header is added when a token resolved. */
23
+ request(method: string, path: string, init?: RequestInit): Promise<Response>;
24
+ deviceCode(): Promise<Response>;
25
+ deviceToken(deviceCode: string): Promise<Response>;
26
+ listSites(): Promise<Response>;
27
+ claimSite(siteId: string, claimToken: string): Promise<Response>;
28
+ bulkAttach(sites: Array<{
29
+ site_id: string;
30
+ manage_token: string;
31
+ }>): Promise<Response>;
32
+ getSite(siteId: string): Promise<Response>;
33
+ createSite(zip: Uint8Array): Promise<Response>;
34
+ redeploy(siteId: string, zip: Uint8Array): Promise<Response>;
35
+ rollback(siteId: string, versionId: string): Promise<Response>;
36
+ setCommentsMode(siteId: string, body: {
37
+ mode?: string;
38
+ enabled?: boolean;
39
+ passcode?: string;
40
+ }): Promise<Response>;
41
+ listComments(siteId: string, query: {
42
+ page?: string;
43
+ status?: string;
44
+ limit?: string;
45
+ }): Promise<Response>;
46
+ getThread(siteId: string, threadId: string): Promise<Response>;
47
+ postComment(siteId: string, body: {
48
+ page_path: string;
49
+ anchor: unknown;
50
+ body: string;
51
+ }): Promise<Response>;
52
+ setThreadStatus(siteId: string, threadId: string, status: "resolve" | "reopen"): Promise<Response>;
53
+ }
54
+ /**
55
+ * The one credential-precedence chain, used (directly or via an override) by
56
+ * every command:
57
+ *
58
+ * token: override.token ?? override.manageToken ?? FLYPOD_TOKEN ?? session.session_token ?? FLYPOD_API_KEY
59
+ * baseUrl: override.baseUrl ?? session.base_url ?? DEPLOY_URL ?? "https://flypod.dev"
60
+ *
61
+ * Pure and synchronous so every rung is directly unit-testable without a
62
+ * filesystem or network.
63
+ */
64
+ export declare function resolveCredentials(env: NodeJS.ProcessEnv, session: CliSession | null, overrides?: ClientOverrides): {
65
+ token?: string;
66
+ baseUrl: string;
67
+ };
68
+ /**
69
+ * Build a client from an already-resolved token/baseUrl — no disk, no env.
70
+ * This is the pure core `createClient` (below) wraps after the async
71
+ * session load; `deploySite` (src/cli.ts) also builds on this directly so
72
+ * that a *published library call* never has a side channel to a session
73
+ * file or ambient env vars it didn't ask for.
74
+ */
75
+ export declare function buildClient(token: string | undefined, baseUrl: string, fetchImpl: FetchLike): FlypodClient;
76
+ /**
77
+ * Build a client with credentials resolved once (a saved session is loaded
78
+ * from disk, so this is async). `opts.fetch`/`opts.env` are the same
79
+ * injection seam `CommandIO` already offers commands, so tests keep working
80
+ * hermetically end to end.
81
+ */
82
+ export declare function createClient(opts: {
83
+ env?: NodeJS.ProcessEnv;
84
+ fetch?: FetchLike;
85
+ overrides?: ClientOverrides;
86
+ }): Promise<FlypodClient>;
87
+ export {};
@@ -0,0 +1,17 @@
1
+ /** The directory the CLI keeps its state in (session + project registry). */
2
+ export declare function configDir(env?: NodeJS.ProcessEnv): string;
3
+ /** The absolute path to the session.json file on this OS. */
4
+ export declare function sessionFilePath(env?: NodeJS.ProcessEnv): string;
5
+ /**
6
+ * The absolute path to projects.json — the folder->site registry that lets
7
+ * `flypod update`/`versions`/`rollback` target the right site without a flag
8
+ * or a file in the user's repo. Sits beside session.json.
9
+ */
10
+ export declare function projectsFilePath(env?: NodeJS.ProcessEnv): string;
11
+ /**
12
+ * Write a file atomically — to <path>.tmp first, then rename. Survives crash
13
+ * mid-write on every OS. Sets file perms to 0o600 on POSIX (no-op on
14
+ * Windows — the file already lives under the user profile, NTFS ACLs scope
15
+ * it to the user). Falls back silently if chmod isn't available.
16
+ */
17
+ export declare function atomicWriteFile(path: string, content: string): Promise<void>;
@@ -0,0 +1,11 @@
1
+ export interface CliSession {
2
+ /** Better Auth session token, sent as `Authorization: Bearer <session_token>`. */
3
+ session_token: string;
4
+ /** Base URL the token was minted against (e.g. https://flypod.dev). */
5
+ base_url: string;
6
+ /** When the session was minted (epoch ms). */
7
+ created_at: number;
8
+ }
9
+ export declare function loadSession(env?: NodeJS.ProcessEnv): Promise<CliSession | null>;
10
+ export declare function saveSession(session: CliSession, env?: NodeJS.ProcessEnv): Promise<string>;
11
+ export declare function clearSession(env?: NodeJS.ProcessEnv): Promise<boolean>;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Build-output folders the common frontend frameworks emit, in priority order.
3
+ * `public` ranks low because some tools use it for *source* assets (Vite/CRA);
4
+ * requiring an index.html disambiguates a built site (e.g. Gatsby) from source.
5
+ */
6
+ export declare const BUILD_DIR_CANDIDATES: string[];
7
+ /**
8
+ * Resolve the directory to deploy. An explicit path is used verbatim. Otherwise
9
+ * the first candidate build folder that exists and contains an index.html wins,
10
+ * so `npx flypod` (no argument) just works from a project root.
11
+ */
12
+ export declare function resolveDeployDir(opts?: {
13
+ cwd?: string;
14
+ explicit?: string;
15
+ }): Promise<string>;
16
+ /**
17
+ * Read files for a deploy. Accepts either a directory (walked recursively) or a
18
+ * single file (deployed as the only file in the site).
19
+ */
20
+ export declare function collectDist(path: string): Promise<Record<string, Uint8Array>>;
21
+ export interface DeployResult {
22
+ site_id: string;
23
+ slug: string;
24
+ url: string;
25
+ version_id: string;
26
+ /** null when the site is owned (authenticated deploy); a number for anonymous. */
27
+ expires_at: number | null;
28
+ /** Per-site claim token. Omitted from the response when already owned. */
29
+ claim_token?: string;
30
+ manage_token: string;
31
+ /** Set when the deploy was authenticated via Bearer apiKey or cookie session. */
32
+ owner_account_id?: string;
33
+ next_actions: unknown[];
34
+ }
35
+ export interface DeployOptions {
36
+ files: Record<string, Uint8Array>;
37
+ /** Defaults to https://flypod.dev — override for self-hosted servers. */
38
+ baseUrl?: string;
39
+ /** Injectable transport — defaults to global fetch; tests pass `app.handle`. */
40
+ handle?: (request: Request) => Promise<Response>;
41
+ /** When set, sent as `Authorization: Bearer <apiKey>` so the deploy is attributed. */
42
+ apiKey?: string;
43
+ }
44
+ /**
45
+ * Zip a files map and POST it to the deploy API; returns the parsed result.
46
+ *
47
+ * Delegates to `FlypodClient.createSite` internally (via `buildClient`, the
48
+ * client's disk/env-free core) so this and every other CLI transport share
49
+ * one request-building path. `buildClient` — not `createClient` — is used
50
+ * deliberately: this is a published library function callers can invoke
51
+ * directly with just `{files, apiKey}`, so it must never reach for a saved
52
+ * session or ambient env vars the caller didn't pass in `opts`.
53
+ */
54
+ export declare function deploySite(opts: DeployOptions): Promise<DeployResult>;
package/dist/src/cli.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  collectDist,
4
4
  deploySite,
5
5
  resolveDeployDir
6
- } from "../cli-ynzcc4xy.js";
6
+ } from "../cli-j9rxpfdv.js";
7
7
  export {
8
8
  resolveDeployDir,
9
9
  deploySite,
package/package.json CHANGED
@@ -1,12 +1,18 @@
1
1
  {
2
2
  "name": "flypod",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Zero-auth deploy primitive. Turns any folder into a live URL in one command. For AI agents and humans.",
5
- "module": "src/cli.ts",
5
+ "module": "./dist/src/cli.js",
6
+ "types": "./dist/src/cli.d.ts",
6
7
  "type": "module",
7
8
  "license": "MIT",
8
9
  "exports": {
9
- ".": "./dist/src/cli.js"
10
+ ".": {
11
+ "types": "./dist/src/cli.d.ts",
12
+ "import": "./dist/src/cli.js",
13
+ "default": "./dist/src/cli.js"
14
+ },
15
+ "./package.json": "./package.json"
10
16
  },
11
17
  "bin": {
12
18
  "flypod": "dist/bin/deploy.js"
@@ -32,21 +38,21 @@
32
38
  "workers"
33
39
  ],
34
40
  "scripts": {
35
- "build": "rm -rf dist && bun build src/cli.ts bin/deploy.ts --outdir dist --target node --splitting",
41
+ "build": "rm -rf dist && bun build src/cli.ts bin/deploy.ts --outdir dist --target node --splitting && tsc -p tsconfig.build.json",
36
42
  "prepublishOnly": "bun run build",
37
43
  "test": "bun run test:unit && bun run test:bdd",
38
44
  "test:unit": "bun test --test-name-pattern='^(?!.*BDD).*' $(find test -name '*.test.ts' ! -path 'test/comments/bdd.test.ts')",
39
45
  "test:bdd": "bun test test/comments/bdd.test.ts",
40
46
  "typecheck": "tsc --noEmit",
47
+ "build:account-page": "bun scripts/build-account-page.ts",
41
48
  "deploy": "wrangler deploy",
42
49
  "dev": "bun --hot index.ts"
43
50
  },
44
51
  "dependencies": {
45
- "@flypod/comments": "workspace:*",
46
- "@modelcontextprotocol/sdk": "^1.20.2",
47
52
  "fflate": "^0.8.3"
48
53
  },
49
54
  "devDependencies": {
55
+ "@flypod/comments": "workspace:*",
50
56
  "@libsql/client": "^0.17.3",
51
57
  "@types/bun": "latest",
52
58
  "better-auth": "1.6.14",
@@ -54,11 +60,7 @@
54
60
  "hono": "^4.12.25",
55
61
  "marked": "^18.0.5",
56
62
  "playwright": "^1.60.0",
57
- "quickpickle": "^1.7.0",
58
63
  "typescript": "^6.0.3",
59
64
  "wrangler": "^4.0.0"
60
- },
61
- "peerDependencies": {
62
- "typescript": "^6.0.3"
63
65
  }
64
66
  }