create-whop-kit 1.0.2 → 1.0.3
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) {
|
|
@@ -437,6 +448,7 @@ async function runDeployPipeline(options) {
|
|
|
437
448
|
`${pc3.bold("3.")} Name it anything (e.g. "${projectName}")`,
|
|
438
449
|
"",
|
|
439
450
|
`${pc3.bold("4.")} Select these permissions:`,
|
|
451
|
+
` ${pc3.green("\u2022")} company:basic:read ${pc3.dim("\u2014 identify your company")}`,
|
|
440
452
|
` ${pc3.green("\u2022")} developer:create_app ${pc3.dim("\u2014 create the OAuth app")}`,
|
|
441
453
|
` ${pc3.green("\u2022")} developer:update_app ${pc3.dim("\u2014 configure redirect URIs")}`,
|
|
442
454
|
` ${pc3.green("\u2022")} developer:manage_api_key ${pc3.dim("\u2014 get the app credentials")}`,
|
|
@@ -464,27 +476,27 @@ async function runDeployPipeline(options) {
|
|
|
464
476
|
}
|
|
465
477
|
const s = p3.spinner();
|
|
466
478
|
s.start("Validating API key...");
|
|
467
|
-
const
|
|
468
|
-
if (!
|
|
479
|
+
const companyId = await validateApiKey(apiKey);
|
|
480
|
+
if (!companyId) {
|
|
469
481
|
s.stop("Invalid API key");
|
|
470
|
-
p3.log.error("Check permissions: developer:create_app, developer:manage_api_key, developer:manage_webhook");
|
|
482
|
+
p3.log.error("Check that the key has permissions: developer:create_app, developer:manage_api_key, developer:manage_webhook, company:basic:read");
|
|
471
483
|
return { productionUrl, githubUrl: githubRepoUrl ?? void 0 };
|
|
472
484
|
}
|
|
473
|
-
s.stop(
|
|
485
|
+
s.stop(`API key valid (company: ${pc3.dim(companyId)})`);
|
|
474
486
|
const redirectUris = [
|
|
475
487
|
"http://localhost:3000/api/auth/callback",
|
|
476
488
|
`${productionUrl}/api/auth/callback`
|
|
477
489
|
];
|
|
478
490
|
s.start("Creating Whop OAuth app...");
|
|
479
|
-
const app = await createWhopApp(apiKey, projectName, redirectUris);
|
|
491
|
+
const app = await createWhopApp(apiKey, projectName, redirectUris, companyId);
|
|
480
492
|
if (!app) {
|
|
481
|
-
s.stop("Failed");
|
|
493
|
+
s.stop("Failed to create app");
|
|
482
494
|
p3.log.error("Create manually: " + pc3.cyan("https://whop.com/dashboard/developer"));
|
|
483
495
|
return { productionUrl, githubUrl: githubRepoUrl ?? void 0 };
|
|
484
496
|
}
|
|
485
497
|
s.stop(`OAuth app created: ${pc3.bold(app.id)}`);
|
|
486
498
|
s.start("Creating webhook...");
|
|
487
|
-
const webhook = await createWhopWebhook(apiKey, `${productionUrl}/api/webhooks/whop`, WEBHOOK_EVENTS);
|
|
499
|
+
const webhook = await createWhopWebhook(apiKey, `${productionUrl}/api/webhooks/whop`, WEBHOOK_EVENTS, companyId);
|
|
488
500
|
if (!webhook) {
|
|
489
501
|
s.stop("Failed (create manually in Whop dashboard)");
|
|
490
502
|
} 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-GJATOBW4.js");
|
|
688
688
|
deployResult = await runDeployPipeline({
|
|
689
689
|
projectDir,
|
|
690
690
|
projectName,
|
package/dist/cli-kit.js
CHANGED