@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.
- package/DEPENDENCIES.json +50 -0
- package/INSTALL.md +79 -0
- package/LICENSE +21 -0
- package/NOTICE +1 -0
- package/README.md +151 -2
- package/THIRD_PARTY_NOTICES.txt +162 -0
- package/bin/zan-saas-cli.js +28 -0
- package/internal/registry/index.js +123 -0
- package/internal/registry/manifest.json +424 -0
- package/npm-shrinkwrap.json +86 -0
- package/package.json +33 -4
- package/skills/README.md +30 -0
- package/skills/zan-saas/SKILL.md +54 -0
- package/skills/zan-saas/references/host-entry.md +25 -0
- package/skills/zan-saas-access/SKILL.md +37 -0
- package/skills/zan-saas-access/references/role-list.md +11 -0
- package/skills/zan-saas-access/references/staff-perms-get.md +11 -0
- package/skills/zan-saas-aftersale/SKILL.md +31 -0
- package/skills/zan-saas-aftersale/references/case-list.md +13 -0
- package/skills/zan-saas-aftersale/references/case-scan.md +31 -0
- package/skills/zan-saas-benefit/SKILL.md +46 -0
- package/skills/zan-saas-benefit/references/card-get.md +7 -0
- package/skills/zan-saas-benefit/references/card-grant-list.md +11 -0
- package/skills/zan-saas-benefit/references/card-list.md +7 -0
- package/skills/zan-saas-benefit/references/customer-card-get.md +7 -0
- package/skills/zan-saas-benefit/references/customer-card-list.md +7 -0
- package/skills/zan-saas-coupon/SKILL.md +41 -0
- package/skills/zan-saas-coupon/references/activity-get.md +11 -0
- package/skills/zan-saas-coupon/references/activity-list.md +15 -0
- package/skills/zan-saas-coupon/references/voucher-get.md +13 -0
- package/skills/zan-saas-coupon/references/voucher-list.md +25 -0
- package/skills/zan-saas-customer/SKILL.md +73 -0
- package/skills/zan-saas-customer/references/customer-scan.md +11 -0
- package/skills/zan-saas-customer/references/segment-list.md +22 -0
- package/skills/zan-saas-fulfillment/SKILL.md +36 -0
- package/skills/zan-saas-fulfillment/references/delivery-get.md +11 -0
- package/skills/zan-saas-fulfillment/references/shipment-list.md +11 -0
- package/skills/zan-saas-fulfillment/references/waybill-get.md +9 -0
- package/skills/zan-saas-interaction/SKILL.md +37 -0
- package/skills/zan-saas-interaction/references/lottery-get.md +11 -0
- package/skills/zan-saas-interaction/references/lottery-list.md +19 -0
- package/skills/zan-saas-item/SKILL.md +61 -0
- package/skills/zan-saas-item/references/attribute-list.md +11 -0
- package/skills/zan-saas-item/references/brand-list.md +7 -0
- package/skills/zan-saas-item/references/classification-get.md +7 -0
- package/skills/zan-saas-item/references/classification-list.md +7 -0
- package/skills/zan-saas-item/references/group-list.md +9 -0
- package/skills/zan-saas-item/references/item-content.md +9 -0
- package/skills/zan-saas-item/references/item-get.md +9 -0
- package/skills/zan-saas-item/references/item-search.md +23 -0
- package/skills/zan-saas-item/references/product-identity.md +11 -0
- package/skills/zan-saas-member/SKILL.md +41 -0
- package/skills/zan-saas-member/references/customer-level-get.md +7 -0
- package/skills/zan-saas-member/references/growth-log-list.md +17 -0
- package/skills/zan-saas-member/references/membership-get.md +7 -0
- package/skills/zan-saas-order/SKILL.md +56 -0
- package/skills/zan-saas-order/references/order-get.md +26 -0
- package/skills/zan-saas-order/references/order-list.md +25 -0
- package/skills/zan-saas-order/references/order-scan.md +35 -0
- package/skills/zan-saas-org/SKILL.md +37 -0
- package/skills/zan-saas-org/references/staff-get.md +15 -0
- package/skills/zan-saas-org/references/staff-role-get.md +11 -0
- package/skills/zan-saas-org/references/unit-get.md +11 -0
- package/skills/zan-saas-org/references/unit-list.md +15 -0
- package/skills/zan-saas-points/SKILL.md +42 -0
- package/skills/zan-saas-points/references/account-get.md +7 -0
- package/skills/zan-saas-points/references/log-list.md +17 -0
- package/skills/zan-saas-points/references/rule-list.md +2 -0
- package/skills/zan-saas-privacy/SKILL.md +30 -0
- package/skills/zan-saas-privacy/references/field-decrypt.md +19 -0
- package/skills/zan-saas-shared/SKILL.md +94 -0
- package/skills/zan-saas-shared/references/authentication.md +52 -0
- package/skills/zan-saas-shared/references/value-processing.md +27 -0
- package/skills/zan-saas-stock/SKILL.md +28 -0
- package/skills/zan-saas-stock/references/log-list.md +11 -0
- package/skills/zan-saas-valuecard/SKILL.md +37 -0
- package/skills/zan-saas-valuecard/references/card-get.md +13 -0
- package/skills/zan-saas-valuecard/references/card-list.md +11 -0
- package/src/auth/browser.js +28 -0
- package/src/auth/callback-server.js +99 -0
- package/src/auth/config.js +53 -0
- package/src/auth/credential-store.js +109 -0
- package/src/auth/oauth-client.js +105 -0
- package/src/auth/pkce.js +28 -0
- package/src/auth/session.js +178 -0
- package/src/auth/tool.js +25 -0
- package/src/cli/command-paths.js +126 -0
- package/src/cli/context-help.js +102 -0
- package/src/cli/diagnostic-command.js +57 -0
- package/src/cli/domain-catalog.js +42 -0
- package/src/cli/help-text.js +32 -0
- package/src/cli/native-loader.js +120 -0
- package/src/cli/native-path.js +22 -0
- package/src/cli/parser-policy.js +141 -0
- package/src/cli/program.js +134 -0
- package/src/cli/skill-catalog.js +241 -0
- package/src/commands/native/access/commands.index.json +24 -0
- package/src/commands/native/access/domain.json +3 -0
- package/src/commands/native/access/role/list/command.js +141 -0
- package/src/commands/native/access/role/list/schema.json +393 -0
- package/src/commands/native/access/staff-perms/get/command.js +119 -0
- package/src/commands/native/access/staff-perms/get/schema.json +703 -0
- package/src/commands/native/aftersale/case/get/command.js +104 -0
- package/src/commands/native/aftersale/case/get/exact-json.js +52 -0
- package/src/commands/native/aftersale/case/get/money.js +28 -0
- package/src/commands/native/aftersale/case/get/projection.js +120 -0
- package/src/commands/native/aftersale/case/get/query.js +72 -0
- package/src/commands/native/aftersale/case/get/schema.json +134 -0
- package/src/commands/native/aftersale/case/list/command.js +135 -0
- package/src/commands/native/aftersale/case/list/schema.json +1095 -0
- package/src/commands/native/aftersale/case/scan/command.js +110 -0
- package/src/commands/native/aftersale/case/scan/query.js +62 -0
- package/src/commands/native/aftersale/case/scan/scan.js +78 -0
- package/src/commands/native/aftersale/case/scan/schema.json +964 -0
- package/src/commands/native/aftersale/case/scan/search.js +108 -0
- package/src/commands/native/aftersale/commands.index.json +42 -0
- package/src/commands/native/aftersale/domain.json +3 -0
- package/src/commands/native/aftersale/refund/list/command.js +97 -0
- package/src/commands/native/aftersale/refund/list/money.js +25 -0
- package/src/commands/native/aftersale/refund/list/projection.js +50 -0
- package/src/commands/native/aftersale/refund/list/query.js +73 -0
- package/src/commands/native/aftersale/refund/list/schema.json +130 -0
- package/src/commands/native/aftersale/shared/query.js +58 -0
- package/src/commands/native/aftersale/shared/search.js +128 -0
- package/src/commands/native/benefit/card-definition/get/command.js +110 -0
- package/src/commands/native/benefit/card-definition/get/schema.json +545 -0
- package/src/commands/native/benefit/card-definition/list/command.js +105 -0
- package/src/commands/native/benefit/card-definition/list/schema.json +690 -0
- package/src/commands/native/benefit/card-grant/list/command.js +135 -0
- package/src/commands/native/benefit/card-grant/list/schema.json +758 -0
- package/src/commands/native/benefit/commands.index.json +51 -0
- package/src/commands/native/benefit/customer-card/get/command.js +110 -0
- package/src/commands/native/benefit/customer-card/get/schema.json +340 -0
- package/src/commands/native/benefit/customer-card/list/command.js +102 -0
- package/src/commands/native/benefit/customer-card/list/schema.json +731 -0
- package/src/commands/native/benefit/domain.json +3 -0
- package/src/commands/native/coupon/activity/get/command.js +183 -0
- package/src/commands/native/coupon/activity/get/schema.json +624 -0
- package/src/commands/native/coupon/activity/list/command.js +169 -0
- package/src/commands/native/coupon/activity/list/schema.json +845 -0
- package/src/commands/native/coupon/commands.index.json +42 -0
- package/src/commands/native/coupon/domain.json +3 -0
- package/src/commands/native/coupon/shared/query.js +15 -0
- package/src/commands/native/coupon/voucher/get/command.js +113 -0
- package/src/commands/native/coupon/voucher/get/schema.json +147 -0
- package/src/commands/native/coupon/voucher/list/command.js +155 -0
- package/src/commands/native/coupon/voucher/list/schema.json +772 -0
- package/src/commands/native/customer/commands.index.json +96 -0
- package/src/commands/native/customer/customer/get/adapter.js +82 -0
- package/src/commands/native/customer/customer/get/command.js +106 -0
- package/src/commands/native/customer/customer/get/schema.json +958 -0
- package/src/commands/native/customer/customer/list/command.js +78 -0
- package/src/commands/native/customer/customer/list/input.js +145 -0
- package/src/commands/native/customer/customer/list/query.js +103 -0
- package/src/commands/native/customer/customer/list/schema.json +969 -0
- package/src/commands/native/customer/customer/scan/command.js +80 -0
- package/src/commands/native/customer/customer/scan/scan.js +92 -0
- package/src/commands/native/customer/customer/scan/schema.json +211 -0
- package/src/commands/native/customer/customer-tag/get/command.js +166 -0
- package/src/commands/native/customer/customer-tag/get/schema.json +317 -0
- package/src/commands/native/customer/customer-tag/list/command.js +143 -0
- package/src/commands/native/customer/customer-tag/list/schema.json +259 -0
- package/src/commands/native/customer/domain.json +3 -0
- package/src/commands/native/customer/segment/list/command.js +96 -0
- package/src/commands/native/customer/segment/list/query.js +98 -0
- package/src/commands/native/customer/segment/list/schema.json +135 -0
- package/src/commands/native/customer/segment-customer/list/command.js +171 -0
- package/src/commands/native/customer/segment-customer/list/schema.json +123 -0
- package/src/commands/native/customer/shared/search-input.js +179 -0
- package/src/commands/native/customer/shared/search-page.js +54 -0
- package/src/commands/native/customer/tag/get/command.js +73 -0
- package/src/commands/native/customer/tag/get/schema.json +339 -0
- package/src/commands/native/customer/tagcategory/get/command.js +80 -0
- package/src/commands/native/customer/tagcategory/get/query.js +98 -0
- package/src/commands/native/customer/tagcategory/get/schema.json +339 -0
- package/src/commands/native/customer/tagcategory/list/command.js +127 -0
- package/src/commands/native/customer/tagcategory/list/schema.json +394 -0
- package/src/commands/native/fulfillment/commands.index.json +33 -0
- package/src/commands/native/fulfillment/delivery/get/command.js +107 -0
- package/src/commands/native/fulfillment/delivery/get/projection.js +142 -0
- package/src/commands/native/fulfillment/delivery/get/schema.json +173 -0
- package/src/commands/native/fulfillment/domain.json +3 -0
- package/src/commands/native/fulfillment/shipment/list/command.js +83 -0
- package/src/commands/native/fulfillment/shipment/list/projection.js +130 -0
- package/src/commands/native/fulfillment/shipment/list/schema.json +752 -0
- package/src/commands/native/fulfillment/waybill/get/command.js +193 -0
- package/src/commands/native/fulfillment/waybill/get/response.js +68 -0
- package/src/commands/native/fulfillment/waybill/get/schema.json +190 -0
- package/src/commands/native/interaction/commands.index.json +24 -0
- package/src/commands/native/interaction/domain.json +3 -0
- package/src/commands/native/interaction/lottery/get/command.js +61 -0
- package/src/commands/native/interaction/lottery/get/query.js +152 -0
- package/src/commands/native/interaction/lottery/get/schema.json +1004 -0
- package/src/commands/native/interaction/lottery/list/command.js +176 -0
- package/src/commands/native/interaction/lottery/list/schema.json +898 -0
- package/src/commands/native/item/attribute/list/command.js +122 -0
- package/src/commands/native/item/attribute/list/schema.json +727 -0
- package/src/commands/native/item/brand/list/command.js +114 -0
- package/src/commands/native/item/brand/list/schema.json +725 -0
- package/src/commands/native/item/classification/get/command.js +87 -0
- package/src/commands/native/item/classification/get/schema.json +596 -0
- package/src/commands/native/item/classification/list/command.js +105 -0
- package/src/commands/native/item/classification/list/schema.json +676 -0
- package/src/commands/native/item/commands.index.json +87 -0
- package/src/commands/native/item/domain.json +1 -0
- package/src/commands/native/item/group/list/command.js +122 -0
- package/src/commands/native/item/group/list/schema.json +809 -0
- package/src/commands/native/item/item/get/command.js +122 -0
- package/src/commands/native/item/item/get/schema.json +3799 -0
- package/src/commands/native/item/item/list/command.js +7 -0
- package/src/commands/native/item/item/list/schema.json +1118 -0
- package/src/commands/native/item/item/scan/command.js +7 -0
- package/src/commands/native/item/item/scan/schema.json +1046 -0
- package/src/commands/native/item/item-content/get/command.js +54 -0
- package/src/commands/native/item/item-content/get/schema.json +677 -0
- package/src/commands/native/item/shared/api.js +31 -0
- package/src/commands/native/item/shared/content.js +20 -0
- package/src/commands/native/item/shared/diagnostics.js +61 -0
- package/src/commands/native/item/shared/h5.js +63 -0
- package/src/commands/native/item/shared/identity.js +62 -0
- package/src/commands/native/item/shared/normalize.js +49 -0
- package/src/commands/native/item/shared/scope.js +22 -0
- package/src/commands/native/item/shared/search-command.js +61 -0
- package/src/commands/native/item/shared/search-options.js +150 -0
- package/src/commands/native/item/shared/search.js +158 -0
- package/src/commands/native/member/commands.index.json +60 -0
- package/src/commands/native/member/customer-level/get/command.js +122 -0
- package/src/commands/native/member/customer-level/get/schema.json +300 -0
- package/src/commands/native/member/domain.json +3 -0
- package/src/commands/native/member/growth/get/command.js +64 -0
- package/src/commands/native/member/growth/get/schema.json +283 -0
- package/src/commands/native/member/growth-log/list/command.js +203 -0
- package/src/commands/native/member/growth-log/list/schema.json +695 -0
- package/src/commands/native/member/level/get/command.js +70 -0
- package/src/commands/native/member/level/get/query.js +125 -0
- package/src/commands/native/member/level/get/schema.json +339 -0
- package/src/commands/native/member/level/list/command.js +50 -0
- package/src/commands/native/member/level/list/query.js +109 -0
- package/src/commands/native/member/level/list/schema.json +104 -0
- package/src/commands/native/member/membership/get/command.js +78 -0
- package/src/commands/native/member/membership/get/schema.json +283 -0
- package/src/commands/native/order/commands.index.json +33 -0
- package/src/commands/native/order/domain.json +3 -0
- package/src/commands/native/order/order/get/command.js +155 -0
- package/src/commands/native/order/order/get/schema.json +1167 -0
- package/src/commands/native/order/order/list/command.js +230 -0
- package/src/commands/native/order/order/list/schema.json +1363 -0
- package/src/commands/native/order/order/scan/command.js +148 -0
- package/src/commands/native/order/order/scan/scan.js +89 -0
- package/src/commands/native/order/order/scan/schema.json +1445 -0
- package/src/commands/native/order/shared/projection.js +183 -0
- package/src/commands/native/order/shared/query.js +84 -0
- package/src/commands/native/order/shared/search.js +112 -0
- package/src/commands/native/org/commands.index.json +42 -0
- package/src/commands/native/org/domain.json +3 -0
- package/src/commands/native/org/shared/single-staff.js +115 -0
- package/src/commands/native/org/staff/get/command.js +148 -0
- package/src/commands/native/org/staff/get/schema.json +114 -0
- package/src/commands/native/org/staff-role/get/command.js +45 -0
- package/src/commands/native/org/staff-role/get/schema.json +93 -0
- package/src/commands/native/org/unit/get/command.js +131 -0
- package/src/commands/native/org/unit/get/schema.json +478 -0
- package/src/commands/native/org/unit/list/command.js +187 -0
- package/src/commands/native/org/unit/list/schema.json +828 -0
- package/src/commands/native/points/account/get/command.js +65 -0
- package/src/commands/native/points/account/get/schema.json +303 -0
- package/src/commands/native/points/commands.index.json +33 -0
- package/src/commands/native/points/domain.json +3 -0
- package/src/commands/native/points/log/list/command.js +141 -0
- package/src/commands/native/points/log/list/schema.json +761 -0
- package/src/commands/native/points/rule/list/command.js +82 -0
- package/src/commands/native/points/rule/list/schema.json +294 -0
- package/src/commands/native/privacy/commands.index.json +15 -0
- package/src/commands/native/privacy/domain.json +3 -0
- package/src/commands/native/privacy/field/decrypt/command.js +185 -0
- package/src/commands/native/privacy/field/decrypt/schema.json +656 -0
- package/src/commands/native/privacy/shared/order-source.js +33 -0
- package/src/commands/native/stock/commands.index.json +15 -0
- package/src/commands/native/stock/domain.json +3 -0
- package/src/commands/native/stock/log/list/command.js +207 -0
- package/src/commands/native/stock/log/list/schema.json +922 -0
- package/src/commands/native/valuecard/card/get/command.js +107 -0
- package/src/commands/native/valuecard/card/get/schema.json +683 -0
- package/src/commands/native/valuecard/card/list/command.js +136 -0
- package/src/commands/native/valuecard/card/list/pagination.js +23 -0
- package/src/commands/native/valuecard/card/list/schema.json +780 -0
- package/src/commands/native/valuecard/commands.index.json +24 -0
- package/src/commands/native/valuecard/domain.json +3 -0
- package/src/commands/native/valuecard/shared/projection.js +57 -0
- package/src/commands/system/api.js +47 -0
- package/src/commands/system/auth.js +118 -0
- package/src/commands/system/contracts.js +373 -0
- package/src/commands/system/doctor.js +24 -0
- package/src/commands/system/install.js +41 -0
- package/src/commands/system/printer.js +16 -0
- package/src/commands/system/schema.js +162 -0
- package/src/commands/system/shop-guidance.js +9 -0
- package/src/commands/system/shop.js +237 -0
- package/src/commands/system/skills.js +49 -0
- package/src/execution/beijing-date-time.js +29 -0
- package/src/execution/beijing-time.js +21 -0
- package/src/execution/bounded-input.js +42 -0
- package/src/execution/command-io.js +137 -0
- package/src/execution/command-policy.js +41 -0
- package/src/execution/command-schema.js +131 -0
- package/src/execution/datetime.js +83 -0
- package/src/execution/error-details.js +399 -0
- package/src/execution/error-model.js +82 -0
- package/src/execution/exact-json.js +80 -0
- package/src/execution/list-total.js +10 -0
- package/src/execution/money.js +59 -0
- package/src/execution/parser-error.js +66 -0
- package/src/execution/privacy.js +197 -0
- package/src/execution/public-schema.js +52 -0
- package/src/execution/query-api.js +101 -0
- package/src/execution/range.js +84 -0
- package/src/execution/request-state.js +55 -0
- package/src/execution/schema-completeness.js +116 -0
- package/src/execution/shop-query.js +54 -0
- package/src/execution/target-shop-default.js +23 -0
- package/src/execution/target-shop.js +49 -0
- package/src/identity/context-store.js +54 -0
- package/src/identity/context.js +38 -0
- package/src/installation/install.js +158 -0
- package/src/installation/npm-error.js +93 -0
- package/src/installation/skill.js +113 -0
- package/src/transport/account-api.js +152 -0
- package/src/transport/api.js +199 -0
- package/src/transport/shop-app.js +63 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 3,
|
|
3
|
+
"domain": "coupon",
|
|
4
|
+
"businessCommands": [
|
|
5
|
+
{
|
|
6
|
+
"path": "coupon.activity.get",
|
|
7
|
+
"kind": "atomic",
|
|
8
|
+
"risk": "read",
|
|
9
|
+
"availability": "available",
|
|
10
|
+
"at": "all",
|
|
11
|
+
"module": "coupon/activity/get/command.js",
|
|
12
|
+
"fingerprint": "8eb9727bc232a48fe2b59ddffb8dd905e55504bba87887a5a73fdd8ebf7a064e"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"path": "coupon.activity.list",
|
|
16
|
+
"kind": "atomic",
|
|
17
|
+
"risk": "read",
|
|
18
|
+
"availability": "available",
|
|
19
|
+
"at": "all",
|
|
20
|
+
"module": "coupon/activity/list/command.js",
|
|
21
|
+
"fingerprint": "fb6320dced053084ee34b8b4952af462882334463cab76e038dd7b2cb7f7b24b"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "coupon.voucher.get",
|
|
25
|
+
"kind": "atomic",
|
|
26
|
+
"risk": "read",
|
|
27
|
+
"availability": "available",
|
|
28
|
+
"at": "all",
|
|
29
|
+
"module": "coupon/voucher/get/command.js",
|
|
30
|
+
"fingerprint": "b4838c07ac5042f9a807954f2afc484ba1602b62141905446eef659b85bf08eb"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"path": "coupon.voucher.list",
|
|
34
|
+
"kind": "atomic",
|
|
35
|
+
"risk": "read",
|
|
36
|
+
"availability": "available",
|
|
37
|
+
"at": "all",
|
|
38
|
+
"module": "coupon/voucher/list/command.js",
|
|
39
|
+
"fingerprint": "d0a09a0443614d23ef3f2d52579e6430af86017d2dd5996428a8829895870c6d"
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { resolveTargetShop } = require('../../../../execution/target-shop');
|
|
4
|
+
const { createShopQuery, failure, bindingPath } = require('../../../../execution/shop-query');
|
|
5
|
+
|
|
6
|
+
function resolveScope(options, context, command) {
|
|
7
|
+
try { return resolveTargetShop(options, context, command); }
|
|
8
|
+
catch (error) {
|
|
9
|
+
if (!error.cliDetails) throw error;
|
|
10
|
+
const { category, targetScope } = error.cliDetails;
|
|
11
|
+
throw failure(command, category, category === 'configuration' ? 'configuration' : 'input', targetScope);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports = { resolveScope, createShopQuery, failure, bindingPath };
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { withTargetShopDefault } = require('../../../../../execution/target-shop-default');
|
|
4
|
+
|
|
5
|
+
const { Command, Option } = require('commander');
|
|
6
|
+
const { resolveScope, createShopQuery, failure, bindingPath } = require('../../shared/query');
|
|
7
|
+
const { validateCommandValue } = require('../../../../../execution/command-schema');
|
|
8
|
+
const { object } = require('../../../../../execution/query-api');
|
|
9
|
+
const { formatDateTime } = require('../../../../../execution/datetime');
|
|
10
|
+
const schema = require('./schema.json');
|
|
11
|
+
|
|
12
|
+
const command = 'coupon.voucher.get';
|
|
13
|
+
const reject = (category, stage, scope, state, facts) =>
|
|
14
|
+
failure(command, category, stage, scope, state, facts);
|
|
15
|
+
|
|
16
|
+
function timestamp(value) {
|
|
17
|
+
if (!Number.isSafeInteger(value) || value < 1) throw new Error('Invalid milliseconds');
|
|
18
|
+
return formatDateTime(value);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function project(data, input, facts) {
|
|
22
|
+
const scope = { kdtId: input.kdtId };
|
|
23
|
+
const invalid = () => reject('protocol', 'response', scope, 'sent', facts);
|
|
24
|
+
if (!object(data) || !object(data.voucher_identity)) throw invalid();
|
|
25
|
+
const identity = data.voucher_identity;
|
|
26
|
+
if (identity.coupon_id !== input.voucherId ||
|
|
27
|
+
identity.coupon_type !== (input.form === 'card' ? 0 : 1)) throw invalid();
|
|
28
|
+
if (!Number.isSafeInteger(data.kdt_id) || data.kdt_id < 1) throw invalid();
|
|
29
|
+
if (data.kdt_id !== input.kdtId) {
|
|
30
|
+
throw reject('scope_unresolved', 'response', scope, 'sent', facts);
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
if (data.valid_start_time > data.valid_end_time) throw invalid();
|
|
34
|
+
const voucher = {
|
|
35
|
+
voucherId: identity.coupon_id, form: input.form, ownerKdtId: data.kdt_id,
|
|
36
|
+
activityId: data.activity_id, status: data.status,
|
|
37
|
+
validity: { startAt: timestamp(data.valid_start_time), endAt: timestamp(data.valid_end_time) }
|
|
38
|
+
};
|
|
39
|
+
if (Object.hasOwn(data, 'send_at')) voucher.sentAt = timestamp(data.send_at);
|
|
40
|
+
if (Object.hasOwn(data, 'user_identity')) {
|
|
41
|
+
if (!object(data.user_identity)) throw invalid();
|
|
42
|
+
if (Object.hasOwn(data.user_identity, 'yz_open_id')) {
|
|
43
|
+
voucher.holder = { yzOpenId: data.user_identity.yz_open_id };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (Object.hasOwn(data, 'used_order_no')) voucher.usage = { orderNo: data.used_order_no };
|
|
47
|
+
const output = { data: { voucher } };
|
|
48
|
+
validateCommandValue(schema, 'output', output);
|
|
49
|
+
return output;
|
|
50
|
+
} catch { throw invalid(); }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function createCommand({ context } = {}) {
|
|
54
|
+
return new Command('get')
|
|
55
|
+
.description('根据持券 ID 和券形态查询一张客户持有的券')
|
|
56
|
+
.allowExcessArguments(false)
|
|
57
|
+
.exitOverride(error => {
|
|
58
|
+
if (['commander.helpDisplayed', 'commander.version'].includes(error.code)) throw error;
|
|
59
|
+
throw reject('parameter', 'input');
|
|
60
|
+
})
|
|
61
|
+
.addOption(new Option('--form <form>', '必填:card 优惠卡券,code 优惠码;不猜测持券类型')
|
|
62
|
+
.choices(['card', 'code']).makeOptionMandatory())
|
|
63
|
+
.requiredOption('--voucher-id <id>', '必填:持券 ID,十进制正安全整数;不是活动 ID 或核销码')
|
|
64
|
+
.option('--kdt-id <id>', '目标店铺正安全整数;省略取有效上下文 shopId,非总部不可跨店')
|
|
65
|
+
.addOption(new Option('--format <format>', 'json 或 pretty,仅改变缩进')
|
|
66
|
+
.choices(['json', 'pretty']).default('json'))
|
|
67
|
+
.option('--dry-run', '本地预览店铺核验和主请求,不读凭证、不联网')
|
|
68
|
+
.addHelpText('after', `
|
|
69
|
+
输出 data.voucher,身份由 form 与 voucherId 共同确定。状态 2 为已冻结;未来整数原样保留。
|
|
70
|
+
默认返回已有 holder 开放 ID、usage 订单引用;源缺失时省略,状态 2/3 不强制补订单。
|
|
71
|
+
有效期与发放时间为北京时间 YYYY-MM-DD HH:mm:ss.SSS,固定毫秒,不猜永久有效。
|
|
72
|
+
不提供 --include,不输出手机号、核销码、面额或活动规则;订单引用不证明支付或交易完成。
|
|
73
|
+
真实执行固定同店凭证,先核验店铺再查详情,最多两次请求;不重试、不切店、不补查。
|
|
74
|
+
支持微商城单店、连锁 D 总部/网店/合伙人;零售单店不在本详情正式支持范围。
|
|
75
|
+
同店核验不证明店铺员工 OAuth 或跨店授权,券状态不证明可用于某笔订单。
|
|
76
|
+
指引:zan-saas skills read zan-saas-coupon references/voucher-get.md
|
|
77
|
+
契约:zan-saas schema coupon.voucher.get
|
|
78
|
+
示例:zan-saas coupon voucher get --form card --voucher-id 2001 --kdt-id 63077 --dry-run
|
|
79
|
+
`)
|
|
80
|
+
.action(async options => {
|
|
81
|
+
const scope = resolveScope(options, context, command);
|
|
82
|
+
let input;
|
|
83
|
+
try {
|
|
84
|
+
if (!/^[1-9]\d*$/.test(options.voucherId)) throw new Error('Invalid ID');
|
|
85
|
+
input = { ...scope, form: options.form, voucherId: Number(options.voucherId) };
|
|
86
|
+
validateCommandValue(schema, 'input', input);
|
|
87
|
+
} catch { throw reject('validation', 'input', scope); }
|
|
88
|
+
const body = { coupon_id: input.voucherId, coupon_type: input.form === 'card' ? 0 : 1 };
|
|
89
|
+
const preview = {
|
|
90
|
+
scope, prerequisites: ['context', 'token-shop-binding'], requests: [
|
|
91
|
+
{ method: 'POST', api: bindingPath, body: {} },
|
|
92
|
+
{ method: 'POST', api: schema.api.path, body }
|
|
93
|
+
]
|
|
94
|
+
};
|
|
95
|
+
validateCommandValue(schema, 'preview', preview);
|
|
96
|
+
let output = preview;
|
|
97
|
+
if (!options.dryRun) {
|
|
98
|
+
const read = await createShopQuery(scope, command);
|
|
99
|
+
let result;
|
|
100
|
+
try { result = await read(schema.api.path, body, 'query'); }
|
|
101
|
+
catch (error) {
|
|
102
|
+
const details = error.cliDetails;
|
|
103
|
+
if (details?.category === 'business_rejected' && details.gatewayCode === undefined &&
|
|
104
|
+
String(details.businessCode) === '161201044') details.category = 'not_found';
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
output = project(result.data, input, result.facts);
|
|
108
|
+
}
|
|
109
|
+
process.stdout.write(`${JSON.stringify(output, null, options.format === 'pretty' ? 2 : 0)}\n`);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
module.exports = { kind: 'atomic', risk: 'read', at: 'all', createCommand: withTargetShopDefault(createCommand) };
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"input": {
|
|
4
|
+
"type": "object",
|
|
5
|
+
"description": "argv 解析并从有效上下文补全后的业务输入,不是 CLI JSON 或上游请求体。",
|
|
6
|
+
"required": ["form", "voucherId", "kdtId"],
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
"properties": {
|
|
9
|
+
"form": { "$ref": "#/definitions/form" },
|
|
10
|
+
"voucherId": { "$ref": "#/definitions/id", "description": "完整持券 ID,与 form 组成身份;不能用活动 ID、码号或核销码替代。" },
|
|
11
|
+
"kdtId": { "$ref": "#/definitions/id", "description": "目标店铺,省略选项时取有效 context.shopId;不表示已经获准访问。" }
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"output": {
|
|
15
|
+
"type": "object",
|
|
16
|
+
"required": ["data"],
|
|
17
|
+
"additionalProperties": false,
|
|
18
|
+
"properties": {
|
|
19
|
+
"data": {
|
|
20
|
+
"type": "object",
|
|
21
|
+
"required": ["voucher"],
|
|
22
|
+
"additionalProperties": false,
|
|
23
|
+
"properties": {
|
|
24
|
+
"voucher": {
|
|
25
|
+
"type": "object",
|
|
26
|
+
"required": ["voucherId", "form", "ownerKdtId", "activityId", "status", "validity"],
|
|
27
|
+
"additionalProperties": false,
|
|
28
|
+
"properties": {
|
|
29
|
+
"voucherId": { "$ref": "#/definitions/id", "description": "持券 ID,必须与输入一致。" },
|
|
30
|
+
"form": { "$ref": "#/definitions/form", "description": "持券形态,必须与输入一致。" },
|
|
31
|
+
"ownerKdtId": { "$ref": "#/definitions/id", "description": "持券归属店铺,必须等于目标店铺;不是发放店铺。" },
|
|
32
|
+
"activityId": { "$ref": "#/definitions/id", "description": "发行来源活动 ID;不是持券 ID,不补查当前活动规则。" },
|
|
33
|
+
"status": {
|
|
34
|
+
"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991,
|
|
35
|
+
"description": "1 正常,2 已冻结,3 已核销,4 不可用,5 已删除;未来安全整数原样保留,不当正常,也不证明订单可用。"
|
|
36
|
+
},
|
|
37
|
+
"validity": {
|
|
38
|
+
"type": "object", "required": ["startAt", "endAt"], "additionalProperties": false,
|
|
39
|
+
"description": "必需有效期,开始不晚于结束;未知、0 或 null 不能推导永久有效。",
|
|
40
|
+
"properties": {
|
|
41
|
+
"startAt": { "$ref": "#/definitions/time", "description": "有效期开始,源为正安全整数毫秒。" },
|
|
42
|
+
"endAt": { "$ref": "#/definitions/time", "description": "有效期结束,源为正安全整数毫秒。" }
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"sentAt": { "$ref": "#/definitions/time", "description": "发放时间,源为正安全整数毫秒;源省略时省略,null 或错型失败。" },
|
|
46
|
+
"holder": {
|
|
47
|
+
"type": "object", "required": ["yzOpenId"], "additionalProperties": false,
|
|
48
|
+
"description": "同次响应已有的持有人开放 ID,源省略时整组省略,不说明没有持有人。",
|
|
49
|
+
"properties": {
|
|
50
|
+
"yzOpenId": { "type": "string", "pattern": "\\S", "description": "客户开放 ID,非空文本;不是手机号、微信 openId 或操作员工 ID。" }
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"usage": {
|
|
54
|
+
"type": "object", "required": ["orderNo"], "additionalProperties": false,
|
|
55
|
+
"description": "同次响应已有的订单关联;源省略时整组省略,即使状态为 2/3 也不补造,不说明从未使用。",
|
|
56
|
+
"properties": {
|
|
57
|
+
"orderNo": { "type": "string", "pattern": "\\S", "description": "非空订单引用,不证明支付、交易完成或最终核销,不提供订单详情。" }
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"preview": {
|
|
67
|
+
"type": "object", "required": ["scope", "prerequisites", "requests"], "additionalProperties": false,
|
|
68
|
+
"properties": {
|
|
69
|
+
"scope": { "$ref": "#/definitions/scope" },
|
|
70
|
+
"prerequisites": { "type": "array", "items": { "type": "string" }, "const": ["context", "token-shop-binding"] },
|
|
71
|
+
"requests": {
|
|
72
|
+
"type": "array", "minItems": 2, "maxItems": 2,
|
|
73
|
+
"items": [
|
|
74
|
+
{
|
|
75
|
+
"type": "object", "required": ["method", "api", "body"], "additionalProperties": false,
|
|
76
|
+
"properties": {
|
|
77
|
+
"method": { "const": "POST" }, "api": { "const": "youzan.shop.basic.get/3.0.0" },
|
|
78
|
+
"body": { "type": "object", "additionalProperties": false, "maxProperties": 0 }
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"type": "object", "required": ["method", "api", "body"], "additionalProperties": false,
|
|
83
|
+
"properties": {
|
|
84
|
+
"method": { "const": "POST" }, "api": { "const": "youzan.ump.voucher.query.detail/1.0.1" },
|
|
85
|
+
"body": {
|
|
86
|
+
"type": "object", "required": ["coupon_id", "coupon_type"], "additionalProperties": false,
|
|
87
|
+
"properties": {
|
|
88
|
+
"coupon_id": { "$ref": "#/definitions/id" },
|
|
89
|
+
"coupon_type": { "type": "integer", "enum": [0, 1], "description": "0 优惠卡券,1 优惠码;不是列表分组的 1/2。" }
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
],
|
|
95
|
+
"additionalItems": false
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
"error": {
|
|
100
|
+
"type": "object", "required": ["success", "code", "message", "details"], "additionalProperties": false,
|
|
101
|
+
"properties": {
|
|
102
|
+
"success": { "const": false }, "code": { "const": -10001 },
|
|
103
|
+
"message": { "type": "string", "minLength": 1, "description": "本地安全错误,不回显上游自由文本。" },
|
|
104
|
+
"details": {
|
|
105
|
+
"type": "object",
|
|
106
|
+
"required": ["command", "category", "stage", "targetScope", "requestState", "nextStep"],
|
|
107
|
+
"additionalProperties": false,
|
|
108
|
+
"properties": {
|
|
109
|
+
"command": { "const": "coupon.voucher.get" },
|
|
110
|
+
"category": { "type": "string", "enum": ["parameter", "validation", "configuration", "authentication", "permission", "scope_unresolved", "transport", "http", "protocol", "business_rejected", "not_found"] },
|
|
111
|
+
"stage": { "type": "string", "enum": ["input", "configuration", "shop-binding", "query", "response"] },
|
|
112
|
+
"targetScope": { "type": "object", "additionalProperties": false, "properties": { "kdtId": { "$ref": "#/definitions/id" } } },
|
|
113
|
+
"requestState": { "type": "string", "enum": ["not_sent", "sent", "unknown"], "description": "当前失败阶段的请求事实,不等于整次调用次数。" },
|
|
114
|
+
"nextStep": { "type": "string", "minLength": 1 },
|
|
115
|
+
"api": { "type": "string", "minLength": 1 },
|
|
116
|
+
"httpStatus": { "type": "integer" },
|
|
117
|
+
"businessCode": { "$ref": "#/definitions/diagnosticCode" },
|
|
118
|
+
"gatewayCode": { "$ref": "#/definitions/diagnosticCode" },
|
|
119
|
+
"trace_id": { "type": "string", "pattern": "^[a-zA-Z0-9_-]{1,128}$" },
|
|
120
|
+
"request_id": { "type": "string", "pattern": "^[a-zA-Z0-9_-]{1,128}$" }
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
"definitions": {
|
|
126
|
+
"id": { "type": "integer", "minimum": 1, "maximum": 9007199254740991 },
|
|
127
|
+
"form": { "type": "string", "enum": ["card", "code"], "description": "card 优惠卡券,code 优惠码;不按数字外观猜测类型。" },
|
|
128
|
+
"time": { "type": "string", "format": "beijing-date-time-ms", "description": "北京时间 Asia/Shanghai,YYYY-MM-DD HH:mm:ss.SSS,固定三位毫秒。" },
|
|
129
|
+
"scope": { "type": "object", "required": ["kdtId"], "additionalProperties": false, "properties": { "kdtId": { "$ref": "#/definitions/id" } } },
|
|
130
|
+
"diagnosticCode": { "anyOf": [
|
|
131
|
+
{ "type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991 },
|
|
132
|
+
{ "type": "string", "pattern": "^-?\\d{1,12}$" }
|
|
133
|
+
] }
|
|
134
|
+
},
|
|
135
|
+
"api": { "method": "POST", "path": "youzan.ump.voucher.query.detail/1.0.1" },
|
|
136
|
+
"success": { "description": "服务端确认成功,复合身份、归属店铺及整个固定投影均通过才输出一次 data;stderr 为空,退出 0。" },
|
|
137
|
+
"errors": { "description": "失败 stdout 为空,stderr 一份安全 JSON,退出 1。主查询明确凭证不存在时为 not_found,不扫描列表、不补查活动;其他业务码不按消息猜语义。" },
|
|
138
|
+
"notes": [
|
|
139
|
+
"无 include 或 selection。holder/usage 默认投影,源省略则省略,显式 null、空白文本或错型失败;不回显手机号、核销码和原始扩展。",
|
|
140
|
+
"本地预览零请求、不读 token;缺上下文仅可带显式合法 --kdt-id 预览,无效或冲突上下文仍拒绝。",
|
|
141
|
+
"真实调用最多同店凭证核验一次和主请求一次,两次使用固定基址与 token 快照;无自动重试、重定向、切店或补查。",
|
|
142
|
+
"真实执行需要 userId/hq/shopId/orgType 有效四字段上下文;非总部目标必须等于 shopId,总部不自动取得跨店访问权。",
|
|
143
|
+
"仅承诺凭证店铺与对象归属店铺一致;不以 send_kdt_id 代替 ownerKdtId,不承诺总部代查和连锁共享券。",
|
|
144
|
+
"主接口正式范围为微商城单店、有赞连锁 D 总部/网店/合伙人;零售单店未在详情正式支持范围列出,不继承列表范围。",
|
|
145
|
+
"应用凭证加本地 fixture 上下文不证明店铺员工身份授权与权限隔离;不提供订单可用性判断或任何业务写入。"
|
|
146
|
+
]
|
|
147
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { readTotal } = require('../../../../../execution/list-total');
|
|
4
|
+
|
|
5
|
+
const { withTargetShopDefault } = require('../../../../../execution/target-shop-default');
|
|
6
|
+
|
|
7
|
+
const { Option } = require('commander');
|
|
8
|
+
const { DiagnosticCommand } = require('../../../../../cli/diagnostic-command');
|
|
9
|
+
const { inputIssue, parseIntegerOption, constraints, modelAt } = require('../../../../../execution/error-details');
|
|
10
|
+
const { createShopQuery, failure, bindingPath } = require('../../shared/query');
|
|
11
|
+
const { validateCommandValue } = require('../../../../../execution/command-schema');
|
|
12
|
+
const { object } = require('../../../../../execution/query-api');
|
|
13
|
+
const { formatDateTime } = require('../../../../../execution/datetime');
|
|
14
|
+
const schema = require('./schema.json');
|
|
15
|
+
|
|
16
|
+
const { resolveTargetShop } = require('../../../../../execution/target-shop');
|
|
17
|
+
|
|
18
|
+
const command = 'coupon.voucher.list';
|
|
19
|
+
const maxPage = 2147483647;
|
|
20
|
+
const positiveId = value => Number.isSafeInteger(value) && value > 0;
|
|
21
|
+
const reject = (category, stage, scope, state, facts) =>
|
|
22
|
+
failure(command, category, stage, scope, state, facts);
|
|
23
|
+
|
|
24
|
+
function project(envelope, input, facts) {
|
|
25
|
+
const scope = { kdtId: input.kdtId };
|
|
26
|
+
const invalid = () => reject('protocol', 'voucher-list-model', scope, 'sent', facts);
|
|
27
|
+
const unresolved = () => reject('scope_unresolved', 'voucher-list-model', scope, 'sent', facts);
|
|
28
|
+
const { page_num: pageNo, page_size: pageSize, data } = envelope;
|
|
29
|
+
const total = readTotal(envelope, 'total', invalid);
|
|
30
|
+
if (pageNo !== input.pageNo ||
|
|
31
|
+
pageSize !== input.pageSize || !Array.isArray(data) || data.length > pageSize ||
|
|
32
|
+
(total !== null && ((data.length > 0 && (pageNo - 1) * pageSize + data.length > total) ||
|
|
33
|
+
(data.length === 0 && (pageNo - 1) * pageSize < total)))) {
|
|
34
|
+
throw invalid();
|
|
35
|
+
}
|
|
36
|
+
const vouchers = data.map(row => {
|
|
37
|
+
if (!object(row) || !object(row.voucher_identity) || !object(row.user_identity) ||
|
|
38
|
+
!positiveId(row.voucher_identity.coupon_id) || !positiveId(row.kdt_id) ||
|
|
39
|
+
!positiveId(row.activity_id) || typeof row.user_identity.yz_open_id !== 'string' ||
|
|
40
|
+
!row.user_identity.yz_open_id.trim() || !Number.isSafeInteger(row.status)) {
|
|
41
|
+
throw invalid();
|
|
42
|
+
}
|
|
43
|
+
const form = row.voucher_identity.coupon_type === 0 ? 'card' :
|
|
44
|
+
row.voucher_identity.coupon_type === 1 ? 'code' : null;
|
|
45
|
+
if (form === null || form !== input.form || row.kdt_id !== input.kdtId ||
|
|
46
|
+
row.user_identity.yz_open_id !== input.yzOpenId) throw unresolved();
|
|
47
|
+
if (!positiveId(row.valid_start_time) || !positiveId(row.valid_end_time) ||
|
|
48
|
+
row.valid_start_time > row.valid_end_time) throw invalid();
|
|
49
|
+
const voucher = {
|
|
50
|
+
voucherId: row.voucher_identity.coupon_id, form, ownerKdtId: row.kdt_id,
|
|
51
|
+
activityId: row.activity_id, yzOpenId: row.user_identity.yz_open_id, status: row.status
|
|
52
|
+
};
|
|
53
|
+
try {
|
|
54
|
+
voucher.validity = { startAt: formatDateTime(row.valid_start_time),
|
|
55
|
+
endAt: formatDateTime(row.valid_end_time) };
|
|
56
|
+
for (const field of ['title', 'description']) {
|
|
57
|
+
if (Object.hasOwn(row, field)) {
|
|
58
|
+
if (typeof row[field] !== 'string') throw invalid();
|
|
59
|
+
voucher[field] = row[field];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (Object.hasOwn(row, 'send_at')) {
|
|
63
|
+
if (!positiveId(row.send_at)) throw invalid();
|
|
64
|
+
voucher.sentAt = formatDateTime(row.send_at);
|
|
65
|
+
}
|
|
66
|
+
} catch { throw invalid(); }
|
|
67
|
+
return voucher;
|
|
68
|
+
});
|
|
69
|
+
const hasMore = total === null ? null : pageNo * pageSize < total;
|
|
70
|
+
const output = { data: { vouchers, pagination: {
|
|
71
|
+
pageNo, pageSize, ...(total === null ? {} : { total }), returnedCount: data.length, hasMore,
|
|
72
|
+
nextPageNo: hasMore === true && pageNo < maxPage ? pageNo + 1 : null
|
|
73
|
+
} } };
|
|
74
|
+
try { validateCommandValue(schema, 'output', output); }
|
|
75
|
+
catch { throw invalid(); }
|
|
76
|
+
return output;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function createCommand({ context } = {}) {
|
|
80
|
+
return new DiagnosticCommand('list', { path: command, schema, parameterCategory: 'parameter' })
|
|
81
|
+
.description('查询一个客户在指定形态及默认活动类别范围内的一页持券')
|
|
82
|
+
.allowExcessArguments(false)
|
|
83
|
+
.addOption(new Option('--form <form>', '必填:card 优惠卡券;code 优惠码')
|
|
84
|
+
.choices(['card', 'code']).makeOptionMandatory())
|
|
85
|
+
.requiredOption('--yz-open-id <id>', '必填:客户有赞开放标识;不是手机号、微信 openId 或员工 ID')
|
|
86
|
+
.option('--kdt-id <id>', '目标店铺正安全整数;省略取有效上下文 shopId')
|
|
87
|
+
.option('--status <n>', '默认类别内筛选:0全部状态、1生效未使用且未过期、2已使用、3未使用已过期、4已使用或已过期', '0')
|
|
88
|
+
.option('--page-no <n>', '固定单页,完整十进制 1..2147483647', '1')
|
|
89
|
+
.option('--page-size <n>', '单页容量 1..200,默认 20', '20')
|
|
90
|
+
.addOption(new Option('--format <format>', 'json 或 pretty,仅改变缩进')
|
|
91
|
+
.choices(['json', 'pretty']).default('json'))
|
|
92
|
+
.option('--dry-run', '本地预览店铺核验与单页请求,不读凭证、不联网')
|
|
93
|
+
.addHelpText('after', `
|
|
94
|
+
输出 data.vouchers 和 data.pagination,页码、容量及 total 取精确根响应。
|
|
95
|
+
筛选 status 0..4 不等于单券状态:1正常、2冻结、3已核销、4不可用、5已删除;未来整数保留。
|
|
96
|
+
validity 和 sentAt 按上游毫秒转北京时间 YYYY-MM-DD HH:mm:ss.SSS,不按时间推算状态。
|
|
97
|
+
hasMore 按 pageNo * pageSize < total;nextPageNo 在页码上限可能为 null,不保证跨页快照。
|
|
98
|
+
无 include、活动筛选、自动翻页或详情补查;不返回面额、折扣、核销码、手机号及未知扩展。
|
|
99
|
+
card 默认普通优惠券类别;不承诺完整覆盖三方券、兑换券、买赠券及运费抵扣券。
|
|
100
|
+
code 仅为优惠码分组默认返回范围,不承诺所有码活动;status=0 只表示上述范围内全部使用状态。
|
|
101
|
+
total 与空页仅描述该范围和筛选,不代表全部券资产,不证明从未领券、客户资格或订单可用性。
|
|
102
|
+
固定同店凭证核验加一次主请求,最多两次应用请求,不重试、不切店或切换身份。
|
|
103
|
+
需有效 userId/hq/shopId/orgType 上下文;店铺核验不证明员工 OAuth 授权。
|
|
104
|
+
支持微商城单店、零售单店、连锁 D 总部/网店/合伙人,仅查凭证所属店铺。
|
|
105
|
+
契约:zan-saas schema coupon.voucher.list
|
|
106
|
+
指引:zan-saas skills read zan-saas-coupon references/voucher-list.md
|
|
107
|
+
示例:zan-saas coupon voucher list --form card --yz-open-id customer-a --page-no 1
|
|
108
|
+
`)
|
|
109
|
+
.action(async options => {
|
|
110
|
+
let scope;
|
|
111
|
+
try { scope = resolveTargetShop(options, context, command); }
|
|
112
|
+
catch (error) {
|
|
113
|
+
if (error.cliDetails) error.cliDetails.stage = error.cliDetails.category === 'configuration' ? 'configuration' : 'input';
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
let input;
|
|
117
|
+
try {
|
|
118
|
+
if (/[\u0000-\u001f\u007f-\u009f]/.test(options.yzOpenId)) {
|
|
119
|
+
throw inputIssue('/yzOpenId', 'invalid_format', constraints(modelAt(schema, 'input', '/yzOpenId')));
|
|
120
|
+
}
|
|
121
|
+
input = { ...scope, form: options.form, yzOpenId: options.yzOpenId.trim(),
|
|
122
|
+
status: parseIntegerOption(options.status, schema, '/status'),
|
|
123
|
+
pageNo: parseIntegerOption(options.pageNo, schema, '/pageNo'),
|
|
124
|
+
pageSize: parseIntegerOption(options.pageSize, schema, '/pageSize') };
|
|
125
|
+
validateCommandValue(schema, 'input', input);
|
|
126
|
+
} catch (error) { error.inputScope = scope; throw error; }
|
|
127
|
+
const request = { method: 'POST', path: schema.api.path, body: {
|
|
128
|
+
activity_type_group: input.form === 'card' ? 1 : 2, yz_open_id: input.yzOpenId,
|
|
129
|
+
status: input.status, page_num: input.pageNo, page_size: input.pageSize
|
|
130
|
+
} };
|
|
131
|
+
const preview = { scope, prerequisites: [{ method: 'POST', path: bindingPath, body: {} }],
|
|
132
|
+
requests: [request] };
|
|
133
|
+
validateCommandValue(schema, 'preview', preview);
|
|
134
|
+
let output = preview;
|
|
135
|
+
if (!options.dryRun) {
|
|
136
|
+
const read = await createShopQuery(scope, command);
|
|
137
|
+
let result;
|
|
138
|
+
try { result = await read(request.path, request.body, 'voucher-list'); }
|
|
139
|
+
catch (error) {
|
|
140
|
+
if (error.cliDetails?.category === 'business_rejected' &&
|
|
141
|
+
String(error.cliDetails.businessCode ?? error.cliDetails.gatewayCode) === '161201523') {
|
|
142
|
+
const facts = Object.fromEntries(['api', 'httpStatus', 'businessCode', 'gatewayCode',
|
|
143
|
+
'trace_id', 'request_id'].filter(key => Object.hasOwn(error.cliDetails, key))
|
|
144
|
+
.map(key => [key, error.cliDetails[key]]));
|
|
145
|
+
throw reject('not_found', 'voucher-list', scope, 'sent', facts);
|
|
146
|
+
}
|
|
147
|
+
throw error;
|
|
148
|
+
}
|
|
149
|
+
output = project(result.envelope, input, result.facts);
|
|
150
|
+
}
|
|
151
|
+
process.stdout.write(`${JSON.stringify(output, null, options.format === 'pretty' ? 2 : 0)}\n`);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
module.exports = { kind: 'atomic', risk: 'read', at: 'all', createCommand: withTargetShopDefault(createCommand), project };
|