@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,148 @@
1
+ 'use strict';
2
+
3
+ const { withTargetShopDefault } = require('../../../../../execution/target-shop-default');
4
+
5
+ const { Command, Option } = require('commander');
6
+ const schema = require('./schema.json');
7
+ const { resolveTargetShop } = require('../../../../../execution/target-shop');
8
+ const { readContext } = require('../../../../../identity/context');
9
+ const { validateCommandValue } = require('../../../../../execution/command-schema');
10
+ const { object } = require('../../../../../execution/query-api');
11
+ const { createBoundShopQuery, failure, bindingPath } = require('../../../../../execution/shop-query');
12
+ const { formatBeijingMilliseconds } = require('../../../../../execution/beijing-time');
13
+
14
+ const command = 'org.staff.get';
15
+ const reject = (category, stage, scope, state, facts) =>
16
+ failure(command, category, stage, scope, state, facts);
17
+
18
+ function buildInput(options, context) {
19
+ let scope;
20
+ try {
21
+ scope = resolveTargetShop(options, context, command);
22
+ } catch (error) {
23
+ if (error.cliDetails?.stage === 'validation') error.cliDetails.stage = 'input';
24
+ throw error;
25
+ }
26
+ const state = readContext(context);
27
+ if (state.status === 'ready' && state.context.orgType !== 'shop') {
28
+ throw reject('permission', 'context', scope);
29
+ }
30
+ try {
31
+ if (typeof options.mobile !== 'string' || /[\x00-\x1f\x7f-\x9f]/.test(options.mobile)) {
32
+ throw new Error('invalid mobile');
33
+ }
34
+ const mobile = options.mobile.replace(/^ +| +$/g, '');
35
+ const include = options.include === undefined ? [] :
36
+ [...new Set(options.include.split(',').map(value => value.trim()))];
37
+ const input = { ...scope, mobile, include };
38
+ validateCommandValue(schema, 'input', input);
39
+ return input;
40
+ } catch {
41
+ throw reject('parameter', 'input', scope);
42
+ }
43
+ }
44
+
45
+ function previewFor(input) {
46
+ return { scope: { kdtId: input.kdtId }, requests: [
47
+ { stage: 'shop-binding', method: 'POST', path: bindingPath, body: {} },
48
+ { stage: 'staff', method: 'POST', path: schema.api.path, body: { account: '***' } }
49
+ ], selection: { include: input.include } };
50
+ }
51
+
52
+ function projectStaff(data, input, facts) {
53
+ const scope = { kdtId: input.kdtId };
54
+ const invalid = stage => reject('protocol', stage, scope, 'sent', facts);
55
+ if (!object(data) || !Number.isSafeInteger(data.kdt_id) || data.kdt_id < 1) {
56
+ throw invalid('staff-model');
57
+ }
58
+ if (data.kdt_id !== input.kdtId ||
59
+ (typeof data.account === 'string' && /^1\d{10}$/.test(data.account) && data.account !== input.mobile)) {
60
+ throw reject('scope_unresolved', 'staff-model', scope, 'sent', facts);
61
+ }
62
+ const staff = { staffId: data.yz_open_id, kdtId: data.kdt_id, status: data.status };
63
+ try {
64
+ for (const [field, source] of Object.entries({ staffNo: 'staff_no', name: 'name',
65
+ account: 'account', contactPhone: 'link_phone' })) {
66
+ if (data[source] !== undefined && data[source] !== null) staff[field] = data[source];
67
+ }
68
+ for (const [field, source] of Object.entries({ createdAt: 'create_time', updatedAt: 'update_time' })) {
69
+ if (data[source] !== undefined && data[source] !== null) {
70
+ staff[field] = formatBeijingMilliseconds(data[source]);
71
+ }
72
+ }
73
+ validateCommandValue(schema, 'output', { data: { staff } });
74
+ } catch {
75
+ throw invalid('staff-model');
76
+ }
77
+ if (input.include.includes('roles')) {
78
+ try {
79
+ if (!Array.isArray(data.roles)) throw new Error('invalid roles');
80
+ staff.roles = data.roles.map(role => {
81
+ if (!object(role)) throw new Error('invalid role');
82
+ return { roleId: role.role_id, ...(role.name === undefined || role.name === null ? {} : { name: role.name }) };
83
+ });
84
+ validateCommandValue(schema, 'output', { data: { staff } });
85
+ } catch {
86
+ throw invalid('staff-roles');
87
+ }
88
+ }
89
+ return { data: { staff } };
90
+ }
91
+
92
+ async function execute(input) {
93
+ const scope = { kdtId: input.kdtId };
94
+ const { read, binding } = await createBoundShopQuery(scope, command);
95
+ if (!Number.isSafeInteger(binding.data.role) || binding.data.role < 0) {
96
+ throw reject('protocol', 'shop-binding', scope, 'sent', binding.facts);
97
+ }
98
+ if (binding.data.role !== 0) {
99
+ throw reject('permission', 'shop-binding', scope, 'sent', binding.facts);
100
+ }
101
+ let staffResponse;
102
+ try {
103
+ staffResponse = await read(schema.api.path, { account: input.mobile }, 'staff', [0, 200]);
104
+ } catch (error) {
105
+ if (error.cliDetails?.category === 'business_rejected' &&
106
+ [error.cliDetails.businessCode, error.cliDetails.gatewayCode].some(code => String(code) === '232500001')) {
107
+ error.cliDetails.category = 'not_found';
108
+ error.message = '查询失败:not_found(staff)';
109
+ }
110
+ throw error;
111
+ }
112
+ return projectStaff(staffResponse.data, input, staffResponse.facts);
113
+ }
114
+
115
+ function createCommand({ context } = {}) {
116
+ return new Command('get')
117
+ .description('按登录账号手机号查询当前授权微商城单店的一个员工档案')
118
+ .allowExcessArguments(false)
119
+ .exitOverride(error => {
120
+ if (['commander.helpDisplayed', 'commander.version'].includes(error.code)) throw error;
121
+ throw reject('parameter', 'input');
122
+ })
123
+ .requiredOption('--mobile <phone>', '必填:员工登录账号手机号,11 位;不是联系人或客户手机号')
124
+ .option('--kdt-id <id>', '当前单店正安全整数;省略取上下文 shopId,不支持跨店或总部')
125
+ .option('--include <modules>', '仅 roles;逗号分隔去重,仅本地投影,不增加请求')
126
+ .addOption(new Option('--format <format>', 'json 或 pretty,仅改变缩进')
127
+ .choices(['json', 'pretty']).default('json'))
128
+ .option('--dry-run', '仅本地预览两步请求,手机号脱敏;不读凭证、不联网')
129
+ .addHelpText('after', '\n先核验凭证同店及单店组织角色,再查询员工;最多两请求,不重试或切店。\n单店角色不能证明微商城产品,适用性与权限由主接口和网关校验。\n时间为北京时间 YYYY-MM-DD HH:mm:ss.SSS,固定三位毫秒,按源 Unix 毫秒转换。\n角色关联不是完整权限或可授予性证明;失败不输出部分员工资料。\n契约:zan-saas schema org.staff.get --format json\n示例:zan-saas org staff get --mobile 13800000000 --include roles --dry-run')
130
+ .action(async options => {
131
+ const input = buildInput(options, context);
132
+ const preview = previewFor(input);
133
+ validateCommandValue(schema, 'preview', preview);
134
+ try {
135
+ const result = options.dryRun ? preview : await execute(input);
136
+ console.log(JSON.stringify(result, null, options.format === 'pretty' ? 2 : 0));
137
+ } catch (error) {
138
+ for (const field of ['businessCode', 'gatewayCode', 'trace_id', 'request_id']) {
139
+ if (String(error.cliDetails?.[field]).includes(input.mobile)) {
140
+ delete error.cliDetails[field];
141
+ }
142
+ }
143
+ throw error;
144
+ }
145
+ });
146
+ }
147
+
148
+ module.exports = { kind: 'atomic', risk: 'read', at: 'shop', createCommand: withTargetShopDefault(createCommand) };
@@ -0,0 +1,114 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "input": {
4
+ "type": "object", "required": ["kdtId", "mobile", "include"], "additionalProperties": false,
5
+ "properties": {
6
+ "kdtId": { "$ref": "#/definitions/shopId" },
7
+ "mobile": { "type": "string", "pattern": "^1[0-9]{10}$", "description": "员工登录账号手机号;仅去首尾普通空格,拒绝控制字符,不用联系人或客户号码。" },
8
+ "include": { "$ref": "#/definitions/include" }
9
+ }
10
+ },
11
+ "output": {
12
+ "type": "object", "required": ["data"], "additionalProperties": false,
13
+ "properties": {
14
+ "data": {
15
+ "type": "object", "required": ["staff"], "additionalProperties": false,
16
+ "properties": {
17
+ "staff": {
18
+ "type": "object", "required": ["staffId", "kdtId", "status"], "additionalProperties": false,
19
+ "properties": {
20
+ "staffId": { "type": "string", "pattern": "\\S", "description": "不透明员工标识;不能用管理账号、手机号、客户或上下文标识替代。" },
21
+ "kdtId": { "$ref": "#/definitions/shopId" },
22
+ "status": { "type": "string", "enum": ["ON", "OFF"], "description": "ON:员工启用;OFF:员工禁用。未知状态失败,不默认启用,不证明权限。" },
23
+ "staffNo": { "type": "string", "description": "员工编号,不是稳定主键;空串保留。" },
24
+ "name": { "type": "string" },
25
+ "account": { "type": "string", "description": "服务端账号原文,可脱敏;完整 11 位手机号必须与查询一致。" },
26
+ "contactPhone": { "type": "string", "description": "员工联系方式,不作为登录账号。" },
27
+ "createdAt": { "type": "string", "format": "beijing-date-time-ms", "$comment": "upstream-time:milliseconds", "description": "创建时间;北京时间 YYYY-MM-DD HH:mm:ss.SSS,固定三位毫秒。" },
28
+ "updatedAt": { "type": "string", "format": "beijing-date-time-ms", "$comment": "upstream-time:milliseconds", "description": "更新时间;北京时间 YYYY-MM-DD HH:mm:ss.SSS,固定三位毫秒;不要求晚于创建时间。" },
29
+ "roles": {
30
+ "type": "array", "description": "仅 include roles 时必需,允许空数组;保持顺序及重复项,不用其他角色关系补值。",
31
+ "items": {
32
+ "type": "object", "required": ["roleId"], "additionalProperties": false,
33
+ "properties": {
34
+ "roleId": { "type": "integer", "minimum": 1, "maximum": 9007199254740991, "description": "当前店铺内角色标识,不是全局枚举或授权证明。" },
35
+ "name": { "type": "string" }
36
+ }
37
+ }
38
+ }
39
+ }
40
+ }
41
+ }
42
+ }
43
+ }
44
+ },
45
+ "preview": {
46
+ "type": "object", "required": ["scope", "requests", "selection"], "additionalProperties": false,
47
+ "properties": {
48
+ "scope": { "type": "object", "required": ["kdtId"], "additionalProperties": false, "properties": { "kdtId": { "$ref": "#/definitions/shopId" } } },
49
+ "requests": {
50
+ "type": "array", "minItems": 2, "maxItems": 2, "additionalItems": false,
51
+ "items": [
52
+ {
53
+ "type": "object", "required": ["stage", "method", "path", "body"], "additionalProperties": false,
54
+ "properties": {
55
+ "stage": { "const": "shop-binding" }, "method": { "const": "POST" },
56
+ "path": { "const": "youzan.shop.basic.get/3.0.0" },
57
+ "body": { "type": "object", "additionalProperties": false, "properties": {} }
58
+ }
59
+ },
60
+ {
61
+ "type": "object", "required": ["stage", "method", "path", "body"], "additionalProperties": false,
62
+ "properties": {
63
+ "stage": { "const": "staff" }, "method": { "const": "POST" },
64
+ "path": { "const": "youzan.shop.single.staff.get/1.0.0" },
65
+ "body": { "type": "object", "required": ["account"], "additionalProperties": false, "properties": { "account": { "const": "***" } } }
66
+ }
67
+ }
68
+ ]
69
+ },
70
+ "selection": { "type": "object", "required": ["include"], "additionalProperties": false, "properties": { "include": { "$ref": "#/definitions/include" } } }
71
+ }
72
+ },
73
+ "error": {
74
+ "type": "object", "required": ["success", "code", "message", "details"], "additionalProperties": false,
75
+ "properties": {
76
+ "success": { "const": false }, "code": { "const": -10001 }, "message": { "type": "string", "minLength": 1 },
77
+ "details": {
78
+ "type": "object", "required": ["category", "stage", "command", "targetScope", "requestState", "nextStep"], "additionalProperties": false,
79
+ "properties": {
80
+ "category": { "enum": ["parameter", "validation", "configuration", "authentication", "permission", "scope_unresolved", "transport", "http", "protocol", "business_rejected", "not_found"] },
81
+ "stage": { "enum": ["input", "context", "scope", "configuration", "shop-binding", "staff", "staff-model", "staff-roles", "transport", "http", "response"] },
82
+ "command": { "const": "org.staff.get" },
83
+ "targetScope": { "type": "object", "additionalProperties": false, "properties": { "kdtId": { "$ref": "#/definitions/shopId" } } },
84
+ "requestState": { "enum": ["not_sent", "sent", "unknown"] },
85
+ "nextStep": { "type": "string", "minLength": 1 },
86
+ "api": { "type": "string" }, "httpStatus": { "type": "integer" },
87
+ "businessCode": { "$ref": "#/definitions/diagnosticCode" },
88
+ "gatewayCode": { "$ref": "#/definitions/diagnosticCode" },
89
+ "trace_id": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,128}$" },
90
+ "request_id": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,128}$" }
91
+ }
92
+ }
93
+ }
94
+ },
95
+ "definitions": {
96
+ "shopId": { "type": "integer", "minimum": 1, "maximum": 9007199254740991, "description": "当前上下文同店正安全整数;上下文必须为 shop,凭证和员工资料均须属于该店。" },
97
+ "include": { "type": "array", "uniqueItems": true, "items": { "enum": ["roles"] } },
98
+ "diagnosticCode": { "anyOf": [ { "type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991 }, { "type": "string", "pattern": "^-?\\d{1,12}$" } ] }
99
+ },
100
+ "modules": {
101
+ "staff": { "base": true, "required": true, "upstreamPath": "data", "description": "有限员工档案;员工标识、店铺标识和状态必需。可选字段缺省或无值时省略。" },
102
+ "roles": { "base": false, "required": false, "upstreamPath": "data.roles", "description": "仅选择时校验并输出当前员工角色关联,无额外请求;不是角色目录或完整权限。" }
103
+ },
104
+ "api": { "method": "POST", "path": "youzan.shop.single.staff.get/1.0.0" },
105
+ "success": { "description": "已核实当前组织为凭证所属单店,员工资料属于同店,员工标识、状态及所有选定模块均有效后返回 data.staff。" },
106
+ "errors": { "description": "明确业务拒绝 232500001 为 not_found;231000407 不凭自由文案改为未找到。冲突成功信号协议失败。HTTP 401/403、传输中断 unknown 保留;失败 stdout 为空,stderr 单一脱敏信封,不返回部分结果。" },
107
+ "notes": [
108
+ "at=shop,仅声明微商城单店;role=0 只证明单店组织角色,产品适用与员工权限由主接口和网关校验。",
109
+ "最多两请求、同一基址/token 快照、10 秒超时、无重试或重定向;不扫描员工或补查类型。",
110
+ "dry-run 不读凭证不联网,预览中的账号固定掩码。",
111
+ "未选择角色时不校验其内容;仅返回本契约声明的员工字段。",
112
+ "员工标识缺失时失败;账号已脱敏时不宣称完整手机号已反向核验。"
113
+ ]
114
+ }
@@ -0,0 +1,45 @@
1
+ 'use strict';
2
+
3
+ const { withTargetShopDefault } = require('../../../../../execution/target-shop-default');
4
+
5
+ const { Command, Option } = require('commander');
6
+ const schema = require('./schema.json');
7
+ const { validateCommandValue } = require('../../../../../execution/command-schema');
8
+ const { failure } = require('../../../../../execution/shop-query');
9
+ const { staffInput, staffPreview, readSingleShopStaff, staffRoles, redactStaffDiagnostics } = require('../../shared/single-staff');
10
+
11
+ const command = 'org.staff-role.get';
12
+
13
+ function createCommand({ context } = {}) {
14
+ return new Command('get')
15
+ .description('按登录账号手机号查询当前授权微商城单店员工的角色关联')
16
+ .allowExcessArguments(false)
17
+ .exitOverride(error => {
18
+ if (['commander.helpDisplayed', 'commander.version'].includes(error.code)) throw error;
19
+ throw failure(command, 'parameter', 'input');
20
+ })
21
+ .requiredOption('--mobile <phone>', '必填:员工登录账号手机号,11 位,不是客户或联系人手机号')
22
+ .option('--kdt-id <id>', '当前单店正安全整数;省略取上下文 shopId,不允许跨店或总部')
23
+ .addOption(new Option('--format <format>', 'json 或 pretty,仅改变缩进')
24
+ .choices(['json', 'pretty']).default('json'))
25
+ .option('--dry-run', '本地预览两步请求,手机号脱敏;不读凭证、不联网')
26
+ .addHelpText('after', '\n只返回当前员工的角色关联,不是角色目录、完整权限或可授予性证明。\n最多两请求,先核验凭证同店及单店组织角色,不重试、不扫描或切店。\n只有成功明确返回空角色数组才输出 [];缺失或错型失败。\n契约:zan-saas schema org.staff-role.get --format json\n示例:zan-saas org staff-role get --mobile 13800000000 --dry-run')
27
+ .action(async options => {
28
+ const input = staffInput(options, context, command, schema);
29
+ const preview = staffPreview(input);
30
+ validateCommandValue(schema, 'preview', preview);
31
+ try {
32
+ let result = preview;
33
+ if (!options.dryRun) {
34
+ const { staff, facts } = await readSingleShopStaff(input, command);
35
+ result = { data: { kdtId: staff.kdt_id, roles: staffRoles(staff, command, facts) } };
36
+ validateCommandValue(schema, 'output', result);
37
+ }
38
+ console.log(JSON.stringify(result, null, options.format === 'pretty' ? 2 : 0));
39
+ } catch (error) {
40
+ throw redactStaffDiagnostics(error, input.mobile);
41
+ }
42
+ });
43
+ }
44
+
45
+ module.exports = { kind: 'atomic', risk: 'read', at: 'shop', createCommand: withTargetShopDefault(createCommand) };
@@ -0,0 +1,93 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "input": {
4
+ "type": "object", "required": ["kdtId", "mobile"], "additionalProperties": false,
5
+ "properties": {
6
+ "kdtId": { "$ref": "#/definitions/shopId" },
7
+ "mobile": { "type": "string", "pattern": "^1[0-9]{10}$", "description": "员工登录账号手机号;仅去首尾普通空格,拒绝控制字符,不接受客户或联系人号码。" }
8
+ }
9
+ },
10
+ "output": {
11
+ "type": "object", "required": ["data"], "additionalProperties": false,
12
+ "properties": {
13
+ "data": {
14
+ "type": "object", "required": ["kdtId", "roles"], "additionalProperties": false,
15
+ "properties": {
16
+ "kdtId": { "$ref": "#/definitions/shopId" },
17
+ "roles": {
18
+ "type": "array", "description": "本次查询返回的员工角色关联;成功且明确为空才返回 [],不是角色目录或完整权限。",
19
+ "items": {
20
+ "type": "object", "required": ["roleId", "name"], "additionalProperties": false,
21
+ "properties": {
22
+ "roleId": { "type": "integer", "minimum": 1, "maximum": 9007199254740991, "description": "员工关联角色的标识;不是员工、管理账号或组织标识。" },
23
+ "name": { "type": "string", "description": "该角色的名称,按本次返回保留;不从名称推断权限。" }
24
+ }
25
+ }
26
+ }
27
+ }
28
+ }
29
+ }
30
+ },
31
+ "preview": {
32
+ "type": "object", "required": ["scope", "requests"], "additionalProperties": false,
33
+ "properties": {
34
+ "scope": { "type": "object", "required": ["kdtId"], "additionalProperties": false, "properties": { "kdtId": { "$ref": "#/definitions/shopId" } } },
35
+ "requests": {
36
+ "type": "array", "minItems": 2, "maxItems": 2, "additionalItems": false,
37
+ "items": [
38
+ {
39
+ "type": "object", "required": ["stage", "method", "path", "body"], "additionalProperties": false,
40
+ "properties": {
41
+ "stage": { "const": "shop-binding" }, "method": { "const": "POST" },
42
+ "path": { "const": "youzan.shop.basic.get/3.0.0" },
43
+ "body": { "type": "object", "additionalProperties": false, "properties": {} }
44
+ }
45
+ },
46
+ {
47
+ "type": "object", "required": ["stage", "method", "path", "body"], "additionalProperties": false,
48
+ "properties": {
49
+ "stage": { "const": "staff" }, "method": { "const": "POST" },
50
+ "path": { "const": "youzan.shop.single.staff.get/1.0.0" },
51
+ "body": { "type": "object", "required": ["account"], "additionalProperties": false, "properties": { "account": { "const": "***" } } }
52
+ }
53
+ }
54
+ ]
55
+ }
56
+ }
57
+ },
58
+ "error": {
59
+ "type": "object", "required": ["success", "code", "message", "details"], "additionalProperties": false,
60
+ "properties": {
61
+ "success": { "const": false }, "code": { "const": -10001 }, "message": { "type": "string", "minLength": 1 },
62
+ "details": {
63
+ "type": "object", "required": ["category", "stage", "command", "targetScope", "requestState", "nextStep"], "additionalProperties": false,
64
+ "properties": {
65
+ "category": { "enum": ["parameter", "validation", "configuration", "authentication", "permission", "scope_unresolved", "transport", "http", "protocol", "business_rejected"] },
66
+ "stage": { "enum": ["input", "context", "scope", "configuration", "shop-binding", "staff", "staff-model", "staff-roles", "transport", "http", "response"] },
67
+ "command": { "const": "org.staff-role.get" },
68
+ "targetScope": { "type": "object", "additionalProperties": false, "properties": { "kdtId": { "$ref": "#/definitions/shopId" } } },
69
+ "requestState": { "enum": ["not_sent", "sent", "unknown"] },
70
+ "nextStep": { "type": "string", "minLength": 1 },
71
+ "api": { "type": "string" }, "httpStatus": { "type": "integer" },
72
+ "businessCode": { "$ref": "#/definitions/diagnosticCode" }, "gatewayCode": { "$ref": "#/definitions/diagnosticCode" },
73
+ "trace_id": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,128}$" },
74
+ "request_id": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,128}$" }
75
+ }
76
+ }
77
+ }
78
+ },
79
+ "definitions": {
80
+ "shopId": { "type": "integer", "minimum": 1, "maximum": 9007199254740991, "description": "当前上下文微商城单店标识;凭证与返回的员工必须属于该店。" },
81
+ "diagnosticCode": { "anyOf": [{ "type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991 }, { "type": "string", "pattern": "^-?\\d{1,12}$" }] }
82
+ },
83
+ "modules": { "roles": { "base": true, "required": true, "upstreamPath": "data.roles", "description": "当前员工的角色关联,全部校验通过才输出。" } },
84
+ "api": { "method": "POST", "path": "youzan.shop.single.staff.get/1.0.0" },
85
+ "success": { "description": "同店及单店组织核验通过,查询成功且员工店铺与角色模型完整后返回 data;明确的空角色数组可成功。" },
86
+ "errors": { "description": "缺失、错型或冲突成功信号均失败;不会补成空角色。HTTP 401/403 保留认证或权限类别,断连状态为 unknown。失败 stdout 为空,stderr 为单一脱敏错误,不自动重试。" },
87
+ "notes": [
88
+ "仅当前授权微商城单店;单店组织角色不证明产品或员工权限,仍由主接口与网关校验。",
89
+ "最多两请求,使用同一基址和凭证快照;不扫描、跨店回退或自动重试。",
90
+ "dry-run 不读凭证、不联网,账号固定掩码;没有上下文时需要显式同店目标才能预览。",
91
+ "不提供角色筛选、角色目录、完整权限或可授予性判断。"
92
+ ]
93
+ }
@@ -0,0 +1,131 @@
1
+ 'use strict';
2
+
3
+ const { withTargetShopDefault } = require('../../../../../execution/target-shop-default');
4
+
5
+ const { Command, Option } = require('commander');
6
+ const schema = require('./schema.json');
7
+ const { resolveTargetShop } = require('../../../../../execution/target-shop');
8
+ const { readContext } = require('../../../../../identity/context');
9
+ const { validateCommandValue } = require('../../../../../execution/command-schema');
10
+ const { object } = require('../../../../../execution/query-api');
11
+ const { createBoundShopQuery, failure, bindingPath } = require('../../../../../execution/shop-query');
12
+
13
+ const command = 'org.unit.get';
14
+ const configPath = 'youzan.shop.configs.get/2.0.0';
15
+ const reject = (category, stage, scope, state, facts) =>
16
+ failure(command, category, stage, scope, state, facts);
17
+
18
+ function buildInput(options, context) {
19
+ let scope;
20
+ try {
21
+ scope = resolveTargetShop(options, context, command);
22
+ } catch (error) {
23
+ if (error.cliDetails?.stage === 'validation') error.cliDetails.stage = 'input';
24
+ throw error;
25
+ }
26
+ const state = readContext(context);
27
+ if (state.status === 'ready' && String(scope.kdtId) !== state.context.shopId) {
28
+ throw reject('permission', 'scope', scope);
29
+ }
30
+ try {
31
+ const include = options.include === undefined ? [] :
32
+ [...new Set(options.include.split(',').map(value => value.trim()))];
33
+ const input = { ...scope, include };
34
+ validateCommandValue(schema, 'input', input);
35
+ return input;
36
+ } catch {
37
+ throw reject('parameter', 'input', scope);
38
+ }
39
+ }
40
+
41
+ function previewFor(input) {
42
+ const requests = [{ stage: 'unit-basic', method: 'POST', path: bindingPath, body: {} }];
43
+ if (input.include.includes('operation-status')) {
44
+ requests.push({ stage: 'operation-status', method: 'POST', path: configPath,
45
+ body: { keys: ['shop_operation_status'], node_kdt_ids: [input.kdtId] } });
46
+ }
47
+ return { scope: { kdtId: input.kdtId }, requests, selection: { include: input.include } };
48
+ }
49
+
50
+ function optionalFields(source, mapping) {
51
+ const result = {};
52
+ for (const [field, upstream] of Object.entries(mapping)) {
53
+ if (source[upstream] !== undefined && source[upstream] !== null) result[field] = source[upstream];
54
+ }
55
+ return result;
56
+ }
57
+
58
+ function projectUnit(data, include) {
59
+ const unit = { kdtId: data.sid, name: data.name, orgRole: data.role,
60
+ ...optionalFields(data, { rootKdtId: 'root_kdt_id', parentKdtId: 'parent_kdt_id',
61
+ lineOfBusiness: 'line_of_business', certType: 'cert_type', logo: 'logo',
62
+ intro: 'intro', url: 'url', physicalUrl: 'physical_url' }) };
63
+ if (include.includes('address')) {
64
+ if (!object(data.shop_address)) throw new Error('invalid address');
65
+ unit.address = { address: data.shop_address.address,
66
+ ...optionalFields(data.shop_address, { province: 'province', city: 'city', county: 'county',
67
+ countyId: 'county_id', lng: 'lng', lat: 'lat' }) };
68
+ }
69
+ if (include.includes('contact')) {
70
+ if (!object(data.customer_service_phone_number)) throw new Error('invalid contact');
71
+ unit.contact = { phoneNumber: data.customer_service_phone_number.phone_number,
72
+ ...optionalFields(data.customer_service_phone_number, { areaCode: 'area_code' }) };
73
+ }
74
+ validateCommandValue(schema, 'output', { data: { unit } });
75
+ return unit;
76
+ }
77
+
78
+ async function execute(input, preview) {
79
+ const scope = { kdtId: input.kdtId };
80
+ const { read, binding } = await createBoundShopQuery(scope, command, 'unit-basic');
81
+ let unit;
82
+ try {
83
+ unit = projectUnit(binding.data, input.include);
84
+ } catch {
85
+ throw reject('protocol', 'unit-model', scope, 'sent', binding.facts);
86
+ }
87
+ if (input.include.includes('operation-status')) {
88
+ const request = preview.requests[1];
89
+ const { data, facts } = await read(request.path, request.body, request.stage);
90
+ const invalid = category => reject(category, request.stage, scope, 'sent', facts);
91
+ if (!Array.isArray(data)) throw invalid('protocol');
92
+ if (data.some(row => !object(row) || !Number.isSafeInteger(row.node_kdt_id) || row.node_kdt_id < 1)) {
93
+ throw invalid('protocol');
94
+ }
95
+ const matches = data.filter(row => row.node_kdt_id === input.kdtId);
96
+ if (matches.length === 0) throw invalid('scope_unresolved');
97
+ if (matches.length !== 1) throw invalid('protocol');
98
+ const configs = matches[0].configs;
99
+ if (!object(configs) || typeof configs.shop_operation_status !== 'string' ||
100
+ !/^[0-3]$/.test(configs.shop_operation_status)) throw invalid('protocol');
101
+ unit.operationStatus = Number(configs.shop_operation_status);
102
+ }
103
+ const output = { data: { unit } };
104
+ validateCommandValue(schema, 'output', output);
105
+ return output;
106
+ }
107
+
108
+ function createCommand({ context } = {}) {
109
+ return new Command('get')
110
+ .description('查询当前授权组织的资料与可选运营状态,不支持临时切换到其他组织')
111
+ .allowExcessArguments(false)
112
+ .exitOverride(error => {
113
+ if (['commander.helpDisplayed', 'commander.version'].includes(error.code)) throw error;
114
+ throw reject('parameter', 'input');
115
+ })
116
+ .option('--kdt-id <id>', '当前组织正安全整数;省略取上下文 shopId,总部也不可跨目标')
117
+ .option('--include <modules>', '可选 address,contact,operation-status;逗号分隔')
118
+ .addOption(new Option('--format <format>', 'json 或 pretty,仅改变缩进')
119
+ .choices(['json', 'pretty']).default('json'))
120
+ .option('--dry-run', '仅本地预览有序请求;不读凭证、不联网')
121
+ .addHelpText('after', '\n默认一次请求;地址和电话不追加请求,运营状态最多追加一次。失败不输出部分资料。\n组织角色不是员工权限角色;不返回店铺类型、QQ、升级历史或任意配置。员工授权与产品支持以服务端为准。\n契约:zan-saas schema org.unit.get --format json\n示例:zan-saas org unit get --kdt-id 63077 --include address,operation-status --dry-run')
122
+ .action(async options => {
123
+ const input = buildInput(options, context);
124
+ const preview = previewFor(input);
125
+ validateCommandValue(schema, 'preview', preview);
126
+ const result = options.dryRun ? preview : await execute(input, preview);
127
+ console.log(JSON.stringify(result, null, options.format === 'pretty' ? 2 : 0));
128
+ });
129
+ }
130
+
131
+ module.exports = { kind: 'atomic', risk: 'read', at: 'all', createCommand: withTargetShopDefault(createCommand) };