affitor 0.1.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/README.md +91 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +33 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/init.d.ts +3 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +194 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/setup-stripe.d.ts +3 -0
- package/dist/commands/setup-stripe.d.ts.map +1 -0
- package/dist/commands/setup-stripe.js +188 -0
- package/dist/commands/setup-stripe.js.map +1 -0
- package/dist/commands/status.d.ts +3 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +95 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/test.d.ts +3 -0
- package/dist/commands/test.d.ts.map +1 -0
- package/dist/commands/test.js +89 -0
- package/dist/commands/test.js.map +1 -0
- package/dist/lib/api-client.d.ts +37 -0
- package/dist/lib/api-client.d.ts.map +1 -0
- package/dist/lib/api-client.js +92 -0
- package/dist/lib/api-client.js.map +1 -0
- package/dist/lib/config.d.ts +12 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +110 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/flags.d.ts +7 -0
- package/dist/lib/flags.d.ts.map +1 -0
- package/dist/lib/flags.js +20 -0
- package/dist/lib/flags.js.map +1 -0
- package/dist/lib/logger.d.ts +24 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/logger.js +78 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/prompts.d.ts +9 -0
- package/dist/lib/prompts.d.ts.map +1 -0
- package/dist/lib/prompts.js +79 -0
- package/dist/lib/prompts.js.map +1 -0
- package/dist/lib/stripe-oauth.d.ts +15 -0
- package/dist/lib/stripe-oauth.d.ts.map +1 -0
- package/dist/lib/stripe-oauth.js +168 -0
- package/dist/lib/stripe-oauth.js.map +1 -0
- package/dist/types.d.ts +84 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +17 -0
- package/dist/types.js.map +1 -0
- package/package.json +54 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface StripeSetupResult {
|
|
2
|
+
stripe_user_id: string;
|
|
3
|
+
webhook_endpoint_id: string;
|
|
4
|
+
webhook_secret: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function runStripeOAuth(opts: {
|
|
7
|
+
clientId: string;
|
|
8
|
+
programId: string;
|
|
9
|
+
webhookUrl: string;
|
|
10
|
+
stripeSecretKey: string;
|
|
11
|
+
}): Promise<StripeSetupResult>;
|
|
12
|
+
export declare class StripeOAuthError extends Error {
|
|
13
|
+
constructor(message: string);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=stripe-oauth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripe-oauth.d.ts","sourceRoot":"","sources":["../../src/lib/stripe-oauth.ts"],"names":[],"mappings":"AAwBA,MAAM,WAAW,iBAAiB;IAChC,cAAc,EAAE,MAAM,CAAC;IACvB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,wBAAsB,cAAc,CAAC,IAAI,EAAE;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;CACzB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAwD7B;AAqKD,qBAAa,gBAAiB,SAAQ,KAAK;gBAC7B,OAAO,EAAE,MAAM;CAI5B"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
import { randomBytes } from "node:crypto";
|
|
3
|
+
import { URL } from "node:url";
|
|
4
|
+
import Stripe from "stripe";
|
|
5
|
+
import open from "open";
|
|
6
|
+
import * as logger from "./logger.js";
|
|
7
|
+
import { OAUTH_CALLBACK_PORT_START, OAUTH_CALLBACK_PORT_END, OAUTH_TIMEOUT_MS, WEBHOOK_EVENTS, } from "../types.js";
|
|
8
|
+
export async function runStripeOAuth(opts) {
|
|
9
|
+
const nonce = randomBytes(16).toString("hex");
|
|
10
|
+
const state = Buffer.from(JSON.stringify({ program_id: opts.programId, nonce })).toString("base64url");
|
|
11
|
+
const port = await findAvailablePort();
|
|
12
|
+
const redirectUri = `http://localhost:${port}/callback`;
|
|
13
|
+
const authCode = await startOAuthFlow({
|
|
14
|
+
clientId: opts.clientId,
|
|
15
|
+
redirectUri,
|
|
16
|
+
state,
|
|
17
|
+
nonce,
|
|
18
|
+
port,
|
|
19
|
+
});
|
|
20
|
+
// Exchange authorization code for connected account ID
|
|
21
|
+
logger.step("Exchanging authorization code...");
|
|
22
|
+
const stripe = new Stripe(opts.stripeSecretKey);
|
|
23
|
+
const tokenResponse = await stripe.oauth.token({
|
|
24
|
+
grant_type: "authorization_code",
|
|
25
|
+
code: authCode,
|
|
26
|
+
});
|
|
27
|
+
if (!tokenResponse.stripe_user_id) {
|
|
28
|
+
throw new StripeOAuthError("Stripe did not return an account ID. Authorization may have failed.");
|
|
29
|
+
}
|
|
30
|
+
const oauthResult = {
|
|
31
|
+
stripe_user_id: tokenResponse.stripe_user_id,
|
|
32
|
+
access_token: tokenResponse.access_token ?? "",
|
|
33
|
+
stripe_publishable_key: tokenResponse.stripe_publishable_key,
|
|
34
|
+
};
|
|
35
|
+
logger.success("Stripe authorized");
|
|
36
|
+
logger.step(`Account: ${oauthResult.stripe_user_id}`);
|
|
37
|
+
const webhook = await createWebhookEndpoint({
|
|
38
|
+
stripeSecretKey: opts.stripeSecretKey,
|
|
39
|
+
stripeAccountId: oauthResult.stripe_user_id,
|
|
40
|
+
webhookUrl: opts.webhookUrl,
|
|
41
|
+
});
|
|
42
|
+
logger.success("Webhook endpoint created");
|
|
43
|
+
for (const event of WEBHOOK_EVENTS) {
|
|
44
|
+
logger.step(`✓ ${event}`);
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
stripe_user_id: oauthResult.stripe_user_id,
|
|
48
|
+
webhook_endpoint_id: webhook.webhook_endpoint_id,
|
|
49
|
+
webhook_secret: webhook.webhook_secret,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
async function startOAuthFlow(opts) {
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
const timeout = setTimeout(() => {
|
|
55
|
+
server.close();
|
|
56
|
+
reject(new StripeOAuthError(`Timed out after ${OAUTH_TIMEOUT_MS / 1000}s waiting for Stripe authorization.\n` +
|
|
57
|
+
"Run `npx affitor setup stripe` to try again."));
|
|
58
|
+
}, OAUTH_TIMEOUT_MS);
|
|
59
|
+
const server = createServer((req, res) => {
|
|
60
|
+
const url = new URL(req.url ?? "/", `http://localhost:${opts.port}`);
|
|
61
|
+
if (url.pathname !== "/callback") {
|
|
62
|
+
res.writeHead(404);
|
|
63
|
+
res.end("Not found");
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const error = url.searchParams.get("error");
|
|
67
|
+
if (error) {
|
|
68
|
+
clearTimeout(timeout);
|
|
69
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
70
|
+
res.end(errorPage("Stripe authorization was cancelled."));
|
|
71
|
+
server.close();
|
|
72
|
+
reject(new StripeOAuthError(`Stripe authorization cancelled: ${error}.\n` +
|
|
73
|
+
"Run `npx affitor setup stripe` to try again."));
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const code = url.searchParams.get("code");
|
|
77
|
+
const returnedState = url.searchParams.get("state");
|
|
78
|
+
if (!code || returnedState !== opts.state) {
|
|
79
|
+
clearTimeout(timeout);
|
|
80
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
81
|
+
res.end(errorPage("Invalid OAuth callback. Please try again."));
|
|
82
|
+
server.close();
|
|
83
|
+
reject(new StripeOAuthError("Invalid OAuth state parameter."));
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
clearTimeout(timeout);
|
|
87
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
88
|
+
res.end(successPage("Stripe connected! You can close this tab and return to the terminal."));
|
|
89
|
+
server.close();
|
|
90
|
+
resolve(code);
|
|
91
|
+
});
|
|
92
|
+
server.listen(opts.port, () => {
|
|
93
|
+
const authorizeUrl = `https://connect.stripe.com/oauth/authorize` +
|
|
94
|
+
`?response_type=code` +
|
|
95
|
+
`&client_id=${opts.clientId}` +
|
|
96
|
+
`&scope=read_write` +
|
|
97
|
+
`&redirect_uri=${encodeURIComponent(opts.redirectUri)}` +
|
|
98
|
+
`&state=${opts.state}`;
|
|
99
|
+
logger.info("Opening Stripe Connect in your browser...");
|
|
100
|
+
logger.debug(`URL: ${authorizeUrl}`);
|
|
101
|
+
open(authorizeUrl).catch(() => {
|
|
102
|
+
logger.warn("Could not open browser automatically.");
|
|
103
|
+
logger.info(`Open this URL manually:\n ${authorizeUrl}`);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
server.on("error", (err) => {
|
|
107
|
+
clearTimeout(timeout);
|
|
108
|
+
reject(new StripeOAuthError(`Failed to start OAuth callback server: ${err.message}`));
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
async function createWebhookEndpoint(opts) {
|
|
113
|
+
const stripe = new Stripe(opts.stripeSecretKey);
|
|
114
|
+
const endpoint = await stripe.webhookEndpoints.create({
|
|
115
|
+
url: opts.webhookUrl,
|
|
116
|
+
enabled_events: [...WEBHOOK_EVENTS],
|
|
117
|
+
description: "Affitor affiliate tracking — auto-configured by CLI",
|
|
118
|
+
}, { stripeAccount: opts.stripeAccountId });
|
|
119
|
+
if (!endpoint.secret) {
|
|
120
|
+
throw new StripeOAuthError("Webhook endpoint created but no signing secret returned. Contact support.");
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
webhook_endpoint_id: endpoint.id,
|
|
124
|
+
webhook_secret: endpoint.secret,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
async function findAvailablePort() {
|
|
128
|
+
for (let port = OAUTH_CALLBACK_PORT_START; port <= OAUTH_CALLBACK_PORT_END; port++) {
|
|
129
|
+
const available = await checkPort(port);
|
|
130
|
+
if (available)
|
|
131
|
+
return port;
|
|
132
|
+
}
|
|
133
|
+
throw new StripeOAuthError(`Ports ${OAUTH_CALLBACK_PORT_START}-${OAUTH_CALLBACK_PORT_END} are all in use.\n` +
|
|
134
|
+
"Close other applications and try again.");
|
|
135
|
+
}
|
|
136
|
+
function checkPort(port) {
|
|
137
|
+
return new Promise((resolve) => {
|
|
138
|
+
const server = createServer();
|
|
139
|
+
server.once("error", () => resolve(false));
|
|
140
|
+
server.once("listening", () => {
|
|
141
|
+
server.close(() => resolve(true));
|
|
142
|
+
});
|
|
143
|
+
server.listen(port);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
function successPage(message) {
|
|
147
|
+
return `<!DOCTYPE html>
|
|
148
|
+
<html><head><title>Affitor</title>
|
|
149
|
+
<style>body{font-family:system-ui;display:flex;justify-content:center;align-items:center;min-height:100vh;margin:0;background:#f8fafc}
|
|
150
|
+
.card{text-align:center;padding:2rem;border-radius:12px;background:white;box-shadow:0 1px 3px rgba(0,0,0,0.1)}
|
|
151
|
+
h1{color:#16a34a;font-size:1.5rem}p{color:#64748b}</style>
|
|
152
|
+
</head><body><div class="card"><h1>✓ ${message}</h1><p>Return to your terminal.</p></div></body></html>`;
|
|
153
|
+
}
|
|
154
|
+
function errorPage(message) {
|
|
155
|
+
return `<!DOCTYPE html>
|
|
156
|
+
<html><head><title>Affitor</title>
|
|
157
|
+
<style>body{font-family:system-ui;display:flex;justify-content:center;align-items:center;min-height:100vh;margin:0;background:#f8fafc}
|
|
158
|
+
.card{text-align:center;padding:2rem;border-radius:12px;background:white;box-shadow:0 1px 3px rgba(0,0,0,0.1)}
|
|
159
|
+
h1{color:#dc2626;font-size:1.5rem}p{color:#64748b}</style>
|
|
160
|
+
</head><body><div class="card"><h1>✗ ${message}</h1><p>Return to your terminal.</p></div></body></html>`;
|
|
161
|
+
}
|
|
162
|
+
export class StripeOAuthError extends Error {
|
|
163
|
+
constructor(message) {
|
|
164
|
+
super(message);
|
|
165
|
+
this.name = "StripeOAuthError";
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=stripe-oauth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripe-oauth.js","sourceRoot":"","sources":["../../src/lib/stripe-oauth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA6C,MAAM,WAAW,CAAC;AACpF,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,EACL,yBAAyB,EACzB,uBAAuB,EACvB,gBAAgB,EAChB,cAAc,GACf,MAAM,aAAa,CAAC;AAmBrB,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,IAKpC;IACC,MAAM,KAAK,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9C,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CACvB,IAAI,CAAC,SAAS,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,SAAS,EAAE,KAAK,EAAE,CAAC,CACtD,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAExB,MAAM,IAAI,GAAG,MAAM,iBAAiB,EAAE,CAAC;IACvC,MAAM,WAAW,GAAG,oBAAoB,IAAI,WAAW,CAAC;IAExD,MAAM,QAAQ,GAAG,MAAM,cAAc,CAAC;QACpC,QAAQ,EA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,MAAM,IAAI,gBAAgB,CACxB,SAAS,yBAAyB,IAAI,uBAAuB,oBAAoB;QAC/E,yCAAyC,CAC5C,CAAC;AACJ,CAAC;AAED,SAAS,SAAS,CAAC,IAAY;IAC7B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,MAAM,GAAG,YAAY,EAAE,CAAC;QAC9B,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;QAC3C,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE;YAC5B,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,WAAW,CAAC,OAAe;IAClC,OAAO;;;;;uCAK8B,OAAO,0DAA0D,CAAC;AACzG,CAAC;AAED,SAAS,SAAS,CAAC,OAAe;IAChC,OAAO;;;;;uCAK8B,OAAO,0DAA0D,CAAC;AACzG,CAAC;AAED,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export interface AffitorConfig {
|
|
2
|
+
version: number;
|
|
3
|
+
program_id: string;
|
|
4
|
+
domain: string;
|
|
5
|
+
tracking_subdomain: string;
|
|
6
|
+
commission: {
|
|
7
|
+
type: CommissionType;
|
|
8
|
+
rate: number;
|
|
9
|
+
duration_months?: number;
|
|
10
|
+
};
|
|
11
|
+
cookie: {
|
|
12
|
+
name: string;
|
|
13
|
+
duration_days: number;
|
|
14
|
+
};
|
|
15
|
+
ref_param: string;
|
|
16
|
+
stripe_connected: boolean;
|
|
17
|
+
stripe_account_id?: string;
|
|
18
|
+
api_key: string;
|
|
19
|
+
api_url: string;
|
|
20
|
+
created_at: string;
|
|
21
|
+
}
|
|
22
|
+
export type CommissionType = "percent" | "fixed" | "recurring_percent" | "recurring_fixed";
|
|
23
|
+
export interface InitOptions {
|
|
24
|
+
name: string;
|
|
25
|
+
domain: string;
|
|
26
|
+
commissionType: CommissionType;
|
|
27
|
+
commissionRate: number;
|
|
28
|
+
cookieDuration: number;
|
|
29
|
+
durationMonths?: number;
|
|
30
|
+
}
|
|
31
|
+
export interface InitResponse {
|
|
32
|
+
program_id: string;
|
|
33
|
+
api_key: string;
|
|
34
|
+
program_slug: string;
|
|
35
|
+
domain: string;
|
|
36
|
+
}
|
|
37
|
+
export interface StripeConnectResponse {
|
|
38
|
+
connected: boolean;
|
|
39
|
+
stripe_account_id: string;
|
|
40
|
+
webhook_endpoint_id: string;
|
|
41
|
+
charges_enabled: boolean;
|
|
42
|
+
payouts_enabled: boolean;
|
|
43
|
+
}
|
|
44
|
+
export interface ProgramStatus {
|
|
45
|
+
program_id: string;
|
|
46
|
+
name: string;
|
|
47
|
+
domain: string;
|
|
48
|
+
dns_verified: boolean;
|
|
49
|
+
stripe_connected: boolean;
|
|
50
|
+
stripe_charges_enabled?: boolean;
|
|
51
|
+
recent_events: {
|
|
52
|
+
clicks_24h: number;
|
|
53
|
+
leads_24h: number;
|
|
54
|
+
sales_24h: number;
|
|
55
|
+
};
|
|
56
|
+
active_partners: number;
|
|
57
|
+
pending_commissions: number;
|
|
58
|
+
}
|
|
59
|
+
export interface TestEventResult {
|
|
60
|
+
event_type: "click" | "lead" | "sale";
|
|
61
|
+
event_id: string;
|
|
62
|
+
received: boolean;
|
|
63
|
+
attributed: boolean;
|
|
64
|
+
message: string;
|
|
65
|
+
}
|
|
66
|
+
export interface CLIFlags {
|
|
67
|
+
json: boolean;
|
|
68
|
+
noInteractive: boolean;
|
|
69
|
+
autoConfirm: boolean;
|
|
70
|
+
quiet: boolean;
|
|
71
|
+
apiKey?: string;
|
|
72
|
+
apiUrl?: string;
|
|
73
|
+
verbose: boolean;
|
|
74
|
+
}
|
|
75
|
+
export declare const API_URL_PROD = "https://api.affitor.com";
|
|
76
|
+
export declare const API_URL_UAT = "https://uat-affitor-cms.vanilla-ott.com";
|
|
77
|
+
export declare const DEFAULT_API_URL = "https://api.affitor.com";
|
|
78
|
+
export declare const CONFIG_DIR = ".affitor";
|
|
79
|
+
export declare const CONFIG_FILE = "config.json";
|
|
80
|
+
export declare const OAUTH_CALLBACK_PORT_START = 3456;
|
|
81
|
+
export declare const OAUTH_CALLBACK_PORT_END = 3465;
|
|
82
|
+
export declare const OAUTH_TIMEOUT_MS = 120000;
|
|
83
|
+
export declare const WEBHOOK_EVENTS: readonly ["customer.created", "checkout.session.completed", "invoice.paid", "invoice.payment_failed", "charge.refunded", "customer.subscription.deleted"];
|
|
84
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,kBAAkB,EAAE,MAAM,CAAC;IAC3B,UAAU,EAAE;QACV,IAAI,EAAE,cAAc,CAAC;QACrB,IAAI,EAAE,MAAM,CAAC;QACb,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B,CAAC;IACF,MAAM,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;IACF,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,OAA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AAC;IAClB,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,OAAO,CAAC;IACd,aAAa,EAAE,OAAO,CAAC;IACvB,WAAW,EAAE,OAAO,CAAC;IACrB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,eAAO,MAAM,YAAY,4BAA4B,CAAC;AACtD,eAAO,MAAM,WAAW,4CAA4C,CAAC;AACrE,eAAO,MAAM,eAAe,4BAAe,CAAC;AAC5C,eAAO,MAAM,UAAU,aAAa,CAAC;AACrC,eAAO,MAAM,WAAW,gBAAgB,CAAC;AACzC,eAAO,MAAM,yBAAyB,OAAO,CAAC;AAC9C,eAAO,MAAM,uBAAuB,OAAO,CAAC;AAC5C,eAAO,MAAM,gBAAgB,SAAU,CAAC;AAExC,eAAO,MAAM,cAAc,2JAOjB,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const API_URL_PROD = "https://api.affitor.com";
|
|
2
|
+
export const API_URL_UAT = "https://uat-affitor-cms.vanilla-ott.com";
|
|
3
|
+
export const DEFAULT_API_URL = API_URL_PROD;
|
|
4
|
+
export const CONFIG_DIR = ".affitor";
|
|
5
|
+
export const CONFIG_FILE = "config.json";
|
|
6
|
+
export const OAUTH_CALLBACK_PORT_START = 3456;
|
|
7
|
+
export const OAUTH_CALLBACK_PORT_END = 3465;
|
|
8
|
+
export const OAUTH_TIMEOUT_MS = 120_000;
|
|
9
|
+
export const WEBHOOK_EVENTS = [
|
|
10
|
+
"customer.created",
|
|
11
|
+
"checkout.session.completed",
|
|
12
|
+
"invoice.paid",
|
|
13
|
+
"invoice.payment_failed",
|
|
14
|
+
"charge.refunded",
|
|
15
|
+
"customer.subscription.deleted",
|
|
16
|
+
];
|
|
17
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAsFA,MAAM,CAAC,MAAM,YAAY,GAAG,yBAAyB,CAAC;AACtD,MAAM,CAAC,MAAM,WAAW,GAAG,yCAAyC,CAAC;AACrE,MAAM,CAAC,MAAM,eAAe,GAAG,YAAY,CAAC;AAC5C,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAAC;AACrC,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAAC;AACzC,MAAM,CAAC,MAAM,yBAAyB,GAAG,IAAI,CAAC;AAC9C,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,CAAC;AAC5C,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC;AAExC,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,kBAAkB;IAClB,4BAA4B;IAC5B,cAAc;IACd,wBAAwB;IACxB,iBAAiB;IACjB,+BAA+B;CACvB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "affitor",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI-native affiliate tracking. Connect Stripe, track commissions, manage partners — all from your terminal.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"affitor": "./dist/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"dev": "tsc --watch",
|
|
12
|
+
"start": "node dist/cli.js",
|
|
13
|
+
"test": "vitest run",
|
|
14
|
+
"test:watch": "vitest",
|
|
15
|
+
"lint": "tsc --noEmit",
|
|
16
|
+
"prepublishOnly": "npm run build"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"affiliate",
|
|
20
|
+
"tracking",
|
|
21
|
+
"stripe",
|
|
22
|
+
"cli",
|
|
23
|
+
"affiliate-marketing",
|
|
24
|
+
"commission",
|
|
25
|
+
"partner",
|
|
26
|
+
"agent",
|
|
27
|
+
"ai"
|
|
28
|
+
],
|
|
29
|
+
"author": "Affitor <hello@affitor.com>",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/Affitor/affiliate-cli"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://affitor.com",
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=18"
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"dist"
|
|
41
|
+
],
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"commander": "^13.1.0",
|
|
44
|
+
"@inquirer/prompts": "^7.5.0",
|
|
45
|
+
"picocolors": "^1.1.1",
|
|
46
|
+
"open": "^10.1.0",
|
|
47
|
+
"stripe": "^17.7.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"typescript": "^5.7.0",
|
|
51
|
+
"vitest": "^3.1.0",
|
|
52
|
+
"@types/node": "^22.0.0"
|
|
53
|
+
}
|
|
54
|
+
}
|