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

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 +105 -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 +102 -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,15 @@
1
+ {
2
+ "schemaVersion": 3,
3
+ "domain": "stock",
4
+ "businessCommands": [
5
+ {
6
+ "path": "stock.log.list",
7
+ "kind": "atomic",
8
+ "risk": "read",
9
+ "availability": "available",
10
+ "at": "all",
11
+ "module": "stock/log/list/command.js",
12
+ "fingerprint": "a03ba88d7a29f5b61a1451874f0c3ab8681c78fc56c0432f3fa317fe8025b8a9"
13
+ }
14
+ ]
15
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "description": "库存:库存变化记录"
3
+ }
@@ -0,0 +1,207 @@
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 { inputIssue, parseIntegerOption, withInputScope, constraints, modelAt } = require('../../../../../execution/error-details');
8
+ const schema = require('./schema.json');
9
+ const { validateCommandValue } = require('../../../../../execution/command-schema');
10
+ const { apiDateTime, normalizeTimes } = require('../../../../../execution/datetime');
11
+ const { parseDateTimeRange } = require('../../../../../execution/range');
12
+ const { requestApi, ApiConfigurationError } = require('../../../../../transport/api');
13
+ const { mappingRequest, channelIdentity, legacyLog } = require('../../../item/shared/identity');
14
+
15
+ const commandPath = 'stock.log.list';
16
+ const SHOP = 'youzan.shop.basic.get/3.0.0';
17
+ const LOG = 'youzan.item.stock.log.query/1.0.0';
18
+ const MAX_PAGE = 2147483647;
19
+ const MAX_RESPONSE_BYTES = 10 * 1024 * 1024;
20
+ const MAX_OUTPUT_BYTES = 5 * 1024 * 1024;
21
+ const object = value => value !== null && typeof value === 'object' && !Array.isArray(value);
22
+ const nextStep = '核对当前店铺、商品和时间范围;失败时停止,不自动切店或重试。';
23
+
24
+ function failure(category, stage, scope = {}, state = 'not_sent', facts = {}) {
25
+ const error = new Error(`库存日志查询失败:${category}(${stage})`);
26
+ error.cliDetails = { category, stage, command: commandPath, targetScope: scope,
27
+ requestState: state, nextStep, ...facts };
28
+ return error;
29
+ }
30
+ function integer(raw, path) {
31
+ return parseIntegerOption(typeof raw === 'string' ? raw.trim() : raw, schema, path);
32
+ }
33
+ function buildInput(options) {
34
+ const scope = { kdtId: integer(options.kdtId, '/kdtId'), item_id: integer(options.itemId, '/item_id'), channel: Number(options.channel) };
35
+ return withInputScope(scope, () => {
36
+ if (!['0', '1'].includes(options.channel)) {
37
+ throw inputIssue('/channel', 'invalid_choice', constraints(modelAt(schema, 'input', '/channel')));
38
+ }
39
+ let createdAt;
40
+ try { createdAt = parseDateTimeRange(options.createdAt, { precision: 'seconds', requireBoth: true }); }
41
+ catch {
42
+ throw inputIssue('/createdAt', 'invalid_format', {
43
+ format: '北京时间 YYYY-MM-DD HH:mm:ss,START..END 必须两端,开始不得晚于结束,仅支持秒精度,非零毫秒不支持'
44
+ });
45
+ }
46
+ const input = { ...scope, createdAt,
47
+ pageNo: integer(options.pageNo, '/pageNo'), pageSize: integer(options.pageSize, '/pageSize') };
48
+ validateCommandValue(schema, 'input', input);
49
+ const body = { begin_date: apiDateTime(createdAt.start), end_date: apiDateTime(createdAt.end),
50
+ page_no: input.pageNo, page_size: input.pageSize };
51
+ return { scope, pageNo: input.pageNo, pageSize: input.pageSize, body };
52
+ });
53
+ }
54
+
55
+ function safeNumbers(value) {
56
+ if (typeof value === 'number' && (!Number.isFinite(value) ||
57
+ (Number.isInteger(value) && !Number.isSafeInteger(value)))) throw new Error('unsafe number');
58
+ if (Array.isArray(value)) value.forEach(safeNumbers);
59
+ else if (object(value)) Object.values(value).forEach(safeNumbers);
60
+ }
61
+ async function read(path, body, stage, scope, responseLimit) {
62
+ let response;
63
+ try {
64
+ response = await requestApi({ path, body }, undefined,
65
+ responseLimit ? { maxResponseBytes: () => responseLimit } : {});
66
+ }
67
+ catch (error) {
68
+ throw failure(error instanceof ApiConfigurationError ? 'configuration' : 'transport', stage, scope,
69
+ error instanceof ApiConfigurationError ? 'not_sent' : 'unknown', { api: path });
70
+ }
71
+ const facts = { api: path, httpStatus: response.httpStatus };
72
+ let result;
73
+ try { result = JSON.parse(response.body); if (!object(result)) result = null; }
74
+ catch { result = null; }
75
+ if (Number.isSafeInteger(result?.code) ||
76
+ (typeof result?.code === 'string' && /^-?\d{1,12}$/.test(result.code))) facts.businessCode = result.code;
77
+ for (const key of ['trace_id', 'request_id']) {
78
+ const value = result?.[key] ?? result?.gw_err_resp?.[key];
79
+ if (typeof value === 'string' && /^[a-zA-Z0-9_-]{1,128}$/.test(value)) facts[key] = value;
80
+ }
81
+ if (object(result?.gw_err_resp) && /^\d{1,12}$/.test(String(result.gw_err_resp.err_code))) {
82
+ facts.gatewayCode = result.gw_err_resp.err_code;
83
+ }
84
+ if (!response.ok) {
85
+ throw failure(response.httpStatus === 401 ? 'authentication' : response.httpStatus === 403 ? 'permission' : 'http',
86
+ stage, scope, 'sent', facts);
87
+ }
88
+ if (!result) throw failure('protocol', stage, scope, 'sent', facts);
89
+ if (result.success === false || !(result.success === true || [0, 200].includes(result.code))) {
90
+ throw failure('business_rejected', stage, scope, 'sent', facts);
91
+ }
92
+ try { safeNumbers(result); }
93
+ catch { throw failure('protocol', stage, scope, 'sent', facts); }
94
+ if (!Object.hasOwn(result, 'data')) throw failure('protocol', stage, scope, 'sent', facts);
95
+ if (Buffer.byteLength(JSON.stringify(result.data) ?? '') > MAX_RESPONSE_BYTES) {
96
+ throw failure('budget_exceeded', stage, scope, 'sent', facts);
97
+ }
98
+ return result.data;
99
+ }
100
+ async function execute({ scope, pageNo, pageSize, body }, format) {
101
+ const shop = await read(SHOP, {}, 'shop-preflight', scope);
102
+ if (!object(shop) || !Number.isSafeInteger(shop.sid) || shop.sid < 1) {
103
+ throw failure('protocol', 'shop-preflight', scope, 'sent', { api: SHOP });
104
+ }
105
+ if (shop.sid !== scope.kdtId) {
106
+ throw failure('scope_unresolved', 'shop-preflight', scope, 'sent', {
107
+ api: SHOP, nextStep: '凭据所属店铺与 --kdt-id 不一致;先取得该店铺的有效授权,再查询。'
108
+ });
109
+ }
110
+ const mapping = mappingRequest(scope);
111
+ const product = await read(mapping.path, mapping.body, 'product-identity', scope);
112
+ let identity;
113
+ try { identity = channelIdentity(product, scope, { skuMapping: true }); }
114
+ catch { throw failure('scope_unresolved', 'product-identity', scope, 'sent', { api: mapping.path }); }
115
+ const raw = await read(LOG, { item_id: identity.channel_item_id, ...body }, 'logs', scope,
116
+ MAX_RESPONSE_BYTES);
117
+ const invalid = () => failure('protocol', 'logs-model', scope, 'sent', { api: LOG });
118
+ if (!object(raw) || !Array.isArray(raw.items) || raw.items.length > pageSize ||
119
+ (raw.paginator !== undefined && !object(raw.paginator))) throw invalid();
120
+ const paginator = raw.paginator || {};
121
+ if ((paginator.page !== undefined && paginator.page !== pageNo) ||
122
+ (paginator.page_size !== undefined && paginator.page_size !== pageSize) ||
123
+ (paginator.total_count != null &&
124
+ (!Number.isSafeInteger(paginator.total_count) || paginator.total_count < 0))) throw invalid();
125
+ let logs;
126
+ try { logs = raw.items.map(log => {
127
+ if (!object(log) || log.kdt_id !== scope.kdtId) throw invalid();
128
+ return legacyLog(log, identity);
129
+ }); } catch { throw invalid(); }
130
+ const total = paginator.total_count ?? null;
131
+ const hasMore = total === null ? null : total > pageNo * pageSize;
132
+ const exhausted = hasMore === false;
133
+ const nextPage = !exhausted && pageNo < MAX_PAGE ? pageNo + 1 : null;
134
+ const result = { data: { logs, pagination: {
135
+ pageNo, pageSize, returned: raw.items.length, ...(total === null ? {} : { total }), hasMore, nextPage,
136
+ continuation: exhausted ? 'none' : nextPage === null ? 'page_limit' : 'next_page',
137
+ paginationExhausted: exhausted, snapshot: false
138
+ } } };
139
+ try {
140
+ result.data.logs = normalizeTimes(logs, { type: 'array', items: { $ref: '#/definitions/log' } },
141
+ schema.definitions);
142
+ validateCommandValue(schema, 'output', result);
143
+ }
144
+ catch { throw invalid(); }
145
+ const text = `${JSON.stringify(result, null, format === 'pretty' ? 2 : 0)}\n`;
146
+ if (Buffer.byteLength(text) > MAX_OUTPUT_BYTES) {
147
+ throw failure('budget_exceeded', 'output-bytes', scope, 'sent', { api: LOG });
148
+ }
149
+ return text;
150
+ }
151
+ function createCommand({ context } = {}) {
152
+ return new DiagnosticCommand('list', { path: commandPath, schema, parameterCategory: 'parameter',
153
+ optionPaths: { '/item_id': 'itemId' } })
154
+ .description('查询指定商品在一段时间内的库存变化记录')
155
+ .allowExcessArguments(false)
156
+ .option('--kdt-id <id>', '目标店铺 ID,必须是当前上下文和凭据所属店铺;省略时使用当前上下文店铺')
157
+ .requiredOption('--item-id <id>', '必填:OneID 商品 ID;内部转换为目标店铺渠道商品 ID')
158
+ .option('--channel <channel>', '商品渠道:0 网店,1 门店;默认0', '0')
159
+ .requiredOption('--created-at <range>', '必填:日志时间 START..END,必须两端,北京时间 YYYY-MM-DD HH:mm:ss;开始不得晚于结束,仅支持秒精度')
160
+ .option('--page-no <n>', '页码,从1开始,最大2147483647', '1')
161
+ .option('--page-size <n>', '每页条数,默认20,CLI预算上限100(不是API上限)', '20')
162
+ .addOption(new Option('--format <format>', 'json 或 pretty(仅改变缩进)').choices(['json', 'pretty']).default('json'))
163
+ .option('--dry-run', '仅本地预览核店、商品映射及条件日志请求,不读凭据、不联网')
164
+ .addHelpText('after', `
165
+ --kdt-id 必须等于当前 context.shopId,包括总部上下文,不自动跨店或查询下级组织。
166
+ 先用同一凭据调用 youzan.shop.basic.get/3.0.0,sid 匹配才查询日志;失败或不匹配即停止。
167
+ 日志请求不另传店铺字段,执行前须核对当前调用店铺与目标一致。
168
+ 核店后读取商品渠道映射,再查询日志,最多3个只读请求,不自动重试或翻页。
169
+ 输入 item_id 是 OneID,旧日志商品和规格标识输出为 channel_item_id/channel_sku_id。
170
+ 日志 sku_id 仅在取得当前唯一规格映射或源明确统一字段时返回;历史规格无法映射时省略统一规格。
171
+ 映射失败停止,不用 OneID 充当旧商品 ID;真实产品和权限范围以服务端为准。
172
+ at: all 只表示不按本地组织位置排除,不表示所有产品可用或任意跨店授权。
173
+ 返回 data.logs 和 data.pagination,保留接口顺序及重复日志,不推算当前库存或库存增减数。
174
+ stock_change 是变更详情字符串,column_events 是字符串数组;不解析或改写。
175
+ 时间输入为北京时间 YYYY-MM-DD HH:mm:ss;可带全零毫秒,非零毫秒在请求前拒绝。
176
+ 区间必须包含 ..,省略边界不补值;可用相同两端表示同一秒,不承诺端点包含性。
177
+ 时间点输出为 YYYY-MM-DD HH:mm:ss.SSS;日期必须有效,开始时间不得晚于结束时间。
178
+ 缺少总数时 hasMore=null,不用空页或短页推定取完;page_limit 不代表查完,snapshot=false。
179
+ 每步解包data解析后最多10MiB,最终stdout最多5MiB,超额整体失败,不输出部分日志。
180
+ 执行需要有效的用户、组织与店铺上下文,可通过登录后选店或 ZAN_SAAS_CONTEXT 提供;目标范围和服务端授权按本命令契约校验,公共调用前置见 zan-saas skills read zan-saas-shared。
181
+ 缺少上下文仍可本地预览;提供无效或目标冲突上下文则拒绝。失败stdout为空,stderr为错误JSON。
182
+
183
+ 示例:
184
+ zan-saas stock log list --kdt-id 63077 --item-id 123 --created-at "2026-09-01 00:00:00..2026-09-02 23:59:59"
185
+ zan-saas stock log list --kdt-id 63077 --item-id 123 --created-at "2026-09-01 00:00:00..2026-09-02 23:59:59" --dry-run
186
+ `)
187
+ .action(async options => {
188
+ const input = buildInput(options);
189
+ if (context && String(input.scope.kdtId) !== context.shopId) {
190
+ throw failure('permission', 'target', input.scope, 'not_sent', {
191
+ nextStep: '--kdt-id 必须等于当前 context.shopId;请先明确并配置要查询的店铺。'
192
+ });
193
+ }
194
+ if (options.dryRun) {
195
+ const plan = { steps: [
196
+ { method: 'POST', path: SHOP, body: {} },
197
+ mappingRequest(input.scope),
198
+ { method: 'POST', path: LOG, body: input.body, bodyFrom: { item_id: 'steps[1].data.channel_item_id' } }
199
+ ], condition: '核店及商品渠道映射匹配后才读取日志;日志 item_id 来自商品响应的 channel_item_id。' };
200
+ validateCommandValue(schema, 'preview', plan);
201
+ process.stdout.write(`${JSON.stringify(plan, null, options.format === 'pretty' ? 2 : 0)}\n`);
202
+ } else process.stdout.write(await execute(input, options.format));
203
+ });
204
+ }
205
+
206
+ module.exports = { kind: 'atomic', risk: 'read', at: 'all' };
207
+ module.exports.createCommand = withTargetShopDefault(createCommand);