@apex-inc/mcp-server 0.3.1 → 0.7.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.
@@ -0,0 +1,191 @@
1
+ ---
2
+ name: apex-partner-network
3
+ description: Build, run, and grow an affiliate / referral program on the Apex Partner Network. Use when a merchant wants to pay partners a commission for driving installs / purchases / subscriptions, manage a roster of affiliates, or invite specific people to promote their product. The SDK wraps programs, memberships, invitations, payouts, fee disclosure, and merchant vouching.
4
+ ---
5
+
6
+ # Apex Partner Network (SDK)
7
+
8
+ The Apex Partner Network is a two-sided affiliate network: merchants own programs, partners join one or many programs across every merchant they work with, Apex facilitates the money rail between them via Stripe Connect.
9
+
10
+ This skill covers the **merchant-facing management SDK** — programmatic access from a Node.js backend using an `apex_sk_*` service key. Partner-facing flows (self-signup, dashboard, Stripe Connect OAuth consent) happen in the hosted portal at `partners.apex.inc`.
11
+
12
+ ## Core mental model
13
+
14
+ | Concept | What it is |
15
+ |---|---|
16
+ | **Program** | A merchant-owned commission offer (CPA or RevShare). Merchants can run multiple. |
17
+ | **Membership** | One partner × one program. Carries the partner's current commission (and its audit history). |
18
+ | **Conversion** | A tracked install/purchase/subscription credited to a partner via their Apex link. |
19
+ | **HoldbackEntry** | One per approved conversion. Splits commission into available + held portions per the partner's trust tier. |
20
+ | **MerchantPayoutBatch** | A settled cycle of all released-available commissions for one partner, fired per the merchant's `autoPayoutPolicy`. |
21
+
22
+ ## SDK bootstrap
23
+
24
+ ```typescript
25
+ import { createManagementClient } from "@apex-inc/sdk/management";
26
+
27
+ const apex = createManagementClient({
28
+ projectKey: "your-project-key",
29
+ apiKey: process.env.APEX_API_KEY!,
30
+ apiUrl: "https://app.apex.inc", // omit for local dev
31
+ });
32
+ ```
33
+
34
+ All calls below go through this client. Under the hood, requests attach `x-api-key` + `x-apex-project` headers to every `/api/mobile/affiliates/*` route.
35
+
36
+ ## Creating your first program
37
+
38
+ ```typescript
39
+ const program = await apex.createProgram({
40
+ name: "Partner Program",
41
+ description: "Refer a customer, earn 20% for 12 months.",
42
+ vertical: "saas",
43
+ commissionStructure: {
44
+ type: "revshare",
45
+ percentage: 20,
46
+ appliesTo: "subscription",
47
+ },
48
+ visibility: "public", // shows in /marketplace for partner discovery
49
+ approvalMode: "manual", // review each applicant
50
+ });
51
+ ```
52
+
53
+ Programs can be `paused`/`archived` later via `updateProgram(id, { status: "paused" })`. Pausing freezes new applications + new conversions but keeps existing memberships alive.
54
+
55
+ ## Inviting a partner
56
+
57
+ ```typescript
58
+ await apex.invitePartner({
59
+ email: "sarah@example.com",
60
+ programId: program.id,
61
+ inviterName: "Alice from Acme",
62
+ inviterMessage: "I'd love to partner with you — here's a special rate.",
63
+ customRate: {
64
+ commissionStructure: {
65
+ type: "revshare",
66
+ percentage: 30, // negotiated higher rate
67
+ appliesTo: "subscription",
68
+ },
69
+ },
70
+ });
71
+ ```
72
+
73
+ Sarah gets a magic-link email. If she's already a partner on Apex, the invite creates a new `AffiliateMembership` bound to this program. If she's new, she claims a handle + completes onboarding at the portal.
74
+
75
+ **Handle rule**: one `@sarah` works across every merchant program she joins. She doesn't need a separate account per merchant.
76
+
77
+ ## Adjusting commission rates
78
+
79
+ Three commission sources are possible:
80
+ - `program_default` — set by the program; member has never been individually adjusted
81
+ - `membership_override` — explicit override set on this membership (sticky; survives program default updates)
82
+ - `invite_override` — set at invite time (sticky same as membership_override)
83
+
84
+ ```typescript
85
+ // Bump this specific partner to 35%
86
+ await apex.updateMembershipRate("prof_sarah", {
87
+ commissionStructure: {
88
+ type: "revshare",
89
+ percentage: 35,
90
+ appliesTo: "subscription",
91
+ },
92
+ reason: "Volume performer — Q3 bump",
93
+ });
94
+
95
+ // ...later, reset them back to program default
96
+ await apex.resetMembershipRate("prof_sarah", "Q3 promo ended");
97
+ ```
98
+
99
+ Updating a program's default does NOT retroactively change existing memberships — call `applyProgramDefaultToMembers(programId)` to fan it out (skips overrides).
100
+
101
+ ## Approving payouts
102
+
103
+ Commissions sit as `pending` until approved. The full batch flow:
104
+
105
+ ```typescript
106
+ // 1. What's owed
107
+ const queue = await apex.listPendingPayouts();
108
+ // {
109
+ // buckets: { "0_30": [...], "30_60": [...], "60_plus": [...] },
110
+ // totals: { "0_30": 1450.00, ... },
111
+ // effectivePolicy: { policy: "manual", source: "project", capUsd: undefined },
112
+ // caps: { daily: undefined }
113
+ // }
114
+
115
+ // 2. Approve (creates HoldbackEntry + transitions to "approved")
116
+ const result = await apex.approvePayouts(
117
+ queue.buckets["0_30"].map(c => c.id),
118
+ );
119
+ // { approved: [{ id, heldbackAmountUsd }], skipped: [...], failed: [...] }
120
+ ```
121
+
122
+ **Approving does NOT fire the Stripe transfer**. The transfer happens at the merchant's `autoPayoutPolicy` cycle (daily / weekly / manual). This decoupling:
123
+
124
+ - lets the merchant review multiple conversions before committing
125
+ - lets the platform batch per (merchant, partner) to minimize Stripe fees
126
+ - gives the holdback release window (90d for NEW partners, 30d for VERIFIED) time to run
127
+
128
+ ## Fee disclosure
129
+
130
+ Merchants should always know what Apex charges them:
131
+
132
+ ```typescript
133
+ const { fees } = await apex.getEffectiveFees();
134
+ // fees: {
135
+ // facilitation_payout: { bps: 25, flatUsd: 0.5, source: "platform_default", isCustom: false },
136
+ // identity_verification: { flatUsd: 2.5, source: "platform_default", isCustom: false },
137
+ // instant_payout: { bps: 100, flatUsd: 0.5, source: "platform_default", isCustom: false },
138
+ // }
139
+ ```
140
+
141
+ Enterprise deals show `isCustom: true` with `source: "merchant_override"`. Admin edits propagate within 60 seconds (cache TTL).
142
+
143
+ ## Vouching for a partner
144
+
145
+ A merchant who knows a partner outside Apex can vouch for them — bumping their trust tier one level for 60 days. This unlocks higher payout caps for the partner immediately. It's NOT free: the merchant takes on indemnity.
146
+
147
+ ```typescript
148
+ await apex.vouchForPartner("prof_sarah", {
149
+ indemnityAcknowledged: true, // MUST be literally true
150
+ reason: "10-year professional relationship, verified off-platform",
151
+ });
152
+ ```
153
+
154
+ **Important**: if the partner commits fraud during the 60-day vouched window, the merchant's account is liable for clawbacks the reserve can't cover. Use sparingly.
155
+
156
+ ## What happens when things fail
157
+
158
+ **Partner reaches a cap**: the batch surfaces a tier-aware message. NEW-tier partners see "processing" (masked); TRUSTED/VERIFIED partners see the reason.
159
+
160
+ **Merchant's Stripe balance is short**: retry fires in 24h. After 48h (2nd fail), the merchant gets an email. After 72h (3rd fail), a dashboard card appears + partner messaging flips. After 7 days (7th fail), Apex opens a support case — **not labeled as fraud** — for human triage.
161
+
162
+ Automation never freezes a merchant's `autoPayoutPolicy`. That's always a human decision.
163
+
164
+ ## Reading auto-payout policy
165
+
166
+ Set per-project or per-program:
167
+
168
+ ```typescript
169
+ await apex.updateProgram(programId, {
170
+ autoPayoutPolicy: "auto_under_cap", // auto-pay up to cap, manual above
171
+ autoPayoutCapUsd: 1000,
172
+ });
173
+ ```
174
+
175
+ Policies:
176
+ - `"manual"` — every payout needs merchant click-to-approve (default)
177
+ - `"auto"` — approved conversions auto-queue for the next payout cycle
178
+ - `"auto_under_cap"` — auto under `autoPayoutCapUsd`, queue above
179
+
180
+ ## What this SDK does NOT cover
181
+
182
+ - **Partner-facing flows** (self-signup at `/apply`, portal dashboard, Stripe Connect Express onboarding) — these happen in the hosted portal + require Cognito auth, not API key auth.
183
+ - **Admin / Fraud Ops** (case queue, appeal decisions, ban list, fee policy edits) — admin Cognito flow, different tooling.
184
+ - **Webhooks** (Stripe Connect events, identity verification status) — those are inbound from Stripe, not outbound from the SDK.
185
+ - **Real-time Stripe transfers** — transfers fire on the merchant's schedule via the platform's payout orchestrator, not synchronously from the SDK.
186
+
187
+ ## See also
188
+
189
+ - `apex-integration-cookbook` — end-to-end patterns combining partner network + communications + experiments
190
+ - MCP tools: `list_partner_programs`, `create_partner_program`, `invite_partner`, `approve_payouts`, `vouch_for_partner`, `get_effective_fees`
191
+ - Docs: `/docs/partner-network/` for concept walkthroughs + integration guides