@discourse/create-site 0.0.0-stage → 0.1.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.
- package/AGENTS.md +66 -0
- package/LICENSE +21 -0
- package/README.md +103 -2
- package/dist/api.d.ts +100 -0
- package/dist/api.js +449 -0
- package/dist/api.js.map +1 -0
- package/dist/browser.d.ts +1 -0
- package/dist/browser.js +53 -0
- package/dist/browser.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +5 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/auth.d.ts +2 -0
- package/dist/commands/auth.js +368 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/common.d.ts +17 -0
- package/dist/commands/common.js +126 -0
- package/dist/commands/common.js.map +1 -0
- package/dist/commands/create.d.ts +2 -0
- package/dist/commands/create.js +605 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/info.d.ts +2 -0
- package/dist/commands/info.js +61 -0
- package/dist/commands/info.js.map +1 -0
- package/dist/commands/status.d.ts +2 -0
- package/dist/commands/status.js +119 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/config.d.ts +49 -0
- package/dist/config.js +151 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp.d.ts +29 -0
- package/dist/mcp.js +132 -0
- package/dist/mcp.js.map +1 -0
- package/dist/output.d.ts +15 -0
- package/dist/output.js +27 -0
- package/dist/output.js.map +1 -0
- package/dist/prompts.d.ts +24 -0
- package/dist/prompts.js +63 -0
- package/dist/prompts.js.map +1 -0
- package/dist/runner.d.ts +3 -0
- package/dist/runner.js +233 -0
- package/dist/runner.js.map +1 -0
- package/dist/store.d.ts +44 -0
- package/dist/store.js +121 -0
- package/dist/store.js.map +1 -0
- package/dist/types.d.ts +42 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +50 -4
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ApiError, getCliInfo } from "../api.js";
|
|
2
|
+
import { TERMS_URLS } from "../config.js";
|
|
3
|
+
import { writeJson } from "../output.js";
|
|
4
|
+
import { emitAuthRequiredPrompt, emitError, filterAllowedTiers, formatTierHint, getEffectiveTiers, orderedTierEntries, resolveToken, } from "./common.js";
|
|
5
|
+
export async function runInfoCommand(env) {
|
|
6
|
+
const resolved = await resolveToken(env);
|
|
7
|
+
if (!resolved) {
|
|
8
|
+
return emitAuthRequiredPrompt(env);
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
const info = await getCliInfo(env.options.idUrl, resolved.token, {
|
|
12
|
+
fetchImpl: env.ctx.fetchImpl,
|
|
13
|
+
});
|
|
14
|
+
const tiers = orderedTierEntries(getEffectiveTiers(info.pricing));
|
|
15
|
+
const filteredPricing = info.pricing
|
|
16
|
+
? { ...info.pricing, tiers: filterAllowedTiers(info.pricing.tiers) }
|
|
17
|
+
: null;
|
|
18
|
+
if (env.options.json) {
|
|
19
|
+
writeJson(env.ctx.stdout, {
|
|
20
|
+
ok: true,
|
|
21
|
+
id_url: env.options.idUrl,
|
|
22
|
+
provisioning_enabled: info.provisioning_enabled,
|
|
23
|
+
user: info.user,
|
|
24
|
+
pricing: filteredPricing,
|
|
25
|
+
available_plans: tiers.map((tier) => ({
|
|
26
|
+
plan: tier.name === "standard" ? "pro" : tier.name,
|
|
27
|
+
tier: tier.name,
|
|
28
|
+
display_name: tier.display_name,
|
|
29
|
+
monthly_price_cents: tier.monthly_price_cents,
|
|
30
|
+
yearly_price_cents: tier.yearly_price_cents,
|
|
31
|
+
trial_days: tier.trial_days,
|
|
32
|
+
allows_region_selection: tier.allows_region_selection,
|
|
33
|
+
})),
|
|
34
|
+
terms_urls: TERMS_URLS,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
env.ctx.stdout.write(`Discourse ID: ${env.options.idUrl}\n`);
|
|
39
|
+
env.ctx.stdout.write(`User: ${info.user.username} <${info.user.email}>\n`);
|
|
40
|
+
env.ctx.stdout.write(`Provisioning enabled: ${info.provisioning_enabled ? "yes" : "no"}\n`);
|
|
41
|
+
env.ctx.stdout.write(`Account terms agreed: age=${info.user.age_terms_agreed ? "yes" : "no"}, user_terms=${info.user.user_terms_agreed ? "yes" : "no"}\n`);
|
|
42
|
+
env.ctx.stdout.write("Plans:\n");
|
|
43
|
+
for (const tier of tiers) {
|
|
44
|
+
const hint = formatTierHint(tier);
|
|
45
|
+
env.ctx.stdout.write(` - ${tier.name} (${tier.display_name})${hint ? `: ${hint}` : ""}\n`);
|
|
46
|
+
}
|
|
47
|
+
env.ctx.stdout.write(`Terms URLs: free=${TERMS_URLS.free}, trial=${TERMS_URLS.trial}, user=${TERMS_URLS.user}\n`);
|
|
48
|
+
}
|
|
49
|
+
return 0;
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (error instanceof ApiError && error.status === 401) {
|
|
53
|
+
if (resolved.fromCache) {
|
|
54
|
+
await env.store.clearToken(env.options.idUrl);
|
|
55
|
+
}
|
|
56
|
+
return emitAuthRequiredPrompt(env, "Your Discourse ID session expired. Please authenticate again.");
|
|
57
|
+
}
|
|
58
|
+
return emitError(env, error, 1);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=info.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"info.js","sourceRoot":"","sources":["../../src/commands/info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EACL,sBAAsB,EACtB,SAAS,EACT,kBAAkB,EAClB,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,GACb,MAAM,aAAa,CAAC;AA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C,CAAC,EAAE,IAAI,CAAC,CAAC;YAC9F,CAAC;YACD,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAClB,oBAAoB,UAAU,CAAC,IAAI,WAAW,UAAU,CAAC,KAAK,UAAU,UAAU,CAAC,IAAI,IAAI,CAC5F,CAAC;QACJ,CAAC;QAED,OAAO,CAAC,CAAC;IACX,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,QAAQ,IAAI,KAAK,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YACtD,IAAI,QAAQ,CAAC,SAAS,EAAE,CAAC;gBACvB,MAAM,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAChD,CAAC;YACD,OAAO,sBAAsB,CAAC,GAAG,EAAE,+DAA+D,CAAC,CAAC;QACtG,CAAC;QACD,OAAO,SAAS,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IAClC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { ApiError, getSiteStatus, waitForSiteReady } from "../api.js";
|
|
2
|
+
import { buildMcpSetup, formatMcpGuidance } from "../mcp.js";
|
|
3
|
+
import { isInteractive, writeJson } from "../output.js";
|
|
4
|
+
import { USER_HANDOFF_MESSAGE, emitAuthRequiredPrompt, emitError, resolveToken, } from "./common.js";
|
|
5
|
+
export async function runStatusCommand(env) {
|
|
6
|
+
const siteToken = env.positionals[0]?.trim();
|
|
7
|
+
if (!siteToken) {
|
|
8
|
+
return emitError(env, new ApiError(400, "missing_site_token", [
|
|
9
|
+
"Missing site token. Usage: discourse-create-site status <token> [--wait] [--json]",
|
|
10
|
+
]), 1);
|
|
11
|
+
}
|
|
12
|
+
const resolved = await resolveToken(env);
|
|
13
|
+
if (!resolved) {
|
|
14
|
+
return emitAuthRequiredPrompt(env);
|
|
15
|
+
}
|
|
16
|
+
const interactive = isInteractive({
|
|
17
|
+
stdinIsTTY: env.ctx.stdinIsTTY,
|
|
18
|
+
stdoutIsTTY: env.ctx.stdoutIsTTY,
|
|
19
|
+
json: env.options.json,
|
|
20
|
+
nonInteractive: env.options.nonInteractive,
|
|
21
|
+
});
|
|
22
|
+
try {
|
|
23
|
+
let site;
|
|
24
|
+
if (env.options.wait && !env.options.noWait) {
|
|
25
|
+
let printedWaiting = false;
|
|
26
|
+
site = await waitForSiteReady(env.options.idUrl, resolved.token, siteToken, {
|
|
27
|
+
timeoutSeconds: env.options.timeoutSeconds ?? 300,
|
|
28
|
+
fetchImpl: env.ctx.fetchImpl,
|
|
29
|
+
sleep: env.ctx.sleep,
|
|
30
|
+
now: env.ctx.now,
|
|
31
|
+
onStatus(current) {
|
|
32
|
+
if (!env.options.json && current.status !== "ready") {
|
|
33
|
+
if (!printedWaiting) {
|
|
34
|
+
env.ctx.stderr.write(`Waiting for ${current.site_url} to be ready`);
|
|
35
|
+
printedWaiting = true;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
env.ctx.stderr.write(".");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
if (!env.options.json && printedWaiting) {
|
|
44
|
+
env.ctx.stderr.write("\n");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
site = await getSiteStatus(env.options.idUrl, resolved.token, siteToken, {
|
|
49
|
+
fetchImpl: env.ctx.fetchImpl,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const mcpSetup = site.status === "ready"
|
|
53
|
+
? buildMcpSetup(site.site_url, site.subdomain, env.ctx.env)
|
|
54
|
+
: undefined;
|
|
55
|
+
if (env.options.json) {
|
|
56
|
+
if (site.status === "ready" && site.redirect_url) {
|
|
57
|
+
const { site_url: _omitted, ...rest } = site;
|
|
58
|
+
writeJson(env.ctx.stdout, {
|
|
59
|
+
ok: true,
|
|
60
|
+
...rest,
|
|
61
|
+
user_handoff: USER_HANDOFF_MESSAGE,
|
|
62
|
+
mcp_setup: mcpSetup,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
writeJson(env.ctx.stdout, {
|
|
67
|
+
ok: true,
|
|
68
|
+
...site,
|
|
69
|
+
...(mcpSetup ? { mcp_setup: mcpSetup } : {}),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if (site.status === "ready" && site.redirect_url && env.options.open && !env.options.noOpen) {
|
|
73
|
+
env.ctx.openBrowser(site.redirect_url);
|
|
74
|
+
}
|
|
75
|
+
return 0;
|
|
76
|
+
}
|
|
77
|
+
env.ctx.stdout.write(`Site: ${site.name || site.subdomain} (${site.status})\n`);
|
|
78
|
+
if (site.redirect_url) {
|
|
79
|
+
env.ctx.stdout.write(`Admin sign-in link (open this directly to claim your admin account): ${site.redirect_url}\n`);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
env.ctx.stdout.write(`Site URL: ${site.site_url}\n`);
|
|
83
|
+
}
|
|
84
|
+
if (mcpSetup) {
|
|
85
|
+
if (site.redirect_url && !env.options.noOpen) {
|
|
86
|
+
if (env.options.open) {
|
|
87
|
+
env.ctx.openBrowser(site.redirect_url);
|
|
88
|
+
}
|
|
89
|
+
else if (interactive) {
|
|
90
|
+
const prompter = env.ctx.prompterFactory();
|
|
91
|
+
try {
|
|
92
|
+
const shouldOpen = await prompter.confirm({
|
|
93
|
+
message: "Open admin setup in browser?",
|
|
94
|
+
defaultValue: true,
|
|
95
|
+
});
|
|
96
|
+
if (shouldOpen) {
|
|
97
|
+
env.ctx.openBrowser(site.redirect_url);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
prompter.close?.();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
env.ctx.stdout.write(`\n${formatMcpGuidance(mcpSetup)}\n`);
|
|
106
|
+
}
|
|
107
|
+
return 0;
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
if (error instanceof ApiError && error.status === 401) {
|
|
111
|
+
if (resolved.fromCache) {
|
|
112
|
+
await env.store.clearToken(env.options.idUrl);
|
|
113
|
+
}
|
|
114
|
+
return emitAuthRequiredPrompt(env, "Your Discourse ID session expired. Please authenticate again.");
|
|
115
|
+
}
|
|
116
|
+
return emitError(env, error, 1);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=status.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status.js","sourceRoot":"","sources":["../../src/commands/status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,gBAAgB,EAA2B,MAAM,WAAW,CAAC;AAC/F,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAExD,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,SAAS,EACT,YAAY,GACb,MAAM,aAAa,CAAC;AAErB,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,GAAuB;IAC5D,MAAM,SAAS,GAAG,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;IAC7C,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,SAAS,CACd,GAAG,EACH,IAAI,QAAQ,CAAC,GAAG,EAAE,oBAAoB,EAAE;YACtC,mFAAmF;SACpF,CAAC,EACF,CAAC,CACF,CAAC;IACJ,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,GAAG,CAAC,CAAC;IACzC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,sBAAsB,CAAC,GAAG,CAAC,CAAC;IACrC,CAAC;IAED,MAAM,WAAW,GAAG,aAAa,CAAC;QAChC,UAAU,EAAE,GAAG,CAAC,GAAG,CA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,EAAE,EAAE,CAAC;oBACrB,CAAC;gBACH,CAAC;YACH,CAAC;YAED,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,iBAAiB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC7D,CAAC;QAED,OAAO,CAAC,CAAC;IACX,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,QAAQ,IAAI,KAAK,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YACtD,IAAI,QAAQ,CAAC,SAAS,EAAE,CAAC;gBACvB,MAAM,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAChD,CAAC;YACD,OAAO,sBAAsB,CAAC,GAAG,EAAE,+DAA+D,CAAC,CAAC;QACtG,CAAC;QACD,OAAO,SAAS,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IAClC,CAAC;AACH,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export declare const DEFAULT_ID_URL = "https://id.discourse.com";
|
|
2
|
+
/**
|
|
3
|
+
* Default non-confidential OAuth client_id values keyed by normalized Discourse ID origin.
|
|
4
|
+
*/
|
|
5
|
+
export declare const DEFAULT_CLIENT_IDS: Record<string, string>;
|
|
6
|
+
export declare const DEVICE_SCOPE = "read site_provision";
|
|
7
|
+
export declare const DEVICE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
|
|
8
|
+
export declare const TERMS_URLS: {
|
|
9
|
+
readonly free: "https://discourse.org/free-terms";
|
|
10
|
+
readonly trial: "https://discourse.org/trial-terms";
|
|
11
|
+
readonly user: "https://discourse.org/user-terms";
|
|
12
|
+
};
|
|
13
|
+
export declare const SUBDOMAIN_REGEX: RegExp;
|
|
14
|
+
export declare const CODE_REGEX: RegExp;
|
|
15
|
+
export declare const VALID_PLANS: readonly ["free", "pro", "standard", "business"];
|
|
16
|
+
export type Plan = (typeof VALID_PLANS)[number];
|
|
17
|
+
export declare const VALID_REGIONS: readonly ["global", "eu"];
|
|
18
|
+
export type Region = (typeof VALID_REGIONS)[number];
|
|
19
|
+
export interface PricingTier {
|
|
20
|
+
name: string;
|
|
21
|
+
display_name: string;
|
|
22
|
+
monthly_price_cents: number | null;
|
|
23
|
+
yearly_price_cents: number | null;
|
|
24
|
+
trial_days: number | null;
|
|
25
|
+
allows_region_selection: boolean;
|
|
26
|
+
limits?: {
|
|
27
|
+
pageviews?: number | null;
|
|
28
|
+
storage_bytes?: number | null;
|
|
29
|
+
monthly_emails?: number | null;
|
|
30
|
+
daily_emails?: number | null;
|
|
31
|
+
};
|
|
32
|
+
plugin_count?: number | null;
|
|
33
|
+
plugin_examples?: unknown;
|
|
34
|
+
}
|
|
35
|
+
export interface PricingData {
|
|
36
|
+
tiers?: Record<string, PricingTier>;
|
|
37
|
+
}
|
|
38
|
+
export declare const FALLBACK_TIERS: Record<string, PricingTier>;
|
|
39
|
+
export declare function normalizeIdUrl(raw?: string): string;
|
|
40
|
+
export declare function resolveClientId(idUrl: string, flag?: string, env?: NodeJS.ProcessEnv): string | undefined;
|
|
41
|
+
export declare function resolveConfigDir(flag?: string, env?: NodeJS.ProcessEnv): string;
|
|
42
|
+
export declare function normalizePlan(raw?: string): Plan | undefined;
|
|
43
|
+
export declare function normalizeRegion(raw?: string): Region | undefined;
|
|
44
|
+
export declare function validateSubdomain(raw: string): string | undefined;
|
|
45
|
+
export declare function slugifySubdomain(communityName: string): string;
|
|
46
|
+
export declare function validateCode(raw: string): string | undefined;
|
|
47
|
+
export declare function termsUrlForPlan(plan: Plan): string;
|
|
48
|
+
export declare function resolveTierName(plan: Plan): string;
|
|
49
|
+
export declare function generateCandidateSubdomain(communityName: string, attempt?: number, generateSuffix?: () => string): string;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
export const DEFAULT_ID_URL = "https://id.discourse.com";
|
|
5
|
+
/**
|
|
6
|
+
* Default non-confidential OAuth client_id values keyed by normalized Discourse ID origin.
|
|
7
|
+
*/
|
|
8
|
+
export const DEFAULT_CLIENT_IDS = {
|
|
9
|
+
"https://id.discourse.com": "sZzDY6daDItt71iT4w0Y2RBPn5Mo7eZS6m4Uyj1wWKM"
|
|
10
|
+
};
|
|
11
|
+
export const DEVICE_SCOPE = "read site_provision";
|
|
12
|
+
export const DEVICE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
|
|
13
|
+
export const TERMS_URLS = {
|
|
14
|
+
free: "https://discourse.org/free-terms",
|
|
15
|
+
trial: "https://discourse.org/trial-terms",
|
|
16
|
+
user: "https://discourse.org/user-terms",
|
|
17
|
+
};
|
|
18
|
+
export const SUBDOMAIN_REGEX = /^(?=[a-z0-9])(?=[a-z0-9-]{2,49}$)[a-z0-9-]+[a-z0-9]$/;
|
|
19
|
+
export const CODE_REGEX = /^[a-zA-Z0-9_-]{1,50}$/;
|
|
20
|
+
export const VALID_PLANS = ["free", "pro", "standard", "business"];
|
|
21
|
+
export const VALID_REGIONS = ["global", "eu"];
|
|
22
|
+
export const FALLBACK_TIERS = {
|
|
23
|
+
free: {
|
|
24
|
+
name: "free",
|
|
25
|
+
display_name: "Free Plan",
|
|
26
|
+
monthly_price_cents: 0,
|
|
27
|
+
yearly_price_cents: 0,
|
|
28
|
+
trial_days: 0,
|
|
29
|
+
allows_region_selection: false,
|
|
30
|
+
},
|
|
31
|
+
standard: {
|
|
32
|
+
name: "standard",
|
|
33
|
+
display_name: "Pro Plan",
|
|
34
|
+
monthly_price_cents: null,
|
|
35
|
+
yearly_price_cents: null,
|
|
36
|
+
trial_days: 14,
|
|
37
|
+
allows_region_selection: true,
|
|
38
|
+
},
|
|
39
|
+
business: {
|
|
40
|
+
name: "business",
|
|
41
|
+
display_name: "Business Plan",
|
|
42
|
+
monthly_price_cents: null,
|
|
43
|
+
yearly_price_cents: null,
|
|
44
|
+
trial_days: 14,
|
|
45
|
+
allows_region_selection: true,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
function isLocalhost(hostname) {
|
|
49
|
+
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]";
|
|
50
|
+
}
|
|
51
|
+
export function normalizeIdUrl(raw) {
|
|
52
|
+
const value = raw?.trim() || DEFAULT_ID_URL;
|
|
53
|
+
let parsed;
|
|
54
|
+
try {
|
|
55
|
+
parsed = new URL(value);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
throw new Error(`Invalid Discourse ID URL "${value}": must be a valid URL.`);
|
|
59
|
+
}
|
|
60
|
+
if (parsed.username || parsed.password) {
|
|
61
|
+
throw new Error(`Invalid Discourse ID URL "${value}": embedded credentials are not allowed.`);
|
|
62
|
+
}
|
|
63
|
+
if (parsed.protocol !== "https:" && !(parsed.protocol === "http:" && isLocalhost(parsed.hostname))) {
|
|
64
|
+
throw new Error(`Invalid Discourse ID URL "${value}": must use https:// (http:// is allowed only for localhost).`);
|
|
65
|
+
}
|
|
66
|
+
return parsed.origin;
|
|
67
|
+
}
|
|
68
|
+
export function resolveClientId(idUrl, flag, env = process.env) {
|
|
69
|
+
const fromFlag = flag?.trim();
|
|
70
|
+
if (fromFlag) {
|
|
71
|
+
return fromFlag;
|
|
72
|
+
}
|
|
73
|
+
const fromEnv = env.DISCOURSE_ID_CLIENT_ID?.trim();
|
|
74
|
+
if (fromEnv) {
|
|
75
|
+
return fromEnv;
|
|
76
|
+
}
|
|
77
|
+
return DEFAULT_CLIENT_IDS[idUrl];
|
|
78
|
+
}
|
|
79
|
+
export function resolveConfigDir(flag, env = process.env) {
|
|
80
|
+
const fromFlag = flag?.trim();
|
|
81
|
+
if (fromFlag) {
|
|
82
|
+
return path.resolve(fromFlag);
|
|
83
|
+
}
|
|
84
|
+
const fromEnv = env.DISCOURSE_CREATE_SITE_CONFIG_DIR?.trim();
|
|
85
|
+
if (fromEnv) {
|
|
86
|
+
return path.resolve(fromEnv);
|
|
87
|
+
}
|
|
88
|
+
const xdg = env.XDG_CONFIG_HOME?.trim();
|
|
89
|
+
if (xdg) {
|
|
90
|
+
return path.join(path.resolve(xdg), "discourse-create-site");
|
|
91
|
+
}
|
|
92
|
+
return path.join(os.homedir(), ".config", "discourse-create-site");
|
|
93
|
+
}
|
|
94
|
+
export function normalizePlan(raw) {
|
|
95
|
+
if (!raw) {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
const normalized = raw.trim().toLowerCase();
|
|
99
|
+
return VALID_PLANS.includes(normalized)
|
|
100
|
+
? normalized
|
|
101
|
+
: undefined;
|
|
102
|
+
}
|
|
103
|
+
export function normalizeRegion(raw) {
|
|
104
|
+
if (!raw) {
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
const normalized = raw.trim().toLowerCase();
|
|
108
|
+
const mapped = normalized === "europe" ? "eu" : normalized;
|
|
109
|
+
return VALID_REGIONS.includes(mapped)
|
|
110
|
+
? mapped
|
|
111
|
+
: undefined;
|
|
112
|
+
}
|
|
113
|
+
export function validateSubdomain(raw) {
|
|
114
|
+
const normalized = raw.trim().toLowerCase();
|
|
115
|
+
return SUBDOMAIN_REGEX.test(normalized) ? normalized : undefined;
|
|
116
|
+
}
|
|
117
|
+
export function slugifySubdomain(communityName) {
|
|
118
|
+
const slug = communityName
|
|
119
|
+
.normalize("NFKD")
|
|
120
|
+
.replace(/[\u0300-\u036f]/g, "")
|
|
121
|
+
.toLowerCase()
|
|
122
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
123
|
+
.replace(/^-+|-+$/g, "")
|
|
124
|
+
.slice(0, 49)
|
|
125
|
+
.replace(/-+$/g, "");
|
|
126
|
+
return SUBDOMAIN_REGEX.test(slug) ? slug : "";
|
|
127
|
+
}
|
|
128
|
+
export function validateCode(raw) {
|
|
129
|
+
const trimmed = raw.trim();
|
|
130
|
+
return CODE_REGEX.test(trimmed) ? trimmed : undefined;
|
|
131
|
+
}
|
|
132
|
+
export function termsUrlForPlan(plan) {
|
|
133
|
+
return plan === "free" ? TERMS_URLS.free : TERMS_URLS.trial;
|
|
134
|
+
}
|
|
135
|
+
export function resolveTierName(plan) {
|
|
136
|
+
return plan === "pro" ? "standard" : plan;
|
|
137
|
+
}
|
|
138
|
+
export function generateCandidateSubdomain(communityName, attempt = 0, generateSuffix = () => crypto.randomBytes(2).toString("hex")) {
|
|
139
|
+
const base = slugifySubdomain(communityName);
|
|
140
|
+
if (attempt === 0 && base) {
|
|
141
|
+
return base;
|
|
142
|
+
}
|
|
143
|
+
const suffix = generateSuffix()
|
|
144
|
+
.toLowerCase()
|
|
145
|
+
.replace(/[^a-z0-9]/g, "")
|
|
146
|
+
.slice(0, 8) || "site";
|
|
147
|
+
const maxPrefixLen = Math.max(2, 49 - suffix.length - 1);
|
|
148
|
+
const prefix = (base || "community").slice(0, maxPrefixLen).replace(/-+$/g, "") || "site";
|
|
149
|
+
return `${prefix}-${suffix}`;
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,CAAC,MAAM,cAAc,GAAG,0BAA0B,CAAC;AAEzD;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAA2B;IACxD,0BAA0B,EAAE,6CAA6C;CAC1E,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,qBAAqB,CAAC;AAClD,MAAM,CAAC,MAAM,iBAAiB,GAAG,8CAA8C,CAAC;AAEhF,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,IAAI,EAAE,kCAAkC;IACxC,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AC,aAAa,CAAC,CAAC;IAC7C,IAAI,OAAO,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,MAAM,GACV,cAAc,EAAE;SACb,WAAW,EAAE;SACb,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC;SACzB,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC;IAE3B,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACzD,MAAM,MAAM,GACV,CAAC,IAAI,IAAI,WAAW,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC;IAE7E,OAAO,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC;AAC/B,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
|
package/dist/mcp.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type DetectedAgentId = "claude_code" | "codex" | "gemini_cli" | "cursor" | "opencode" | "antigravity" | "generic";
|
|
2
|
+
export interface DetectedAgent {
|
|
3
|
+
id: DetectedAgentId;
|
|
4
|
+
name: string;
|
|
5
|
+
}
|
|
6
|
+
export interface McpClientInstruction {
|
|
7
|
+
client: string;
|
|
8
|
+
summary: string;
|
|
9
|
+
command?: string;
|
|
10
|
+
config_snippet?: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
export declare const POST_MCP_SETUP_NOTE = "Restart your coding agents after the setup. Most agents read their skills directory and MCP configuration at startup.";
|
|
13
|
+
export interface McpSetupInfo {
|
|
14
|
+
enabled_by_default: false;
|
|
15
|
+
admin_mcp_url: string;
|
|
16
|
+
site_setting: "mcp_server_enabled";
|
|
17
|
+
transport: "streamable-http";
|
|
18
|
+
mcp_endpoint: string;
|
|
19
|
+
oauth_metadata_url: string;
|
|
20
|
+
user_prompt_suggestion: "now add mcp support";
|
|
21
|
+
agent_instructions: string;
|
|
22
|
+
post_setup_note: string;
|
|
23
|
+
detected_client: DetectedAgent;
|
|
24
|
+
steps: string[];
|
|
25
|
+
client_instructions: McpClientInstruction;
|
|
26
|
+
}
|
|
27
|
+
export declare function detectAgentClient(env?: NodeJS.ProcessEnv): DetectedAgent;
|
|
28
|
+
export declare function buildMcpSetup(siteUrl: string, subdomain: string, env?: NodeJS.ProcessEnv): McpSetupInfo;
|
|
29
|
+
export declare function formatMcpGuidance(setup: McpSetupInfo): string;
|
package/dist/mcp.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
export const POST_MCP_SETUP_NOTE = "Restart your coding agents after the setup. Most agents read their skills directory and MCP configuration at startup.";
|
|
2
|
+
function hasNonEmptyEnv(env, ...keys) {
|
|
3
|
+
return keys.some((key) => Boolean(env[key]?.trim()));
|
|
4
|
+
}
|
|
5
|
+
export function detectAgentClient(env = process.env) {
|
|
6
|
+
if (hasNonEmptyEnv(env, "CLAUDECODE", "CLAUDE_CODE_ENTRYPOINT")) {
|
|
7
|
+
return { id: "claude_code", name: "Claude Code" };
|
|
8
|
+
}
|
|
9
|
+
if (hasNonEmptyEnv(env, "CODEX_THREAD_ID", "CODEX_SANDBOX", "CODEX_CI", "CODEX_MANAGED_BY_NPM")) {
|
|
10
|
+
return { id: "codex", name: "Codex" };
|
|
11
|
+
}
|
|
12
|
+
if (hasNonEmptyEnv(env, "GEMINI_CLI")) {
|
|
13
|
+
return { id: "gemini_cli", name: "Gemini CLI" };
|
|
14
|
+
}
|
|
15
|
+
if (hasNonEmptyEnv(env, "CURSOR_AGENT", "CURSOR_CLI")) {
|
|
16
|
+
return { id: "cursor", name: "Cursor" };
|
|
17
|
+
}
|
|
18
|
+
if (hasNonEmptyEnv(env, "OPENCODE", "OPENCODE_CLIENT")) {
|
|
19
|
+
return { id: "opencode", name: "OpenCode" };
|
|
20
|
+
}
|
|
21
|
+
if (hasNonEmptyEnv(env, "ANTIGRAVITY_CLI_ALIAS", "ANTIGRAVITY_AGENT")) {
|
|
22
|
+
return { id: "antigravity", name: "Antigravity" };
|
|
23
|
+
}
|
|
24
|
+
return { id: "generic", name: "Generic MCP Client" };
|
|
25
|
+
}
|
|
26
|
+
function buildClientInstructions(detected, subdomain, mcpEndpoint) {
|
|
27
|
+
switch (detected.id) {
|
|
28
|
+
case "claude_code":
|
|
29
|
+
return {
|
|
30
|
+
client: detected.name,
|
|
31
|
+
summary: `Add the Discourse MCP server in ${detected.name}:`,
|
|
32
|
+
command: `claude mcp add --transport http ${subdomain} ${mcpEndpoint}`,
|
|
33
|
+
};
|
|
34
|
+
case "codex":
|
|
35
|
+
return {
|
|
36
|
+
client: detected.name,
|
|
37
|
+
summary: `Add the Discourse MCP server in ${detected.name}:`,
|
|
38
|
+
command: `codex mcp add ${subdomain} --url ${mcpEndpoint}`,
|
|
39
|
+
};
|
|
40
|
+
case "gemini_cli":
|
|
41
|
+
return {
|
|
42
|
+
client: detected.name,
|
|
43
|
+
summary: `Add the Discourse MCP server in ${detected.name}:`,
|
|
44
|
+
command: `gemini mcp add --transport http ${subdomain} ${mcpEndpoint}`,
|
|
45
|
+
};
|
|
46
|
+
case "cursor":
|
|
47
|
+
return {
|
|
48
|
+
client: detected.name,
|
|
49
|
+
summary: `Add this server entry to your ${detected.name} MCP configuration:`,
|
|
50
|
+
config_snippet: {
|
|
51
|
+
mcpServers: {
|
|
52
|
+
[subdomain]: {
|
|
53
|
+
url: mcpEndpoint,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
case "opencode":
|
|
59
|
+
return {
|
|
60
|
+
client: detected.name,
|
|
61
|
+
summary: `Add this remote MCP entry to your ${detected.name} configuration:`,
|
|
62
|
+
config_snippet: {
|
|
63
|
+
mcp: {
|
|
64
|
+
[subdomain]: {
|
|
65
|
+
type: "remote",
|
|
66
|
+
url: mcpEndpoint,
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
case "antigravity":
|
|
72
|
+
return {
|
|
73
|
+
client: detected.name,
|
|
74
|
+
summary: `Add this server entry to your ${detected.name} MCP configuration:`,
|
|
75
|
+
config_snippet: {
|
|
76
|
+
mcpServers: {
|
|
77
|
+
[subdomain]: {
|
|
78
|
+
serverUrl: mcpEndpoint,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
case "generic":
|
|
84
|
+
return {
|
|
85
|
+
client: detected.name,
|
|
86
|
+
summary: "Configure a remote Streamable HTTP MCP server in your AI client using the endpoint below (OAuth 2.0 auto-discovery is supported):",
|
|
87
|
+
config_snippet: {
|
|
88
|
+
name: subdomain,
|
|
89
|
+
transport: "http",
|
|
90
|
+
url: mcpEndpoint,
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
export function buildMcpSetup(siteUrl, subdomain, env = process.env) {
|
|
96
|
+
const origin = new URL(siteUrl).origin;
|
|
97
|
+
const adminMcpUrl = `${origin}/admin/config/mcp/settings`;
|
|
98
|
+
const mcpEndpoint = `${origin}/mcp`;
|
|
99
|
+
const oauthMetadataUrl = `${origin}/.well-known/oauth-protected-resource/mcp`;
|
|
100
|
+
const detectedClient = detectAgentClient(env);
|
|
101
|
+
const userPromptSuggestion = "now add mcp support";
|
|
102
|
+
return {
|
|
103
|
+
enabled_by_default: false,
|
|
104
|
+
admin_mcp_url: adminMcpUrl,
|
|
105
|
+
site_setting: "mcp_server_enabled",
|
|
106
|
+
transport: "streamable-http",
|
|
107
|
+
mcp_endpoint: mcpEndpoint,
|
|
108
|
+
oauth_metadata_url: oauthMetadataUrl,
|
|
109
|
+
user_prompt_suggestion: userPromptSuggestion,
|
|
110
|
+
agent_instructions: `Do NOT tell the user to run a separate command outside this session. Tell the user to enable MCP (\`mcp_server_enabled\`) at ${adminMcpUrl} after admin sign-in, then reply "${userPromptSuggestion}". When the user replies, add/configure the remote Streamable HTTP MCP server "${subdomain}" for ${mcpEndpoint} (OAuth discovery: ${oauthMetadataUrl}) directly in this environment. Once MCP setup is confirmed, include this note: "${POST_MCP_SETUP_NOTE}"`,
|
|
111
|
+
post_setup_note: POST_MCP_SETUP_NOTE,
|
|
112
|
+
detected_client: detectedClient,
|
|
113
|
+
steps: [
|
|
114
|
+
"Open the admin sign-in link directly to claim and finish setting up your admin account.",
|
|
115
|
+
`Once admin sign-in is complete, enable MCP (\`mcp_server_enabled\`) at ${adminMcpUrl}`,
|
|
116
|
+
`Once enabled, reply "${userPromptSuggestion}" here so your agent adds MCP for ${mcpEndpoint}.`,
|
|
117
|
+
],
|
|
118
|
+
client_instructions: buildClientInstructions(detectedClient, subdomain, mcpEndpoint),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
export function formatMcpGuidance(setup) {
|
|
122
|
+
return [
|
|
123
|
+
"Enable Discourse MCP on your new community:",
|
|
124
|
+
` 1. ${setup.steps[0]}`,
|
|
125
|
+
" 2. Once admin sign-in is complete, enable MCP (`mcp_server_enabled`):",
|
|
126
|
+
` ${setup.admin_mcp_url}`,
|
|
127
|
+
` 3. Once enabled, tell your AI agent: "${setup.user_prompt_suggestion}"`,
|
|
128
|
+
` MCP endpoint (Streamable HTTP): ${setup.mcp_endpoint}`,
|
|
129
|
+
` Note: ${setup.post_setup_note}`,
|
|
130
|
+
].join("\n");
|
|
131
|
+
}
|
|
132
|
+
//#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,kBAAkB,EAAE,gBAAgB;QACpC,sBAAsB,EAAE,oBAAoB;QAC5C,kBAAkB,EAAE,gIAAgI,WAAW,qCAAqC,oBAAoB,kFAAkF,SAAS,SAAS,WAAW,sBAAsB,gBAAgB,oFAAoF,mBAAmB,GAAG;QACvd,eAAe,EAAE,mBAAmB;QACpC,eAAe,EAAE,cAAc;QAC/B,KAAK,EAAE;YACL,yFAAyF;YACzF,0EAA0E,WAAW,EAAE;YACvF,wBAAwB,oBAAoB,qCAAqC,WAAW,GAAG;SAChG;QACD,mBAAmB,EAAE,uBAAuB,CAAC,cAAc,EAAE,SAAS,EAAE,WAAW,CAAC;KACrF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAmB;IACnD,OAAO;QACL,6CAA6C;QAC7C,QAAQ,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;QACxB,yEAAyE;QACzE,QAAQ,KAAK,CAAC,aAAa,EAAE;QAC7B,2CAA2C,KAAK,CAAC,sBAAsB,GAAG;QAC1E,wCAAwC,KAAK,CAAC,YAAY,EAAE;QAC5D,WAAW,KAAK,CAAC,eAAe,EAAE;KACnC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
|
package/dist/output.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Writable } from "node:stream";
|
|
2
|
+
export declare function writeJson(stream: Writable, payload: unknown): void;
|
|
3
|
+
export declare function isInteractive(options: {
|
|
4
|
+
stdinIsTTY: boolean;
|
|
5
|
+
stdoutIsTTY: boolean;
|
|
6
|
+
json: boolean;
|
|
7
|
+
nonInteractive: boolean;
|
|
8
|
+
}): boolean;
|
|
9
|
+
export declare function formatCliError(error: unknown): {
|
|
10
|
+
code: string;
|
|
11
|
+
message: string;
|
|
12
|
+
errors: string[];
|
|
13
|
+
status?: number;
|
|
14
|
+
retryAfterSeconds?: number;
|
|
15
|
+
};
|
package/dist/output.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function writeJson(stream, payload) {
|
|
2
|
+
stream.write(`${JSON.stringify(payload, null, 2)}\n`);
|
|
3
|
+
}
|
|
4
|
+
export function isInteractive(options) {
|
|
5
|
+
return options.stdinIsTTY && options.stdoutIsTTY && !options.json && !options.nonInteractive;
|
|
6
|
+
}
|
|
7
|
+
export function formatCliError(error) {
|
|
8
|
+
if (error instanceof Error && "code" in error && "status" in error && "errors" in error) {
|
|
9
|
+
const apiErr = error;
|
|
10
|
+
return {
|
|
11
|
+
code: apiErr.code,
|
|
12
|
+
message: apiErr.message,
|
|
13
|
+
errors: apiErr.errors,
|
|
14
|
+
status: apiErr.status,
|
|
15
|
+
...(apiErr.retryAfterSeconds !== undefined
|
|
16
|
+
? { retryAfterSeconds: apiErr.retryAfterSeconds }
|
|
17
|
+
: {}),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
21
|
+
return {
|
|
22
|
+
code: "error",
|
|
23
|
+
message,
|
|
24
|
+
errors: [message],
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=output.js.map
|