calabasas 0.23.1 → 0.24.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.
Files changed (2) hide show
  1. package/dist/index.js +44 -50
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2085,59 +2085,53 @@ Run \`calabasas logout\` to clear credentials.`, "Already logged in");
2085
2085
  }
2086
2086
  const s = p.spinner();
2087
2087
  s.start("Opening browser for authentication...");
2088
+ const webOrigin = new URL(getWebUrl()).origin;
2089
+ function corsHeaders() {
2090
+ return {
2091
+ "Access-Control-Allow-Origin": webOrigin,
2092
+ "Access-Control-Allow-Methods": "POST, OPTIONS",
2093
+ "Access-Control-Allow-Headers": "Content-Type"
2094
+ };
2095
+ }
2088
2096
  const server = http.createServer((req, res) => {
2089
2097
  const url = new URL(req.url || "", `http://localhost:${CALLBACK_PORT}`);
2090
- if (url.pathname === "/callback") {
2091
- const apiKey = url.searchParams.get("key");
2092
- if (apiKey) {
2093
- saveConfig({ apiKey });
2094
- res.writeHead(200, { "Content-Type": "text/html" });
2095
- res.end(`
2096
- <!DOCTYPE html>
2097
- <html>
2098
- <head>
2099
- <meta charset="utf-8">
2100
- <title>Calabasas CLI</title>
2101
- <style>
2102
- body { font-family: system-ui; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background: #0a0a0a; color: white; }
2103
- .container { text-align: center; }
2104
- h1 { color: #22c55e; }
2105
- </style>
2106
- </head>
2107
- <body>
2108
- <div class="container">
2109
- <h1>Authenticated!</h1>
2110
- <p>You can close this window and return to the terminal.</p>
2111
- </div>
2112
- </body>
2113
- </html>
2114
- `);
2115
- s.stop("Authenticated!");
2116
- p.note(`calabasas bot add - Add a Discord bot
2098
+ if (req.method === "OPTIONS") {
2099
+ res.writeHead(204, { ...corsHeaders(), "Access-Control-Max-Age": "600" });
2100
+ res.end();
2101
+ return;
2102
+ }
2103
+ if (url.pathname === "/callback" && req.method === "POST") {
2104
+ const chunks = [];
2105
+ req.on("data", (chunk) => chunks.push(chunk));
2106
+ req.on("end", () => {
2107
+ let apiKey;
2108
+ try {
2109
+ const parsed = JSON.parse(Buffer.concat(chunks).toString("utf8"));
2110
+ if (typeof parsed.key === "string")
2111
+ apiKey = parsed.key;
2112
+ } catch {}
2113
+ if (apiKey) {
2114
+ saveConfig({ apiKey });
2115
+ res.writeHead(204, corsHeaders());
2116
+ res.end();
2117
+ s.stop("Authenticated!");
2118
+ p.note(`calabasas bot add - Add a Discord bot
2117
2119
  calabasas bot list - List your bots
2118
2120
  calabasas generate - Generate event handlers`, "Available commands");
2119
- p.outro("Logged in successfully!");
2120
- setTimeout(() => {
2121
- server.close();
2122
- process.exit(0);
2123
- }, 500);
2124
- } else {
2125
- res.writeHead(400, { "Content-Type": "text/html" });
2126
- res.end(`
2127
- <!DOCTYPE html>
2128
- <html>
2129
- <head><meta charset="utf-8"><title>Error</title></head>
2130
- <body>
2131
- <h1>Authentication failed</h1>
2132
- <p>No API key received.</p>
2133
- </body>
2134
- </html>
2135
- `);
2136
- }
2137
- } else {
2138
- res.writeHead(404);
2139
- res.end("Not found");
2121
+ p.outro("Logged in successfully!");
2122
+ setTimeout(() => {
2123
+ server.close();
2124
+ process.exit(0);
2125
+ }, 500);
2126
+ } else {
2127
+ res.writeHead(400, { ...corsHeaders(), "Content-Type": "application/json" });
2128
+ res.end(JSON.stringify({ error: "Missing or invalid key" }));
2129
+ }
2130
+ });
2131
+ return;
2140
2132
  }
2133
+ res.writeHead(404);
2134
+ res.end("Not found");
2141
2135
  });
2142
2136
  server.listen(CALLBACK_PORT, async () => {
2143
2137
  const authUrl = `${getWebUrl()}/auth/cli?callback=http://localhost:${CALLBACK_PORT}/callback`;
@@ -2621,11 +2615,11 @@ async function generate(options) {
2621
2615
  if (text.includes("roles") && text.includes("true"))
2622
2616
  syncExports.push("syncRole", "syncRoleBatch");
2623
2617
  if (text.includes("members") && text.includes("true"))
2624
- syncExports.push("syncMember", "syncMemberBatch", "deleteMemberBatch");
2618
+ syncExports.push("syncMember", "syncMemberBatch", "deleteMemberBatch", "bootstrapMemberCache");
2625
2619
  if (text.includes("presence") && text.includes("true"))
2626
2620
  syncExports.push("syncPresence", "syncPresenceBatch");
2627
2621
  if (syncExports.length === 0) {
2628
- syncExports.push("syncGuild", "syncChannel", "syncChannelBatch", "syncRole", "syncRoleBatch", "syncMember", "syncMemberBatch", "deleteMemberBatch", "syncPresence", "syncPresenceBatch");
2622
+ syncExports.push("syncGuild", "syncChannel", "syncChannelBatch", "syncRole", "syncRoleBatch", "syncMember", "syncMemberBatch", "deleteMemberBatch", "bootstrapMemberCache", "syncPresence", "syncPresenceBatch");
2629
2623
  }
2630
2624
  syncExports.push("updateSyncState");
2631
2625
  steps.push(`${stepNum}. Re-export sync mutations in convex/discord.ts:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "calabasas",
3
- "version": "0.23.1",
3
+ "version": "0.24.1",
4
4
  "description": "CLI for Calabasas - Discord Gateway as a Service for Convex",
5
5
  "type": "module",
6
6
  "bin": {