@tokenbuddy/tokenbuddy 1.0.5 → 1.0.6

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.
Files changed (40) hide show
  1. package/dist/src/buyer-store.d.ts +20 -0
  2. package/dist/src/buyer-store.d.ts.map +1 -1
  3. package/dist/src/buyer-store.js +73 -1
  4. package/dist/src/buyer-store.js.map +1 -1
  5. package/dist/src/cli.d.ts.map +1 -1
  6. package/dist/src/cli.js +390 -62
  7. package/dist/src/cli.js.map +1 -1
  8. package/dist/src/daemon.d.ts +6 -5
  9. package/dist/src/daemon.d.ts.map +1 -1
  10. package/dist/src/daemon.js +298 -92
  11. package/dist/src/daemon.js.map +1 -1
  12. package/dist/src/doctor-diagnostics.d.ts +97 -0
  13. package/dist/src/doctor-diagnostics.d.ts.map +1 -0
  14. package/dist/src/doctor-diagnostics.js +547 -0
  15. package/dist/src/doctor-diagnostics.js.map +1 -0
  16. package/dist/src/init-payment-options.d.ts +34 -0
  17. package/dist/src/init-payment-options.d.ts.map +1 -0
  18. package/dist/src/init-payment-options.js +90 -0
  19. package/dist/src/init-payment-options.js.map +1 -0
  20. package/dist/src/provider-install.d.ts +37 -2
  21. package/dist/src/provider-install.d.ts.map +1 -1
  22. package/dist/src/provider-install.js +317 -67
  23. package/dist/src/provider-install.js.map +1 -1
  24. package/dist/src/seller-catalog.d.ts +79 -0
  25. package/dist/src/seller-catalog.d.ts.map +1 -0
  26. package/dist/src/seller-catalog.js +126 -0
  27. package/dist/src/seller-catalog.js.map +1 -0
  28. package/dist/src/tb-proxyd.js +13 -2
  29. package/dist/src/tb-proxyd.js.map +1 -1
  30. package/package.json +1 -1
  31. package/src/buyer-store.ts +113 -1
  32. package/src/cli.ts +490 -67
  33. package/src/daemon.ts +346 -117
  34. package/src/doctor-diagnostics.ts +850 -0
  35. package/src/init-payment-options.ts +131 -0
  36. package/src/provider-install.ts +426 -76
  37. package/src/seller-catalog.ts +222 -0
  38. package/src/tb-proxyd.ts +14 -2
  39. package/tests/e2e.test.ts +9 -0
  40. package/tests/tokenbuddy.test.ts +628 -19
@@ -0,0 +1,131 @@
1
+ import * as p from "@clack/prompts";
2
+ import type { PaymentConfig } from "./buyer-store.js";
3
+ import type { ProviderCandidate } from "./provider-install.js";
4
+
5
+ export type InitPaymentMethod = "clawtip";
6
+
7
+ export interface InitPaymentOption {
8
+ value: InitPaymentMethod;
9
+ label: string;
10
+ hint?: string;
11
+ }
12
+
13
+ export interface ComingSoonPaymentOption {
14
+ id: string;
15
+ label: string;
16
+ }
17
+
18
+ export interface ExistingClawtipBinding {
19
+ config: Record<string, unknown>;
20
+ resourceUrl?: string;
21
+ orderNo?: string;
22
+ }
23
+
24
+ export interface InitTerminalOption {
25
+ value: string;
26
+ label: string;
27
+ hint?: string;
28
+ }
29
+
30
+ export const OTHER_TERMINAL_OPTION: InitTerminalOption = {
31
+ value: "other",
32
+ label: "Other",
33
+ hint: "I will configure my own terminal using the TokenBuddy proxy endpoints."
34
+ };
35
+
36
+ export const INIT_PAYMENT_OPTIONS: InitPaymentOption[] = [
37
+ {
38
+ value: "clawtip",
39
+ label: "JD ClawTip Pay (Scan QR Code to activate)",
40
+ hint: "1 Fen activation fee"
41
+ }
42
+ ];
43
+
44
+ export const INIT_COMING_SOON_PAYMENT_OPTIONS = [
45
+ {
46
+ id: "wechat-pay",
47
+ label: "WeChat Pay"
48
+ },
49
+ {
50
+ id: "alipay-agent-payment",
51
+ label: "Alipay Agent Payment"
52
+ },
53
+ {
54
+ id: "coinbase-smart-wallet",
55
+ label: "Coinbase Smart Wallet"
56
+ }
57
+ ] satisfies ReadonlyArray<ComingSoonPaymentOption>;
58
+
59
+ export function noteInitComingSoonPayments(
60
+ note: (message?: string, title?: string) => void = p.note
61
+ ): void {
62
+ note(
63
+ INIT_COMING_SOON_PAYMENT_OPTIONS.map((entry) => `- ${entry.label}(接入中)`).join("\n"),
64
+ "更多支付方式"
65
+ );
66
+ }
67
+
68
+ export function buildInitTerminalOptions(providers: ProviderCandidate[]): InitTerminalOption[] {
69
+ const detected = providers
70
+ .filter((provider) => provider.detected)
71
+ .map((provider) => {
72
+ if (provider.status === "configured") {
73
+ return {
74
+ value: `${provider.id}:installed`,
75
+ label: `${provider.name}(已安装)`,
76
+ hint: provider.reason
77
+ };
78
+ }
79
+ return {
80
+ value: provider.id,
81
+ label: provider.name,
82
+ hint: provider.reason
83
+ };
84
+ });
85
+
86
+ return [...detected, OTHER_TERMINAL_OPTION];
87
+ }
88
+
89
+ export function validateInitTerminalSelection(selected: string[] | undefined): string | undefined {
90
+ if (!selected || selected.length === 0) {
91
+ return "Select at least one terminal or choose Other.";
92
+ }
93
+ const actionable = selected.filter((value) => !value.endsWith(":installed"));
94
+ if (actionable.length === 0) {
95
+ return "Installed terminals are already configured. Select another terminal or choose Other.";
96
+ }
97
+ return undefined;
98
+ }
99
+
100
+ function stringField(value: unknown): string | undefined {
101
+ return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
102
+ }
103
+
104
+ export function detectExistingClawtipBinding(payment: PaymentConfig | undefined): ExistingClawtipBinding | undefined {
105
+ if (!payment || payment.method !== "clawtip" || !payment.config || typeof payment.config !== "object") {
106
+ return undefined;
107
+ }
108
+ const config = payment.config as Record<string, unknown>;
109
+ const resourceUrl = stringField(config.resourceUrl);
110
+ const orderNo = stringField(config.orderNo);
111
+ if (!resourceUrl && !orderNo) {
112
+ return undefined;
113
+ }
114
+ return {
115
+ config,
116
+ resourceUrl,
117
+ orderNo,
118
+ };
119
+ }
120
+
121
+ export function buildInitSuccessMessage(summaryLines: string[] = []): string {
122
+ const lines = ["✅ TokenBuddy setup completed successfully."];
123
+ for (const line of summaryLines) {
124
+ const trimmed = line.trim();
125
+ if (trimmed) {
126
+ lines.push(`- ${trimmed}`);
127
+ }
128
+ }
129
+ lines.push("Run `tb doctor` to audit status anytime.");
130
+ return lines.join("\n");
131
+ }