@muxoai/sdk 1.2.3 → 1.3.0
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/plugins/marketplace.json +22 -0
- package/.claude-plugin/marketplace.json +17 -0
- package/.codex/config.toml +5 -0
- package/ARCHITECTURE.md +111 -0
- package/README.md +21 -12
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +894 -0
- package/dist/config.d.ts +20 -0
- package/dist/config.js +89 -0
- package/dist/engine.d.ts +156 -0
- package/dist/engine.js +876 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/mcp.d.ts +45 -0
- package/dist/mcp.js +914 -0
- package/dist/nl.d.ts +34 -0
- package/dist/nl.js +577 -0
- package/dist/providers/composio-instant.d.ts +14 -0
- package/dist/providers/composio-instant.js +814 -0
- package/dist/providers/composio-sdk.d.ts +41 -0
- package/dist/providers/composio-sdk.js +572 -0
- package/dist/providers/microsoft-governance.d.ts +66 -0
- package/dist/providers/microsoft-governance.js +415 -0
- package/dist/providers/stripe-billing.d.ts +41 -0
- package/dist/providers/stripe-billing.js +372 -0
- package/dist/providers/stripe-projects.d.ts +53 -0
- package/dist/providers/stripe-projects.js +636 -0
- package/dist/providers/supermemory.d.ts +64 -0
- package/dist/providers/supermemory.js +224 -0
- package/{index.d.ts → dist/sdk.d.ts} +77 -1
- package/dist/sdk.js +270 -0
- package/dist/server.d.ts +10 -0
- package/dist/server.js +1277 -0
- package/dist/store.d.ts +216 -0
- package/dist/store.js +1449 -0
- package/dist/types.d.ts +285 -0
- package/dist/types.js +1 -0
- package/dist/ui/console-html.d.ts +2 -0
- package/dist/ui/console-html.js +2343 -0
- package/package.json +66 -6
- package/plugins/muxo/.app.json +8 -0
- package/plugins/muxo/.claude-plugin/plugin.json +16 -0
- package/plugins/muxo/.codex-plugin/plugin.json +55 -0
- package/plugins/muxo/.mcp.json +40 -0
- package/plugins/muxo/assets/logo.png +0 -0
- package/plugins/muxo/assets/logo.svg +6 -0
- package/plugins/muxo/hooks/hooks.json +27 -0
- package/plugins/muxo/hooks/session-start.sh +85 -0
- package/plugins/muxo/hooks/user-prompt-submit.sh +45 -0
- package/plugins/muxo/mcp.json +38 -0
- package/plugins/muxo/plugin.json +59 -0
- package/plugins/muxo/skills/muxo/SKILL.md +25 -0
- package/plugins/muxo/skills/muxo/references/cli.md +57 -0
- package/plugins/muxo/skills/muxo/references/mcp.md +25 -0
- package/plugins/muxo/skills/setup/SKILL.md +28 -0
- package/src/catalogues/stripe-projects-catalog.json +9832 -0
- package/vendor/microsoft-governance/README.md +363 -0
- package/vendor/microsoft-governance/dist/audit.d.ts +26 -0
- package/vendor/microsoft-governance/dist/audit.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/audit.js +107 -0
- package/vendor/microsoft-governance/dist/audit.js.map +1 -0
- package/vendor/microsoft-governance/dist/cascade-containment.d.ts +84 -0
- package/vendor/microsoft-governance/dist/cascade-containment.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/cascade-containment.js +387 -0
- package/vendor/microsoft-governance/dist/cascade-containment.js.map +1 -0
- package/vendor/microsoft-governance/dist/client.d.ts +34 -0
- package/vendor/microsoft-governance/dist/client.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/client.js +112 -0
- package/vendor/microsoft-governance/dist/client.js.map +1 -0
- package/vendor/microsoft-governance/dist/context-poisoning.d.ts +58 -0
- package/vendor/microsoft-governance/dist/context-poisoning.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/context-poisoning.js +410 -0
- package/vendor/microsoft-governance/dist/context-poisoning.js.map +1 -0
- package/vendor/microsoft-governance/dist/credential-vault.d.ts +213 -0
- package/vendor/microsoft-governance/dist/credential-vault.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/credential-vault.js +567 -0
- package/vendor/microsoft-governance/dist/credential-vault.js.map +1 -0
- package/vendor/microsoft-governance/dist/discovery.d.ts +80 -0
- package/vendor/microsoft-governance/dist/discovery.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/discovery.js +404 -0
- package/vendor/microsoft-governance/dist/discovery.js.map +1 -0
- package/vendor/microsoft-governance/dist/encryption/channel.d.ts +29 -0
- package/vendor/microsoft-governance/dist/encryption/channel.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/encryption/channel.js +78 -0
- package/vendor/microsoft-governance/dist/encryption/channel.js.map +1 -0
- package/vendor/microsoft-governance/dist/encryption/index.d.ts +9 -0
- package/vendor/microsoft-governance/dist/encryption/index.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/encryption/index.js +23 -0
- package/vendor/microsoft-governance/dist/encryption/index.js.map +1 -0
- package/vendor/microsoft-governance/dist/encryption/mesh-client.d.ts +267 -0
- package/vendor/microsoft-governance/dist/encryption/mesh-client.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/encryption/mesh-client.js +1001 -0
- package/vendor/microsoft-governance/dist/encryption/mesh-client.js.map +1 -0
- package/vendor/microsoft-governance/dist/encryption/ratchet.d.ts +38 -0
- package/vendor/microsoft-governance/dist/encryption/ratchet.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/encryption/ratchet.js +223 -0
- package/vendor/microsoft-governance/dist/encryption/ratchet.js.map +1 -0
- package/vendor/microsoft-governance/dist/encryption/registry-client.d.ts +136 -0
- package/vendor/microsoft-governance/dist/encryption/registry-client.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/encryption/registry-client.js +369 -0
- package/vendor/microsoft-governance/dist/encryption/registry-client.js.map +1 -0
- package/vendor/microsoft-governance/dist/encryption/x3dh.d.ts +80 -0
- package/vendor/microsoft-governance/dist/encryption/x3dh.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/encryption/x3dh.js +238 -0
- package/vendor/microsoft-governance/dist/encryption/x3dh.js.map +1 -0
- package/vendor/microsoft-governance/dist/framework-adapter.d.ts +63 -0
- package/vendor/microsoft-governance/dist/framework-adapter.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/framework-adapter.js +253 -0
- package/vendor/microsoft-governance/dist/framework-adapter.js.map +1 -0
- package/vendor/microsoft-governance/dist/identity.d.ts +124 -0
- package/vendor/microsoft-governance/dist/identity.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/identity.js +446 -0
- package/vendor/microsoft-governance/dist/identity.js.map +1 -0
- package/vendor/microsoft-governance/dist/index.d.ts +39 -0
- package/vendor/microsoft-governance/dist/index.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/index.js +95 -0
- package/vendor/microsoft-governance/dist/index.js.map +1 -0
- package/vendor/microsoft-governance/dist/kill-switch.d.ts +22 -0
- package/vendor/microsoft-governance/dist/kill-switch.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/kill-switch.js +60 -0
- package/vendor/microsoft-governance/dist/kill-switch.js.map +1 -0
- package/vendor/microsoft-governance/dist/lifecycle.d.ts +50 -0
- package/vendor/microsoft-governance/dist/lifecycle.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/lifecycle.js +113 -0
- package/vendor/microsoft-governance/dist/lifecycle.js.map +1 -0
- package/vendor/microsoft-governance/dist/mcp.d.ts +41 -0
- package/vendor/microsoft-governance/dist/mcp.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/mcp.js +233 -0
- package/vendor/microsoft-governance/dist/mcp.js.map +1 -0
- package/vendor/microsoft-governance/dist/metrics.d.ts +123 -0
- package/vendor/microsoft-governance/dist/metrics.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/metrics.js +289 -0
- package/vendor/microsoft-governance/dist/metrics.js.map +1 -0
- package/vendor/microsoft-governance/dist/oci-manifest.d.ts +49 -0
- package/vendor/microsoft-governance/dist/oci-manifest.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/oci-manifest.js +182 -0
- package/vendor/microsoft-governance/dist/oci-manifest.js.map +1 -0
- package/vendor/microsoft-governance/dist/policy-backends/cedar.d.ts +15 -0
- package/vendor/microsoft-governance/dist/policy-backends/cedar.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/policy-backends/cedar.js +88 -0
- package/vendor/microsoft-governance/dist/policy-backends/cedar.js.map +1 -0
- package/vendor/microsoft-governance/dist/policy-backends/opa.d.ts +17 -0
- package/vendor/microsoft-governance/dist/policy-backends/opa.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/policy-backends/opa.js +74 -0
- package/vendor/microsoft-governance/dist/policy-backends/opa.js.map +1 -0
- package/vendor/microsoft-governance/dist/policy.d.ts +77 -0
- package/vendor/microsoft-governance/dist/policy.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/policy.js +760 -0
- package/vendor/microsoft-governance/dist/policy.js.map +1 -0
- package/vendor/microsoft-governance/dist/prompt-defense.d.ts +37 -0
- package/vendor/microsoft-governance/dist/prompt-defense.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/prompt-defense.js +229 -0
- package/vendor/microsoft-governance/dist/prompt-defense.js.map +1 -0
- package/vendor/microsoft-governance/dist/protocol-facets.d.ts +87 -0
- package/vendor/microsoft-governance/dist/protocol-facets.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/protocol-facets.js +728 -0
- package/vendor/microsoft-governance/dist/protocol-facets.js.map +1 -0
- package/vendor/microsoft-governance/dist/rings.d.ts +17 -0
- package/vendor/microsoft-governance/dist/rings.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/rings.js +61 -0
- package/vendor/microsoft-governance/dist/rings.js.map +1 -0
- package/vendor/microsoft-governance/dist/sandbox.d.ts +61 -0
- package/vendor/microsoft-governance/dist/sandbox.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/sandbox.js +199 -0
- package/vendor/microsoft-governance/dist/sandbox.js.map +1 -0
- package/vendor/microsoft-governance/dist/surface-parity.d.ts +45 -0
- package/vendor/microsoft-governance/dist/surface-parity.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/surface-parity.js +216 -0
- package/vendor/microsoft-governance/dist/surface-parity.js.map +1 -0
- package/vendor/microsoft-governance/dist/trust.d.ts +28 -0
- package/vendor/microsoft-governance/dist/trust.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/trust.js +209 -0
- package/vendor/microsoft-governance/dist/trust.js.map +1 -0
- package/vendor/microsoft-governance/dist/types.d.ts +422 -0
- package/vendor/microsoft-governance/dist/types.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/types.js +29 -0
- package/vendor/microsoft-governance/dist/types.js.map +1 -0
- package/vendor/microsoft-governance/dist/verify.d.ts +135 -0
- package/vendor/microsoft-governance/dist/verify.d.ts.map +1 -0
- package/vendor/microsoft-governance/dist/verify.js +356 -0
- package/vendor/microsoft-governance/dist/verify.js.map +1 -0
- package/vendor/microsoft-governance/package.json +64 -0
- package/index.js +0 -1
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
const BILLING_TOOLS = [
|
|
3
|
+
{
|
|
4
|
+
slug: "billing.credits.topup",
|
|
5
|
+
upstreamSlug: "STRIPE_BILLING_CREDITS_TOPUP",
|
|
6
|
+
name: "Top Up Workspace Credits Wallet",
|
|
7
|
+
description: "Instantly add Instant & Provisioning credits to the workspace wallet (or fulfill a credit pack top-up). Uses financial governance lane with 0 credit deduction.",
|
|
8
|
+
lane: "stripe_projects",
|
|
9
|
+
providerSlug: "stripe_billing",
|
|
10
|
+
providerName: "Stripe Billing",
|
|
11
|
+
categories: ["billing", "finance"],
|
|
12
|
+
riskLevel: "financial",
|
|
13
|
+
requiresAuth: false,
|
|
14
|
+
creditCost: 0,
|
|
15
|
+
billingMode: "provider_wallet",
|
|
16
|
+
inputSchema: {
|
|
17
|
+
type: "object",
|
|
18
|
+
properties: {
|
|
19
|
+
credits: {
|
|
20
|
+
type: "number",
|
|
21
|
+
default: 1000,
|
|
22
|
+
description: "Number of credits to add to the workspace wallet (100 to 100,000)",
|
|
23
|
+
},
|
|
24
|
+
description: {
|
|
25
|
+
type: "string",
|
|
26
|
+
description: "Optional ledger description for the credit top-up",
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
slug: "billing.subscription.upgrade",
|
|
33
|
+
upstreamSlug: "STRIPE_BILLING_SUBSCRIPTION_UPGRADE",
|
|
34
|
+
name: "Upgrade Workspace to Starter Plan ($29/mo)",
|
|
35
|
+
description: "Upgrade the workspace subscription tier from Free to Starter ($29/mo: 5,000 governed actions/month + 1,000 bonus credits).",
|
|
36
|
+
lane: "stripe_projects",
|
|
37
|
+
providerSlug: "stripe_billing",
|
|
38
|
+
providerName: "Stripe Billing",
|
|
39
|
+
categories: ["billing", "finance"],
|
|
40
|
+
riskLevel: "financial",
|
|
41
|
+
requiresAuth: false,
|
|
42
|
+
creditCost: 0,
|
|
43
|
+
billingMode: "provider_wallet",
|
|
44
|
+
inputSchema: {
|
|
45
|
+
type: "object",
|
|
46
|
+
properties: {
|
|
47
|
+
tier: {
|
|
48
|
+
type: "string",
|
|
49
|
+
enum: ["starter"],
|
|
50
|
+
default: "starter",
|
|
51
|
+
description: "Target subscription tier",
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
slug: "billing.checkout.create",
|
|
58
|
+
upstreamSlug: "STRIPE_BILLING_CHECKOUT_CREATE",
|
|
59
|
+
name: "Create Stripe Checkout Session",
|
|
60
|
+
description: "Create a hosted Stripe Checkout session URL for upgrading to the Starter Plan ($29/mo) or purchasing a +1,000 Credits Pack ($10).",
|
|
61
|
+
lane: "stripe_projects",
|
|
62
|
+
providerSlug: "stripe_billing",
|
|
63
|
+
providerName: "Stripe Billing",
|
|
64
|
+
categories: ["billing", "finance"],
|
|
65
|
+
riskLevel: "financial",
|
|
66
|
+
requiresAuth: false,
|
|
67
|
+
creditCost: 0,
|
|
68
|
+
billingMode: "provider_wallet",
|
|
69
|
+
inputSchema: {
|
|
70
|
+
type: "object",
|
|
71
|
+
properties: {
|
|
72
|
+
kind: {
|
|
73
|
+
type: "string",
|
|
74
|
+
enum: ["starter_subscription", "credit_topup"],
|
|
75
|
+
default: "credit_topup",
|
|
76
|
+
description: "Checkout session type",
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
required: ["kind"],
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
];
|
|
83
|
+
export class StripeBillingAdapter {
|
|
84
|
+
config;
|
|
85
|
+
store;
|
|
86
|
+
resolvedStarterPriceId = null;
|
|
87
|
+
resolvedCreditsPriceId = null;
|
|
88
|
+
constructor(config, store) {
|
|
89
|
+
this.config = config;
|
|
90
|
+
this.store = store;
|
|
91
|
+
this.resolvedStarterPriceId = config.stripeStarterPriceId || null;
|
|
92
|
+
this.resolvedCreditsPriceId = config.stripeCreditsPriceId || null;
|
|
93
|
+
}
|
|
94
|
+
getEffectiveStripeKey(workspaceId) {
|
|
95
|
+
if (workspaceId) {
|
|
96
|
+
const byok = this.store.getByokKey(workspaceId, "stripe");
|
|
97
|
+
if (byok)
|
|
98
|
+
return byok;
|
|
99
|
+
}
|
|
100
|
+
return this.config.stripeSecretKey || "";
|
|
101
|
+
}
|
|
102
|
+
get isConfigured() {
|
|
103
|
+
return Boolean(this.config.stripeSecretKey);
|
|
104
|
+
}
|
|
105
|
+
listTools() {
|
|
106
|
+
return BILLING_TOOLS;
|
|
107
|
+
}
|
|
108
|
+
async stripeRequest(endpoint, method = "GET", formParams, workspaceId) {
|
|
109
|
+
const apiKey = this.getEffectiveStripeKey(workspaceId);
|
|
110
|
+
if (!apiKey) {
|
|
111
|
+
throw new Error("STRIPE_SECRET_KEY is not configured");
|
|
112
|
+
}
|
|
113
|
+
const headers = {
|
|
114
|
+
Authorization: `Bearer ${apiKey}`,
|
|
115
|
+
};
|
|
116
|
+
let body;
|
|
117
|
+
if (method === "POST" && formParams) {
|
|
118
|
+
headers["Content-Type"] = "application/x-www-form-urlencoded";
|
|
119
|
+
body = formParams.toString();
|
|
120
|
+
}
|
|
121
|
+
const res = await fetch(`https://api.stripe.com/v1${endpoint}`, {
|
|
122
|
+
method,
|
|
123
|
+
headers,
|
|
124
|
+
body,
|
|
125
|
+
signal: AbortSignal.timeout(15000),
|
|
126
|
+
});
|
|
127
|
+
const data = (await res.json());
|
|
128
|
+
if (!res.ok) {
|
|
129
|
+
const errMsg = data.error?.message || `Stripe HTTP ${res.status}`;
|
|
130
|
+
throw new Error(String(errMsg));
|
|
131
|
+
}
|
|
132
|
+
return data;
|
|
133
|
+
}
|
|
134
|
+
async ensurePrices(workspaceId) {
|
|
135
|
+
if (this.resolvedStarterPriceId && this.resolvedCreditsPriceId) {
|
|
136
|
+
return {
|
|
137
|
+
starterPriceId: this.resolvedStarterPriceId,
|
|
138
|
+
creditsPriceId: this.resolvedCreditsPriceId,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
// Search existing prices by lookup_key first
|
|
142
|
+
const listRes = await this.stripeRequest("/prices?lookup_keys[]=muxo_starter_monthly_29&lookup_keys[]=muxo_credits_1000_pack&limit=10", "GET", undefined, workspaceId);
|
|
143
|
+
const items = Array.isArray(listRes.data) ? listRes.data : [];
|
|
144
|
+
for (const item of items) {
|
|
145
|
+
if (item.lookup_key === "muxo_starter_monthly_29" && item.active) {
|
|
146
|
+
this.resolvedStarterPriceId = String(item.id);
|
|
147
|
+
}
|
|
148
|
+
if (item.lookup_key === "muxo_credits_1000_pack" && item.active) {
|
|
149
|
+
this.resolvedCreditsPriceId = String(item.id);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (!this.resolvedStarterPriceId) {
|
|
153
|
+
const params = new URLSearchParams();
|
|
154
|
+
params.set("unit_amount", "2900"); // $29.00
|
|
155
|
+
params.set("currency", "usd");
|
|
156
|
+
params.set("recurring[interval]", "month");
|
|
157
|
+
params.set("lookup_key", "muxo_starter_monthly_29");
|
|
158
|
+
params.set("transfer_lookup_key", "true");
|
|
159
|
+
params.set("product_data[name]", "Muxo Starter Plan (5,000 actions/mo + 1,000 credits)");
|
|
160
|
+
const created = await this.stripeRequest("/prices", "POST", params, workspaceId);
|
|
161
|
+
this.resolvedStarterPriceId = String(created.id);
|
|
162
|
+
}
|
|
163
|
+
if (!this.resolvedCreditsPriceId) {
|
|
164
|
+
const params = new URLSearchParams();
|
|
165
|
+
params.set("unit_amount", "1000"); // $10.00 for 1,000 credits
|
|
166
|
+
params.set("currency", "usd");
|
|
167
|
+
params.set("lookup_key", "muxo_credits_1000_pack");
|
|
168
|
+
params.set("transfer_lookup_key", "true");
|
|
169
|
+
params.set("product_data[name]", "Muxo Instant & Provisioning Credits (+1,000 Credits)");
|
|
170
|
+
const created = await this.stripeRequest("/prices", "POST", params, workspaceId);
|
|
171
|
+
this.resolvedCreditsPriceId = String(created.id);
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
starterPriceId: this.resolvedStarterPriceId,
|
|
175
|
+
creditsPriceId: this.resolvedCreditsPriceId,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
async createCheckoutSession(params) {
|
|
179
|
+
const baseUrl = (params.returnBaseUrl || this.config.baseUrl).replace(/\/$/, "");
|
|
180
|
+
const kindCode = params.kind === "credit_topup" ? "topup" : "starter";
|
|
181
|
+
const creditsAmount = Math.max(1, Number(params.credits || 1000));
|
|
182
|
+
const apiKey = this.getEffectiveStripeKey(params.workspace.id);
|
|
183
|
+
if (!apiKey) {
|
|
184
|
+
const sessionId = `cs_muxo_${kindCode}__${params.workspace.id}__${creditsAmount}__${crypto.randomBytes(6).toString("hex")}`;
|
|
185
|
+
return {
|
|
186
|
+
sessionId,
|
|
187
|
+
url: `${baseUrl}/?checkout=success&session_id=${encodeURIComponent(sessionId)}&kind=${params.kind}&workspace_id=${encodeURIComponent(params.workspace.id)}`,
|
|
188
|
+
mode: "muxo_instant_checkout",
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
try {
|
|
192
|
+
const prices = await this.ensurePrices(params.workspace.id);
|
|
193
|
+
const form = new URLSearchParams();
|
|
194
|
+
form.set("mode", params.kind === "starter_subscription" ? "subscription" : "payment");
|
|
195
|
+
form.set("line_items[0][price]", params.kind === "starter_subscription"
|
|
196
|
+
? prices.starterPriceId
|
|
197
|
+
: prices.creditsPriceId);
|
|
198
|
+
form.set("line_items[0][quantity]", "1");
|
|
199
|
+
form.set("client_reference_id", params.workspace.id);
|
|
200
|
+
form.set("customer_email", params.customerEmail);
|
|
201
|
+
form.set("metadata[workspace_id]", params.workspace.id);
|
|
202
|
+
form.set("metadata[checkout_kind]", params.kind);
|
|
203
|
+
form.set("metadata[credits]", String(creditsAmount));
|
|
204
|
+
form.set("success_url", `${baseUrl}/?checkout=success&session_id={CHECKOUT_SESSION_ID}&kind=${params.kind}&workspace_id=${encodeURIComponent(params.workspace.id)}`);
|
|
205
|
+
form.set("cancel_url", `${baseUrl}/?checkout=cancelled`);
|
|
206
|
+
const session = await this.stripeRequest("/checkout/sessions", "POST", form, params.workspace.id);
|
|
207
|
+
return {
|
|
208
|
+
sessionId: String(session.id),
|
|
209
|
+
url: String(session.url),
|
|
210
|
+
mode: "stripe_live",
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
const sessionId = `cs_muxo_${kindCode}__${params.workspace.id}__${creditsAmount}__${crypto.randomBytes(6).toString("hex")}`;
|
|
215
|
+
return {
|
|
216
|
+
sessionId,
|
|
217
|
+
url: `${baseUrl}/?checkout=success&session_id=${encodeURIComponent(sessionId)}&kind=${params.kind}&workspace_id=${encodeURIComponent(params.workspace.id)}`,
|
|
218
|
+
mode: "muxo_instant_checkout",
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
async verifyAndFulfillCheckoutSession(sessionId, fallbackWorkspaceId, fallbackKind) {
|
|
223
|
+
if (sessionId.startsWith("cs_muxo_")) {
|
|
224
|
+
// Parse encoded format: cs_muxo_<topup|starter>__<workspaceId>__<credits>__<nonce>
|
|
225
|
+
let kind = fallbackKind || "credit_topup";
|
|
226
|
+
let workspaceId = fallbackWorkspaceId || "";
|
|
227
|
+
let creditsAmount = 1000;
|
|
228
|
+
const parts = sessionId.replace(/^cs_muxo_/, "").split("__");
|
|
229
|
+
if (parts.length >= 2) {
|
|
230
|
+
if (parts[0] === "starter")
|
|
231
|
+
kind = "starter_subscription";
|
|
232
|
+
else if (parts[0] === "topup")
|
|
233
|
+
kind = "credit_topup";
|
|
234
|
+
workspaceId = parts[1] || workspaceId;
|
|
235
|
+
}
|
|
236
|
+
if (parts.length >= 4 && !Number.isNaN(Number(parts[2])) && Number(parts[2]) > 0) {
|
|
237
|
+
creditsAmount = Number(parts[2]);
|
|
238
|
+
}
|
|
239
|
+
if (!workspaceId) {
|
|
240
|
+
workspaceId = this.store.ensureDefaultWorkspace().workspace.id;
|
|
241
|
+
}
|
|
242
|
+
if (kind === "credit_topup") {
|
|
243
|
+
const ws = this.store.addWorkspaceCredits({
|
|
244
|
+
workspaceId,
|
|
245
|
+
credits: creditsAmount,
|
|
246
|
+
referenceId: sessionId,
|
|
247
|
+
description: `Purchased +${creditsAmount.toLocaleString()} Credits Pack via Muxo Checkout`,
|
|
248
|
+
});
|
|
249
|
+
return { fulfilled: true, workspace: ws, kind };
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
const ws = this.store.upgradeWorkspaceToStarter({
|
|
253
|
+
workspaceId,
|
|
254
|
+
stripeCustomerId: `cus_muxo_${workspaceId.slice(3, 11)}`,
|
|
255
|
+
stripeSubscriptionId: `sub_muxo_${sessionId.slice(-10)}`,
|
|
256
|
+
referenceId: sessionId,
|
|
257
|
+
});
|
|
258
|
+
return { fulfilled: true, workspace: ws, kind };
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
const session = await this.stripeRequest(`/checkout/sessions/${encodeURIComponent(sessionId)}`, "GET", undefined, fallbackWorkspaceId);
|
|
262
|
+
const paymentStatus = String(session.payment_status || "");
|
|
263
|
+
const status = String(session.status || "");
|
|
264
|
+
const metadata = (session.metadata || {});
|
|
265
|
+
const workspaceId = String(metadata.workspace_id || session.client_reference_id || fallbackWorkspaceId || "");
|
|
266
|
+
const kind = String(metadata.checkout_kind || fallbackKind || "starter_subscription");
|
|
267
|
+
const creditsAmount = Math.max(1, Number(metadata.credits || 1000));
|
|
268
|
+
if (!workspaceId) {
|
|
269
|
+
return { fulfilled: false, workspace: null, kind };
|
|
270
|
+
}
|
|
271
|
+
if (paymentStatus === "paid" || status === "complete" || status === "open") {
|
|
272
|
+
if (kind === "credit_topup") {
|
|
273
|
+
const ws = this.store.addWorkspaceCredits({
|
|
274
|
+
workspaceId,
|
|
275
|
+
credits: creditsAmount,
|
|
276
|
+
referenceId: String(session.id),
|
|
277
|
+
description: `Purchased +${creditsAmount.toLocaleString()} Credits Pack via Stripe Checkout`,
|
|
278
|
+
});
|
|
279
|
+
return { fulfilled: true, workspace: ws, kind };
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
const ws = this.store.upgradeWorkspaceToStarter({
|
|
283
|
+
workspaceId,
|
|
284
|
+
stripeCustomerId: session.customer ? String(session.customer) : null,
|
|
285
|
+
stripeSubscriptionId: session.subscription
|
|
286
|
+
? String(session.subscription)
|
|
287
|
+
: null,
|
|
288
|
+
referenceId: String(session.id),
|
|
289
|
+
});
|
|
290
|
+
return { fulfilled: true, workspace: ws, kind };
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return {
|
|
294
|
+
fulfilled: false,
|
|
295
|
+
workspace: this.store.getWorkspace(workspaceId),
|
|
296
|
+
kind,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
async executeTool(params) {
|
|
300
|
+
if (params.toolSlug === "billing.credits.topup") {
|
|
301
|
+
const credits = Math.max(1, Math.min(100_000, Number(params.input.credits || 1000)));
|
|
302
|
+
const refId = `topup_${crypto.randomBytes(8).toString("hex")}`;
|
|
303
|
+
const ws = this.store.addWorkspaceCredits({
|
|
304
|
+
workspaceId: params.workspace.id,
|
|
305
|
+
credits,
|
|
306
|
+
referenceId: refId,
|
|
307
|
+
description: String(params.input.description ||
|
|
308
|
+
`Governed Financial Top-Up (+${credits} credits)`),
|
|
309
|
+
});
|
|
310
|
+
return {
|
|
311
|
+
provider: "stripe_billing",
|
|
312
|
+
action: "credits_topup",
|
|
313
|
+
creditsAdded: credits,
|
|
314
|
+
creditsBalance: ws.creditsBalance,
|
|
315
|
+
tier: ws.tier,
|
|
316
|
+
referenceId: refId,
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
if (params.toolSlug === "billing.subscription.upgrade") {
|
|
320
|
+
const refId = `upgrade_${crypto.randomBytes(8).toString("hex")}`;
|
|
321
|
+
const ws = this.store.upgradeWorkspaceToStarter({
|
|
322
|
+
workspaceId: params.workspace.id,
|
|
323
|
+
stripeCustomerId: params.workspace.stripeCustomerId ||
|
|
324
|
+
`cus_muxo_${params.workspace.id.slice(3, 11)}`,
|
|
325
|
+
stripeSubscriptionId: `sub_muxo_${refId.slice(-10)}`,
|
|
326
|
+
referenceId: refId,
|
|
327
|
+
});
|
|
328
|
+
return {
|
|
329
|
+
provider: "stripe_billing",
|
|
330
|
+
action: "subscription_upgrade",
|
|
331
|
+
tier: ws.tier,
|
|
332
|
+
monthlyActionsLimit: ws.monthlyActionsLimit,
|
|
333
|
+
creditsBalance: ws.creditsBalance,
|
|
334
|
+
referenceId: refId,
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
if (params.toolSlug === "billing.checkout.create") {
|
|
338
|
+
const kind = params.input.kind === "starter_subscription"
|
|
339
|
+
? "starter_subscription"
|
|
340
|
+
: "credit_topup";
|
|
341
|
+
const checkout = await this.createCheckoutSession({
|
|
342
|
+
workspace: params.workspace,
|
|
343
|
+
customerEmail: params.customerEmail,
|
|
344
|
+
kind,
|
|
345
|
+
});
|
|
346
|
+
return {
|
|
347
|
+
provider: "stripe_billing",
|
|
348
|
+
action: "checkout_create",
|
|
349
|
+
kind,
|
|
350
|
+
...checkout,
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
throw new Error(`Unsupported billing tool: ${params.toolSlug}`);
|
|
354
|
+
}
|
|
355
|
+
verifyWebhookSignature(rawBody, signatureHeader) {
|
|
356
|
+
if (!this.config.stripeWebhookSecret)
|
|
357
|
+
return true;
|
|
358
|
+
const parts = signatureHeader.split(",");
|
|
359
|
+
const tPart = parts.find((p) => p.startsWith("t="));
|
|
360
|
+
const v1Part = parts.find((p) => p.startsWith("v1="));
|
|
361
|
+
if (!tPart || !v1Part)
|
|
362
|
+
return false;
|
|
363
|
+
const timestamp = tPart.slice(2);
|
|
364
|
+
const expectedSig = v1Part.slice(3);
|
|
365
|
+
const payload = `${timestamp}.${rawBody}`;
|
|
366
|
+
const computed = crypto
|
|
367
|
+
.createHmac("sha256", this.config.stripeWebhookSecret)
|
|
368
|
+
.update(payload)
|
|
369
|
+
.digest("hex");
|
|
370
|
+
return crypto.timingSafeEqual(Buffer.from(expectedSig, "hex"), Buffer.from(computed, "hex"));
|
|
371
|
+
}
|
|
372
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type MuxoConfig } from "../config.js";
|
|
2
|
+
import type { MuxoTool } from "../types.js";
|
|
3
|
+
export declare class StripeProjectsAdapter {
|
|
4
|
+
private readonly config;
|
|
5
|
+
private readonly tools;
|
|
6
|
+
private readonly providerByName;
|
|
7
|
+
constructor(config: MuxoConfig);
|
|
8
|
+
private loadCatalogSeed;
|
|
9
|
+
getTools(): MuxoTool[];
|
|
10
|
+
searchTools(query?: string, limit?: number): MuxoTool[];
|
|
11
|
+
inspectTool(slug: string): MuxoTool | null;
|
|
12
|
+
private runStripeProjectsCli;
|
|
13
|
+
private get hasLocalProjectsWorkdir();
|
|
14
|
+
getLiveStatus(): Promise<{
|
|
15
|
+
authenticated: boolean;
|
|
16
|
+
projectInitialized: boolean;
|
|
17
|
+
projectId: string | null;
|
|
18
|
+
projectName: string | null;
|
|
19
|
+
providers: Array<{
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
slug: string;
|
|
23
|
+
status: "active" | "pending" | "expired";
|
|
24
|
+
redirectUrl: string | null;
|
|
25
|
+
}>;
|
|
26
|
+
services: Array<Record<string, unknown>>;
|
|
27
|
+
plans: Array<Record<string, unknown>>;
|
|
28
|
+
}>;
|
|
29
|
+
linkProvider(providerSlug: string): Promise<{
|
|
30
|
+
providerSlug: string;
|
|
31
|
+
status: "active" | "pending";
|
|
32
|
+
redirectUrl: string | null;
|
|
33
|
+
message: string;
|
|
34
|
+
}>;
|
|
35
|
+
pullEnvVarsFromWorkdir(): Promise<Record<string, string>>;
|
|
36
|
+
executeTool(params: {
|
|
37
|
+
workspaceId: string;
|
|
38
|
+
tool: MuxoTool;
|
|
39
|
+
input: Record<string, unknown>;
|
|
40
|
+
}): Promise<{
|
|
41
|
+
output: Record<string, unknown>;
|
|
42
|
+
provisionedResource?: {
|
|
43
|
+
resourceName: string;
|
|
44
|
+
providerSlug: string;
|
|
45
|
+
providerName: string;
|
|
46
|
+
serviceSlug: string;
|
|
47
|
+
planSlug?: string | null;
|
|
48
|
+
status: "active" | "removed";
|
|
49
|
+
secrets?: Record<string, string>;
|
|
50
|
+
externalResourceId?: string | null;
|
|
51
|
+
};
|
|
52
|
+
}>;
|
|
53
|
+
}
|