@seasonkoh/webaz 0.1.27 → 0.1.29

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 (121) hide show
  1. package/README.md +4 -3
  2. package/README.zh-CN.md +7 -6
  3. package/dist/currency.js +16 -0
  4. package/dist/deposit-rails.js +52 -0
  5. package/dist/direct-pay-aml-monitor.js +67 -0
  6. package/dist/direct-pay-aml-review.js +40 -0
  7. package/dist/direct-pay-base-bond-entry.js +5 -0
  8. package/dist/direct-pay-bond-rail-clearance.js +94 -0
  9. package/dist/direct-pay-compliance-ingress.js +145 -0
  10. package/dist/direct-pay-controls.js +136 -0
  11. package/dist/direct-pay-create.js +162 -0
  12. package/dist/direct-pay-deferral-quota.js +43 -0
  13. package/dist/direct-pay-disclosures.js +44 -0
  14. package/dist/direct-pay-eligibility.js +46 -0
  15. package/dist/direct-pay-fee-ar.js +241 -0
  16. package/dist/direct-pay-launch-readiness.js +108 -0
  17. package/dist/direct-pay-launch-summary.js +68 -0
  18. package/dist/direct-pay-ledger.js +94 -0
  19. package/dist/direct-receive-account-qr.js +77 -0
  20. package/dist/direct-receive-accounts.js +82 -0
  21. package/dist/direct-receive-deferral.js +142 -0
  22. package/dist/direct-receive-deposits.js +260 -0
  23. package/dist/direct-receive-payment-instruction.js +26 -0
  24. package/dist/fx-rates.js +71 -0
  25. package/dist/layer0-foundation/L0-1-database/schema.js +531 -1
  26. package/dist/layer0-foundation/L0-2-state-machine/genuine-sale.js +15 -5
  27. package/dist/layer0-foundation/L0-2-state-machine/transitions.js +41 -0
  28. package/dist/layer0-foundation/L0-5-manifest/manifest.js +1 -1
  29. package/dist/layer1-agent/L1-1-mcp-server/cli.js +64 -0
  30. package/dist/layer1-agent/L1-1-mcp-server/network-mode.js +80 -0
  31. package/dist/layer1-agent/L1-1-mcp-server/server.js +251 -69
  32. package/dist/layer4-economics/L4-4-skill-market/skill-engine.js +4 -4
  33. package/dist/ledger.js +12 -3
  34. package/dist/mcp.js +23 -4
  35. package/dist/merchant-bond-domain.js +64 -0
  36. package/dist/merchant-bond-exposure.js +78 -0
  37. package/dist/merchant-bond-watcher.js +26 -0
  38. package/dist/payment-rails.js +29 -0
  39. package/dist/product-verification.js +93 -0
  40. package/dist/pwa/acp-feed.js +3 -2
  41. package/dist/pwa/contract-fingerprint.js +3 -0
  42. package/dist/pwa/direct-pay-guards.js +20 -0
  43. package/dist/pwa/direct-pay-order-redaction.js +24 -0
  44. package/dist/pwa/endpoint-actions.js +3 -0
  45. package/dist/pwa/public/app-account.js +977 -0
  46. package/dist/pwa/public/app-admin.js +608 -0
  47. package/dist/pwa/public/app-agents.js +63 -0
  48. package/dist/pwa/public/app-ai.js +2162 -0
  49. package/dist/pwa/public/app-chat-poll.js +29 -0
  50. package/dist/pwa/public/app-contribution.js +836 -0
  51. package/dist/pwa/public/app-create-kinds.js +17 -0
  52. package/dist/pwa/public/app-direct-pay-accounts.js +141 -0
  53. package/dist/pwa/public/app-direct-pay-buyer.js +72 -0
  54. package/dist/pwa/public/app-direct-pay-compliance.js +67 -0
  55. package/dist/pwa/public/app-direct-pay-deferral-admin.js +72 -0
  56. package/dist/pwa/public/app-direct-pay-deferral.js +61 -0
  57. package/dist/pwa/public/app-direct-pay-fee-center.js +33 -0
  58. package/dist/pwa/public/app-direct-pay-fee-ops.js +112 -0
  59. package/dist/pwa/public/app-direct-pay-product-verify.js +103 -0
  60. package/dist/pwa/public/app-direct-pay-readiness.js +38 -0
  61. package/dist/pwa/public/app-direct-pay-store-verify.js +100 -0
  62. package/dist/pwa/public/app-direct-pay.js +227 -0
  63. package/dist/pwa/public/app-discover.js +1296 -0
  64. package/dist/pwa/public/app-external-links.js +32 -0
  65. package/dist/pwa/public/app-listings.js +226 -0
  66. package/dist/pwa/public/app-prelaunch-waz.js +39 -0
  67. package/dist/pwa/public/app-price.js +55 -0
  68. package/dist/pwa/public/app-product-media.js +15 -0
  69. package/dist/pwa/public/app-profile.js +1692 -0
  70. package/dist/pwa/public/app-seller.js +199 -0
  71. package/dist/pwa/public/app-shop.js +1145 -0
  72. package/dist/pwa/public/app.js +13388 -22277
  73. package/dist/pwa/public/i18n.js +413 -196
  74. package/dist/pwa/public/index.html +27 -0
  75. package/dist/pwa/public/openapi.json +579 -1
  76. package/dist/pwa/routes/admin-analytics.js +4 -2
  77. package/dist/pwa/routes/admin-direct-receive-deposits.js +321 -0
  78. package/dist/pwa/routes/agent-grants.js +255 -0
  79. package/dist/pwa/routes/buyer-feeds.js +2 -1
  80. package/dist/pwa/routes/chat.js +6 -1
  81. package/dist/pwa/routes/dashboards.js +2 -1
  82. package/dist/pwa/routes/direct-pay-availability.js +196 -0
  83. package/dist/pwa/routes/direct-pay-disclosure-acks.js +74 -0
  84. package/dist/pwa/routes/direct-pay-timeouts.js +71 -0
  85. package/dist/pwa/routes/direct-receive-accounts.js +155 -0
  86. package/dist/pwa/routes/direct-receive-payment-instructions.js +45 -0
  87. package/dist/pwa/routes/fx.js +12 -0
  88. package/dist/pwa/routes/leaderboard.js +47 -9
  89. package/dist/pwa/routes/listings.js +2 -2
  90. package/dist/pwa/routes/logistics.js +4 -0
  91. package/dist/pwa/routes/manifests.js +38 -0
  92. package/dist/pwa/routes/me-data.js +5 -2
  93. package/dist/pwa/routes/orders-action.js +117 -9
  94. package/dist/pwa/routes/orders-create.js +4 -0
  95. package/dist/pwa/routes/orders-read.js +36 -0
  96. package/dist/pwa/routes/p2p-products.js +2 -2
  97. package/dist/pwa/routes/products-create.js +5 -3
  98. package/dist/pwa/routes/products-links.js +34 -0
  99. package/dist/pwa/routes/products-list.js +2 -1
  100. package/dist/pwa/routes/products-update.js +22 -2
  101. package/dist/pwa/routes/promoter.js +3 -0
  102. package/dist/pwa/routes/referral.js +4 -0
  103. package/dist/pwa/routes/returns.js +26 -1
  104. package/dist/pwa/routes/rewards-apply.js +10 -5
  105. package/dist/pwa/routes/rewards-clearing-mature.js +96 -0
  106. package/dist/pwa/routes/rewards-escrow-expire.js +6 -2
  107. package/dist/pwa/routes/shops.js +2 -1
  108. package/dist/pwa/routes/url-claim.js +2 -2
  109. package/dist/pwa/routes/users-public.js +8 -0
  110. package/dist/pwa/routes/wallet-read.js +3 -0
  111. package/dist/pwa/routes/webauthn.js +7 -2
  112. package/dist/pwa/server-schema.js +9 -0
  113. package/dist/pwa/server.js +261 -1706
  114. package/dist/runtime/agent-grant-scopes.js +128 -0
  115. package/dist/runtime/agent-grant-verifier.js +67 -0
  116. package/dist/runtime/agent-pairing.js +60 -0
  117. package/dist/runtime/apply-webaz-runtime-schema.js +15 -0
  118. package/dist/runtime/webaz-schema-helpers.js +1952 -0
  119. package/dist/store-verification.js +77 -0
  120. package/dist/version.js +1 -1
  121. package/package.json +80 -2
@@ -20,6 +20,43 @@ export const VALID_TRANSITIONS = {
20
20
  requiresEvidence: false,
21
21
  description: '下单后付款前取消订单'
22
22
  },
23
+ // ── Direct Pay (Rail 1) 直付:只"支付"这一步变,之后汇入既有流程 ──────────────
24
+ // 设计稿 docs/modules/DIRECT-PAYMENT-MODULE-DESIGN.INTERNAL.md §4。
25
+ // 本金(货款)不经协议;协议不验证付款;买家声明已付款 → 汇入 accepted(卖家发货)。
26
+ 'created→direct_pay_window': {
27
+ allowedRoles: ['system'], // 直付下单路由锁定卖家费用质押后,以 system 显式推进(非超时驱动)
28
+ requiresEvidence: false,
29
+ description: 'Rail1 直付:卖家已质押平台费、展示收款方式,进入付款窗口'
30
+ },
31
+ 'direct_pay_window→accepted': {
32
+ allowedRoles: ['buyer'],
33
+ requiresEvidence: false,
34
+ description: 'Rail1 直付:买家声明"我已付款" → 汇入既有流程(卖家发货);协议不验证付款,谎报则卖家不发货(零损失自纠正)'
35
+ },
36
+ 'direct_pay_window→cancelled': {
37
+ allowedRoles: ['buyer', 'system'],
38
+ requiresEvidence: false,
39
+ description: 'Rail1 直付:付款前买家取消(或卖家请求取消经买家确认)→ 释放费用质押'
40
+ },
41
+ 'direct_pay_window→direct_expired_unconfirmed': {
42
+ // deadlineField 供【专属 cron(direct-pay-timeouts.ts)】读取;故意【不设 autoFaultState】→
43
+ // 通用 engine.checkTimeouts(需 deadlineField+autoFaultState 两者)绝不触发本转移,避免漏掉释放质押等副作用。
44
+ allowedRoles: ['system'],
45
+ deadlineField: 'direct_pay_window_deadline',
46
+ requiresEvidence: false,
47
+ description: 'Rail1 直付:付款窗口超时未标记 → 不静默关单,转可争议态(专属 cron 释放费用质押 + 停用收款指令)'
48
+ },
49
+ 'direct_expired_unconfirmed→disputed': {
50
+ allowedRoles: ['buyer'],
51
+ requiresEvidence: true,
52
+ evidenceHint: '上传付款凭证(证据分级:链上 tx / 银行回执 / 截图)',
53
+ description: 'Rail1 直付:买家"我确实付了" → 升级争议(证据级信誉裁决,本档无资金赔付)'
54
+ },
55
+ 'direct_expired_unconfirmed→cancelled': {
56
+ allowedRoles: ['buyer', 'system'],
57
+ requiresEvidence: false,
58
+ description: 'Rail1 直付:买家确认未付 / 宽限期后系统关单(终态)'
59
+ },
23
60
  // ── 卖家接单 ──────────────────────────────────────────────
24
61
  'paid→accepted': {
25
62
  allowedRoles: ['seller'],
@@ -243,6 +280,8 @@ export const CURRENT_RESPONSIBLE = {
243
280
  in_transit: 'logistics', // 等物流投递
244
281
  delivered: 'buyer', // 等买家确认
245
282
  disputed: 'arbitrator', // 等仲裁处理
283
+ direct_pay_window: 'buyer', // Rail1: 等买家付款并标记
284
+ direct_expired_unconfirmed: 'buyer', // Rail1: 等买家确认未付 或 升级争议
246
285
  };
247
286
  /** Phase 1 self-fulfill 覆盖表:seller 一人承担 shipped/picked_up/in_transit 全程 */
248
287
  export const CURRENT_RESPONSIBLE_SELF_FULFILL = {
@@ -275,6 +314,8 @@ export const ORDER_STATE_MEANINGS = {
275
314
  refunded_full: { zh: '仲裁裁全额退款,订单作废(终态)', en: 'arbitration full refund, order voided (terminal)' },
276
315
  dispute_dismissed: { zh: '争议被驳回(无效,终态)', en: 'dispute dismissed (terminal)' },
277
316
  expired: { zh: '订单超时自动失败(通用兜底,终态)', en: 'order expired (generic timeout, terminal)' },
317
+ direct_pay_window: { zh: 'Rail1 直付:已质押平台费,等买家付款(协议不持货款)', en: 'Rail1 direct-pay: fee-staked, awaiting buyer off-protocol payment (protocol holds no funds)' },
318
+ direct_expired_unconfirmed: { zh: 'Rail1 直付:付款窗口超时未标记(不静默关单,留争议/确认窗口)', en: 'Rail1 direct-pay: payment window expired unmarked (not silently closed; dispute/confirm window open)' },
278
319
  };
279
320
  /** 订单/争议生命周期契约 —— 集成方 agent 读它即懂"订单怎么流转 + 每步谁驱动 + 何时 + 含义"。 */
280
321
  export function orderLifecycleContract() {
@@ -303,7 +303,7 @@ async function getLiveStats() {
303
303
  const disputes = await n('SELECT COUNT(*) as n FROM disputes');
304
304
  const skills = await n("SELECT COUNT(*) as n FROM skills WHERE active = 1");
305
305
  const totalVolume = ((await dbOne("SELECT COALESCE(SUM(total_amount),0) as v FROM orders WHERE status = 'completed'"))?.v ?? 0);
306
- return { users, active_products: products, total_orders: orders, completed_orders: completed, total_disputes: disputes, active_skills: skills, total_volume_dcp: totalVolume };
306
+ return { users, active_products: products, total_orders: orders, completed_orders: completed, total_disputes: disputes, active_skills: skills, total_volume_waz: totalVolume };
307
307
  }
308
308
  catch {
309
309
  return null;
@@ -0,0 +1,64 @@
1
+ /**
2
+ * MCP 命令行标志(--version / --help / --mode / --doctor)。
3
+ *
4
+ * 目的:让人 / 陌生 agent 在【不启动 stdio server】的前提下验证安装、看清运行模式与真网络可达性。
5
+ * 无标志 → cliQuickResponse 返回 null,mcp.ts 照常启动 server(既有 MCP 客户端从不传 argv → 零破坏)。
6
+ * 模式判定复用 resolveMode(network-mode.ts)—— 与 server.ts 同一真相源,--mode/--doctor 报的就是 server 实际用的。
7
+ */
8
+ import { SOFTWARE_VERSION } from '../../version.js';
9
+ import { resolveMode } from './network-mode.js';
10
+ const HELP = `webaz — WebAZ MCP server (@seasonkoh/webaz)
11
+
12
+ Usage:
13
+ npx @seasonkoh/webaz start the MCP stdio server (what MCP clients invoke)
14
+ npx @seasonkoh/webaz --version print version and exit
15
+ npx @seasonkoh/webaz --mode print the resolved run mode and exit
16
+ npx @seasonkoh/webaz --doctor print mode + config + live-network reachability, then exit
17
+ npx @seasonkoh/webaz --help show this help
18
+
19
+ Modes (RFC-003):
20
+ network WEBAZ_API_KEY set — can transact on the live webaz.xyz network
21
+ network_readonly no key (DEFAULT) — public reads hit live webaz.xyz; transactions need a key
22
+ sandbox explicit WEBAZ_MODE=sandbox — local SQLite, isolated from the live network
23
+
24
+ Env:
25
+ WEBAZ_API_KEY your api_key (get one at https://webaz.xyz/#welcome). Set → network mode.
26
+ WEBAZ_MODE force a mode: network | network_readonly | sandbox (sandbox is opt-in only)
27
+ WEBAZ_API_URL network endpoint (default https://webaz.xyz)`;
28
+ /** 同步、纯:处理 --version/-v · --help/-h · --mode。命中 → 返回要打印的字符串;无这些标志 → null(mcp.ts 照常启动 server)。 */
29
+ export function cliQuickResponse(argv, env) {
30
+ const has = (...names) => names.some(n => argv.includes(n));
31
+ if (has('--version', '-v'))
32
+ return SOFTWARE_VERSION;
33
+ if (has('--help', '-h'))
34
+ return HELP;
35
+ if (has('--mode'))
36
+ return resolveMode(env);
37
+ return null;
38
+ }
39
+ /** --doctor:模式 + 配置 + 真网络可达性。fetch 可注入便于测试;5s 超时保护,绝不 hang。sandbox 不探网络。 */
40
+ export async function runDoctor(env, fetchImpl = fetch) {
41
+ const mode = resolveMode(env);
42
+ const url = (env.WEBAZ_API_URL ?? 'https://webaz.xyz').replace(/\/+$/, '');
43
+ const hasKey = !!(env.WEBAZ_API_KEY ?? '');
44
+ const lines = [
45
+ `webaz doctor — @seasonkoh/webaz v${SOFTWARE_VERSION}`,
46
+ ` mode: ${mode}`,
47
+ ` api_key: ${hasKey ? 'set (network transactions enabled)' : 'not set (network read-only; set WEBAZ_API_KEY to transact)'}`,
48
+ ` api_url: ${url}`,
49
+ ];
50
+ if (mode === 'sandbox') {
51
+ lines.push(' reachability: skipped (sandbox = local SQLite, isolated from the live network)');
52
+ return lines.join('\n');
53
+ }
54
+ let reach;
55
+ try {
56
+ const r = await fetchImpl(`${url}/api/protocol-status`, { signal: AbortSignal.timeout(5000) });
57
+ reach = r.ok ? `ok (${url} reachable, HTTP ${r.status})` : `degraded (HTTP ${r.status})`;
58
+ }
59
+ catch (e) {
60
+ reach = `unreachable (${e.message})`;
61
+ }
62
+ lines.push(` reachability: ${reach}`);
63
+ return lines.join('\n');
64
+ }
@@ -0,0 +1,80 @@
1
+ /**
2
+ * RFC-003 — MCP NETWORK-mode tool gating (pure, testable; no I/O).
3
+ *
4
+ * In `network` / `network_readonly` mode the dispatcher hard-fails any tool that is
5
+ * NOT allowed through, so an un-migrated tool can't silently fall back to the local
6
+ * sandbox (a write would become a phantom op). This module holds the allow-sets +
7
+ * the predicate so the gate decision is unit-testable without booting the stdio
8
+ * server. (Extracted from server.ts; behavior unchanged except adding webaz_pair.)
9
+ */
10
+ /**
11
+ * 解析运行模式(纯函数,单一真相源 —— server.ts 的 MODE + CLI 的 --mode/--doctor 都用它,杜绝漂移)。
12
+ * 显式 WEBAZ_MODE(network|network_readonly|sandbox)优先;否则有 api_key → network,无 key → network_readonly。
13
+ * sandbox 只能显式设置(无 key 【不】回落 sandbox)。key 的真伪判定与 server.ts 一致(WEBAZ_API_KEY ?? '' 的真值性)。
14
+ */
15
+ export function resolveMode(env) {
16
+ const m = (env.WEBAZ_MODE ?? '').toLowerCase();
17
+ if (m === 'network' || m === 'sandbox' || m === 'network_readonly')
18
+ return m;
19
+ return (env.WEBAZ_API_KEY ?? '') ? 'network' : 'network_readonly';
20
+ }
21
+ // Tools that talk to the live webaz.xyz network (Bearer api_key where needed).
22
+ // Un-listed tools run sandbox (local). `_mode` annotation = network for these.
23
+ export const NETWORK_TOOLS = new Set([
24
+ // RFC-020 onboarding/auth: pairing is the no-key credential bootstrap — it MUST be
25
+ // reachable in the default network_readonly install (you pair to GET a credential).
26
+ 'webaz_pair',
27
+ 'webaz_price_history',
28
+ 'webaz_leaderboard',
29
+ 'webaz_verify_price',
30
+ 'webaz_place_order',
31
+ 'webaz_list_product',
32
+ 'webaz_update_order',
33
+ 'webaz_search',
34
+ 'webaz_get_status',
35
+ 'webaz_feedback',
36
+ 'webaz_contribute',
37
+ // Batch 1(只读 + 低危自身写):走 webaz.xyz Bearer api_key。
38
+ 'webaz_notifications',
39
+ 'webaz_nearby',
40
+ 'webaz_profile',
41
+ 'webaz_shareables',
42
+ 'webaz_mykey',
43
+ // Batch 2(低危写,无钱无 escrow):走 webaz.xyz Bearer api_key。
44
+ 'webaz_follows',
45
+ 'webaz_like',
46
+ 'webaz_blocklist',
47
+ 'webaz_default_address',
48
+ 'webaz_chat',
49
+ 'webaz_rfq',
50
+ 'webaz_referral',
51
+ // Batch 3(商务):
52
+ 'webaz_secondhand',
53
+ 'webaz_skill',
54
+ 'webaz_skill_market',
55
+ 'webaz_auction',
56
+ // Batch 4(资金/质押,守恒由服务端 RFC-014 保证;wallet 只读,写=Passkey 仅 PWA):
57
+ 'webaz_wallet',
58
+ 'webaz_trial',
59
+ 'webaz_charity',
60
+ 'webaz_bid',
61
+ 'webaz_auto_bid',
62
+ // Batch 5(铁律/敏感):
63
+ 'webaz_dispute',
64
+ 'webaz_claim_verify',
65
+ 'webaz_rotate_key',
66
+ 'webaz_revoke_key',
67
+ // #1122:share_link 现有服务端端点 /api/share-link,可走网络。
68
+ 'webaz_share_link',
69
+ ]);
70
+ // Not in NETWORK_TOOLS but still allowed to run in NETWORK mode as self-aware /
71
+ // onboarding tools (non-data ops): info = local introspection; register = redirect
72
+ // the human to webaz.xyz. Everything else un-migrated hard-fails.
73
+ export const NETWORK_SELF_AWARE = new Set(['webaz_info', 'webaz_register']);
74
+ /**
75
+ * In NETWORK / network_readonly mode, may this tool proceed (vs migration-pending
76
+ * hard-fail)? True for migrated network tools and the self-aware onboarding tools.
77
+ */
78
+ export function toolAllowedInNetworkMode(tool) {
79
+ return NETWORK_TOOLS.has(tool) || NETWORK_SELF_AWARE.has(tool);
80
+ }