@alipay/alipay-aipay 1.7.0 → 1.7.2

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 (169) hide show
  1. package/README.md +30 -0
  2. package/dist/commands/install-current.js +15 -7
  3. package/dist/commands/install.js +20 -16
  4. package/dist/commands/uninstall.js +8 -3
  5. package/dist/commands/update.js +34 -16
  6. package/dist/index.js +10 -4
  7. package/dist/utils/channels.js +67 -0
  8. package/dist/utils/config.js +15 -11
  9. package/dist/utils/file.js +23 -10
  10. package/dist/utils/npm.js +19 -33
  11. package/package.json +8 -3
  12. package/skill/SKILL.md +2 -0
  13. package/skill/references/normal/json/release-channel.json +1 -0
  14. package/skill/references/normal/scripts/self_update.mjs +62 -17
  15. package/skill/references/normal/self-update.md +3 -1
  16. package/skill-pre/SKILL.md +65 -0
  17. package/skill-pre/VERSION +1 -0
  18. package/skill-pre/references/integration/flow.md +602 -0
  19. package/skill-pre/references/integration/modules/alipay-sdk-reminder.md +281 -0
  20. package/skill-pre/references/integration/modules/checklist.md +154 -0
  21. package/skill-pre/references/integration/modules/code-examples/csharp/1-/351/200/232/347/224/250/346/216/245/345/217/243//345/274/202/346/255/245/351/200/232/347/237/245/345/244/204/347/220/206/344/273/243/347/240/201/347/244/272/344/276/213.md +199 -0
  22. package/skill-pre/references/integration/modules/code-examples/csharp/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/345/205/263/351/227/255/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +68 -0
  23. package/skill-pre/references/integration/modules/code-examples/csharp/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +83 -0
  24. package/skill-pre/references/integration/modules/code-examples/csharp/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +80 -0
  25. package/skill-pre/references/integration/modules/code-examples/csharp/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +73 -0
  26. package/skill-pre/references/integration/modules/code-examples/csharp/2-/347/275/221/347/253/231/346/224/257/344/273/230//347/273/237/344/270/200/346/224/266/345/215/225/344/270/213/345/215/225/345/271/266/346/224/257/344/273/230/351/241/265/351/235/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +62 -0
  27. package/skill-pre/references/integration/modules/code-examples/csharp/3-APP/346/224/257/344/273/230/APP/346/224/257/344/273/230/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +132 -0
  28. package/skill-pre/references/integration/modules/code-examples/csharp/4-/346/214/211/351/207/217/344/273/230/350/264/271/A2MPaymentDemo.md +640 -0
  29. package/skill-pre/references/integration/modules/code-examples/java/1-/351/200/232/347/224/250/346/216/245/345/217/243//345/274/202/346/255/245/351/200/232/347/237/245/345/244/204/347/220/206/344/273/243/347/240/201/347/244/272/344/276/213.md +184 -0
  30. package/skill-pre/references/integration/modules/code-examples/java/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/345/205/263/351/227/255/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +72 -0
  31. package/skill-pre/references/integration/modules/code-examples/java/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +96 -0
  32. package/skill-pre/references/integration/modules/code-examples/java/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +81 -0
  33. package/skill-pre/references/integration/modules/code-examples/java/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +77 -0
  34. package/skill-pre/references/integration/modules/code-examples/java/2-/347/275/221/347/253/231/346/224/257/344/273/230//347/273/237/344/270/200/346/224/266/345/215/225/344/270/213/345/215/225/345/271/266/346/224/257/344/273/230/351/241/265/351/235/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +69 -0
  35. package/skill-pre/references/integration/modules/code-examples/java/3-APP/346/224/257/344/273/230/APP/346/224/257/344/273/230/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +138 -0
  36. package/skill-pre/references/integration/modules/code-examples/java/4-/346/214/211/351/207/217/344/273/230/350/264/271/A2MPaymentDemoController.md +623 -0
  37. package/skill-pre/references/integration/modules/code-examples/nodejs/1-/351/200/232/347/224/250/346/216/245/345/217/243//345/274/202/346/255/245/351/200/232/347/237/245/345/244/204/347/220/206/344/273/243/347/240/201/347/244/272/344/276/213.md +135 -0
  38. package/skill-pre/references/integration/modules/code-examples/nodejs/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/345/205/263/351/227/255/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +51 -0
  39. package/skill-pre/references/integration/modules/code-examples/nodejs/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +63 -0
  40. package/skill-pre/references/integration/modules/code-examples/nodejs/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +59 -0
  41. package/skill-pre/references/integration/modules/code-examples/nodejs/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +54 -0
  42. package/skill-pre/references/integration/modules/code-examples/nodejs/2-/347/275/221/347/253/231/346/224/257/344/273/230//347/273/237/344/270/200/346/224/266/345/215/225/344/270/213/345/215/225/345/271/266/346/224/257/344/273/230/351/241/265/351/235/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +84 -0
  43. package/skill-pre/references/integration/modules/code-examples/nodejs/3-APP/346/224/257/344/273/230/APP/346/224/257/344/273/230/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +71 -0
  44. package/skill-pre/references/integration/modules/code-examples/nodejs/4-/346/214/211/351/207/217/344/273/230/350/264/271/A2MPaymentDemo.md +498 -0
  45. package/skill-pre/references/integration/modules/code-examples/php/1-/351/200/232/347/224/250/346/216/245/345/217/243//345/274/202/346/255/245/351/200/232/347/237/245/345/244/204/347/220/206/344/273/243/347/240/201/347/244/272/344/276/213.md +157 -0
  46. package/skill-pre/references/integration/modules/code-examples/php/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/345/205/263/351/227/255/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +59 -0
  47. package/skill-pre/references/integration/modules/code-examples/php/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +73 -0
  48. package/skill-pre/references/integration/modules/code-examples/php/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +69 -0
  49. package/skill-pre/references/integration/modules/code-examples/php/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +65 -0
  50. package/skill-pre/references/integration/modules/code-examples/php/2-/347/275/221/347/253/231/346/224/257/344/273/230//347/273/237/344/270/200/346/224/266/345/215/225/344/270/213/345/215/225/345/271/266/346/224/257/344/273/230/351/241/265/351/235/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +59 -0
  51. package/skill-pre/references/integration/modules/code-examples/php/3-APP/346/224/257/344/273/230/APP/346/224/257/344/273/230/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +110 -0
  52. package/skill-pre/references/integration/modules/code-examples/php/4-/346/214/211/351/207/217/344/273/230/350/264/271/A2MPaymentDemo.md +806 -0
  53. package/skill-pre/references/integration/modules/code-examples/python/1-/351/200/232/347/224/250/346/216/245/345/217/243//345/274/202/346/255/245/351/200/232/347/237/245/345/244/204/347/220/206/344/273/243/347/240/201/347/244/272/344/276/213.md +128 -0
  54. package/skill-pre/references/integration/modules/code-examples/python/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/345/205/263/351/227/255/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +57 -0
  55. package/skill-pre/references/integration/modules/code-examples/python/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +70 -0
  56. package/skill-pre/references/integration/modules/code-examples/python/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +65 -0
  57. package/skill-pre/references/integration/modules/code-examples/python/1-/351/200/232/347/224/250/346/216/245/345/217/243//347/273/237/344/270/200/346/224/266/345/215/225/344/272/244/346/230/223/351/200/200/346/254/276/346/237/245/350/257/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +62 -0
  58. package/skill-pre/references/integration/modules/code-examples/python/2-/347/275/221/347/253/231/346/224/257/344/273/230//347/273/237/344/270/200/346/224/266/345/215/225/344/270/213/345/215/225/345/271/266/346/224/257/344/273/230/351/241/265/351/235/242/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +51 -0
  59. package/skill-pre/references/integration/modules/code-examples/python/3-APP/346/224/257/344/273/230/APP/346/224/257/344/273/230/346/216/245/345/217/243/344/273/243/347/240/201/347/244/272/344/276/213.md +47 -0
  60. package/skill-pre/references/integration/modules/code-examples/python/4-/346/214/211/351/207/217/344/273/230/350/264/271/A2MPaymentDemo.md +541 -0
  61. package/skill-pre/references/integration/modules/interface-contract/aipay-interface-contract.md +52 -0
  62. package/skill-pre/references/integration/modules/interface-contract/apppay-interface-contract.md +45 -0
  63. package/skill-pre/references/integration/modules/interface-contract/common-trade-contract.md +42 -0
  64. package/skill-pre/references/integration/modules/interface-contract/notify-url-contract.md +68 -0
  65. package/skill-pre/references/integration/modules/interface-contract/webpay-interface-contract.md +44 -0
  66. package/skill-pre/references/integration/modules/interface-guide.md +61 -0
  67. package/skill-pre/references/integration/modules/product-decision.md +73 -0
  68. package/skill-pre/references/integration/modules/sandbox/a2m-sandbox-test.md +235 -0
  69. package/skill-pre/references/integration/modules/sandbox/alipay-sandbox-tool.md +142 -0
  70. package/skill-pre/references/integration/modules/sandbox/sandbox-setup-guide.md +239 -0
  71. package/skill-pre/references/integration/modules/scripts/local_402_sandbox_pay.py +900 -0
  72. package/skill-pre/references/integration/modules/scripts/sandbox_config.sh +347 -0
  73. package/skill-pre/references/integration/modules/troubleshooting-flow.md +28 -0
  74. package/skill-pre/references/normal/alipay-cli-env.md +169 -0
  75. package/skill-pre/references/normal/conversation-telemetry.md +101 -0
  76. package/skill-pre/references/normal/full-process-routing.md +92 -0
  77. package/skill-pre/references/normal/integration-worker.md +90 -0
  78. package/skill-pre/references/normal/json/customer-messages.json +1 -0
  79. package/skill-pre/references/normal/json/managed-jq-assets.json +1 -0
  80. package/skill-pre/references/normal/json/policy-rules.json +1 -0
  81. package/skill-pre/references/normal/json/release-channel.json +1 -0
  82. package/skill-pre/references/normal/rejection-guide.md +41 -0
  83. package/skill-pre/references/normal/scripts/agent_platform.mjs +43 -0
  84. package/skill-pre/references/normal/scripts/alipay_cli_env.mjs +34 -0
  85. package/skill-pre/references/normal/scripts/alipay_cli_env.sh +55 -0
  86. package/skill-pre/references/normal/scripts/alipay_cli_refresh.mjs +129 -0
  87. package/skill-pre/references/normal/scripts/auth_runtime_runner.mjs +60 -0
  88. package/skill-pre/references/normal/scripts/checklist_sections.mjs +43 -0
  89. package/skill-pre/references/normal/scripts/common.sh +365 -0
  90. package/skill-pre/references/normal/scripts/conversation_telemetry.mjs +105 -0
  91. package/skill-pre/references/normal/scripts/detect_dev_tool.sh +79 -0
  92. package/skill-pre/references/normal/scripts/flow_loader.mjs +237 -0
  93. package/skill-pre/references/normal/scripts/integration_context_runner.mjs +151 -0
  94. package/skill-pre/references/normal/scripts/integration_message_runner.mjs +1456 -0
  95. package/skill-pre/references/normal/scripts/interaction_reply.mjs +140 -0
  96. package/skill-pre/references/normal/scripts/managed_jq.mjs +215 -0
  97. package/skill-pre/references/normal/scripts/onboarding_discovery_runner.mjs +387 -0
  98. package/skill-pre/references/normal/scripts/onboarding_message_runner.mjs +1425 -0
  99. package/skill-pre/references/normal/scripts/onboarding_recovery_runner.mjs +100 -0
  100. package/skill-pre/references/normal/scripts/open_official_url.sh +205 -0
  101. package/skill-pre/references/normal/scripts/platform_compat.mjs +42 -0
  102. package/skill-pre/references/normal/scripts/preview_runtime.mjs +151 -0
  103. package/skill-pre/references/normal/scripts/project_route_inspector.sh +132 -0
  104. package/skill-pre/references/normal/scripts/python_script_runner.mjs +58 -0
  105. package/skill-pre/references/normal/scripts/render_customer_message.mjs +1792 -0
  106. package/skill-pre/references/normal/scripts/runtime.mjs +271 -0
  107. package/skill-pre/references/normal/scripts/self_update.mjs +376 -0
  108. package/skill-pre/references/normal/scripts/telemetry.mjs +2102 -0
  109. package/skill-pre/references/normal/self-update.md +7 -0
  110. package/skill-pre/references/normal/telemetry.md +70 -0
  111. package/skill-pre/references/onboarding/assets/keygen.html +927 -0
  112. package/skill-pre/references/onboarding/flow.md +607 -0
  113. package/skill-pre/references/onboarding/modules/app-release.md +90 -0
  114. package/skill-pre/references/onboarding/modules/authorization.md +43 -0
  115. package/skill-pre/references/onboarding/modules/error-handling.md +62 -0
  116. package/skill-pre/references/onboarding/modules/product-sign.md +49 -0
  117. package/skill-pre/references/onboarding/modules/scripts/app.sh +1485 -0
  118. package/skill-pre/references/onboarding/modules/scripts/ar_sign_apply.sh +331 -0
  119. package/skill-pre/references/onboarding/modules/scripts/auth.sh +1040 -0
  120. package/skill-pre/references/onboarding/modules/scripts/download_key_tool.sh +4 -0
  121. package/skill-pre/references/onboarding/modules/scripts/error_handler.sh +841 -0
  122. package/skill-pre/references/onboarding/modules/scripts/mcc.sh +1085 -0
  123. package/skill-pre/references/onboarding/modules/scripts/network_retry.sh +135 -0
  124. package/skill-pre/references/onboarding/modules/scripts/query_sign_status.sh +105 -0
  125. package/skill-pre/references/onboarding/modules/scripts/service.sh +528 -0
  126. package/skill-pre/references/onboarding/modules/scripts/sign_status_parser.sh +58 -0
  127. package/skill-pre/references/onboarding/modules/scripts/upload_screenshots.sh +208 -0
  128. package/skill-pre/references/onboarding/modules/scripts/upload_special_license.sh +195 -0
  129. package/skill-pre/references/onboarding/modules/service-registration.md +40 -0
  130. package/skill-pre/references/runtime-entry.md +99 -0
  131. package/dist/commands/install-current.d.ts +0 -4
  132. package/dist/commands/install-current.d.ts.map +0 -1
  133. package/dist/commands/install-current.js.map +0 -1
  134. package/dist/commands/install.d.ts +0 -10
  135. package/dist/commands/install.d.ts.map +0 -1
  136. package/dist/commands/install.js.map +0 -1
  137. package/dist/commands/prepare-tools.d.ts +0 -5
  138. package/dist/commands/prepare-tools.d.ts.map +0 -1
  139. package/dist/commands/prepare-tools.js.map +0 -1
  140. package/dist/commands/uninstall.d.ts +0 -10
  141. package/dist/commands/uninstall.d.ts.map +0 -1
  142. package/dist/commands/uninstall.js.map +0 -1
  143. package/dist/commands/update.d.ts +0 -10
  144. package/dist/commands/update.d.ts.map +0 -1
  145. package/dist/commands/update.js.map +0 -1
  146. package/dist/index.d.ts +0 -2
  147. package/dist/index.d.ts.map +0 -1
  148. package/dist/index.js.map +0 -1
  149. package/dist/types.d.ts +0 -42
  150. package/dist/types.d.ts.map +0 -1
  151. package/dist/types.js.map +0 -1
  152. package/dist/utils/alipay-cli.d.ts +0 -20
  153. package/dist/utils/alipay-cli.d.ts.map +0 -1
  154. package/dist/utils/alipay-cli.js.map +0 -1
  155. package/dist/utils/config.d.ts +0 -52
  156. package/dist/utils/config.d.ts.map +0 -1
  157. package/dist/utils/config.js.map +0 -1
  158. package/dist/utils/file.d.ts +0 -77
  159. package/dist/utils/file.d.ts.map +0 -1
  160. package/dist/utils/file.js.map +0 -1
  161. package/dist/utils/jq.d.ts +0 -17
  162. package/dist/utils/jq.d.ts.map +0 -1
  163. package/dist/utils/jq.js.map +0 -1
  164. package/dist/utils/npm.d.ts +0 -17
  165. package/dist/utils/npm.d.ts.map +0 -1
  166. package/dist/utils/npm.js.map +0 -1
  167. package/dist/utils/shell.d.ts +0 -24
  168. package/dist/utils/shell.d.ts.map +0 -1
  169. package/dist/utils/shell.js.map +0 -1
@@ -0,0 +1,387 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawn } from 'node:child_process';
4
+ import path from 'node:path';
5
+ import process from 'node:process';
6
+ import { fileURLToPath } from 'node:url';
7
+
8
+ import { renderMessage } from './render_customer_message.mjs';
9
+ import { renderDiscoverySummary } from './onboarding_message_runner.mjs';
10
+ import { currentRunContext, emitStageMetric, telemetryEnabled } from './telemetry.mjs';
11
+
12
+ const internalPrefix = 'ALIPAY_AIPAY_INTERNAL:';
13
+ const scriptDir = path.dirname(fileURLToPath(import.meta.url));
14
+ const onboardingScriptsDir = path.resolve(scriptDir, '../../onboarding/modules/scripts');
15
+ const scriptPaths = Object.freeze({
16
+ signing: path.join(onboardingScriptsDir, 'query_sign_status.sh'),
17
+ service: path.join(onboardingScriptsDir, 'service.sh'),
18
+ application: path.join(onboardingScriptsDir, 'app.sh')
19
+ });
20
+ const productSalesCodes = Object.freeze({
21
+ aipay: 'I1080300001000160457',
22
+ webpay: 'I1080300001000041203',
23
+ apppay: 'I1080300001000041313'
24
+ });
25
+ const signStatuses = new Set(['NOT_SIGNED', 'SIGN_SUBMITTED', 'SIGNED_EFFECTIVE', 'OTHER_STATUS']);
26
+ const authSignReuseReceiptPrefix = 'AIPAY_SIGN_REUSE_V1.';
27
+ const signFlowByProduct = Object.freeze({
28
+ aipay: Object.freeze({ notSigned: 'FLOW:AI_PAY_NOT_SIGNED', signed: 'FLOW:AI_PAY_SIGNED' }),
29
+ webpay: Object.freeze({ notSigned: 'FLOW:PC_WEB_NOT_SIGNED', signed: 'FLOW:PC_WEB_SIGNED' }),
30
+ apppay: Object.freeze({ notSigned: 'FLOW:APP_NOT_SIGNED', signed: 'FLOW:APP_SIGNED' })
31
+ });
32
+ const serviceFlows = new Set(['FLOW:CREATE_NEW', 'FLOW:SELECT']);
33
+ const applicationFlows = new Set(['FLOW:CREATE_NEW', 'FLOW:SELECT', 'FLOW:PENDING_APPLICATIONS']);
34
+
35
+ function parseArgs(argv) {
36
+ const command = argv[2];
37
+ const args = {};
38
+ for (let index = 3; index < argv.length; index += 1) {
39
+ const token = argv[index];
40
+ if (!token.startsWith('--')) throw new Error(`未知参数 ${token}`);
41
+ const value = argv[index + 1];
42
+ if (value === undefined || value.startsWith('--')) throw new Error(`参数 ${token} 缺少取值`);
43
+ const name = token.slice(2);
44
+ if (Object.prototype.hasOwnProperty.call(args, name)) throw new Error(`参数 ${token} 重复`);
45
+ args[name] = value;
46
+ index += 1;
47
+ }
48
+ return { command, args };
49
+ }
50
+
51
+ function required(args, name) {
52
+ const value = args[name];
53
+ if (typeof value !== 'string' || !value) throw new Error(`缺少参数 --${name}`);
54
+ return value;
55
+ }
56
+
57
+ function internalLines(stderr) {
58
+ return String(stderr || '')
59
+ .split(/\r?\n/u)
60
+ .filter((line) => line.startsWith(internalPrefix))
61
+ .map((line) => line.slice(internalPrefix.length));
62
+ }
63
+
64
+ function uniqueValue(lines, prefix) {
65
+ const values = lines.filter((line) => line.startsWith(prefix)).map((line) => line.slice(prefix.length));
66
+ return values.length === 1 ? values[0] : '';
67
+ }
68
+
69
+ function uniqueFlow(lines, allowed) {
70
+ const values = lines.filter((line) => line.startsWith('FLOW:') && allowed.has(line));
71
+ return values.length === 1 ? values[0] : '';
72
+ }
73
+
74
+ function allowedSignFlowValues(productType) {
75
+ const flows = signFlowByProduct[productType];
76
+ return new Set([flows.notSigned, flows.signed, 'FLOW:OTHER_STATUS']);
77
+ }
78
+
79
+ function normalizeSignFlow(value) {
80
+ if (typeof value !== 'string' || value.length === 0) return '';
81
+ return value.startsWith('FLOW:') ? value : `FLOW:${value}`;
82
+ }
83
+
84
+ function legalSignReuseDescription(productType) {
85
+ const flows = signFlowByProduct[productType];
86
+ return [
87
+ `NOT_SIGNED + ${flows.notSigned}`,
88
+ `SIGNED_EFFECTIVE + ${flows.signed}`,
89
+ `SIGN_SUBMITTED + ${flows.signed}`,
90
+ 'OTHER_STATUS + FLOW:OTHER_STATUS'
91
+ ].join(';');
92
+ }
93
+
94
+ function assertValidSignReuse({ productType, salesCode, signStatus, flow }) {
95
+ if (!productSalesCodes[productType]) {
96
+ throw new Error('签约复用 productType 非法,仅支持 aipay、webpay、apppay');
97
+ }
98
+ if (salesCode !== productSalesCodes[productType]) {
99
+ throw new Error(`签约复用 salesCode 与 productType 不匹配;${productType} 必须使用 ${productSalesCodes[productType]}`);
100
+ }
101
+ const normalizedFlow = normalizeSignFlow(flow);
102
+ if (!signStatuses.has(signStatus) || !allowedSignFlowValues(productType).has(normalizedFlow)) {
103
+ throw new Error(`签约复用状态或 flow 非法;允许组合:${legalSignReuseDescription(productType)}`);
104
+ }
105
+ const flows = signFlowByProduct[productType];
106
+ const validPair =
107
+ (signStatus === 'NOT_SIGNED' && normalizedFlow === flows.notSigned)
108
+ || ((signStatus === 'SIGNED_EFFECTIVE' || signStatus === 'SIGN_SUBMITTED') && normalizedFlow === flows.signed)
109
+ || (signStatus === 'OTHER_STATUS' && normalizedFlow === 'FLOW:OTHER_STATUS');
110
+ if (!validPair) {
111
+ throw new Error(`签约复用 status/flow 组合矛盾;允许组合:${legalSignReuseDescription(productType)}`);
112
+ }
113
+ return { signStatus, flow: normalizedFlow };
114
+ }
115
+
116
+ function decodeBase64UrlJson(value) {
117
+ const normalized = value.replace(/-/gu, '+').replace(/_/gu, '/');
118
+ const padded = normalized + '='.repeat((4 - (normalized.length % 4)) % 4);
119
+ return JSON.parse(Buffer.from(padded, 'base64').toString('utf8'));
120
+ }
121
+
122
+ function parseSignReuseReceipt(receipt, productType, salesCode) {
123
+ if (typeof receipt !== 'string' || !receipt.startsWith(authSignReuseReceiptPrefix)) {
124
+ throw new Error('签约复用回执格式非法;必须使用 AUTH_SIGN_REUSE_RECEIPT 原值');
125
+ }
126
+ let parsed;
127
+ try {
128
+ parsed = decodeBase64UrlJson(receipt.slice(authSignReuseReceiptPrefix.length));
129
+ } catch {
130
+ throw new Error('签约复用回执无法解析;必须使用 AUTH_SIGN_REUSE_RECEIPT 原值');
131
+ }
132
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
133
+ throw new Error('签约复用回执内容非法');
134
+ }
135
+ const unknownKeys = Object.keys(parsed).filter((key) => ![
136
+ 'schema_ver',
137
+ 'product_type',
138
+ 'sales_code',
139
+ 'sign_status',
140
+ 'flow'
141
+ ].includes(key));
142
+ if (unknownKeys.length > 0) throw new Error(`签约复用回执包含未知字段:${unknownKeys.join('、')}`);
143
+ if (parsed.schema_ver !== 1) throw new Error('签约复用回执版本非法;当前仅支持 schema_ver=1');
144
+ if (parsed.product_type !== productType) throw new Error('签约复用回执与当前 product-type 不匹配');
145
+ if (parsed.sales_code !== salesCode) throw new Error('签约复用回执与当前 sales-code 不匹配');
146
+ const validated = assertValidSignReuse({
147
+ productType,
148
+ salesCode,
149
+ signStatus: parsed.sign_status,
150
+ flow: parsed.flow
151
+ });
152
+ return {
153
+ query_status: 'SUCCESS',
154
+ source: 'AUTH_REUSE',
155
+ sign_status: validated.signStatus,
156
+ flow: validated.flow
157
+ };
158
+ }
159
+
160
+ function parseArray(value) {
161
+ if (!value) return null;
162
+ try {
163
+ const parsed = JSON.parse(value);
164
+ return Array.isArray(parsed) ? parsed : null;
165
+ } catch {
166
+ return null;
167
+ }
168
+ }
169
+
170
+ function runScript(script, args) {
171
+ return new Promise((resolve) => {
172
+ const child = spawn('bash', [script, ...args], {
173
+ cwd: onboardingScriptsDir,
174
+ env: { ...process.env, ALIPAY_AIPAY_SUPPRESS_AUTH_LOGOUT: '1' },
175
+ stdio: ['ignore', 'pipe', 'pipe']
176
+ });
177
+ let stdout = '';
178
+ let stderr = '';
179
+ child.stdout.setEncoding('utf8');
180
+ child.stderr.setEncoding('utf8');
181
+ child.stdout.on('data', (chunk) => { stdout += chunk; });
182
+ child.stderr.on('data', (chunk) => { stderr += chunk; });
183
+ child.on('error', (error) => resolve({ status: null, stdout, stderr, spawnError: error }));
184
+ child.on('close', (status) => resolve({ status, stdout, stderr, spawnError: null }));
185
+ });
186
+ }
187
+
188
+ function failedBranch(result, extra = {}) {
189
+ return {
190
+ query_status: 'QUERY_FAILED',
191
+ ...extra,
192
+ customer_output: result.stdout.trim() ? true : false
193
+ };
194
+ }
195
+
196
+ function signingBranch(result, productType) {
197
+ const lines = internalLines(result.stderr);
198
+ const signStatus = uniqueValue(lines, 'SIGN_STATUS=');
199
+ const flow = uniqueFlow(lines, allowedSignFlowValues(productType));
200
+ if (result.status !== 0 || !signStatuses.has(signStatus) || !flow) return failedBranch(result);
201
+ try {
202
+ const validated = assertValidSignReuse({
203
+ productType,
204
+ salesCode: productSalesCodes[productType],
205
+ signStatus,
206
+ flow
207
+ });
208
+ return { query_status: 'SUCCESS', source: 'QUERY', sign_status: validated.signStatus, flow: validated.flow };
209
+ } catch {
210
+ return failedBranch(result);
211
+ }
212
+ }
213
+
214
+ function reusedSigningBranch(args, productType) {
215
+ const salesCode = productSalesCodes[productType];
216
+ const receipt = args['reuse-sign-receipt'];
217
+ const signStatus = args['reuse-sign-status'];
218
+ const flow = args['reuse-sign-flow'];
219
+ if (receipt === undefined && signStatus === undefined && flow === undefined) return null;
220
+ if (receipt !== undefined) {
221
+ const fromReceipt = parseSignReuseReceipt(receipt, productType, salesCode);
222
+ if (signStatus !== undefined || flow !== undefined) {
223
+ if (signStatus === undefined || flow === undefined) {
224
+ throw new Error('签约复用旧双参数必须同时提供 --reuse-sign-status 与 --reuse-sign-flow');
225
+ }
226
+ const fromLegacy = assertValidSignReuse({ productType, salesCode, signStatus, flow });
227
+ if (fromLegacy.signStatus !== fromReceipt.sign_status || fromLegacy.flow !== fromReceipt.flow) {
228
+ throw new Error('签约复用回执与旧双参数冲突,禁止降级复用');
229
+ }
230
+ }
231
+ return fromReceipt;
232
+ }
233
+ if (signStatus === undefined || flow === undefined) {
234
+ throw new Error('签约复用旧双参数必须同时提供 --reuse-sign-status 与 --reuse-sign-flow');
235
+ }
236
+ const validated = assertValidSignReuse({ productType, salesCode, signStatus, flow });
237
+ return { query_status: 'SUCCESS', source: 'AUTH_REUSE', sign_status: validated.signStatus, flow: validated.flow };
238
+ }
239
+
240
+ function serviceBranch(result) {
241
+ const lines = internalLines(result.stderr);
242
+ const candidates = parseArray(uniqueValue(lines, 'SERVICE_CANDIDATES_JSON='));
243
+ const flow = uniqueFlow(lines, serviceFlows);
244
+ if (result.status !== 0 || !candidates || !flow) return failedBranch(result, { applicable: true });
245
+ return { query_status: 'SUCCESS', applicable: true, flow, candidates };
246
+ }
247
+
248
+ function applicationBranch(result) {
249
+ const lines = internalLines(result.stderr);
250
+ const candidates = parseArray(uniqueValue(lines, 'APP_CANDIDATES_JSON='));
251
+ const applicationType = uniqueValue(lines, 'APPLICATION_TYPE=');
252
+ const flow = uniqueFlow(lines, applicationFlows);
253
+ if (result.status !== 0 || !candidates || !['WEBAPP', 'MOBILEAPP'].includes(applicationType) || !flow) {
254
+ return failedBranch(result);
255
+ }
256
+ return { query_status: 'SUCCESS', application_type: applicationType, flow, candidates };
257
+ }
258
+
259
+ function authBlockerFlows(result) {
260
+ return internalLines(result.stderr).filter((line) => [
261
+ 'AUTH_FLOW:AUTH_REQUIRED',
262
+ 'AUTH_FLOW:SCOPE_MISMATCH',
263
+ 'AUTH_FLOW:MCC_MISMATCH'
264
+ ].includes(line));
265
+ }
266
+
267
+ function hasAuthBlocker(result) {
268
+ return authBlockerFlows(result).length > 0;
269
+ }
270
+
271
+ function authRecoveryAction(results) {
272
+ const flows = new Set(results.flatMap(authBlockerFlows));
273
+ if (flows.has('AUTH_FLOW:SCOPE_MISMATCH') || flows.has('AUTH_FLOW:MCC_MISMATCH')) return 'MISMATCH';
274
+ if (flows.has('AUTH_FLOW:AUTH_REQUIRED')) return 'INIT';
275
+ return '';
276
+ }
277
+
278
+ function hasLocalFsRecovery(result) {
279
+ return internalLines(result.stderr).includes('CLI_FLOW:RETRY_WITH_LOCAL_FS_PERMISSION');
280
+ }
281
+
282
+ function hasNetworkRecovery(result) {
283
+ return internalLines(result.stderr).some((line) =>
284
+ line.startsWith('NETWORK_RETRY_EXHAUSTED=') && line.endsWith(':RETRY_WITH_NETWORK'));
285
+ }
286
+
287
+ function emitEnvelope(envelope) {
288
+ process.stderr.write(`${internalPrefix}DISCOVERY_RESULT=${JSON.stringify(envelope)}\n`);
289
+ }
290
+
291
+ async function runDiscovery(args) {
292
+ const productType = required(args, 'product-type');
293
+ if (!productSalesCodes[productType]) throw new Error('product-type 非法,仅支持 aipay、webpay、apppay');
294
+ if (telemetryEnabled()) {
295
+ const run = currentRunContext();
296
+ if (!run?.run_id || run.terminal || run.product_type !== productType.toUpperCase()
297
+ || !['onboarding_only', 'full_process'].includes(run.root_intent)) {
298
+ throw new Error('discovery 必须在当前产品匹配的 active onboarding run 内执行');
299
+ }
300
+ }
301
+ const salesCode = required(args, 'sales-code');
302
+ if (salesCode !== productSalesCodes[productType]) throw new Error('sales-code 与 product-type 不匹配');
303
+ const reusedSigning = reusedSigningBranch(args, productType);
304
+
305
+ const signingPromise = reusedSigning
306
+ ? Promise.resolve(null)
307
+ : runScript(scriptPaths.signing, ['--sales-code', salesCode, '--product-type', productType]);
308
+ const servicePromise = productType === 'aipay'
309
+ ? runScript(scriptPaths.service, ['list'])
310
+ : Promise.resolve(null);
311
+ const applicationPromise = runScript(scriptPaths.application, [
312
+ 'list', '--product-type', productType, '--sales-code', salesCode
313
+ ]);
314
+ const [signingResult, serviceResult, applicationResult] = await Promise.all([
315
+ signingPromise,
316
+ servicePromise,
317
+ applicationPromise
318
+ ]);
319
+
320
+ const executedResults = [signingResult, serviceResult, applicationResult].filter(Boolean);
321
+ const recoveryAction = authRecoveryAction(executedResults);
322
+ const globalBlocker = recoveryAction ? 'AUTHORIZATION_INVALID' : '';
323
+ const retryWithLocalFs = !globalBlocker && executedResults.some(hasLocalFsRecovery);
324
+ const retryWithNetwork = !globalBlocker && !retryWithLocalFs && executedResults.some(hasNetworkRecovery);
325
+ const envelope = {
326
+ schema_ver: 1,
327
+ product_type: productType,
328
+ signing: reusedSigning || signingBranch(signingResult, productType),
329
+ service: productType === 'aipay'
330
+ ? serviceBranch(serviceResult)
331
+ : { query_status: 'NOT_APPLICABLE', applicable: false },
332
+ application: applicationBranch(applicationResult)
333
+ };
334
+ if (envelope.signing.query_status === 'SUCCESS'
335
+ && (envelope.signing.sign_status === 'SIGNED_EFFECTIVE' || envelope.signing.sign_status === 'SIGN_SUBMITTED')) {
336
+ emitStageMetric('onboarding.confirm_signing');
337
+ }
338
+ if (globalBlocker) {
339
+ envelope.global_blocker = globalBlocker;
340
+ envelope.auth_recovery_action = recoveryAction;
341
+ }
342
+ emitEnvelope(envelope);
343
+ if (retryWithLocalFs) {
344
+ process.stderr.write(`${internalPrefix}DISCOVERY_FLOW:RETRY_WITH_LOCAL_FS_PERMISSION\n`);
345
+ } else if (retryWithNetwork) {
346
+ process.stderr.write(`${internalPrefix}DISCOVERY_FLOW:RETRY_WITH_NETWORK\n`);
347
+ }
348
+
349
+ const customerOutputResults = retryWithLocalFs
350
+ ? []
351
+ : globalBlocker
352
+ ? executedResults.filter(hasAuthBlocker)
353
+ : executedResults;
354
+ const customerOutputs = customerOutputResults
355
+ .map((result) => result.stdout.trim())
356
+ .filter(Boolean);
357
+ let uniqueCustomerOutputs = [...new Set(customerOutputs)];
358
+ if (globalBlocker) uniqueCustomerOutputs = uniqueCustomerOutputs.slice(0, 1);
359
+ if (!globalBlocker && !retryWithLocalFs) {
360
+ uniqueCustomerOutputs.push(renderDiscoverySummary(productType, {
361
+ signStatus: envelope.signing.query_status === 'SUCCESS' ? envelope.signing.sign_status : 'QUERY_FAILED',
362
+ serviceFlow: envelope.service.query_status === 'SUCCESS' ? envelope.service.flow : 'QUERY_FAILED',
363
+ appFlow: envelope.application.query_status === 'SUCCESS' ? envelope.application.flow : 'QUERY_FAILED'
364
+ }));
365
+ if (envelope.application.query_status === 'SUCCESS') {
366
+ uniqueCustomerOutputs.push(renderMessage('application.key.methods', 'DEFAULT', {}));
367
+ process.stderr.write(`${internalPrefix}CUSTOMER_MESSAGE_DELIVERY_REQUIRED=application.key.methods\n`);
368
+ }
369
+ }
370
+ if (uniqueCustomerOutputs.length > 0) process.stdout.write(`${uniqueCustomerOutputs.join('\n\n')}\n`);
371
+ return globalBlocker || retryWithLocalFs || retryWithNetwork ? 2 : 0;
372
+ }
373
+
374
+ export async function runOnboardingDiscoveryCli(argv = process.argv) {
375
+ const { command, args } = parseArgs(argv);
376
+ if (command !== 'run') {
377
+ throw new Error('用法: onboarding_discovery_runner.mjs run --product-type <aipay|webpay|apppay> --sales-code <code> [--reuse-sign-receipt <AUTH_SIGN_REUSE_RECEIPT> | --reuse-sign-status <status> --reuse-sign-flow <flow>]');
378
+ }
379
+ process.exitCode = await runDiscovery(args);
380
+ }
381
+
382
+ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
383
+ runOnboardingDiscoveryCli().catch((error) => {
384
+ process.stderr.write(`${internalPrefix}DISCOVERY_RUNNER_ERROR=${String(error?.message || error).replace(/[\r\n]/gu, ' ')}\n`);
385
+ process.exitCode = 1;
386
+ });
387
+ }