create-whop-kit 1.0.5 → 1.0.7

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.
@@ -201,72 +201,55 @@ function headers(apiKey) {
201
201
  "Content-Type": "application/json"
202
202
  };
203
203
  }
204
- async function getCompanyId(apiKey) {
204
+ async function validateApiKey(apiKey) {
205
205
  try {
206
- const res = await fetch(`${WHOP_API}/companies`, {
206
+ const res = await fetch(`${WHOP_API}/apps?per_page=1`, {
207
207
  headers: headers(apiKey)
208
208
  });
209
- if (!res.ok) return null;
210
- const data = await res.json();
211
- const companies = data.data || data;
212
- if (Array.isArray(companies) && companies.length > 0) {
213
- return companies[0].id;
214
- }
215
- return null;
209
+ return res.ok;
216
210
  } catch {
217
- return null;
211
+ return false;
218
212
  }
219
213
  }
220
- async function validateApiKey(apiKey) {
221
- return getCompanyId(apiKey);
222
- }
223
- async function createWhopApp(apiKey, name, redirectUris, companyId) {
214
+ async function createWhopApp(apiKey, name, redirectUris) {
224
215
  try {
225
216
  const res = await fetch(`${WHOP_API}/apps`, {
226
217
  method: "POST",
227
218
  headers: headers(apiKey),
228
219
  body: JSON.stringify({
229
220
  name,
230
- company_id: companyId,
231
221
  redirect_uris: redirectUris
232
222
  })
233
223
  });
234
- if (!res.ok) {
235
- const err = await res.text().catch(() => "");
236
- console.error(`[Whop API] Create app failed (${res.status}): ${err}`);
237
- return null;
224
+ if (res.ok) {
225
+ const data = await res.json();
226
+ return { id: data.id, client_secret: data.client_secret };
238
227
  }
239
- const data = await res.json();
240
- return {
241
- id: data.id,
242
- client_secret: data.client_secret
243
- };
228
+ const err = await res.text().catch(() => "");
229
+ console.error(`[Whop API] Create app failed (${res.status}): ${err}`);
230
+ return null;
244
231
  } catch (err) {
245
232
  console.error("[Whop API] Create app error:", err);
246
233
  return null;
247
234
  }
248
235
  }
249
- async function createWhopWebhook(apiKey, url, events, companyId) {
236
+ async function createWhopWebhook(apiKey, url, events) {
250
237
  try {
251
238
  const res = await fetch(`${WHOP_API}/webhooks`, {
252
239
  method: "POST",
253
240
  headers: headers(apiKey),
254
- body: JSON.stringify({
255
- url,
256
- events,
257
- company_id: companyId
258
- })
241
+ body: JSON.stringify({ url, events })
259
242
  });
260
- if (!res.ok) {
261
- const err = await res.text().catch(() => "");
262
- console.error(`[Whop API] Create webhook failed (${res.status}): ${err}`);
263
- return null;
243
+ if (res.ok) {
244
+ const data = await res.json();
245
+ return {
246
+ id: data.id,
247
+ secret: data.secret || data.signing_secret || data.webhook_secret || ""
248
+ };
264
249
  }
265
- const data = await res.json();
266
- return {
267
- id: data.id,
268
- secret: data.secret || data.signing_secret || data.webhook_secret || ""
269
- };
250
+ const err = await res.text().catch(() => "");
251
+ console.error(`[Whop API] Create webhook failed (${res.status}): ${err}`);
252
+ return null;
270
253
  } catch (err) {
271
254
  console.error("[Whop API] Create webhook error:", err);
272
255
  return null;
@@ -414,39 +397,58 @@ async function runDeployPipeline(options) {
414
397
  `${pc3.bold("1.")} Go to ${pc3.cyan("https://whop.com/dashboard/developer")}`,
415
398
  `${pc3.bold("2.")} Click ${pc3.bold('"Create"')} under "Company API Keys"`,
416
399
  `${pc3.bold("3.")} Give it a name (e.g. "${projectName}")`,
417
- `${pc3.bold("4.")} Click Create ${pc3.dim("(default permissions are fine)")}`,
418
- `${pc3.bold("5.")} Copy the key and paste it below`
400
+ `${pc3.bold("4.")} Click Create and copy the key`,
401
+ `${pc3.bold("5.")} Paste it below`
419
402
  ].join("\n"),
420
403
  "Whop Company API Key"
421
404
  );
422
405
  openUrl("https://whop.com/dashboard/developer");
423
406
  let apiKey = options.whopCompanyKey ?? "";
424
- if (!apiKey) {
425
- const result = await p3.text({
426
- message: "Paste your Company API key",
427
- placeholder: "paste the key here...",
428
- validate: (v) => !v ? "API key is required" : void 0
429
- });
430
- if (p3.isCancel(result)) {
407
+ let keyValid = false;
408
+ for (let attempt = 0; attempt < 3; attempt++) {
409
+ if (!apiKey) {
410
+ const result = await p3.text({
411
+ message: attempt === 0 ? "Paste your Company API key" : "Paste a new Company API key",
412
+ placeholder: "paste the key here...",
413
+ validate: (v) => !v ? "API key is required" : void 0
414
+ });
415
+ if (p3.isCancel(result)) {
416
+ return { productionUrl, githubUrl: githubRepoUrl ?? void 0 };
417
+ }
418
+ apiKey = result;
419
+ }
420
+ const s2 = p3.spinner();
421
+ s2.start("Validating API key...");
422
+ keyValid = await validateApiKey(apiKey);
423
+ if (keyValid) {
424
+ s2.stop("API key valid");
425
+ break;
426
+ }
427
+ s2.stop("API key invalid");
428
+ if (attempt < 2) {
429
+ const retry = await p3.confirm({
430
+ message: "Try a different key?",
431
+ initialValue: true
432
+ });
433
+ if (p3.isCancel(retry) || !retry) {
434
+ return { productionUrl, githubUrl: githubRepoUrl ?? void 0 };
435
+ }
436
+ apiKey = "";
437
+ } else {
438
+ p3.log.error("Could not validate. Configure Whop manually via the setup wizard.");
431
439
  return { productionUrl, githubUrl: githubRepoUrl ?? void 0 };
432
440
  }
433
- apiKey = result;
434
441
  }
435
- const s = p3.spinner();
436
- s.start("Validating API key...");
437
- const companyId = await validateApiKey(apiKey);
438
- if (!companyId) {
439
- s.stop("Invalid API key");
440
- p3.log.error("Check that the key has permissions: developer:create_app, developer:manage_api_key, developer:manage_webhook, company:basic:read");
442
+ if (!keyValid) {
441
443
  return { productionUrl, githubUrl: githubRepoUrl ?? void 0 };
442
444
  }
443
- s.stop(`API key valid (company: ${pc3.dim(companyId)})`);
444
445
  const redirectUris = [
445
446
  "http://localhost:3000/api/auth/callback",
446
447
  `${productionUrl}/api/auth/callback`
447
448
  ];
449
+ const s = p3.spinner();
448
450
  s.start("Creating Whop OAuth app...");
449
- const app = await createWhopApp(apiKey, projectName, redirectUris, companyId);
451
+ const app = await createWhopApp(apiKey, projectName, redirectUris);
450
452
  if (!app) {
451
453
  s.stop("Failed to create app");
452
454
  p3.log.error("Create manually: " + pc3.cyan("https://whop.com/dashboard/developer"));
@@ -454,7 +456,7 @@ async function runDeployPipeline(options) {
454
456
  }
455
457
  s.stop(`OAuth app created: ${pc3.bold(app.id)}`);
456
458
  s.start("Creating webhook...");
457
- const webhook = await createWhopWebhook(apiKey, `${productionUrl}/api/webhooks/whop`, WEBHOOK_EVENTS, companyId);
459
+ const webhook = await createWhopWebhook(apiKey, `${productionUrl}/api/webhooks/whop`, WEBHOOK_EVENTS);
458
460
  if (!webhook) {
459
461
  s.stop("Failed (create manually in Whop dashboard)");
460
462
  } else {
@@ -684,7 +684,7 @@ var init_default = defineCommand({
684
684
  });
685
685
  if (!isCancelled(deployChoice) && deployChoice === "deploy") {
686
686
  deployAttempted = true;
687
- const { runDeployPipeline } = await import("./deploy-L6ITPGHX.js");
687
+ const { runDeployPipeline } = await import("./deploy-AMH7INFV.js");
688
688
  deployResult = await runDeployPipeline({
689
689
  projectDir,
690
690
  projectName,
package/dist/cli-kit.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  } from "./chunk-HOQ5QQ2M.js";
10
10
  import {
11
11
  runDeployPipeline
12
- } from "./chunk-X5LIASNE.js";
12
+ } from "./chunk-E2IWGU3U.js";
13
13
  import {
14
14
  detectPackageManager,
15
15
  exec
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  runDeployPipeline
4
- } from "./chunk-X5LIASNE.js";
4
+ } from "./chunk-E2IWGU3U.js";
5
5
  import "./chunk-42L7PRMT.js";
6
6
  export {
7
7
  runDeployPipeline
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-whop-kit",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Scaffold and manage Whop-powered apps with whop-kit",
5
5
  "type": "module",
6
6
  "license": "MIT",