create-whop-kit 1.0.2 → 1.0.4
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.
|
@@ -230,23 +230,33 @@ function headers(apiKey) {
|
|
|
230
230
|
"Content-Type": "application/json"
|
|
231
231
|
};
|
|
232
232
|
}
|
|
233
|
-
async function
|
|
233
|
+
async function getCompanyId(apiKey) {
|
|
234
234
|
try {
|
|
235
|
-
const res = await fetch(`${WHOP_API}/
|
|
235
|
+
const res = await fetch(`${WHOP_API}/companies`, {
|
|
236
236
|
headers: headers(apiKey)
|
|
237
237
|
});
|
|
238
|
-
|
|
238
|
+
if (!res.ok) return null;
|
|
239
|
+
const data = await res.json();
|
|
240
|
+
const companies = data.data || data;
|
|
241
|
+
if (Array.isArray(companies) && companies.length > 0) {
|
|
242
|
+
return companies[0].id;
|
|
243
|
+
}
|
|
244
|
+
return null;
|
|
239
245
|
} catch {
|
|
240
|
-
return
|
|
246
|
+
return null;
|
|
241
247
|
}
|
|
242
248
|
}
|
|
243
|
-
async function
|
|
249
|
+
async function validateApiKey(apiKey) {
|
|
250
|
+
return getCompanyId(apiKey);
|
|
251
|
+
}
|
|
252
|
+
async function createWhopApp(apiKey, name, redirectUris, companyId) {
|
|
244
253
|
try {
|
|
245
254
|
const res = await fetch(`${WHOP_API}/apps`, {
|
|
246
255
|
method: "POST",
|
|
247
256
|
headers: headers(apiKey),
|
|
248
257
|
body: JSON.stringify({
|
|
249
258
|
name,
|
|
259
|
+
company_id: companyId,
|
|
250
260
|
redirect_uris: redirectUris
|
|
251
261
|
})
|
|
252
262
|
});
|
|
@@ -265,14 +275,15 @@ async function createWhopApp(apiKey, name, redirectUris) {
|
|
|
265
275
|
return null;
|
|
266
276
|
}
|
|
267
277
|
}
|
|
268
|
-
async function createWhopWebhook(apiKey, url, events) {
|
|
278
|
+
async function createWhopWebhook(apiKey, url, events, companyId) {
|
|
269
279
|
try {
|
|
270
280
|
const res = await fetch(`${WHOP_API}/webhooks`, {
|
|
271
281
|
method: "POST",
|
|
272
282
|
headers: headers(apiKey),
|
|
273
283
|
body: JSON.stringify({
|
|
274
284
|
url,
|
|
275
|
-
events
|
|
285
|
+
events,
|
|
286
|
+
company_id: companyId
|
|
276
287
|
})
|
|
277
288
|
});
|
|
278
289
|
if (!res.ok) {
|
|
@@ -427,25 +438,13 @@ async function runDeployPipeline(options) {
|
|
|
427
438
|
if (!p3.isCancel(connectWhop) && connectWhop) {
|
|
428
439
|
p3.note(
|
|
429
440
|
[
|
|
430
|
-
`We need a Company API key to
|
|
431
|
-
"",
|
|
432
|
-
`${pc3.bold("1.")} Go to the Whop Developer Dashboard`,
|
|
433
|
-
` ${pc3.cyan("https://whop.com/dashboard/developer")}`,
|
|
441
|
+
`We need a Company API key to set up OAuth and webhooks.`,
|
|
434
442
|
"",
|
|
443
|
+
`${pc3.bold("1.")} Go to ${pc3.cyan("https://whop.com/dashboard/developer")}`,
|
|
435
444
|
`${pc3.bold("2.")} Click ${pc3.bold('"Create"')} under "Company API Keys"`,
|
|
436
|
-
""
|
|
437
|
-
`${pc3.bold("
|
|
438
|
-
""
|
|
439
|
-
`${pc3.bold("4.")} Select these permissions:`,
|
|
440
|
-
` ${pc3.green("\u2022")} developer:create_app ${pc3.dim("\u2014 create the OAuth app")}`,
|
|
441
|
-
` ${pc3.green("\u2022")} developer:update_app ${pc3.dim("\u2014 configure redirect URIs")}`,
|
|
442
|
-
` ${pc3.green("\u2022")} developer:manage_api_key ${pc3.dim("\u2014 get the app credentials")}`,
|
|
443
|
-
` ${pc3.green("\u2022")} developer:manage_webhook ${pc3.dim("\u2014 set up payment webhooks")}`,
|
|
444
|
-
"",
|
|
445
|
-
`${pc3.bold("5.")} Create the key and paste it below`,
|
|
446
|
-
"",
|
|
447
|
-
`${pc3.dim("This key is used once to set everything up.")}`,
|
|
448
|
-
`${pc3.dim("Your app uses OAuth (openid, profile, email) for user sign-in.")}`
|
|
445
|
+
`${pc3.bold("3.")} Give it a name (e.g. "${projectName}")`,
|
|
446
|
+
`${pc3.bold("4.")} Click Create ${pc3.dim("(default permissions are fine)")}`,
|
|
447
|
+
`${pc3.bold("5.")} Copy the key and paste it below`
|
|
449
448
|
].join("\n"),
|
|
450
449
|
"Whop Company API Key"
|
|
451
450
|
);
|
|
@@ -464,27 +463,27 @@ async function runDeployPipeline(options) {
|
|
|
464
463
|
}
|
|
465
464
|
const s = p3.spinner();
|
|
466
465
|
s.start("Validating API key...");
|
|
467
|
-
const
|
|
468
|
-
if (!
|
|
466
|
+
const companyId = await validateApiKey(apiKey);
|
|
467
|
+
if (!companyId) {
|
|
469
468
|
s.stop("Invalid API key");
|
|
470
|
-
p3.log.error("Check permissions: developer:create_app, developer:manage_api_key, developer:manage_webhook");
|
|
469
|
+
p3.log.error("Check that the key has permissions: developer:create_app, developer:manage_api_key, developer:manage_webhook, company:basic:read");
|
|
471
470
|
return { productionUrl, githubUrl: githubRepoUrl ?? void 0 };
|
|
472
471
|
}
|
|
473
|
-
s.stop(
|
|
472
|
+
s.stop(`API key valid (company: ${pc3.dim(companyId)})`);
|
|
474
473
|
const redirectUris = [
|
|
475
474
|
"http://localhost:3000/api/auth/callback",
|
|
476
475
|
`${productionUrl}/api/auth/callback`
|
|
477
476
|
];
|
|
478
477
|
s.start("Creating Whop OAuth app...");
|
|
479
|
-
const app = await createWhopApp(apiKey, projectName, redirectUris);
|
|
478
|
+
const app = await createWhopApp(apiKey, projectName, redirectUris, companyId);
|
|
480
479
|
if (!app) {
|
|
481
|
-
s.stop("Failed");
|
|
480
|
+
s.stop("Failed to create app");
|
|
482
481
|
p3.log.error("Create manually: " + pc3.cyan("https://whop.com/dashboard/developer"));
|
|
483
482
|
return { productionUrl, githubUrl: githubRepoUrl ?? void 0 };
|
|
484
483
|
}
|
|
485
484
|
s.stop(`OAuth app created: ${pc3.bold(app.id)}`);
|
|
486
485
|
s.start("Creating webhook...");
|
|
487
|
-
const webhook = await createWhopWebhook(apiKey, `${productionUrl}/api/webhooks/whop`, WEBHOOK_EVENTS);
|
|
486
|
+
const webhook = await createWhopWebhook(apiKey, `${productionUrl}/api/webhooks/whop`, WEBHOOK_EVENTS, companyId);
|
|
488
487
|
if (!webhook) {
|
|
489
488
|
s.stop("Failed (create manually in Whop dashboard)");
|
|
490
489
|
} else {
|
package/dist/cli-create.js
CHANGED
|
@@ -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-
|
|
687
|
+
const { runDeployPipeline } = await import("./deploy-REOQQOZH.js");
|
|
688
688
|
deployResult = await runDeployPipeline({
|
|
689
689
|
projectDir,
|
|
690
690
|
projectName,
|
package/dist/cli-kit.js
CHANGED