|
1
|
const hostname = process.env.REPLIT_CONNECTORS_HOSTNAME; |
|
2
|
const token = process.env.REPL_IDENTITY ? "repl " + process.env.REPL_IDENTITY |
|
3
|
: process.env.WEB_REPL_RENEWAL ? "depl " + process.env.WEB_REPL_RENEWAL : null; |
|
4
|
|
|
5
|
const [method, path, bodyJson] = process.argv.slice(2); |
|
6
|
if (!method || !path) { |
|
7
|
console.log("Usage: node whop-api.mjs <METHOD> <path> ['{...}']"); |
|
8
|
console.log(" node whop-api.mjs GET '/api/v1/products?company_id=biz_xxx'"); |
|
9
|
console.log(" node whop-api.mjs POST /api/v1/plans '{\"company_id\":\"biz_xxx\",...}'"); |
|
10
|
process.exit(0); |
|
11
|
} |
|
12
|
|
|
13
|
const resp = await fetch(`https://${hostname}/api/v2/proxy/${path}`, { |
|
14
|
method, |
|
15
|
headers: { |
|
16
|
"Content-Type": "application/json", |
|
17
|
"X-Replit-Token": token, |
|
18
|
"Connector-Name": "whop", |
|
19
|
}, |
|
20
|
...(bodyJson ? { body: bodyJson } : {}), |
|
21
|
}); |
|
22
|
console.log(JSON.stringify(await resp.json(), null, 2)); |