@hasna/microservices 0.0.16 → 0.0.18
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 +143 -23
- package/bin/index.js +784 -13987
- package/bin/mcp.js +298 -10973
- package/dist/index.js +251 -10056
- package/package.json +36 -26
- package/microservices/microservice-ads/package.json +0 -28
- package/microservices/microservice-ads/src/cli/index.ts +0 -605
- package/microservices/microservice-ads/src/db/campaigns.ts +0 -797
- package/microservices/microservice-ads/src/db/database.ts +0 -91
- package/microservices/microservice-ads/src/db/migrations.ts +0 -60
- package/microservices/microservice-ads/src/index.ts +0 -39
- package/microservices/microservice-ads/src/mcp/index.ts +0 -480
- package/microservices/microservice-analytics/package.json +0 -28
- package/microservices/microservice-analytics/src/cli/index.ts +0 -373
- package/microservices/microservice-analytics/src/db/analytics.ts +0 -564
- package/microservices/microservice-analytics/src/db/database.ts +0 -91
- package/microservices/microservice-analytics/src/db/migrations.ts +0 -50
- package/microservices/microservice-analytics/src/index.ts +0 -37
- package/microservices/microservice-analytics/src/mcp/index.ts +0 -334
- package/microservices/microservice-assets/package.json +0 -28
- package/microservices/microservice-assets/src/cli/index.ts +0 -375
- package/microservices/microservice-assets/src/db/assets.ts +0 -370
- package/microservices/microservice-assets/src/db/database.ts +0 -91
- package/microservices/microservice-assets/src/db/migrations.ts +0 -51
- package/microservices/microservice-assets/src/index.ts +0 -32
- package/microservices/microservice-assets/src/mcp/index.ts +0 -346
- package/microservices/microservice-bookkeeping/package.json +0 -28
- package/microservices/microservice-bookkeeping/src/cli/index.ts +0 -386
- package/microservices/microservice-bookkeeping/src/db/bookkeeping.ts +0 -591
- package/microservices/microservice-bookkeeping/src/db/database.ts +0 -91
- package/microservices/microservice-bookkeeping/src/db/migrations.ts +0 -52
- package/microservices/microservice-bookkeeping/src/index.ts +0 -32
- package/microservices/microservice-bookkeeping/src/mcp/index.ts +0 -284
- package/microservices/microservice-calendar/package.json +0 -28
- package/microservices/microservice-calendar/src/cli/index.ts +0 -287
- package/microservices/microservice-calendar/src/db/calendar.ts +0 -328
- package/microservices/microservice-calendar/src/db/database.ts +0 -91
- package/microservices/microservice-calendar/src/db/migrations.ts +0 -47
- package/microservices/microservice-calendar/src/index.ts +0 -24
- package/microservices/microservice-calendar/src/mcp/index.ts +0 -226
- package/microservices/microservice-company/package.json +0 -28
- package/microservices/microservice-company/src/cli/index.ts +0 -1126
- package/microservices/microservice-company/src/db/company.ts +0 -854
- package/microservices/microservice-company/src/db/database.ts +0 -91
- package/microservices/microservice-company/src/db/migrations.ts +0 -214
- package/microservices/microservice-company/src/db/workflow-migrations.ts +0 -44
- package/microservices/microservice-company/src/index.ts +0 -60
- package/microservices/microservice-company/src/lib/audit.ts +0 -168
- package/microservices/microservice-company/src/lib/finance.ts +0 -299
- package/microservices/microservice-company/src/lib/settings.ts +0 -85
- package/microservices/microservice-company/src/lib/workflows.ts +0 -698
- package/microservices/microservice-company/src/mcp/index.ts +0 -991
- package/microservices/microservice-compliance/package.json +0 -28
- package/microservices/microservice-compliance/src/cli/index.ts +0 -467
- package/microservices/microservice-compliance/src/db/compliance.ts +0 -633
- package/microservices/microservice-compliance/src/db/database.ts +0 -91
- package/microservices/microservice-compliance/src/db/migrations.ts +0 -63
- package/microservices/microservice-compliance/src/index.ts +0 -46
- package/microservices/microservice-compliance/src/mcp/index.ts +0 -438
- package/microservices/microservice-contacts/package.json +0 -28
- package/microservices/microservice-contacts/src/cli/index.ts +0 -393
- package/microservices/microservice-contacts/src/db/companies.ts +0 -167
- package/microservices/microservice-contacts/src/db/contacts.ts +0 -249
- package/microservices/microservice-contacts/src/db/database.ts +0 -91
- package/microservices/microservice-contacts/src/db/migrations.ts +0 -71
- package/microservices/microservice-contacts/src/db/relationships.ts +0 -53
- package/microservices/microservice-contacts/src/index.ts +0 -42
- package/microservices/microservice-contacts/src/mcp/index.ts +0 -303
- package/microservices/microservice-contracts/package.json +0 -28
- package/microservices/microservice-contracts/src/cli/index.ts +0 -770
- package/microservices/microservice-contracts/src/db/contracts.ts +0 -925
- package/microservices/microservice-contracts/src/db/database.ts +0 -91
- package/microservices/microservice-contracts/src/db/migrations.ts +0 -141
- package/microservices/microservice-contracts/src/index.ts +0 -43
- package/microservices/microservice-contracts/src/mcp/index.ts +0 -617
- package/microservices/microservice-crm/package.json +0 -28
- package/microservices/microservice-crm/src/cli/index.ts +0 -396
- package/microservices/microservice-crm/src/db/database.ts +0 -91
- package/microservices/microservice-crm/src/db/migrations.ts +0 -66
- package/microservices/microservice-crm/src/db/pipeline.ts +0 -397
- package/microservices/microservice-crm/src/index.ts +0 -34
- package/microservices/microservice-crm/src/mcp/index.ts +0 -294
- package/microservices/microservice-documents/package.json +0 -28
- package/microservices/microservice-documents/src/cli/index.ts +0 -246
- package/microservices/microservice-documents/src/db/database.ts +0 -91
- package/microservices/microservice-documents/src/db/documents.ts +0 -316
- package/microservices/microservice-documents/src/db/migrations.ts +0 -49
- package/microservices/microservice-documents/src/index.ts +0 -24
- package/microservices/microservice-documents/src/mcp/index.ts +0 -202
- package/microservices/microservice-domains/package.json +0 -28
- package/microservices/microservice-domains/src/cli/index.ts +0 -1111
- package/microservices/microservice-domains/src/db/database.ts +0 -91
- package/microservices/microservice-domains/src/db/domains.ts +0 -1164
- package/microservices/microservice-domains/src/db/migrations.ts +0 -60
- package/microservices/microservice-domains/src/index.ts +0 -65
- package/microservices/microservice-domains/src/lib/brandsight.ts +0 -350
- package/microservices/microservice-domains/src/lib/godaddy.ts +0 -338
- package/microservices/microservice-domains/src/lib/namecheap.ts +0 -262
- package/microservices/microservice-domains/src/lib/registrar.ts +0 -355
- package/microservices/microservice-domains/src/mcp/index.ts +0 -781
- package/microservices/microservice-expenses/package.json +0 -28
- package/microservices/microservice-expenses/src/cli/index.ts +0 -267
- package/microservices/microservice-expenses/src/db/database.ts +0 -91
- package/microservices/microservice-expenses/src/db/expenses.ts +0 -345
- package/microservices/microservice-expenses/src/db/migrations.ts +0 -45
- package/microservices/microservice-expenses/src/index.ts +0 -25
- package/microservices/microservice-expenses/src/mcp/index.ts +0 -196
- package/microservices/microservice-habits/package.json +0 -28
- package/microservices/microservice-habits/src/cli/index.ts +0 -315
- package/microservices/microservice-habits/src/db/database.ts +0 -91
- package/microservices/microservice-habits/src/db/habits.ts +0 -451
- package/microservices/microservice-habits/src/db/migrations.ts +0 -46
- package/microservices/microservice-habits/src/index.ts +0 -31
- package/microservices/microservice-habits/src/mcp/index.ts +0 -313
- package/microservices/microservice-health/package.json +0 -28
- package/microservices/microservice-health/src/cli/index.ts +0 -484
- package/microservices/microservice-health/src/db/database.ts +0 -91
- package/microservices/microservice-health/src/db/health.ts +0 -708
- package/microservices/microservice-health/src/db/migrations.ts +0 -70
- package/microservices/microservice-health/src/index.ts +0 -63
- package/microservices/microservice-health/src/mcp/index.ts +0 -437
- package/microservices/microservice-hiring/package.json +0 -28
- package/microservices/microservice-hiring/src/cli/index.ts +0 -741
- package/microservices/microservice-hiring/src/db/database.ts +0 -91
- package/microservices/microservice-hiring/src/db/hiring.ts +0 -1085
- package/microservices/microservice-hiring/src/db/migrations.ts +0 -89
- package/microservices/microservice-hiring/src/index.ts +0 -80
- package/microservices/microservice-hiring/src/lib/scoring.ts +0 -206
- package/microservices/microservice-hiring/src/mcp/index.ts +0 -709
- package/microservices/microservice-inventory/package.json +0 -28
- package/microservices/microservice-inventory/src/cli/index.ts +0 -365
- package/microservices/microservice-inventory/src/db/database.ts +0 -91
- package/microservices/microservice-inventory/src/db/inventory.ts +0 -393
- package/microservices/microservice-inventory/src/db/migrations.ts +0 -54
- package/microservices/microservice-inventory/src/index.ts +0 -28
- package/microservices/microservice-inventory/src/mcp/index.ts +0 -250
- package/microservices/microservice-invoices/dashboard/index.html +0 -12
- package/microservices/microservice-invoices/dashboard/package.json +0 -29
- package/microservices/microservice-invoices/dashboard/tsconfig.json +0 -14
- package/microservices/microservice-invoices/dashboard/vite.config.ts +0 -15
- package/microservices/microservice-invoices/package.json +0 -31
- package/microservices/microservice-invoices/src/cli/index.ts +0 -308
- package/microservices/microservice-invoices/src/db/business.ts +0 -241
- package/microservices/microservice-invoices/src/db/clients.ts +0 -127
- package/microservices/microservice-invoices/src/db/database.ts +0 -91
- package/microservices/microservice-invoices/src/db/invoices.ts +0 -345
- package/microservices/microservice-invoices/src/db/migrations.ts +0 -184
- package/microservices/microservice-invoices/src/index.ts +0 -56
- package/microservices/microservice-invoices/src/mcp/index.ts +0 -242
- package/microservices/microservice-invoices/src/server/index.ts +0 -162
- package/microservices/microservice-leads/package.json +0 -28
- package/microservices/microservice-leads/src/cli/index.ts +0 -596
- package/microservices/microservice-leads/src/db/database.ts +0 -91
- package/microservices/microservice-leads/src/db/leads.ts +0 -520
- package/microservices/microservice-leads/src/db/lists.ts +0 -151
- package/microservices/microservice-leads/src/db/migrations.ts +0 -93
- package/microservices/microservice-leads/src/index.ts +0 -65
- package/microservices/microservice-leads/src/lib/enrichment.ts +0 -202
- package/microservices/microservice-leads/src/lib/scoring.ts +0 -134
- package/microservices/microservice-leads/src/mcp/index.ts +0 -533
- package/microservices/microservice-notes/package.json +0 -28
- package/microservices/microservice-notes/src/cli/index.ts +0 -63
- package/microservices/microservice-notes/src/db/database.ts +0 -91
- package/microservices/microservice-notes/src/db/migrations.ts +0 -40
- package/microservices/microservice-notes/src/db/notes.ts +0 -114
- package/microservices/microservice-notes/src/index.ts +0 -2
- package/microservices/microservice-notes/src/mcp/index.ts +0 -37
- package/microservices/microservice-notifications/package.json +0 -28
- package/microservices/microservice-notifications/src/cli/index.ts +0 -349
- package/microservices/microservice-notifications/src/db/database.ts +0 -91
- package/microservices/microservice-notifications/src/db/migrations.ts +0 -62
- package/microservices/microservice-notifications/src/db/notifications.ts +0 -509
- package/microservices/microservice-notifications/src/index.ts +0 -41
- package/microservices/microservice-notifications/src/mcp/index.ts +0 -422
- package/microservices/microservice-payments/package.json +0 -28
- package/microservices/microservice-payments/src/cli/index.ts +0 -609
- package/microservices/microservice-payments/src/db/database.ts +0 -91
- package/microservices/microservice-payments/src/db/migrations.ts +0 -81
- package/microservices/microservice-payments/src/db/payments.ts +0 -1204
- package/microservices/microservice-payments/src/index.ts +0 -51
- package/microservices/microservice-payments/src/mcp/index.ts +0 -683
- package/microservices/microservice-payroll/package.json +0 -28
- package/microservices/microservice-payroll/src/cli/index.ts +0 -643
- package/microservices/microservice-payroll/src/db/database.ts +0 -91
- package/microservices/microservice-payroll/src/db/migrations.ts +0 -95
- package/microservices/microservice-payroll/src/db/payroll.ts +0 -1377
- package/microservices/microservice-payroll/src/index.ts +0 -48
- package/microservices/microservice-payroll/src/mcp/index.ts +0 -666
- package/microservices/microservice-products/package.json +0 -28
- package/microservices/microservice-products/src/cli/index.ts +0 -416
- package/microservices/microservice-products/src/db/categories.ts +0 -154
- package/microservices/microservice-products/src/db/database.ts +0 -91
- package/microservices/microservice-products/src/db/migrations.ts +0 -58
- package/microservices/microservice-products/src/db/pricing-tiers.ts +0 -66
- package/microservices/microservice-products/src/db/products.ts +0 -452
- package/microservices/microservice-products/src/index.ts +0 -53
- package/microservices/microservice-products/src/mcp/index.ts +0 -453
- package/microservices/microservice-projects/package.json +0 -28
- package/microservices/microservice-projects/src/cli/index.ts +0 -480
- package/microservices/microservice-projects/src/db/database.ts +0 -91
- package/microservices/microservice-projects/src/db/migrations.ts +0 -65
- package/microservices/microservice-projects/src/db/projects.ts +0 -715
- package/microservices/microservice-projects/src/index.ts +0 -57
- package/microservices/microservice-projects/src/mcp/index.ts +0 -501
- package/microservices/microservice-proposals/package.json +0 -28
- package/microservices/microservice-proposals/src/cli/index.ts +0 -400
- package/microservices/microservice-proposals/src/db/database.ts +0 -91
- package/microservices/microservice-proposals/src/db/migrations.ts +0 -52
- package/microservices/microservice-proposals/src/db/proposals.ts +0 -532
- package/microservices/microservice-proposals/src/index.ts +0 -37
- package/microservices/microservice-proposals/src/mcp/index.ts +0 -375
- package/microservices/microservice-reading/package.json +0 -28
- package/microservices/microservice-reading/src/cli/index.ts +0 -464
- package/microservices/microservice-reading/src/db/database.ts +0 -91
- package/microservices/microservice-reading/src/db/migrations.ts +0 -59
- package/microservices/microservice-reading/src/db/reading.ts +0 -524
- package/microservices/microservice-reading/src/index.ts +0 -51
- package/microservices/microservice-reading/src/mcp/index.ts +0 -368
- package/microservices/microservice-shipping/package.json +0 -28
- package/microservices/microservice-shipping/src/cli/index.ts +0 -606
- package/microservices/microservice-shipping/src/db/database.ts +0 -91
- package/microservices/microservice-shipping/src/db/migrations.ts +0 -69
- package/microservices/microservice-shipping/src/db/shipping.ts +0 -1093
- package/microservices/microservice-shipping/src/index.ts +0 -53
- package/microservices/microservice-shipping/src/mcp/index.ts +0 -533
- package/microservices/microservice-social/package.json +0 -29
- package/microservices/microservice-social/src/cli/index.ts +0 -1583
- package/microservices/microservice-social/src/db/database.ts +0 -91
- package/microservices/microservice-social/src/db/migrations.ts +0 -160
- package/microservices/microservice-social/src/db/social.ts +0 -1076
- package/microservices/microservice-social/src/index.ts +0 -46
- package/microservices/microservice-social/src/lib/audience.ts +0 -353
- package/microservices/microservice-social/src/lib/content-ai.ts +0 -278
- package/microservices/microservice-social/src/lib/media.ts +0 -311
- package/microservices/microservice-social/src/lib/mentions.ts +0 -434
- package/microservices/microservice-social/src/lib/metrics-sync.ts +0 -264
- package/microservices/microservice-social/src/lib/publisher.ts +0 -377
- package/microservices/microservice-social/src/lib/scheduler.ts +0 -229
- package/microservices/microservice-social/src/lib/sentiment.ts +0 -256
- package/microservices/microservice-social/src/lib/threads.ts +0 -291
- package/microservices/microservice-social/src/mcp/index.ts +0 -1425
- package/microservices/microservice-social/src/server/index.ts +0 -441
- package/microservices/microservice-subscriptions/package.json +0 -28
- package/microservices/microservice-subscriptions/src/cli/index.ts +0 -715
- package/microservices/microservice-subscriptions/src/db/database.ts +0 -91
- package/microservices/microservice-subscriptions/src/db/migrations.ts +0 -125
- package/microservices/microservice-subscriptions/src/db/subscriptions.ts +0 -1256
- package/microservices/microservice-subscriptions/src/index.ts +0 -41
- package/microservices/microservice-subscriptions/src/mcp/index.ts +0 -631
- package/microservices/microservice-timesheets/package.json +0 -28
- package/microservices/microservice-timesheets/src/cli/index.ts +0 -373
- package/microservices/microservice-timesheets/src/db/database.ts +0 -91
- package/microservices/microservice-timesheets/src/db/locale.ts +0 -217
- package/microservices/microservice-timesheets/src/db/migrations.ts +0 -74
- package/microservices/microservice-timesheets/src/db/timesheets.ts +0 -447
- package/microservices/microservice-timesheets/src/index.ts +0 -44
- package/microservices/microservice-timesheets/src/mcp/index.ts +0 -269
- package/microservices/microservice-transcriber/package.json +0 -29
- package/microservices/microservice-transcriber/src/cli/index.ts +0 -1593
- package/microservices/microservice-transcriber/src/db/annotations.ts +0 -37
- package/microservices/microservice-transcriber/src/db/comments.ts +0 -166
- package/microservices/microservice-transcriber/src/db/database.ts +0 -91
- package/microservices/microservice-transcriber/src/db/migrations.ts +0 -118
- package/microservices/microservice-transcriber/src/db/proofread.ts +0 -119
- package/microservices/microservice-transcriber/src/db/transcripts.ts +0 -395
- package/microservices/microservice-transcriber/src/index.ts +0 -43
- package/microservices/microservice-transcriber/src/lib/config.ts +0 -77
- package/microservices/microservice-transcriber/src/lib/diff.ts +0 -91
- package/microservices/microservice-transcriber/src/lib/downloader.ts +0 -638
- package/microservices/microservice-transcriber/src/lib/feeds.ts +0 -62
- package/microservices/microservice-transcriber/src/lib/live.ts +0 -94
- package/microservices/microservice-transcriber/src/lib/notion.ts +0 -129
- package/microservices/microservice-transcriber/src/lib/proofread.ts +0 -296
- package/microservices/microservice-transcriber/src/lib/providers.ts +0 -713
- package/microservices/microservice-transcriber/src/lib/summarizer.ts +0 -147
- package/microservices/microservice-transcriber/src/lib/translator.ts +0 -75
- package/microservices/microservice-transcriber/src/lib/webhook.ts +0 -37
- package/microservices/microservice-transcriber/src/mcp/index.ts +0 -1330
- package/microservices/microservice-transcriber/src/server/index.ts +0 -199
- package/microservices/microservice-travel/package.json +0 -28
- package/microservices/microservice-travel/src/cli/index.ts +0 -505
- package/microservices/microservice-travel/src/db/database.ts +0 -91
- package/microservices/microservice-travel/src/db/migrations.ts +0 -77
- package/microservices/microservice-travel/src/db/travel.ts +0 -802
- package/microservices/microservice-travel/src/index.ts +0 -60
- package/microservices/microservice-travel/src/mcp/index.ts +0 -495
- package/microservices/microservice-wiki/package.json +0 -28
- package/microservices/microservice-wiki/src/cli/index.ts +0 -345
- package/microservices/microservice-wiki/src/db/database.ts +0 -91
- package/microservices/microservice-wiki/src/db/migrations.ts +0 -55
- package/microservices/microservice-wiki/src/db/wiki.ts +0 -395
- package/microservices/microservice-wiki/src/index.ts +0 -32
- package/microservices/microservice-wiki/src/mcp/index.ts +0 -344
|
@@ -1,715 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
|
|
3
|
-
import { Command } from "commander";
|
|
4
|
-
import { readFileSync, writeFileSync } from "node:fs";
|
|
5
|
-
import {
|
|
6
|
-
createPlan,
|
|
7
|
-
getPlan,
|
|
8
|
-
listPlans,
|
|
9
|
-
updatePlan,
|
|
10
|
-
deletePlan,
|
|
11
|
-
createSubscriber,
|
|
12
|
-
getSubscriber,
|
|
13
|
-
listSubscribers,
|
|
14
|
-
cancelSubscriber,
|
|
15
|
-
upgradeSubscriber,
|
|
16
|
-
downgradeSubscriber,
|
|
17
|
-
listEvents,
|
|
18
|
-
getMrr,
|
|
19
|
-
getArr,
|
|
20
|
-
getChurnRate,
|
|
21
|
-
listExpiring,
|
|
22
|
-
getSubscriberStats,
|
|
23
|
-
pauseSubscriber,
|
|
24
|
-
resumeSubscriber,
|
|
25
|
-
extendTrial,
|
|
26
|
-
createDunning,
|
|
27
|
-
listDunning,
|
|
28
|
-
updateDunning,
|
|
29
|
-
bulkImportSubscribers,
|
|
30
|
-
exportSubscribers,
|
|
31
|
-
parseImportCsv,
|
|
32
|
-
getLtv,
|
|
33
|
-
getNrr,
|
|
34
|
-
getCohortReport,
|
|
35
|
-
comparePlans,
|
|
36
|
-
getExpiringRenewals,
|
|
37
|
-
} from "../db/subscriptions.js";
|
|
38
|
-
|
|
39
|
-
const program = new Command();
|
|
40
|
-
|
|
41
|
-
program
|
|
42
|
-
.name("microservice-subscriptions")
|
|
43
|
-
.description("Subscription and recurring billing management microservice")
|
|
44
|
-
.version("0.0.1");
|
|
45
|
-
|
|
46
|
-
// --- Plans ---
|
|
47
|
-
|
|
48
|
-
const planCmd = program
|
|
49
|
-
.command("plan")
|
|
50
|
-
.description("Plan management");
|
|
51
|
-
|
|
52
|
-
planCmd
|
|
53
|
-
.command("create")
|
|
54
|
-
.description("Create a new plan")
|
|
55
|
-
.requiredOption("--name <name>", "Plan name")
|
|
56
|
-
.requiredOption("--price <price>", "Price")
|
|
57
|
-
.option("--interval <interval>", "Billing interval (monthly/yearly/lifetime)", "monthly")
|
|
58
|
-
.option("--features <features>", "Comma-separated features")
|
|
59
|
-
.option("--json", "Output as JSON", false)
|
|
60
|
-
.action((opts) => {
|
|
61
|
-
const plan = createPlan({
|
|
62
|
-
name: opts.name,
|
|
63
|
-
price: parseFloat(opts.price),
|
|
64
|
-
interval: opts.interval,
|
|
65
|
-
features: opts.features ? opts.features.split(",").map((f: string) => f.trim()) : undefined,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
if (opts.json) {
|
|
69
|
-
console.log(JSON.stringify(plan, null, 2));
|
|
70
|
-
} else {
|
|
71
|
-
console.log(`Created plan: ${plan.name} — $${plan.price}/${plan.interval} (${plan.id})`);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
planCmd
|
|
76
|
-
.command("list")
|
|
77
|
-
.description("List plans")
|
|
78
|
-
.option("--active", "Show active plans only")
|
|
79
|
-
.option("--interval <interval>", "Filter by interval")
|
|
80
|
-
.option("--json", "Output as JSON", false)
|
|
81
|
-
.action((opts) => {
|
|
82
|
-
const plans = listPlans({
|
|
83
|
-
active_only: opts.active,
|
|
84
|
-
interval: opts.interval,
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
if (opts.json) {
|
|
88
|
-
console.log(JSON.stringify(plans, null, 2));
|
|
89
|
-
} else {
|
|
90
|
-
if (plans.length === 0) {
|
|
91
|
-
console.log("No plans found.");
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
for (const p of plans) {
|
|
95
|
-
const status = p.active ? "" : " [inactive]";
|
|
96
|
-
console.log(` ${p.name} — $${p.price}/${p.interval}${status} (${p.id})`);
|
|
97
|
-
}
|
|
98
|
-
console.log(`\n${plans.length} plan(s)`);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
planCmd
|
|
103
|
-
.command("get")
|
|
104
|
-
.description("Get a plan by ID")
|
|
105
|
-
.argument("<id>", "Plan ID")
|
|
106
|
-
.option("--json", "Output as JSON", false)
|
|
107
|
-
.action((id, opts) => {
|
|
108
|
-
const plan = getPlan(id);
|
|
109
|
-
if (!plan) {
|
|
110
|
-
console.error(`Plan '${id}' not found.`);
|
|
111
|
-
process.exit(1);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (opts.json) {
|
|
115
|
-
console.log(JSON.stringify(plan, null, 2));
|
|
116
|
-
} else {
|
|
117
|
-
console.log(`${plan.name}`);
|
|
118
|
-
console.log(` Price: $${plan.price}/${plan.interval}`);
|
|
119
|
-
console.log(` Active: ${plan.active}`);
|
|
120
|
-
if (plan.features.length) console.log(` Features: ${plan.features.join(", ")}`);
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
planCmd
|
|
125
|
-
.command("update")
|
|
126
|
-
.description("Update a plan")
|
|
127
|
-
.argument("<id>", "Plan ID")
|
|
128
|
-
.option("--name <name>", "Plan name")
|
|
129
|
-
.option("--price <price>", "Price")
|
|
130
|
-
.option("--interval <interval>", "Billing interval")
|
|
131
|
-
.option("--features <features>", "Comma-separated features")
|
|
132
|
-
.option("--active <active>", "Active status (true/false)")
|
|
133
|
-
.option("--json", "Output as JSON", false)
|
|
134
|
-
.action((id, opts) => {
|
|
135
|
-
const input: Record<string, unknown> = {};
|
|
136
|
-
if (opts.name !== undefined) input.name = opts.name;
|
|
137
|
-
if (opts.price !== undefined) input.price = parseFloat(opts.price);
|
|
138
|
-
if (opts.interval !== undefined) input.interval = opts.interval;
|
|
139
|
-
if (opts.features !== undefined) input.features = opts.features.split(",").map((f: string) => f.trim());
|
|
140
|
-
if (opts.active !== undefined) input.active = opts.active === "true";
|
|
141
|
-
|
|
142
|
-
const plan = updatePlan(id, input);
|
|
143
|
-
if (!plan) {
|
|
144
|
-
console.error(`Plan '${id}' not found.`);
|
|
145
|
-
process.exit(1);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (opts.json) {
|
|
149
|
-
console.log(JSON.stringify(plan, null, 2));
|
|
150
|
-
} else {
|
|
151
|
-
console.log(`Updated: ${plan.name} — $${plan.price}/${plan.interval}`);
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
// --- Subscribers ---
|
|
156
|
-
|
|
157
|
-
const subCmd = program
|
|
158
|
-
.command("subscriber")
|
|
159
|
-
.alias("sub")
|
|
160
|
-
.description("Subscriber management");
|
|
161
|
-
|
|
162
|
-
subCmd
|
|
163
|
-
.command("add")
|
|
164
|
-
.description("Add a new subscriber")
|
|
165
|
-
.requiredOption("--plan <id>", "Plan ID")
|
|
166
|
-
.requiredOption("--name <name>", "Customer name")
|
|
167
|
-
.requiredOption("--email <email>", "Customer email")
|
|
168
|
-
.option("--status <status>", "Initial status", "active")
|
|
169
|
-
.option("--trial-ends <date>", "Trial end date (YYYY-MM-DD)")
|
|
170
|
-
.option("--json", "Output as JSON", false)
|
|
171
|
-
.action((opts) => {
|
|
172
|
-
const subscriber = createSubscriber({
|
|
173
|
-
plan_id: opts.plan,
|
|
174
|
-
customer_name: opts.name,
|
|
175
|
-
customer_email: opts.email,
|
|
176
|
-
status: opts.status,
|
|
177
|
-
trial_ends_at: opts.trialEnds,
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
if (opts.json) {
|
|
181
|
-
console.log(JSON.stringify(subscriber, null, 2));
|
|
182
|
-
} else {
|
|
183
|
-
console.log(`Added subscriber: ${subscriber.customer_name} <${subscriber.customer_email}> (${subscriber.id})`);
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
subCmd
|
|
188
|
-
.command("list")
|
|
189
|
-
.description("List subscribers")
|
|
190
|
-
.option("--plan <id>", "Filter by plan ID")
|
|
191
|
-
.option("--status <status>", "Filter by status")
|
|
192
|
-
.option("--search <query>", "Search by name or email")
|
|
193
|
-
.option("--limit <n>", "Limit results")
|
|
194
|
-
.option("--json", "Output as JSON", false)
|
|
195
|
-
.action((opts) => {
|
|
196
|
-
const subscribers = listSubscribers({
|
|
197
|
-
plan_id: opts.plan,
|
|
198
|
-
status: opts.status,
|
|
199
|
-
search: opts.search,
|
|
200
|
-
limit: opts.limit ? parseInt(opts.limit) : undefined,
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
if (opts.json) {
|
|
204
|
-
console.log(JSON.stringify(subscribers, null, 2));
|
|
205
|
-
} else {
|
|
206
|
-
if (subscribers.length === 0) {
|
|
207
|
-
console.log("No subscribers found.");
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
for (const s of subscribers) {
|
|
211
|
-
console.log(` ${s.customer_name} <${s.customer_email}> — ${s.status} (${s.id})`);
|
|
212
|
-
}
|
|
213
|
-
console.log(`\n${subscribers.length} subscriber(s)`);
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
subCmd
|
|
218
|
-
.command("get")
|
|
219
|
-
.description("Get a subscriber by ID")
|
|
220
|
-
.argument("<id>", "Subscriber ID")
|
|
221
|
-
.option("--json", "Output as JSON", false)
|
|
222
|
-
.action((id, opts) => {
|
|
223
|
-
const subscriber = getSubscriber(id);
|
|
224
|
-
if (!subscriber) {
|
|
225
|
-
console.error(`Subscriber '${id}' not found.`);
|
|
226
|
-
process.exit(1);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
if (opts.json) {
|
|
230
|
-
console.log(JSON.stringify(subscriber, null, 2));
|
|
231
|
-
} else {
|
|
232
|
-
console.log(`${subscriber.customer_name} <${subscriber.customer_email}>`);
|
|
233
|
-
console.log(` Status: ${subscriber.status}`);
|
|
234
|
-
console.log(` Plan: ${subscriber.plan_id}`);
|
|
235
|
-
console.log(` Period: ${subscriber.current_period_start} — ${subscriber.current_period_end || "N/A"}`);
|
|
236
|
-
if (subscriber.canceled_at) console.log(` Canceled: ${subscriber.canceled_at}`);
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
subCmd
|
|
241
|
-
.command("cancel")
|
|
242
|
-
.description("Cancel a subscription")
|
|
243
|
-
.argument("<id>", "Subscriber ID")
|
|
244
|
-
.option("--json", "Output as JSON", false)
|
|
245
|
-
.action((id, opts) => {
|
|
246
|
-
const subscriber = cancelSubscriber(id);
|
|
247
|
-
if (!subscriber) {
|
|
248
|
-
console.error(`Subscriber '${id}' not found.`);
|
|
249
|
-
process.exit(1);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (opts.json) {
|
|
253
|
-
console.log(JSON.stringify(subscriber, null, 2));
|
|
254
|
-
} else {
|
|
255
|
-
console.log(`Canceled subscription for ${subscriber.customer_name}`);
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
subCmd
|
|
260
|
-
.command("upgrade")
|
|
261
|
-
.description("Upgrade a subscriber to a new plan")
|
|
262
|
-
.argument("<id>", "Subscriber ID")
|
|
263
|
-
.requiredOption("--plan <id>", "New plan ID")
|
|
264
|
-
.option("--json", "Output as JSON", false)
|
|
265
|
-
.action((id, opts) => {
|
|
266
|
-
const subscriber = upgradeSubscriber(id, opts.plan);
|
|
267
|
-
if (!subscriber) {
|
|
268
|
-
console.error(`Subscriber '${id}' not found or plan not found.`);
|
|
269
|
-
process.exit(1);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
if (opts.json) {
|
|
273
|
-
console.log(JSON.stringify(subscriber, null, 2));
|
|
274
|
-
} else {
|
|
275
|
-
console.log(`Upgraded ${subscriber.customer_name} to plan ${subscriber.plan_id}`);
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
subCmd
|
|
280
|
-
.command("downgrade")
|
|
281
|
-
.description("Downgrade a subscriber to a new plan")
|
|
282
|
-
.argument("<id>", "Subscriber ID")
|
|
283
|
-
.requiredOption("--plan <id>", "New plan ID")
|
|
284
|
-
.option("--json", "Output as JSON", false)
|
|
285
|
-
.action((id, opts) => {
|
|
286
|
-
const subscriber = downgradeSubscriber(id, opts.plan);
|
|
287
|
-
if (!subscriber) {
|
|
288
|
-
console.error(`Subscriber '${id}' not found or plan not found.`);
|
|
289
|
-
process.exit(1);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
if (opts.json) {
|
|
293
|
-
console.log(JSON.stringify(subscriber, null, 2));
|
|
294
|
-
} else {
|
|
295
|
-
console.log(`Downgraded ${subscriber.customer_name} to plan ${subscriber.plan_id}`);
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
// --- Pause / Resume ---
|
|
300
|
-
|
|
301
|
-
subCmd
|
|
302
|
-
.command("pause")
|
|
303
|
-
.description("Pause a subscription")
|
|
304
|
-
.argument("<id>", "Subscriber ID")
|
|
305
|
-
.option("--resume-date <date>", "Scheduled resume date (YYYY-MM-DD)")
|
|
306
|
-
.option("--json", "Output as JSON", false)
|
|
307
|
-
.action((id, opts) => {
|
|
308
|
-
const subscriber = pauseSubscriber(id, opts.resumeDate);
|
|
309
|
-
if (!subscriber) {
|
|
310
|
-
console.error(`Subscriber '${id}' not found or cannot be paused.`);
|
|
311
|
-
process.exit(1);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
if (opts.json) {
|
|
315
|
-
console.log(JSON.stringify(subscriber, null, 2));
|
|
316
|
-
} else {
|
|
317
|
-
console.log(`Paused subscription for ${subscriber.customer_name}`);
|
|
318
|
-
if (subscriber.resume_at) console.log(` Scheduled resume: ${subscriber.resume_at}`);
|
|
319
|
-
}
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
subCmd
|
|
323
|
-
.command("resume")
|
|
324
|
-
.description("Resume a paused subscription")
|
|
325
|
-
.argument("<id>", "Subscriber ID")
|
|
326
|
-
.option("--json", "Output as JSON", false)
|
|
327
|
-
.action((id, opts) => {
|
|
328
|
-
const subscriber = resumeSubscriber(id);
|
|
329
|
-
if (!subscriber) {
|
|
330
|
-
console.error(`Subscriber '${id}' not found or not paused.`);
|
|
331
|
-
process.exit(1);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
if (opts.json) {
|
|
335
|
-
console.log(JSON.stringify(subscriber, null, 2));
|
|
336
|
-
} else {
|
|
337
|
-
console.log(`Resumed subscription for ${subscriber.customer_name}`);
|
|
338
|
-
}
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
// --- Trial Extension ---
|
|
342
|
-
|
|
343
|
-
subCmd
|
|
344
|
-
.command("extend-trial")
|
|
345
|
-
.description("Extend a subscriber's trial period")
|
|
346
|
-
.argument("<id>", "Subscriber ID")
|
|
347
|
-
.requiredOption("--days <days>", "Number of days to extend")
|
|
348
|
-
.option("--json", "Output as JSON", false)
|
|
349
|
-
.action((id, opts) => {
|
|
350
|
-
const subscriber = extendTrial(id, parseInt(opts.days));
|
|
351
|
-
if (!subscriber) {
|
|
352
|
-
console.error(`Subscriber '${id}' not found.`);
|
|
353
|
-
process.exit(1);
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
if (opts.json) {
|
|
357
|
-
console.log(JSON.stringify(subscriber, null, 2));
|
|
358
|
-
} else {
|
|
359
|
-
console.log(`Extended trial for ${subscriber.customer_name} by ${opts.days} days`);
|
|
360
|
-
console.log(` New trial end: ${subscriber.trial_ends_at}`);
|
|
361
|
-
}
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
// --- Bulk Import/Export ---
|
|
365
|
-
|
|
366
|
-
subCmd
|
|
367
|
-
.command("import")
|
|
368
|
-
.description("Bulk import subscribers from a CSV file")
|
|
369
|
-
.requiredOption("--file <path>", "Path to CSV file")
|
|
370
|
-
.option("--json", "Output as JSON", false)
|
|
371
|
-
.action((opts) => {
|
|
372
|
-
const csvContent = readFileSync(opts.file, "utf-8");
|
|
373
|
-
const data = parseImportCsv(csvContent);
|
|
374
|
-
const imported = bulkImportSubscribers(data);
|
|
375
|
-
|
|
376
|
-
if (opts.json) {
|
|
377
|
-
console.log(JSON.stringify({ imported: imported.length, subscribers: imported }, null, 2));
|
|
378
|
-
} else {
|
|
379
|
-
console.log(`Imported ${imported.length} subscriber(s) from ${opts.file}`);
|
|
380
|
-
for (const s of imported) {
|
|
381
|
-
console.log(` ${s.customer_name} <${s.customer_email}> (${s.id})`);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
subCmd
|
|
387
|
-
.command("export")
|
|
388
|
-
.description("Export subscribers")
|
|
389
|
-
.option("--format <format>", "Output format (csv/json)", "csv")
|
|
390
|
-
.option("--file <path>", "Output file path (prints to stdout if omitted)")
|
|
391
|
-
.action((opts) => {
|
|
392
|
-
const output = exportSubscribers(opts.format as "csv" | "json");
|
|
393
|
-
if (opts.file) {
|
|
394
|
-
writeFileSync(opts.file, output, "utf-8");
|
|
395
|
-
console.log(`Exported to ${opts.file}`);
|
|
396
|
-
} else {
|
|
397
|
-
console.log(output);
|
|
398
|
-
}
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
// --- Dunning ---
|
|
402
|
-
|
|
403
|
-
const dunningCmd = program
|
|
404
|
-
.command("dunning")
|
|
405
|
-
.description("Dunning attempt management");
|
|
406
|
-
|
|
407
|
-
dunningCmd
|
|
408
|
-
.command("list")
|
|
409
|
-
.description("List dunning attempts")
|
|
410
|
-
.option("--subscriber <id>", "Filter by subscriber ID")
|
|
411
|
-
.option("--status <status>", "Filter by status")
|
|
412
|
-
.option("--limit <n>", "Limit results", "20")
|
|
413
|
-
.option("--json", "Output as JSON", false)
|
|
414
|
-
.action((opts) => {
|
|
415
|
-
const attempts = listDunning({
|
|
416
|
-
subscriber_id: opts.subscriber,
|
|
417
|
-
status: opts.status,
|
|
418
|
-
limit: parseInt(opts.limit),
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
if (opts.json) {
|
|
422
|
-
console.log(JSON.stringify(attempts, null, 2));
|
|
423
|
-
} else {
|
|
424
|
-
if (attempts.length === 0) {
|
|
425
|
-
console.log("No dunning attempts found.");
|
|
426
|
-
return;
|
|
427
|
-
}
|
|
428
|
-
for (const a of attempts) {
|
|
429
|
-
console.log(` [${a.created_at}] #${a.attempt_number} ${a.status} — subscriber: ${a.subscriber_id}`);
|
|
430
|
-
if (a.next_retry_at) console.log(` Next retry: ${a.next_retry_at}`);
|
|
431
|
-
}
|
|
432
|
-
console.log(`\n${attempts.length} attempt(s)`);
|
|
433
|
-
}
|
|
434
|
-
});
|
|
435
|
-
|
|
436
|
-
dunningCmd
|
|
437
|
-
.command("create")
|
|
438
|
-
.description("Create a dunning attempt")
|
|
439
|
-
.requiredOption("--subscriber <id>", "Subscriber ID")
|
|
440
|
-
.option("--attempt <n>", "Attempt number", "1")
|
|
441
|
-
.option("--status <status>", "Status", "pending")
|
|
442
|
-
.option("--next-retry <date>", "Next retry date")
|
|
443
|
-
.option("--json", "Output as JSON", false)
|
|
444
|
-
.action((opts) => {
|
|
445
|
-
const attempt = createDunning({
|
|
446
|
-
subscriber_id: opts.subscriber,
|
|
447
|
-
attempt_number: parseInt(opts.attempt),
|
|
448
|
-
status: opts.status,
|
|
449
|
-
next_retry_at: opts.nextRetry,
|
|
450
|
-
});
|
|
451
|
-
|
|
452
|
-
if (opts.json) {
|
|
453
|
-
console.log(JSON.stringify(attempt, null, 2));
|
|
454
|
-
} else {
|
|
455
|
-
console.log(`Created dunning attempt #${attempt.attempt_number} for subscriber ${attempt.subscriber_id}`);
|
|
456
|
-
}
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
dunningCmd
|
|
460
|
-
.command("update")
|
|
461
|
-
.description("Update a dunning attempt")
|
|
462
|
-
.argument("<id>", "Dunning attempt ID")
|
|
463
|
-
.option("--status <status>", "New status")
|
|
464
|
-
.option("--next-retry <date>", "Next retry date")
|
|
465
|
-
.option("--json", "Output as JSON", false)
|
|
466
|
-
.action((id, opts) => {
|
|
467
|
-
const input: Record<string, unknown> = {};
|
|
468
|
-
if (opts.status) input.status = opts.status;
|
|
469
|
-
if (opts.nextRetry !== undefined) input.next_retry_at = opts.nextRetry;
|
|
470
|
-
|
|
471
|
-
const attempt = updateDunning(id, input);
|
|
472
|
-
if (!attempt) {
|
|
473
|
-
console.error(`Dunning attempt '${id}' not found.`);
|
|
474
|
-
process.exit(1);
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
if (opts.json) {
|
|
478
|
-
console.log(JSON.stringify(attempt, null, 2));
|
|
479
|
-
} else {
|
|
480
|
-
console.log(`Updated dunning attempt ${attempt.id} — status: ${attempt.status}`);
|
|
481
|
-
}
|
|
482
|
-
});
|
|
483
|
-
|
|
484
|
-
// --- Analytics ---
|
|
485
|
-
|
|
486
|
-
program
|
|
487
|
-
.command("ltv")
|
|
488
|
-
.description("Show lifetime value per subscriber and average")
|
|
489
|
-
.option("--json", "Output as JSON", false)
|
|
490
|
-
.action((opts) => {
|
|
491
|
-
const result = getLtv();
|
|
492
|
-
|
|
493
|
-
if (opts.json) {
|
|
494
|
-
console.log(JSON.stringify(result, null, 2));
|
|
495
|
-
} else {
|
|
496
|
-
if (result.subscribers.length === 0) {
|
|
497
|
-
console.log("No subscribers found.");
|
|
498
|
-
return;
|
|
499
|
-
}
|
|
500
|
-
console.log("Lifetime Value Report:");
|
|
501
|
-
for (const s of result.subscribers) {
|
|
502
|
-
console.log(` ${s.customer_name} <${s.customer_email}> — $${s.ltv.toFixed(2)} (${s.months_active}mo on ${s.plan_name})`);
|
|
503
|
-
}
|
|
504
|
-
console.log(`\nAverage LTV: $${result.average_ltv.toFixed(2)}`);
|
|
505
|
-
}
|
|
506
|
-
});
|
|
507
|
-
|
|
508
|
-
program
|
|
509
|
-
.command("nrr")
|
|
510
|
-
.description("Calculate net revenue retention for a month")
|
|
511
|
-
.requiredOption("--month <month>", "Month in YYYY-MM format")
|
|
512
|
-
.option("--json", "Output as JSON", false)
|
|
513
|
-
.action((opts) => {
|
|
514
|
-
const result = getNrr(opts.month);
|
|
515
|
-
|
|
516
|
-
if (opts.json) {
|
|
517
|
-
console.log(JSON.stringify(result, null, 2));
|
|
518
|
-
} else {
|
|
519
|
-
console.log(`NRR for ${result.month}:`);
|
|
520
|
-
console.log(` Start MRR: $${result.start_mrr.toFixed(2)}`);
|
|
521
|
-
console.log(` Expansion: +$${result.expansion.toFixed(2)}`);
|
|
522
|
-
console.log(` Contraction: -$${result.contraction.toFixed(2)}`);
|
|
523
|
-
console.log(` Churn: -$${result.churn.toFixed(2)}`);
|
|
524
|
-
console.log(` NRR: ${result.nrr.toFixed(2)}%`);
|
|
525
|
-
}
|
|
526
|
-
});
|
|
527
|
-
|
|
528
|
-
program
|
|
529
|
-
.command("cohort-report")
|
|
530
|
-
.description("Show cohort retention analysis")
|
|
531
|
-
.option("--months <n>", "Number of months to analyze", "6")
|
|
532
|
-
.option("--json", "Output as JSON", false)
|
|
533
|
-
.action((opts) => {
|
|
534
|
-
const report = getCohortReport(parseInt(opts.months));
|
|
535
|
-
|
|
536
|
-
if (opts.json) {
|
|
537
|
-
console.log(JSON.stringify(report, null, 2));
|
|
538
|
-
} else {
|
|
539
|
-
if (report.length === 0) {
|
|
540
|
-
console.log("No cohort data available.");
|
|
541
|
-
return;
|
|
542
|
-
}
|
|
543
|
-
console.log("Cohort Retention Report:");
|
|
544
|
-
console.log(" Cohort | Total | Retained | Retention");
|
|
545
|
-
console.log(" -----------|-------|----------|----------");
|
|
546
|
-
for (const c of report) {
|
|
547
|
-
console.log(` ${c.cohort} | ${String(c.total).padStart(5)} | ${String(c.retained).padStart(8)} | ${c.retention_rate.toFixed(1)}%`);
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
});
|
|
551
|
-
|
|
552
|
-
planCmd
|
|
553
|
-
.command("compare")
|
|
554
|
-
.description("Compare two plans side by side")
|
|
555
|
-
.argument("<id1>", "First plan ID")
|
|
556
|
-
.argument("<id2>", "Second plan ID")
|
|
557
|
-
.option("--json", "Output as JSON", false)
|
|
558
|
-
.action((id1, id2, opts) => {
|
|
559
|
-
const result = comparePlans(id1, id2);
|
|
560
|
-
if (!result) {
|
|
561
|
-
console.error("One or both plans not found.");
|
|
562
|
-
process.exit(1);
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
if (opts.json) {
|
|
566
|
-
console.log(JSON.stringify(result, null, 2));
|
|
567
|
-
} else {
|
|
568
|
-
console.log(`Plan Comparison:`);
|
|
569
|
-
console.log(` ${result.plan1.name} vs ${result.plan2.name}`);
|
|
570
|
-
console.log(` Price: $${result.plan1.price}/${result.plan1.interval} vs $${result.plan2.price}/${result.plan2.interval}`);
|
|
571
|
-
console.log(` Price diff: $${result.price_diff} (${result.price_diff_pct > 0 ? "+" : ""}${result.price_diff_pct}%)`);
|
|
572
|
-
console.log(` Interval match: ${result.interval_match ? "Yes" : "No"}`);
|
|
573
|
-
if (result.common_features.length) console.log(` Common features: ${result.common_features.join(", ")}`);
|
|
574
|
-
if (result.features_only_in_plan1.length) console.log(` Only in ${result.plan1.name}: ${result.features_only_in_plan1.join(", ")}`);
|
|
575
|
-
if (result.features_only_in_plan2.length) console.log(` Only in ${result.plan2.name}: ${result.features_only_in_plan2.join(", ")}`);
|
|
576
|
-
}
|
|
577
|
-
});
|
|
578
|
-
|
|
579
|
-
program
|
|
580
|
-
.command("expiring-renewals")
|
|
581
|
-
.description("List subscribers with renewals expiring soon")
|
|
582
|
-
.option("--days <days>", "Days ahead to check", "7")
|
|
583
|
-
.option("--json", "Output as JSON", false)
|
|
584
|
-
.action((opts) => {
|
|
585
|
-
const expiring = getExpiringRenewals(parseInt(opts.days));
|
|
586
|
-
|
|
587
|
-
if (opts.json) {
|
|
588
|
-
console.log(JSON.stringify(expiring, null, 2));
|
|
589
|
-
} else {
|
|
590
|
-
if (expiring.length === 0) {
|
|
591
|
-
console.log(`No renewals expiring in the next ${opts.days} days.`);
|
|
592
|
-
return;
|
|
593
|
-
}
|
|
594
|
-
for (const s of expiring) {
|
|
595
|
-
console.log(` ${s.customer_name} <${s.customer_email}> — renews ${s.current_period_end}`);
|
|
596
|
-
}
|
|
597
|
-
console.log(`\n${expiring.length} upcoming renewal(s)`);
|
|
598
|
-
}
|
|
599
|
-
});
|
|
600
|
-
|
|
601
|
-
program
|
|
602
|
-
.command("mrr")
|
|
603
|
-
.description("Get monthly recurring revenue")
|
|
604
|
-
.option("--json", "Output as JSON", false)
|
|
605
|
-
.action((opts) => {
|
|
606
|
-
const mrr = getMrr();
|
|
607
|
-
if (opts.json) {
|
|
608
|
-
console.log(JSON.stringify({ mrr }));
|
|
609
|
-
} else {
|
|
610
|
-
console.log(`MRR: $${mrr.toFixed(2)}`);
|
|
611
|
-
}
|
|
612
|
-
});
|
|
613
|
-
|
|
614
|
-
program
|
|
615
|
-
.command("arr")
|
|
616
|
-
.description("Get annual recurring revenue")
|
|
617
|
-
.option("--json", "Output as JSON", false)
|
|
618
|
-
.action((opts) => {
|
|
619
|
-
const arr = getArr();
|
|
620
|
-
if (opts.json) {
|
|
621
|
-
console.log(JSON.stringify({ arr }));
|
|
622
|
-
} else {
|
|
623
|
-
console.log(`ARR: $${arr.toFixed(2)}`);
|
|
624
|
-
}
|
|
625
|
-
});
|
|
626
|
-
|
|
627
|
-
program
|
|
628
|
-
.command("churn")
|
|
629
|
-
.description("Get churn rate")
|
|
630
|
-
.option("--period <days>", "Period in days", "30")
|
|
631
|
-
.option("--json", "Output as JSON", false)
|
|
632
|
-
.action((opts) => {
|
|
633
|
-
const rate = getChurnRate(parseInt(opts.period));
|
|
634
|
-
if (opts.json) {
|
|
635
|
-
console.log(JSON.stringify({ churn_rate: rate, period_days: parseInt(opts.period) }));
|
|
636
|
-
} else {
|
|
637
|
-
console.log(`Churn rate (${opts.period}d): ${rate}%`);
|
|
638
|
-
}
|
|
639
|
-
});
|
|
640
|
-
|
|
641
|
-
program
|
|
642
|
-
.command("events")
|
|
643
|
-
.description("List subscription events")
|
|
644
|
-
.option("--subscriber <id>", "Filter by subscriber ID")
|
|
645
|
-
.option("--type <type>", "Filter by event type")
|
|
646
|
-
.option("--limit <n>", "Limit results", "20")
|
|
647
|
-
.option("--json", "Output as JSON", false)
|
|
648
|
-
.action((opts) => {
|
|
649
|
-
const events = listEvents({
|
|
650
|
-
subscriber_id: opts.subscriber,
|
|
651
|
-
type: opts.type,
|
|
652
|
-
limit: parseInt(opts.limit),
|
|
653
|
-
});
|
|
654
|
-
|
|
655
|
-
if (opts.json) {
|
|
656
|
-
console.log(JSON.stringify(events, null, 2));
|
|
657
|
-
} else {
|
|
658
|
-
if (events.length === 0) {
|
|
659
|
-
console.log("No events found.");
|
|
660
|
-
return;
|
|
661
|
-
}
|
|
662
|
-
for (const e of events) {
|
|
663
|
-
console.log(` [${e.occurred_at}] ${e.type} — subscriber: ${e.subscriber_id}`);
|
|
664
|
-
}
|
|
665
|
-
console.log(`\n${events.length} event(s)`);
|
|
666
|
-
}
|
|
667
|
-
});
|
|
668
|
-
|
|
669
|
-
program
|
|
670
|
-
.command("expiring")
|
|
671
|
-
.description("List subscriptions expiring soon")
|
|
672
|
-
.option("--days <days>", "Days ahead to check", "7")
|
|
673
|
-
.option("--json", "Output as JSON", false)
|
|
674
|
-
.action((opts) => {
|
|
675
|
-
const expiring = listExpiring(parseInt(opts.days));
|
|
676
|
-
|
|
677
|
-
if (opts.json) {
|
|
678
|
-
console.log(JSON.stringify(expiring, null, 2));
|
|
679
|
-
} else {
|
|
680
|
-
if (expiring.length === 0) {
|
|
681
|
-
console.log(`No subscriptions expiring in the next ${opts.days} days.`);
|
|
682
|
-
return;
|
|
683
|
-
}
|
|
684
|
-
for (const s of expiring) {
|
|
685
|
-
console.log(` ${s.customer_name} <${s.customer_email}> — expires ${s.current_period_end}`);
|
|
686
|
-
}
|
|
687
|
-
console.log(`\n${expiring.length} expiring subscription(s)`);
|
|
688
|
-
}
|
|
689
|
-
});
|
|
690
|
-
|
|
691
|
-
program
|
|
692
|
-
.command("stats")
|
|
693
|
-
.description("Get subscriber statistics")
|
|
694
|
-
.option("--json", "Output as JSON", false)
|
|
695
|
-
.action((opts) => {
|
|
696
|
-
const stats = getSubscriberStats();
|
|
697
|
-
const mrr = getMrr();
|
|
698
|
-
const arr = getArr();
|
|
699
|
-
|
|
700
|
-
if (opts.json) {
|
|
701
|
-
console.log(JSON.stringify({ ...stats, mrr, arr }, null, 2));
|
|
702
|
-
} else {
|
|
703
|
-
console.log("Subscriber Statistics:");
|
|
704
|
-
console.log(` Total: ${stats.total}`);
|
|
705
|
-
console.log(` Active: ${stats.active}`);
|
|
706
|
-
console.log(` Trialing: ${stats.trialing}`);
|
|
707
|
-
console.log(` Past Due: ${stats.past_due}`);
|
|
708
|
-
console.log(` Canceled: ${stats.canceled}`);
|
|
709
|
-
console.log(` Expired: ${stats.expired}`);
|
|
710
|
-
console.log(` MRR: $${mrr.toFixed(2)}`);
|
|
711
|
-
console.log(` ARR: $${arr.toFixed(2)}`);
|
|
712
|
-
}
|
|
713
|
-
});
|
|
714
|
-
|
|
715
|
-
program.parse(process.argv);
|