@youzan-cloud/zan-saas-cli 0.0.0-stage → 0.1.0-beta.4

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 (329) hide show
  1. package/DEPENDENCIES.json +50 -0
  2. package/INSTALL.md +79 -0
  3. package/LICENSE +21 -0
  4. package/NOTICE +1 -0
  5. package/README.md +151 -2
  6. package/THIRD_PARTY_NOTICES.txt +162 -0
  7. package/bin/zan-saas-cli.js +28 -0
  8. package/internal/registry/index.js +123 -0
  9. package/internal/registry/manifest.json +424 -0
  10. package/npm-shrinkwrap.json +86 -0
  11. package/package.json +33 -4
  12. package/skills/README.md +30 -0
  13. package/skills/zan-saas/SKILL.md +54 -0
  14. package/skills/zan-saas/references/host-entry.md +25 -0
  15. package/skills/zan-saas-access/SKILL.md +37 -0
  16. package/skills/zan-saas-access/references/role-list.md +11 -0
  17. package/skills/zan-saas-access/references/staff-perms-get.md +11 -0
  18. package/skills/zan-saas-aftersale/SKILL.md +31 -0
  19. package/skills/zan-saas-aftersale/references/case-list.md +13 -0
  20. package/skills/zan-saas-aftersale/references/case-scan.md +31 -0
  21. package/skills/zan-saas-benefit/SKILL.md +46 -0
  22. package/skills/zan-saas-benefit/references/card-get.md +7 -0
  23. package/skills/zan-saas-benefit/references/card-grant-list.md +11 -0
  24. package/skills/zan-saas-benefit/references/card-list.md +7 -0
  25. package/skills/zan-saas-benefit/references/customer-card-get.md +7 -0
  26. package/skills/zan-saas-benefit/references/customer-card-list.md +7 -0
  27. package/skills/zan-saas-coupon/SKILL.md +41 -0
  28. package/skills/zan-saas-coupon/references/activity-get.md +11 -0
  29. package/skills/zan-saas-coupon/references/activity-list.md +15 -0
  30. package/skills/zan-saas-coupon/references/voucher-get.md +13 -0
  31. package/skills/zan-saas-coupon/references/voucher-list.md +25 -0
  32. package/skills/zan-saas-customer/SKILL.md +73 -0
  33. package/skills/zan-saas-customer/references/customer-scan.md +11 -0
  34. package/skills/zan-saas-customer/references/segment-list.md +22 -0
  35. package/skills/zan-saas-fulfillment/SKILL.md +36 -0
  36. package/skills/zan-saas-fulfillment/references/delivery-get.md +11 -0
  37. package/skills/zan-saas-fulfillment/references/shipment-list.md +11 -0
  38. package/skills/zan-saas-fulfillment/references/waybill-get.md +9 -0
  39. package/skills/zan-saas-interaction/SKILL.md +37 -0
  40. package/skills/zan-saas-interaction/references/lottery-get.md +11 -0
  41. package/skills/zan-saas-interaction/references/lottery-list.md +19 -0
  42. package/skills/zan-saas-item/SKILL.md +61 -0
  43. package/skills/zan-saas-item/references/attribute-list.md +11 -0
  44. package/skills/zan-saas-item/references/brand-list.md +7 -0
  45. package/skills/zan-saas-item/references/classification-get.md +7 -0
  46. package/skills/zan-saas-item/references/classification-list.md +7 -0
  47. package/skills/zan-saas-item/references/group-list.md +9 -0
  48. package/skills/zan-saas-item/references/item-content.md +9 -0
  49. package/skills/zan-saas-item/references/item-get.md +9 -0
  50. package/skills/zan-saas-item/references/item-search.md +23 -0
  51. package/skills/zan-saas-item/references/product-identity.md +11 -0
  52. package/skills/zan-saas-member/SKILL.md +41 -0
  53. package/skills/zan-saas-member/references/customer-level-get.md +7 -0
  54. package/skills/zan-saas-member/references/growth-log-list.md +17 -0
  55. package/skills/zan-saas-member/references/membership-get.md +7 -0
  56. package/skills/zan-saas-order/SKILL.md +56 -0
  57. package/skills/zan-saas-order/references/order-get.md +26 -0
  58. package/skills/zan-saas-order/references/order-list.md +25 -0
  59. package/skills/zan-saas-order/references/order-scan.md +35 -0
  60. package/skills/zan-saas-org/SKILL.md +37 -0
  61. package/skills/zan-saas-org/references/staff-get.md +15 -0
  62. package/skills/zan-saas-org/references/staff-role-get.md +11 -0
  63. package/skills/zan-saas-org/references/unit-get.md +11 -0
  64. package/skills/zan-saas-org/references/unit-list.md +15 -0
  65. package/skills/zan-saas-points/SKILL.md +42 -0
  66. package/skills/zan-saas-points/references/account-get.md +7 -0
  67. package/skills/zan-saas-points/references/log-list.md +17 -0
  68. package/skills/zan-saas-points/references/rule-list.md +2 -0
  69. package/skills/zan-saas-privacy/SKILL.md +30 -0
  70. package/skills/zan-saas-privacy/references/field-decrypt.md +19 -0
  71. package/skills/zan-saas-shared/SKILL.md +94 -0
  72. package/skills/zan-saas-shared/references/authentication.md +52 -0
  73. package/skills/zan-saas-shared/references/value-processing.md +27 -0
  74. package/skills/zan-saas-stock/SKILL.md +28 -0
  75. package/skills/zan-saas-stock/references/log-list.md +11 -0
  76. package/skills/zan-saas-valuecard/SKILL.md +37 -0
  77. package/skills/zan-saas-valuecard/references/card-get.md +13 -0
  78. package/skills/zan-saas-valuecard/references/card-list.md +11 -0
  79. package/src/auth/browser.js +28 -0
  80. package/src/auth/callback-server.js +99 -0
  81. package/src/auth/config.js +53 -0
  82. package/src/auth/credential-store.js +109 -0
  83. package/src/auth/oauth-client.js +105 -0
  84. package/src/auth/pkce.js +28 -0
  85. package/src/auth/session.js +178 -0
  86. package/src/auth/tool.js +25 -0
  87. package/src/cli/command-paths.js +126 -0
  88. package/src/cli/context-help.js +102 -0
  89. package/src/cli/diagnostic-command.js +57 -0
  90. package/src/cli/domain-catalog.js +42 -0
  91. package/src/cli/help-text.js +32 -0
  92. package/src/cli/native-loader.js +120 -0
  93. package/src/cli/native-path.js +22 -0
  94. package/src/cli/parser-policy.js +141 -0
  95. package/src/cli/program.js +134 -0
  96. package/src/cli/skill-catalog.js +241 -0
  97. package/src/commands/native/access/commands.index.json +24 -0
  98. package/src/commands/native/access/domain.json +3 -0
  99. package/src/commands/native/access/role/list/command.js +141 -0
  100. package/src/commands/native/access/role/list/schema.json +393 -0
  101. package/src/commands/native/access/staff-perms/get/command.js +119 -0
  102. package/src/commands/native/access/staff-perms/get/schema.json +703 -0
  103. package/src/commands/native/aftersale/case/get/command.js +104 -0
  104. package/src/commands/native/aftersale/case/get/exact-json.js +52 -0
  105. package/src/commands/native/aftersale/case/get/money.js +28 -0
  106. package/src/commands/native/aftersale/case/get/projection.js +120 -0
  107. package/src/commands/native/aftersale/case/get/query.js +72 -0
  108. package/src/commands/native/aftersale/case/get/schema.json +134 -0
  109. package/src/commands/native/aftersale/case/list/command.js +135 -0
  110. package/src/commands/native/aftersale/case/list/schema.json +1095 -0
  111. package/src/commands/native/aftersale/case/scan/command.js +110 -0
  112. package/src/commands/native/aftersale/case/scan/query.js +62 -0
  113. package/src/commands/native/aftersale/case/scan/scan.js +78 -0
  114. package/src/commands/native/aftersale/case/scan/schema.json +964 -0
  115. package/src/commands/native/aftersale/case/scan/search.js +108 -0
  116. package/src/commands/native/aftersale/commands.index.json +42 -0
  117. package/src/commands/native/aftersale/domain.json +3 -0
  118. package/src/commands/native/aftersale/refund/list/command.js +97 -0
  119. package/src/commands/native/aftersale/refund/list/money.js +25 -0
  120. package/src/commands/native/aftersale/refund/list/projection.js +50 -0
  121. package/src/commands/native/aftersale/refund/list/query.js +73 -0
  122. package/src/commands/native/aftersale/refund/list/schema.json +130 -0
  123. package/src/commands/native/aftersale/shared/query.js +58 -0
  124. package/src/commands/native/aftersale/shared/search.js +128 -0
  125. package/src/commands/native/benefit/card-definition/get/command.js +110 -0
  126. package/src/commands/native/benefit/card-definition/get/schema.json +545 -0
  127. package/src/commands/native/benefit/card-definition/list/command.js +106 -0
  128. package/src/commands/native/benefit/card-definition/list/schema.json +690 -0
  129. package/src/commands/native/benefit/card-grant/list/command.js +135 -0
  130. package/src/commands/native/benefit/card-grant/list/schema.json +758 -0
  131. package/src/commands/native/benefit/commands.index.json +51 -0
  132. package/src/commands/native/benefit/customer-card/get/command.js +110 -0
  133. package/src/commands/native/benefit/customer-card/get/schema.json +340 -0
  134. package/src/commands/native/benefit/customer-card/list/command.js +103 -0
  135. package/src/commands/native/benefit/customer-card/list/schema.json +731 -0
  136. package/src/commands/native/benefit/domain.json +3 -0
  137. package/src/commands/native/coupon/activity/get/command.js +183 -0
  138. package/src/commands/native/coupon/activity/get/schema.json +624 -0
  139. package/src/commands/native/coupon/activity/list/command.js +169 -0
  140. package/src/commands/native/coupon/activity/list/schema.json +845 -0
  141. package/src/commands/native/coupon/commands.index.json +42 -0
  142. package/src/commands/native/coupon/domain.json +3 -0
  143. package/src/commands/native/coupon/shared/query.js +15 -0
  144. package/src/commands/native/coupon/voucher/get/command.js +113 -0
  145. package/src/commands/native/coupon/voucher/get/schema.json +147 -0
  146. package/src/commands/native/coupon/voucher/list/command.js +155 -0
  147. package/src/commands/native/coupon/voucher/list/schema.json +772 -0
  148. package/src/commands/native/customer/commands.index.json +96 -0
  149. package/src/commands/native/customer/customer/get/adapter.js +82 -0
  150. package/src/commands/native/customer/customer/get/command.js +106 -0
  151. package/src/commands/native/customer/customer/get/schema.json +958 -0
  152. package/src/commands/native/customer/customer/list/command.js +78 -0
  153. package/src/commands/native/customer/customer/list/input.js +145 -0
  154. package/src/commands/native/customer/customer/list/query.js +103 -0
  155. package/src/commands/native/customer/customer/list/schema.json +969 -0
  156. package/src/commands/native/customer/customer/scan/command.js +80 -0
  157. package/src/commands/native/customer/customer/scan/scan.js +92 -0
  158. package/src/commands/native/customer/customer/scan/schema.json +211 -0
  159. package/src/commands/native/customer/customer-tag/get/command.js +166 -0
  160. package/src/commands/native/customer/customer-tag/get/schema.json +317 -0
  161. package/src/commands/native/customer/customer-tag/list/command.js +143 -0
  162. package/src/commands/native/customer/customer-tag/list/schema.json +259 -0
  163. package/src/commands/native/customer/domain.json +3 -0
  164. package/src/commands/native/customer/segment/list/command.js +96 -0
  165. package/src/commands/native/customer/segment/list/query.js +98 -0
  166. package/src/commands/native/customer/segment/list/schema.json +135 -0
  167. package/src/commands/native/customer/segment-customer/list/command.js +171 -0
  168. package/src/commands/native/customer/segment-customer/list/schema.json +123 -0
  169. package/src/commands/native/customer/shared/search-input.js +179 -0
  170. package/src/commands/native/customer/shared/search-page.js +54 -0
  171. package/src/commands/native/customer/tag/get/command.js +73 -0
  172. package/src/commands/native/customer/tag/get/schema.json +339 -0
  173. package/src/commands/native/customer/tagcategory/get/command.js +80 -0
  174. package/src/commands/native/customer/tagcategory/get/query.js +98 -0
  175. package/src/commands/native/customer/tagcategory/get/schema.json +339 -0
  176. package/src/commands/native/customer/tagcategory/list/command.js +127 -0
  177. package/src/commands/native/customer/tagcategory/list/schema.json +394 -0
  178. package/src/commands/native/fulfillment/commands.index.json +33 -0
  179. package/src/commands/native/fulfillment/delivery/get/command.js +107 -0
  180. package/src/commands/native/fulfillment/delivery/get/projection.js +142 -0
  181. package/src/commands/native/fulfillment/delivery/get/schema.json +173 -0
  182. package/src/commands/native/fulfillment/domain.json +3 -0
  183. package/src/commands/native/fulfillment/shipment/list/command.js +83 -0
  184. package/src/commands/native/fulfillment/shipment/list/projection.js +130 -0
  185. package/src/commands/native/fulfillment/shipment/list/schema.json +752 -0
  186. package/src/commands/native/fulfillment/waybill/get/command.js +193 -0
  187. package/src/commands/native/fulfillment/waybill/get/response.js +68 -0
  188. package/src/commands/native/fulfillment/waybill/get/schema.json +190 -0
  189. package/src/commands/native/interaction/commands.index.json +24 -0
  190. package/src/commands/native/interaction/domain.json +3 -0
  191. package/src/commands/native/interaction/lottery/get/command.js +61 -0
  192. package/src/commands/native/interaction/lottery/get/query.js +152 -0
  193. package/src/commands/native/interaction/lottery/get/schema.json +1004 -0
  194. package/src/commands/native/interaction/lottery/list/command.js +176 -0
  195. package/src/commands/native/interaction/lottery/list/schema.json +898 -0
  196. package/src/commands/native/item/attribute/list/command.js +122 -0
  197. package/src/commands/native/item/attribute/list/schema.json +727 -0
  198. package/src/commands/native/item/brand/list/command.js +114 -0
  199. package/src/commands/native/item/brand/list/schema.json +725 -0
  200. package/src/commands/native/item/classification/get/command.js +87 -0
  201. package/src/commands/native/item/classification/get/schema.json +596 -0
  202. package/src/commands/native/item/classification/list/command.js +105 -0
  203. package/src/commands/native/item/classification/list/schema.json +676 -0
  204. package/src/commands/native/item/commands.index.json +87 -0
  205. package/src/commands/native/item/domain.json +1 -0
  206. package/src/commands/native/item/group/list/command.js +122 -0
  207. package/src/commands/native/item/group/list/schema.json +809 -0
  208. package/src/commands/native/item/item/get/command.js +122 -0
  209. package/src/commands/native/item/item/get/schema.json +3799 -0
  210. package/src/commands/native/item/item/list/command.js +7 -0
  211. package/src/commands/native/item/item/list/schema.json +1118 -0
  212. package/src/commands/native/item/item/scan/command.js +7 -0
  213. package/src/commands/native/item/item/scan/schema.json +1046 -0
  214. package/src/commands/native/item/item-content/get/command.js +54 -0
  215. package/src/commands/native/item/item-content/get/schema.json +677 -0
  216. package/src/commands/native/item/shared/api.js +31 -0
  217. package/src/commands/native/item/shared/content.js +20 -0
  218. package/src/commands/native/item/shared/diagnostics.js +61 -0
  219. package/src/commands/native/item/shared/h5.js +63 -0
  220. package/src/commands/native/item/shared/identity.js +62 -0
  221. package/src/commands/native/item/shared/normalize.js +49 -0
  222. package/src/commands/native/item/shared/scope.js +22 -0
  223. package/src/commands/native/item/shared/search-command.js +61 -0
  224. package/src/commands/native/item/shared/search-options.js +150 -0
  225. package/src/commands/native/item/shared/search.js +158 -0
  226. package/src/commands/native/member/commands.index.json +60 -0
  227. package/src/commands/native/member/customer-level/get/command.js +122 -0
  228. package/src/commands/native/member/customer-level/get/schema.json +300 -0
  229. package/src/commands/native/member/domain.json +3 -0
  230. package/src/commands/native/member/growth/get/command.js +64 -0
  231. package/src/commands/native/member/growth/get/schema.json +283 -0
  232. package/src/commands/native/member/growth-log/list/command.js +203 -0
  233. package/src/commands/native/member/growth-log/list/schema.json +695 -0
  234. package/src/commands/native/member/level/get/command.js +70 -0
  235. package/src/commands/native/member/level/get/query.js +125 -0
  236. package/src/commands/native/member/level/get/schema.json +339 -0
  237. package/src/commands/native/member/level/list/command.js +50 -0
  238. package/src/commands/native/member/level/list/query.js +109 -0
  239. package/src/commands/native/member/level/list/schema.json +104 -0
  240. package/src/commands/native/member/membership/get/command.js +78 -0
  241. package/src/commands/native/member/membership/get/schema.json +283 -0
  242. package/src/commands/native/order/commands.index.json +33 -0
  243. package/src/commands/native/order/domain.json +3 -0
  244. package/src/commands/native/order/order/get/command.js +155 -0
  245. package/src/commands/native/order/order/get/schema.json +1167 -0
  246. package/src/commands/native/order/order/list/command.js +230 -0
  247. package/src/commands/native/order/order/list/schema.json +1363 -0
  248. package/src/commands/native/order/order/scan/command.js +148 -0
  249. package/src/commands/native/order/order/scan/scan.js +89 -0
  250. package/src/commands/native/order/order/scan/schema.json +1445 -0
  251. package/src/commands/native/order/shared/projection.js +183 -0
  252. package/src/commands/native/order/shared/query.js +84 -0
  253. package/src/commands/native/order/shared/search.js +112 -0
  254. package/src/commands/native/org/commands.index.json +42 -0
  255. package/src/commands/native/org/domain.json +3 -0
  256. package/src/commands/native/org/shared/single-staff.js +115 -0
  257. package/src/commands/native/org/staff/get/command.js +148 -0
  258. package/src/commands/native/org/staff/get/schema.json +114 -0
  259. package/src/commands/native/org/staff-role/get/command.js +45 -0
  260. package/src/commands/native/org/staff-role/get/schema.json +93 -0
  261. package/src/commands/native/org/unit/get/command.js +131 -0
  262. package/src/commands/native/org/unit/get/schema.json +478 -0
  263. package/src/commands/native/org/unit/list/command.js +187 -0
  264. package/src/commands/native/org/unit/list/schema.json +828 -0
  265. package/src/commands/native/points/account/get/command.js +65 -0
  266. package/src/commands/native/points/account/get/schema.json +303 -0
  267. package/src/commands/native/points/commands.index.json +33 -0
  268. package/src/commands/native/points/domain.json +3 -0
  269. package/src/commands/native/points/log/list/command.js +141 -0
  270. package/src/commands/native/points/log/list/schema.json +761 -0
  271. package/src/commands/native/points/rule/list/command.js +82 -0
  272. package/src/commands/native/points/rule/list/schema.json +294 -0
  273. package/src/commands/native/privacy/commands.index.json +15 -0
  274. package/src/commands/native/privacy/domain.json +3 -0
  275. package/src/commands/native/privacy/field/decrypt/command.js +185 -0
  276. package/src/commands/native/privacy/field/decrypt/schema.json +656 -0
  277. package/src/commands/native/privacy/shared/order-source.js +33 -0
  278. package/src/commands/native/stock/commands.index.json +15 -0
  279. package/src/commands/native/stock/domain.json +3 -0
  280. package/src/commands/native/stock/log/list/command.js +207 -0
  281. package/src/commands/native/stock/log/list/schema.json +922 -0
  282. package/src/commands/native/valuecard/card/get/command.js +107 -0
  283. package/src/commands/native/valuecard/card/get/schema.json +683 -0
  284. package/src/commands/native/valuecard/card/list/command.js +136 -0
  285. package/src/commands/native/valuecard/card/list/pagination.js +23 -0
  286. package/src/commands/native/valuecard/card/list/schema.json +780 -0
  287. package/src/commands/native/valuecard/commands.index.json +24 -0
  288. package/src/commands/native/valuecard/domain.json +3 -0
  289. package/src/commands/native/valuecard/shared/projection.js +57 -0
  290. package/src/commands/system/api.js +47 -0
  291. package/src/commands/system/auth.js +118 -0
  292. package/src/commands/system/contracts.js +373 -0
  293. package/src/commands/system/doctor.js +24 -0
  294. package/src/commands/system/install.js +41 -0
  295. package/src/commands/system/printer.js +16 -0
  296. package/src/commands/system/schema.js +162 -0
  297. package/src/commands/system/shop-guidance.js +9 -0
  298. package/src/commands/system/shop.js +237 -0
  299. package/src/commands/system/skills.js +49 -0
  300. package/src/execution/beijing-date-time.js +29 -0
  301. package/src/execution/beijing-time.js +21 -0
  302. package/src/execution/bounded-input.js +42 -0
  303. package/src/execution/command-io.js +137 -0
  304. package/src/execution/command-policy.js +41 -0
  305. package/src/execution/command-schema.js +131 -0
  306. package/src/execution/datetime.js +83 -0
  307. package/src/execution/error-details.js +399 -0
  308. package/src/execution/error-model.js +82 -0
  309. package/src/execution/exact-json.js +80 -0
  310. package/src/execution/list-total.js +10 -0
  311. package/src/execution/money.js +59 -0
  312. package/src/execution/parser-error.js +66 -0
  313. package/src/execution/privacy.js +197 -0
  314. package/src/execution/public-schema.js +52 -0
  315. package/src/execution/query-api.js +101 -0
  316. package/src/execution/range.js +84 -0
  317. package/src/execution/request-state.js +55 -0
  318. package/src/execution/schema-completeness.js +116 -0
  319. package/src/execution/shop-query.js +54 -0
  320. package/src/execution/target-shop-default.js +23 -0
  321. package/src/execution/target-shop.js +49 -0
  322. package/src/identity/context-store.js +54 -0
  323. package/src/identity/context.js +38 -0
  324. package/src/installation/install.js +158 -0
  325. package/src/installation/npm-error.js +93 -0
  326. package/src/installation/skill.js +113 -0
  327. package/src/transport/account-api.js +152 -0
  328. package/src/transport/api.js +199 -0
  329. package/src/transport/shop-app.js +63 -0
@@ -0,0 +1,82 @@
1
+ 'use strict';
2
+
3
+ const { withTargetShopDefault } = require('../../../../../execution/target-shop-default');
4
+
5
+ const { Command, Option } = require('commander');
6
+ const { resolveTargetShop } = require('../../../../../execution/target-shop');
7
+ const { validateCommandValue } = require('../../../../../execution/command-schema');
8
+ const { createShopQuery, failure, bindingPath } = require('../../../../../execution/shop-query');
9
+ const { object } = require('../../../../../execution/query-api');
10
+ const schema = require('./schema.json');
11
+
12
+ const command = 'points.rule.list';
13
+ const outputLimit = 5 * 1024 * 1024;
14
+ const reject = (category, stage, scope, state, facts) =>
15
+ failure(command, category, stage, scope, state, facts);
16
+
17
+ function project(data) {
18
+ if (!object(data) || !Array.isArray(data.rules) || data.rules.some(rule => !object(rule))) {
19
+ throw new Error('Invalid rules');
20
+ }
21
+ const output = { data: { rules: data.rules.map(rule => ({
22
+ ruleId: rule.rule_id,
23
+ ruleName: rule.rule_name,
24
+ givePoints: rule.give_points,
25
+ ...(Object.hasOwn(rule, 'trade_limit') ? { tradeLimit: rule.trade_limit } : {}),
26
+ ...(Object.hasOwn(rule, 'fans_follow') ? { fansFollow: rule.fans_follow } : {}),
27
+ ...(Object.hasOwn(rule, 'is_send_notice') ? { isSendNotice: rule.is_send_notice } : {}),
28
+ ...(Object.hasOwn(rule, 'item_ids') ? { channel_item_ids: rule.item_ids } : {})
29
+ })) } };
30
+ validateCommandValue(schema, 'output', output);
31
+ return output;
32
+ }
33
+
34
+ function createCommand({ context } = {}) {
35
+ return new Command('list')
36
+ .description('读取商家自定义积分奖励及部分条件配置,不包含默认规则或完整触发条件')
37
+ .allowExcessArguments(false)
38
+ .exitOverride(error => {
39
+ if (['commander.helpDisplayed', 'commander.version'].includes(error.code)) throw error;
40
+ throw reject('parameter', 'input');
41
+ })
42
+ .option('--kdt-id <id>', '目标店铺正安全整数;省略取有效上下文 shopId,非总部不可跨店')
43
+ .addOption(new Option('--format <format>', 'json 或 pretty,仅改变缩进')
44
+ .choices(['json', 'pretty']).default('json'))
45
+ .option('--dry-run', '本地预览规则及店铺核验请求,不读凭证、不联网')
46
+ .addHelpText('after', `
47
+ 输出仅 data.rules;ruleId、ruleName、givePoints 必需,tradeLimit、fansFollow、isSendNotice、channel_item_ids 可选。
48
+ fansFollow:数字0不要求关注公众号,1要求;它是规则配置,不是客户实际关注状态。
49
+ isSendNotice:数字0不发通知,1配置发送获得积分的微信模板消息;不证明已发送或送达。
50
+ 保留规则及商品引用的顺序和重复;明确空数组仅表示本接口未返回商家自定义规则。
51
+ 不输出金额阈值 amountLimit,不解析名称中的金额,不承诺完整规则条件或实际发放、通知结果。
52
+ 没有客户、分页、fields 或商品详情请求;最多一次店铺核验与一次主查询,不重试或换店。
53
+ 选定输出按紧凑 UTF-8 JSON 限制 5MiB(json/pretty 相同);超额整体失败,不截断规则或 channel_item_ids。
54
+ 真实执行需四字段上下文和同店授权凭证;店铺核验不证明员工 OAuth。
55
+ 产品范围限主辅 API 交集:微商城单店、零售单店及有赞连锁 D 总部/网店/合伙人。
56
+ 契约:zan-saas schema points.rule.list --format json
57
+ 示例:zan-saas points rule list
58
+ 示例:zan-saas points rule list --kdt-id 63077 --dry-run
59
+ `)
60
+ .action(async options => {
61
+ const scope = resolveTargetShop(options, context, command);
62
+ validateCommandValue(schema, 'input', scope);
63
+ const preview = {
64
+ method: 'POST', path: schema.api.path, body: {}, scope,
65
+ prerequisites: [{ method: 'POST', path: bindingPath, body: {} }]
66
+ };
67
+ validateCommandValue(schema, 'preview', preview);
68
+ let output = preview;
69
+ if (!options.dryRun) {
70
+ const read = await createShopQuery(scope, command);
71
+ const { data, facts } = await read(preview.path, preview.body, 'rules');
72
+ try { output = project(data); }
73
+ catch { throw reject('protocol', 'rules-model', scope, 'sent', facts); }
74
+ if (Buffer.byteLength(JSON.stringify(output), 'utf8') > outputLimit) {
75
+ throw reject('budget_exceeded', 'output-budget', scope, 'sent', facts);
76
+ }
77
+ }
78
+ process.stdout.write(`${JSON.stringify(output, null, options.format === 'pretty' ? 2 : 0)}\n`);
79
+ });
80
+ }
81
+
82
+ module.exports = { kind: 'atomic', risk: 'read', at: 'all', createCommand: withTargetShopDefault(createCommand) };
@@ -0,0 +1,294 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "input": {
4
+ "$ref": "#/definitions/scope",
5
+ "description": "CLI 解析参数并完成必要上下文补全后的业务输入;不是直接传入 CLI 的 JSON。原始选项、必填条件和默认值见 options。"
6
+ },
7
+ "output": {
8
+ "type": "object",
9
+ "required": [
10
+ "data"
11
+ ],
12
+ "additionalProperties": false,
13
+ "properties": {
14
+ "data": {
15
+ "type": "object",
16
+ "required": [
17
+ "rules"
18
+ ],
19
+ "additionalProperties": false,
20
+ "properties": {
21
+ "rules": {
22
+ "type": "array",
23
+ "items": {
24
+ "$ref": "#/definitions/rule"
25
+ }
26
+ }
27
+ }
28
+ }
29
+ }
30
+ },
31
+ "preview": {
32
+ "type": "object",
33
+ "required": [
34
+ "method",
35
+ "path",
36
+ "body",
37
+ "scope",
38
+ "prerequisites"
39
+ ],
40
+ "additionalProperties": false,
41
+ "properties": {
42
+ "method": {
43
+ "const": "POST"
44
+ },
45
+ "path": {
46
+ "const": "youzan.scrm.customer.points.rule.list/1.0.0"
47
+ },
48
+ "body": {
49
+ "type": "object",
50
+ "additionalProperties": false
51
+ },
52
+ "scope": {
53
+ "$ref": "#/definitions/scope"
54
+ },
55
+ "prerequisites": {
56
+ "type": "array",
57
+ "minItems": 1,
58
+ "maxItems": 1,
59
+ "items": {
60
+ "type": "object",
61
+ "required": [
62
+ "method",
63
+ "path",
64
+ "body"
65
+ ],
66
+ "additionalProperties": false,
67
+ "properties": {
68
+ "method": {
69
+ "const": "POST"
70
+ },
71
+ "path": {
72
+ "const": "youzan.shop.basic.get/3.0.0"
73
+ },
74
+ "body": {
75
+ "type": "object",
76
+ "additionalProperties": false
77
+ }
78
+ }
79
+ }
80
+ }
81
+ }
82
+ },
83
+ "error": {
84
+ "type": "object",
85
+ "required": [
86
+ "success",
87
+ "code",
88
+ "message",
89
+ "details"
90
+ ],
91
+ "additionalProperties": false,
92
+ "properties": {
93
+ "success": {
94
+ "const": false
95
+ },
96
+ "code": {
97
+ "const": -10001
98
+ },
99
+ "message": {
100
+ "type": "string",
101
+ "minLength": 1
102
+ },
103
+ "details": {
104
+ "type": "object",
105
+ "additionalProperties": false,
106
+ "required": [
107
+ "category",
108
+ "stage",
109
+ "command",
110
+ "targetScope",
111
+ "requestState",
112
+ "nextStep"
113
+ ],
114
+ "properties": {
115
+ "category": {
116
+ "enum": [
117
+ "parameter",
118
+ "validation",
119
+ "configuration",
120
+ "permission",
121
+ "authentication",
122
+ "scope_unresolved",
123
+ "transport",
124
+ "http",
125
+ "protocol",
126
+ "business_rejected",
127
+ "budget_exceeded"
128
+ ]
129
+ },
130
+ "stage": {
131
+ "type": "string",
132
+ "minLength": 1
133
+ },
134
+ "command": {
135
+ "const": "points.rule.list"
136
+ },
137
+ "targetScope": {
138
+ "type": "object",
139
+ "additionalProperties": false,
140
+ "properties": {
141
+ "kdtId": {
142
+ "$ref": "#/definitions/positiveInteger"
143
+ }
144
+ }
145
+ },
146
+ "requestState": {
147
+ "enum": [
148
+ "not_sent",
149
+ "sent",
150
+ "unknown"
151
+ ]
152
+ },
153
+ "nextStep": {
154
+ "type": "string",
155
+ "minLength": 1
156
+ },
157
+ "api": {
158
+ "type": "string"
159
+ },
160
+ "httpStatus": {
161
+ "type": "integer",
162
+ "minimum": 100,
163
+ "maximum": 599
164
+ },
165
+ "businessCode": {
166
+ "$ref": "#/definitions/diagnosticCode"
167
+ },
168
+ "gatewayCode": {
169
+ "$ref": "#/definitions/diagnosticCode"
170
+ },
171
+ "trace_id": {
172
+ "type": "string",
173
+ "pattern": "^[a-zA-Z0-9_-]{1,128}$"
174
+ },
175
+ "request_id": {
176
+ "type": "string",
177
+ "pattern": "^[a-zA-Z0-9_-]{1,128}$"
178
+ }
179
+ }
180
+ }
181
+ }
182
+ },
183
+ "definitions": {
184
+ "positiveInteger": {
185
+ "type": "integer",
186
+ "minimum": 1,
187
+ "maximum": 9007199254740991
188
+ },
189
+ "safeInteger": {
190
+ "type": "integer",
191
+ "minimum": -9007199254740991,
192
+ "maximum": 9007199254740991
193
+ },
194
+ "scope": {
195
+ "type": "object",
196
+ "required": [
197
+ "kdtId"
198
+ ],
199
+ "additionalProperties": false,
200
+ "properties": {
201
+ "kdtId": {
202
+ "$ref": "#/definitions/positiveInteger"
203
+ }
204
+ }
205
+ },
206
+ "rule": {
207
+ "type": "object",
208
+ "required": [
209
+ "ruleId",
210
+ "ruleName",
211
+ "givePoints"
212
+ ],
213
+ "additionalProperties": false,
214
+ "properties": {
215
+ "ruleId": {
216
+ "$ref": "#/definitions/positiveInteger",
217
+ "description": "本店铺规则 ID,不跨店关联或要求集合唯一。"
218
+ },
219
+ "ruleName": {
220
+ "type": "string",
221
+ "description": "源规则名称,保留空串,不解析金额或规则类别。"
222
+ },
223
+ "givePoints": {
224
+ "$ref": "#/definitions/safeInteger",
225
+ "description": "奖励积分值,保留 0 和明确返回的负整数,不等于账户余额。"
226
+ },
227
+ "tradeLimit": {
228
+ "$ref": "#/definitions/safeInteger",
229
+ "description": "达到该交易次数才发放;不根据数值推断规则类别。"
230
+ },
231
+ "fansFollow": {
232
+ "type": "integer",
233
+ "enum": [
234
+ 0,
235
+ 1
236
+ ],
237
+ "description": "是否配置领取积分前须关注公众号:数字0不要求,1要求;不表示客户实际关注状态。"
238
+ },
239
+ "isSendNotice": {
240
+ "type": "integer",
241
+ "enum": [
242
+ 0,
243
+ 1
244
+ ],
245
+ "description": "是否配置发送获得积分的微信模板消息通知:数字0否,1是;不证明已发送或送达。"
246
+ },
247
+ "channel_item_ids": {
248
+ "type": "array",
249
+ "items": {
250
+ "$ref": "#/definitions/positiveInteger"
251
+ },
252
+ "description": "旧模型渠道商品 ID 引用,保留顺序及重复;不是OneID,不承诺引用商品当前仍存在。缺失省略。"
253
+ }
254
+ }
255
+ },
256
+ "diagnosticCode": {
257
+ "oneOf": [
258
+ {
259
+ "$ref": "#/definitions/safeInteger"
260
+ },
261
+ {
262
+ "type": "string",
263
+ "pattern": "^-?\\d{1,12}$"
264
+ }
265
+ ]
266
+ }
267
+ },
268
+ "modules": {
269
+ "rules": {
270
+ "base": true,
271
+ "upstreamPath": "data.rules",
272
+ "required": true,
273
+ "description": "商家自定义积分奖励及部分条件配置;不包含默认规则或完整触发条件,明确空数组成功,缺失失败。"
274
+ }
275
+ },
276
+ "api": {
277
+ "method": "POST",
278
+ "path": "youzan.scrm.customer.points.rule.list/1.0.0"
279
+ },
280
+ "success": {
281
+ "description": "店铺核验通过,规则列表明确取得、满足递归模型及 5 MiB 输出预算后成功。"
282
+ },
283
+ "errors": {
284
+ "description": "失败 stdout 为空,stderr 为一份脱敏错误 JSON,退出码非零;不返回部分成功,不自动重试、切换身份或目标。按 error 模型及安全下一步处理。"
285
+ },
286
+ "notes": [
287
+ "仅查询商家自定义积分规则,不分页、不读取客户或商品详情;空数组不表示没有默认规则。",
288
+ "可选字段缺失省略,已选字段 null、错型或非安全整数整体失败;保留 0、空名称、顺序和重复。",
289
+ "不返回金额阈值,不能还原完整规则触发条件;不覆盖所有积分获取渠道、积分抵现、积分商城开关或实际发放与通知结果,不从规则名称解析条件。",
290
+ "紧凑 UTF-8 JSON 输出最多 5 MiB,json/pretty 使用同一预算,超额整体失败;不是流式内存限制。",
291
+ "支持微商城单店、零售单店和连锁 D 总部、网店及合伙人。",
292
+ "本地 --dry-run 不读取凭证、不联网;预览只证明构造计划,不证明对象存在或权限有效。真实执行仍需有效上下文及目标范围授权,at 声明不替代服务端授权。"
293
+ ]
294
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "schemaVersion": 3,
3
+ "domain": "privacy",
4
+ "businessCommands": [
5
+ {
6
+ "path": "privacy.field.decrypt",
7
+ "kind": "atomic",
8
+ "risk": "read",
9
+ "availability": "preview_only",
10
+ "at": "all",
11
+ "module": "privacy/field/decrypt/command.js",
12
+ "fingerprint": "6cef4a999c9a3536435b2f2d4df98e702f7d45edaf97640c8ef69854bb39f289"
13
+ }
14
+ ]
15
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "description": "隐私数据:订单字段受控解密,仅支持离线预览"
3
+ }
@@ -0,0 +1,185 @@
1
+ 'use strict';
2
+
3
+ const { withTargetShopDefault } = require('../../../../../execution/target-shop-default');
4
+
5
+ const { Option } = require('commander');
6
+ const { DiagnosticCommand } = require('../../../../../cli/diagnostic-command');
7
+ const { InputIssueError, inputIssue, constraints, modelAt } = require('../../../../../execution/error-details');
8
+ const { readContext } = require('../../../../../identity/context');
9
+ const { resolveTargetShop } = require('../../../../../execution/target-shop');
10
+ const { readJsonInput } = require('../../../../../execution/bounded-input');
11
+ const { validateCommandValue } = require('../../../../../execution/command-schema');
12
+ const { discloseFields, privacyError, OUTPUT_LIMIT } = require('../../../../../execution/privacy');
13
+ const { loadOrderSource } = require('../../shared/order-source');
14
+ const schema = require('./schema.json');
15
+
16
+ const command = 'privacy.field.decrypt';
17
+
18
+ function reject(category, stage, scope = {}, state = 'not_sent') {
19
+ return privacyError(command, category, stage, scope, state);
20
+ }
21
+
22
+ function documentIssue(reason, expected) {
23
+ return new InputIssueError([{ source: 'input', option: '--input-file', reason, expected }]);
24
+ }
25
+
26
+ async function buildInput(options, context, stdin) {
27
+ let input;
28
+ try {
29
+ let document;
30
+ try { document = await readJsonInput(options.inputFile, { stdin }); }
31
+ catch {
32
+ throw documentIssue('invalid_format', {
33
+ format: '可读取的 UTF-8 JSON 文件或 stdin,最多64KiB,不含重复 JSON 成员'
34
+ });
35
+ }
36
+ if (!document || typeof document !== 'object' || Array.isArray(document)) {
37
+ throw documentIssue('invalid_type', { type: 'object' });
38
+ }
39
+ if (Object.keys(document).some(key => !['object', 'values'].includes(key))) {
40
+ throw documentIssue('unexpected_property', { additionalProperties: false });
41
+ }
42
+ if (typeof options.reason !== 'string' || /[\u0000-\u001f\u007f-\u009f\u2028\u2029]/u.test(options.reason)) {
43
+ throw inputIssue('/reason', typeof options.reason === 'string' ? 'invalid_format' : 'invalid_type',
44
+ constraints(modelAt(schema, 'input', '/reason')));
45
+ }
46
+ input = { kdtId: options.kdtId, object: document.object, values: document.values,
47
+ reason: options.reason.trim(), format: options.format, dryRun: options.dryRun === true };
48
+ validateCommandValue(schema, 'input', input);
49
+ if (!Number.isSafeInteger(Number(input.kdtId))) {
50
+ throw inputIssue('/kdtId', 'out_of_range', {
51
+ type: 'string', pattern: '^[1-9]\\d*$', maximum: Number.MAX_SAFE_INTEGER
52
+ });
53
+ }
54
+ if (new Set(input.values.map(item => item.key)).size !== input.values.length ||
55
+ new Set(input.values.map(item => item.field)).size !== input.values.length) {
56
+ throw inputIssue('/values', 'constraint', { format: '每项 key 和 field 分别唯一' });
57
+ }
58
+ for (const [index, item] of input.values.entries()) {
59
+ if (Buffer.byteLength(item.ciphertext) > 16384) {
60
+ throw inputIssue(`/values/${index}/ciphertext`, 'out_of_range', {
61
+ type: 'string', minLength: 1, maxLength: 16384, format: 'UTF-8 最多16384字节'
62
+ });
63
+ }
64
+ }
65
+ } catch (error) {
66
+ // Keep field diagnostics, while preserving the direct buildInput error contract.
67
+ if (error.section === 'input') {
68
+ error.cliDetails = reject('validation', 'input').cliDetails;
69
+ throw error;
70
+ }
71
+ throw reject('validation', 'input');
72
+ }
73
+ try { resolveTargetShop({ kdtId: input.kdtId, dryRun: input.dryRun }, context, command); }
74
+ catch (error) {
75
+ throw reject(error.cliDetails?.category || 'configuration', 'scope');
76
+ }
77
+ return input;
78
+ }
79
+
80
+ function preview(input) {
81
+ const output = { plan: { kdtId: input.kdtId, object: input.object,
82
+ fields: input.values.map(item => item.field), itemCount: input.values.length,
83
+ maximumApiRequests: 4, requiresSensitiveAuthorization: true } };
84
+ validateCommandValue(schema, 'preview', output);
85
+ return output;
86
+ }
87
+
88
+ function serialize(output, format, scope, limit = OUTPUT_LIMIT) {
89
+ const json = JSON.stringify(output, null, format === 'pretty' ? 2 : 0);
90
+ if (Buffer.byteLength(`${json}\n`) > limit) throw reject('limit', 'output-model', scope, 'sent');
91
+ return json;
92
+ }
93
+
94
+ async function execute(input, context, { provider, outputLimit = OUTPUT_LIMIT } = {}) {
95
+ const scope = Object.freeze({ kdtId: input.kdtId });
96
+ const fields = Object.freeze(input.values.map(item => item.field));
97
+ const expectedCiphertexts = Object.freeze(Object.fromEntries(input.values.map(item => [item.field, item.ciphertext])));
98
+ const request = Object.freeze({ scope, object: Object.freeze({ ...input.object }), fields,
99
+ expectedCiphertexts, reason: input.reason, allowEmptyPlaintext: true, preserveStage: true });
100
+ let serialized;
101
+ if (!provider || typeof provider.authorize !== 'function') {
102
+ throw privacyError(command, 'provider_unavailable', 'privacy-authorization', scope);
103
+ }
104
+ const adaptedProvider = {
105
+ authorize: async (fixed, { environment }) => {
106
+ const session = await provider.authorize(fixed, environment);
107
+ if (!session || typeof session.bindSource !== 'function' || typeof session.record !== 'function') {
108
+ return session;
109
+ }
110
+ return {
111
+ verifySource: ({ sourceData, values }) => session.bindSource({
112
+ sourceData, fields: values.map(value => value.field),
113
+ ciphertexts: values.map(value => value.value)
114
+ }),
115
+ recordAccess: event => session.record({
116
+ ...event,
117
+ requestState: event.requestState || 'sent',
118
+ outcome: event.outcome === 'release_authorized' ? 'prepared_for_cli' :
119
+ event.outcome === 'unknown' ? 'unknown' : 'rejected'
120
+ })
121
+ };
122
+ }
123
+ };
124
+ try {
125
+ await discloseFields(request, { command, allowedFields: fields, provider: adaptedProvider,
126
+ readSource: async (read, fixed) => {
127
+ const loaded = await loadOrderSource(fixed, read, context, command);
128
+ return {
129
+ sourceData: loaded.sourceData,
130
+ values: loaded.ciphertexts.map((value, index) => ({ field: fixed.fields[index], value }))
131
+ };
132
+ },
133
+ validateResult: result => {
134
+ const output = { data: { values: result.values.map((item, index) =>
135
+ ({ key: input.values[index].key, ...item })) } };
136
+ validateCommandValue(schema, 'output', output);
137
+ serialized = serialize(output, input.format, scope, outputLimit);
138
+ } });
139
+ } catch (error) {
140
+ const stageMap = {
141
+ source: 'source-binding',
142
+ 'ciphertext-verification': 'verify',
143
+ decryption: 'decrypt',
144
+ 'sensitive-audit': 'audit'
145
+ };
146
+ if (error?.cliDetails) {
147
+ if (error.cliDetails.stage === 'sensitive-audit') error.cliDetails.category = 'audit_failed';
148
+ if (error.cliDetails.category === 'transport') error.cliDetails.stage = 'transport';
149
+ else if (stageMap[error.cliDetails.stage]) error.cliDetails.stage = stageMap[error.cliDetails.stage];
150
+ error.message = `查询失败:${error.cliDetails.category}(${error.cliDetails.stage})`;
151
+ }
152
+ throw error;
153
+ }
154
+ return serialized;
155
+ }
156
+
157
+ function createCommand({ context, stdin, privacyDependencies } = {}) {
158
+ return new DiagnosticCommand('decrypt', { path: command, schema,
159
+ optionPaths: { '/object': 'inputFile', '/values': 'inputFile' } })
160
+ .description('核验单笔订单来源后受控解密;员工授权及审计尚未接入,当前仅离线预览')
161
+ .allowExcessArguments(false)
162
+ .option('--kdt-id <id>', '目标店铺正十进制安全整数;省略时使用当前上下文店铺')
163
+ .requiredOption('--input-file <path>', '必填:最多 64KiB UTF-8 JSON;- 为有界 stdin')
164
+ .requiredOption('--reason <text>', '必填:1 至 200 个 Unicode 码点的用途,不填个人信息')
165
+ .addOption(new Option('--format <format>', 'json 或 pretty,仅改变缩进').choices(['json', 'pretty']).default('json'))
166
+ .option('--dry-run', '校验输入并输出不含密文、key 和用途的计划;零凭证、零网络')
167
+ .addHelpText('after', `
168
+ 仅接受一笔明确订单的一至三个收货姓名、电话或详细地址字段,输入关联 key 与字段须各自唯一。
169
+ 密文不证明对象授权,打星值不能恢复;来源不符、非密文、权限或审计失败均拒绝,不输出部分明文。
170
+ 当前缺少真实员工字段授权、服务端来源绑定及可靠审计适配,执行在发送业务请求前拒绝,不表示功能验收完成。
171
+ 接入后至多四次有赞业务请求,不初始化应用、不重发、重定向、换店、换应用或身份。
172
+ 执行需要有效四字段上下文,非总部目标须匹配当前店铺;总部也不表示跨店授权。
173
+ stdout 明文可能被终端、重定向或 Agent 保存。不得据单对象权限推导批量导出或第三方传输权限。
174
+ 模型与字段含义见 zan-saas schema privacy.field.decrypt;指引见 zan-saas skills read zan-saas-privacy。
175
+ 示例:zan-saas privacy field decrypt --kdt-id 63077 --input-file ciphertext.json --reason "核对本次配送" --dry-run
176
+ `)
177
+ .action(async options => {
178
+ const input = await buildInput(options, context, stdin);
179
+ const output = input.dryRun ? serialize(preview(input), input.format, { kdtId: input.kdtId }) :
180
+ await execute(input, readContext(context).context, privacyDependencies);
181
+ console.log(output);
182
+ });
183
+ }
184
+
185
+ module.exports = { kind: 'atomic', risk: 'read', at: 'all', availability: 'preview_only', createCommand: withTargetShopDefault(createCommand), buildInput, execute, serialize };