@youzan-cloud/zan-saas-cli 0.0.0-stage → 0.1.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +106 -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 +103 -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,193 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { withTargetShopDefault } = require('../../../../../execution/target-shop-default');
|
|
4
|
+
|
|
5
|
+
const { Command, Option } = require('commander');
|
|
6
|
+
const { resolveTargetShop } = require('../../../../../execution/target-shop');
|
|
7
|
+
const { validateCommandValue } = require('../../../../../execution/command-schema');
|
|
8
|
+
const { createShopQuery, failure, bindingPath } = require('../../../../../execution/shop-query');
|
|
9
|
+
const { object } = require('../../../../../execution/query-api');
|
|
10
|
+
const { readWaybill } = require('./response');
|
|
11
|
+
const schema = require('./schema.json');
|
|
12
|
+
|
|
13
|
+
const command = 'fulfillment.waybill.get';
|
|
14
|
+
const path = schema.api.path;
|
|
15
|
+
const nextStep = '核对物流公司 ID、运单号和平台发货记录;失败时停止,不自动切换店铺、身份或接口。';
|
|
16
|
+
const reject = (category, stage, scope, state = 'not_sent', facts = {}) => {
|
|
17
|
+
const error = failure(command, category, stage, scope, state, facts);
|
|
18
|
+
error.cliDetails.nextStep = nextStep;
|
|
19
|
+
return error;
|
|
20
|
+
};
|
|
21
|
+
const safeNumber = value => typeof value === 'number' && Number.isSafeInteger(value);
|
|
22
|
+
|
|
23
|
+
function scopeFor(input) {
|
|
24
|
+
return { kdtId: input.kdtId, carrierId: input.carrierId,
|
|
25
|
+
waybillSuffix: input.waybillNo.slice(-4) };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function addScope(error, input) {
|
|
29
|
+
if (error?.cliDetails) {
|
|
30
|
+
error.cliDetails.targetScope = scopeFor(input);
|
|
31
|
+
}
|
|
32
|
+
return error;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function maskedWaybill(waybillNo) {
|
|
36
|
+
const suffix = waybillNo.slice(-4);
|
|
37
|
+
return `${'*'.repeat(Math.max(0, waybillNo.length - suffix.length))}${suffix}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function buildInput(options, context) {
|
|
41
|
+
const scope = resolveTargetShop(options, context, command);
|
|
42
|
+
try {
|
|
43
|
+
if (typeof options.waybillNo !== 'string' || /[\u0000-\u001f\u007f-\u009f]/u.test(options.waybillNo)) {
|
|
44
|
+
throw new TypeError('invalid waybill number');
|
|
45
|
+
}
|
|
46
|
+
const input = {
|
|
47
|
+
...scope,
|
|
48
|
+
carrierId: Number(options.carrierId),
|
|
49
|
+
waybillNo: options.waybillNo
|
|
50
|
+
};
|
|
51
|
+
if (!/^[1-9]\d*$/.test(options.carrierId) || !safeNumber(input.carrierId)) throw new TypeError('invalid carrier id');
|
|
52
|
+
validateCommandValue(schema, 'input', input);
|
|
53
|
+
return Object.freeze(input);
|
|
54
|
+
} catch {
|
|
55
|
+
throw reject('parameter', 'input', scope);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function projectEvent(item, scope, facts) {
|
|
60
|
+
if (!object(item) || typeof item.context !== 'string') {
|
|
61
|
+
throw reject('protocol', 'events', scope, 'sent', facts);
|
|
62
|
+
}
|
|
63
|
+
const event = { description: item.context };
|
|
64
|
+
for (const [source, target] of [['status', 'statusText'], ['time', 'timeText']]) {
|
|
65
|
+
if (item[source] !== undefined && item[source] !== null) {
|
|
66
|
+
if (typeof item[source] !== 'string') throw reject('protocol', 'events', scope, 'sent', facts);
|
|
67
|
+
event[target] = item[source];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return event;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function project(data, input, facts) {
|
|
74
|
+
const scope = scopeFor(input);
|
|
75
|
+
try {
|
|
76
|
+
if (!object(data) || !['1', ''].includes(data.status)) {
|
|
77
|
+
const category = data?.status === '0' ? 'data_unavailable' :
|
|
78
|
+
data?.status === '2' ? 'upstream_query_failed' : 'protocol';
|
|
79
|
+
throw reject(category, 'query-status', scope, 'sent', facts);
|
|
80
|
+
}
|
|
81
|
+
if (data.nu !== input.waybillNo || data.express_id !== input.carrierId) {
|
|
82
|
+
throw reject('scope_unresolved', 'waybill-model', scope, 'sent', facts);
|
|
83
|
+
}
|
|
84
|
+
if (!safeNumber(data.state) || data.state < 0) {
|
|
85
|
+
throw reject('protocol', 'waybill-model', scope, 'sent', facts);
|
|
86
|
+
}
|
|
87
|
+
if (typeof data.data !== 'string' || Buffer.byteLength(data.data, 'utf8') > 1024 * 1024) {
|
|
88
|
+
throw reject('protocol', 'events', scope, 'sent', facts);
|
|
89
|
+
}
|
|
90
|
+
let rawEvents;
|
|
91
|
+
try { rawEvents = JSON.parse(data.data); } catch { throw reject('protocol', 'events', scope, 'sent', facts); }
|
|
92
|
+
if (!Array.isArray(rawEvents) || rawEvents.length > 1000) {
|
|
93
|
+
throw reject('protocol', 'events', scope, 'sent', facts);
|
|
94
|
+
}
|
|
95
|
+
const waybill = {
|
|
96
|
+
waybillNo: data.nu,
|
|
97
|
+
carrierId: data.express_id,
|
|
98
|
+
state: data.state,
|
|
99
|
+
events: rawEvents.map(item => projectEvent(item, scope, facts))
|
|
100
|
+
};
|
|
101
|
+
for (const [source, target] of [['name', 'carrierName'], ['com', 'carrierCode']]) {
|
|
102
|
+
if (data[source] !== undefined && data[source] !== null) {
|
|
103
|
+
if (typeof data[source] !== 'string') throw reject('protocol', 'waybill-model', scope, 'sent', facts);
|
|
104
|
+
waybill[target] = data[source];
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const output = { data: { waybill } };
|
|
108
|
+
if (Buffer.byteLength(JSON.stringify(output), 'utf8') > 5 * 1024 * 1024) {
|
|
109
|
+
throw reject('protocol', 'waybill-model', scope, 'sent', facts);
|
|
110
|
+
}
|
|
111
|
+
validateCommandValue(schema, 'output', output);
|
|
112
|
+
return output;
|
|
113
|
+
} catch (error) {
|
|
114
|
+
if (error?.cliDetails) throw error;
|
|
115
|
+
throw reject('protocol', 'waybill-model', scope, 'sent', facts);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async function execute(input) {
|
|
120
|
+
try {
|
|
121
|
+
const read = await createShopQuery(input, command, {
|
|
122
|
+
transportOptions: {
|
|
123
|
+
maxResponseBytes: () => 10 * 1024 * 1024,
|
|
124
|
+
timeoutMs: 30000,
|
|
125
|
+
limitCategory: 'protocol',
|
|
126
|
+
limitStage: currentPath => currentPath === bindingPath ? 'shop-binding' : 'waybill-response'
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
const response = await read(path, {
|
|
130
|
+
express_id: input.carrierId,
|
|
131
|
+
express_no: input.waybillNo
|
|
132
|
+
}, 'waybill');
|
|
133
|
+
if (response.responseBytes > 10 * 1024 * 1024) {
|
|
134
|
+
throw reject('protocol', 'waybill-response', scopeFor(input), 'sent', response.facts);
|
|
135
|
+
}
|
|
136
|
+
let data;
|
|
137
|
+
try { data = readWaybill(response.rawBody); }
|
|
138
|
+
catch { throw reject('protocol', 'waybill-model', scopeFor(input), 'sent', response.facts); }
|
|
139
|
+
return project(data, input, response.facts);
|
|
140
|
+
} catch (error) {
|
|
141
|
+
addScope(error, input);
|
|
142
|
+
const details = error.cliDetails;
|
|
143
|
+
if (details?.category === 'business_rejected' && details.stage === 'waybill' &&
|
|
144
|
+
details.api === path && !Object.hasOwn(details, 'gatewayCode') &&
|
|
145
|
+
[120009001, '120009001'].includes(details.businessCode)) {
|
|
146
|
+
details.category = 'not_found_in_scope';
|
|
147
|
+
error.message = '查询失败:not_found_in_scope(waybill)';
|
|
148
|
+
}
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function createCommand({ context } = {}) {
|
|
154
|
+
return new Command('get')
|
|
155
|
+
.description('按物流公司 ID 和运单号查询运输状态与物流轨迹')
|
|
156
|
+
.allowExcessArguments(false)
|
|
157
|
+
.exitOverride(error => {
|
|
158
|
+
if (['commander.helpDisplayed', 'commander.version'].includes(error.code)) throw error;
|
|
159
|
+
throw reject('parameter', 'input');
|
|
160
|
+
})
|
|
161
|
+
.requiredOption('--carrier-id <id>', '有赞快递公司正整数 ID,不接受公司名称或编码')
|
|
162
|
+
.requiredOption('--waybill-no <no>', '运单号字符串,保留大小写和前导零,长度 1 至 128')
|
|
163
|
+
.option('--kdt-id <id>', '目标店铺正安全整数;省略取有效上下文 shopId')
|
|
164
|
+
.addOption(new Option('--format <format>', 'json 或 pretty,仅改变缩进')
|
|
165
|
+
.choices(['json', 'pretty']).default('json'))
|
|
166
|
+
.option('--dry-run', '本地预览请求计划;不读取凭证、不联网')
|
|
167
|
+
.addHelpText('after', `
|
|
168
|
+
输出 data.waybill:waybillNo、carrierId、state 和固定 events 轨迹数组。
|
|
169
|
+
轨迹来自同一次 goodsexpress.get 响应,不能用 --include 关闭;timeText 保留承运商原文。每次请求最多等待 30 秒。
|
|
170
|
+
先核验凭证店铺 sid,再发送一次运单查询;最多两次请求,不重试、切店或调用电子面单接口。
|
|
171
|
+
查询命中不证明订单、配送单或售后归属;失败 stdout 为空,stderr 为安全错误 JSON。
|
|
172
|
+
契约:zan-saas schema fulfillment.waybill.get
|
|
173
|
+
示例:zan-saas fulfillment waybill get --kdt-id 63077 --carrier-id 6 --waybill-no 73179966 --dry-run
|
|
174
|
+
`)
|
|
175
|
+
.action(async options => {
|
|
176
|
+
const input = buildInput(options, context);
|
|
177
|
+
const preview = {
|
|
178
|
+
scope: { kdtId: input.kdtId, carrierId: input.carrierId, waybillNo: maskedWaybill(input.waybillNo) },
|
|
179
|
+
prerequisites: [{ method: 'POST', path: bindingPath, body: {} }],
|
|
180
|
+
requests: [{ method: 'POST', path, body: {
|
|
181
|
+
express_id: input.carrierId, express_no: maskedWaybill(input.waybillNo)
|
|
182
|
+
} }],
|
|
183
|
+
condition: '仅在店铺核验返回的 sid 等于目标 kdtId 时发送运单请求。轨迹固定解析,不支持关闭。'
|
|
184
|
+
};
|
|
185
|
+
validateCommandValue(schema, 'preview', preview);
|
|
186
|
+
const result = options.dryRun ? preview : await execute(input);
|
|
187
|
+
process.stdout.write(`${JSON.stringify(result, null, options.format === 'pretty' ? 2 : 0)}\n`);
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
module.exports = {
|
|
192
|
+
kind: 'atomic', risk: 'read', at: 'all', createCommand: withTargetShopDefault(createCommand), buildInput, project, execute
|
|
193
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { parseExactJson } = require('../../../../../execution/exact-json');
|
|
4
|
+
|
|
5
|
+
class NumericToken {
|
|
6
|
+
constructor(text) { this.text = text; }
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function parseResponse(text) {
|
|
10
|
+
JSON.parse(text);
|
|
11
|
+
const tokens = text.match(/"(?:[^"\\]|\\.)*"|-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?|true|false|null|[{}\[\]:,]/g);
|
|
12
|
+
let index = 0;
|
|
13
|
+
function value() {
|
|
14
|
+
const token = tokens[index++];
|
|
15
|
+
if (token === '{') {
|
|
16
|
+
const result = Object.create(null);
|
|
17
|
+
while (tokens[index] !== '}') {
|
|
18
|
+
const key = JSON.parse(tokens[index++]);
|
|
19
|
+
index++;
|
|
20
|
+
result[key] = value();
|
|
21
|
+
if (tokens[index] !== ',') break;
|
|
22
|
+
index++;
|
|
23
|
+
}
|
|
24
|
+
index++;
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
if (token === '[') {
|
|
28
|
+
const result = [];
|
|
29
|
+
while (tokens[index] !== ']') {
|
|
30
|
+
result.push(value());
|
|
31
|
+
if (tokens[index] !== ',') break;
|
|
32
|
+
index++;
|
|
33
|
+
}
|
|
34
|
+
index++;
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
return /^-?\d/.test(token) ? new NumericToken(token) : JSON.parse(token);
|
|
38
|
+
}
|
|
39
|
+
return value();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function integer(value, minimum = 0) {
|
|
43
|
+
if (!(value instanceof NumericToken)) throw new Error('Expected numeric token');
|
|
44
|
+
const match = /^(-?)(\d+)(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/.exec(value.text);
|
|
45
|
+
const fraction = match[3] || '';
|
|
46
|
+
const significant = `${match[2]}${fraction}`.replace(/^0+/, '');
|
|
47
|
+
const digits = significant.replace(/0+$/, '');
|
|
48
|
+
if (!digits) {
|
|
49
|
+
if (minimum > 0) throw new Error('Invalid integer');
|
|
50
|
+
return 0;
|
|
51
|
+
}
|
|
52
|
+
const scale = Number(match[4] || 0) - fraction.length + significant.length - digits.length;
|
|
53
|
+
if (match[1] || scale < 0 || digits.length + scale > 16) throw new Error('Invalid integer');
|
|
54
|
+
const exact = BigInt(digits) * 10n ** BigInt(scale);
|
|
55
|
+
if (exact > BigInt(Number.MAX_SAFE_INTEGER) || exact < BigInt(minimum)) throw new Error('Invalid integer');
|
|
56
|
+
return Number(exact);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function readWaybill(rawBody) {
|
|
60
|
+
const data = parseExactJson(rawBody, text => new NumericToken(text)).data;
|
|
61
|
+
if (data && ['1', ''].includes(data.status)) {
|
|
62
|
+
data.express_id = integer(data.express_id, 1);
|
|
63
|
+
data.state = integer(data.state);
|
|
64
|
+
}
|
|
65
|
+
return data;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
module.exports = { readWaybill };
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"input": {
|
|
4
|
+
"type": "object",
|
|
5
|
+
"required": ["kdtId", "carrierId", "waybillNo"],
|
|
6
|
+
"additionalProperties": false,
|
|
7
|
+
"properties": {
|
|
8
|
+
"kdtId": { "$ref": "#/definitions/shopId" },
|
|
9
|
+
"carrierId": { "$ref": "#/definitions/carrierId" },
|
|
10
|
+
"waybillNo": { "$ref": "#/definitions/waybillNo" }
|
|
11
|
+
},
|
|
12
|
+
"description": "CLI 解析参数并完成必要上下文补全后的业务输入。"
|
|
13
|
+
},
|
|
14
|
+
"output": {
|
|
15
|
+
"type": "object",
|
|
16
|
+
"required": ["data"],
|
|
17
|
+
"additionalProperties": false,
|
|
18
|
+
"properties": {
|
|
19
|
+
"data": {
|
|
20
|
+
"type": "object",
|
|
21
|
+
"required": ["waybill"],
|
|
22
|
+
"additionalProperties": false,
|
|
23
|
+
"properties": {
|
|
24
|
+
"waybill": { "$ref": "#/definitions/waybill" }
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"preview": {
|
|
30
|
+
"type": "object",
|
|
31
|
+
"required": ["scope", "prerequisites", "requests", "condition"],
|
|
32
|
+
"additionalProperties": false,
|
|
33
|
+
"properties": {
|
|
34
|
+
"scope": {
|
|
35
|
+
"type": "object",
|
|
36
|
+
"required": ["kdtId", "carrierId", "waybillNo"],
|
|
37
|
+
"additionalProperties": false,
|
|
38
|
+
"properties": {
|
|
39
|
+
"kdtId": { "$ref": "#/definitions/shopId" },
|
|
40
|
+
"carrierId": { "$ref": "#/definitions/carrierId" },
|
|
41
|
+
"waybillNo": { "type": "string", "minLength": 1, "maxLength": 128 }
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"prerequisites": {
|
|
45
|
+
"type": "array",
|
|
46
|
+
"minItems": 1,
|
|
47
|
+
"maxItems": 1,
|
|
48
|
+
"items": {
|
|
49
|
+
"type": "object",
|
|
50
|
+
"required": ["method", "path", "body"],
|
|
51
|
+
"additionalProperties": false,
|
|
52
|
+
"properties": {
|
|
53
|
+
"method": { "const": "POST" },
|
|
54
|
+
"path": { "const": "youzan.shop.basic.get/3.0.0" },
|
|
55
|
+
"body": { "type": "object", "maxProperties": 0 }
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"requests": {
|
|
60
|
+
"type": "array",
|
|
61
|
+
"minItems": 1,
|
|
62
|
+
"maxItems": 1,
|
|
63
|
+
"items": {
|
|
64
|
+
"type": "object",
|
|
65
|
+
"required": ["method", "path", "body"],
|
|
66
|
+
"additionalProperties": false,
|
|
67
|
+
"properties": {
|
|
68
|
+
"method": { "const": "POST" },
|
|
69
|
+
"path": { "const": "youzan.logistics.goodsexpress.get/3.0.0" },
|
|
70
|
+
"body": {
|
|
71
|
+
"type": "object",
|
|
72
|
+
"required": ["express_id", "express_no"],
|
|
73
|
+
"additionalProperties": false,
|
|
74
|
+
"properties": {
|
|
75
|
+
"express_id": { "$ref": "#/definitions/carrierId" },
|
|
76
|
+
"express_no": { "type": "string", "minLength": 1 }
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"condition": { "const": "仅在店铺核验返回的 sid 等于目标 kdtId 时发送运单请求。轨迹固定解析,不支持关闭。" }
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
"error": {
|
|
86
|
+
"type": "object",
|
|
87
|
+
"required": ["success", "code", "message", "details"],
|
|
88
|
+
"additionalProperties": false,
|
|
89
|
+
"properties": {
|
|
90
|
+
"success": { "const": false },
|
|
91
|
+
"code": { "const": -10001 },
|
|
92
|
+
"message": { "type": "string", "minLength": 1 },
|
|
93
|
+
"details": {
|
|
94
|
+
"type": "object",
|
|
95
|
+
"required": ["category", "stage", "command", "targetScope", "requestState", "nextStep"],
|
|
96
|
+
"additionalProperties": false,
|
|
97
|
+
"properties": {
|
|
98
|
+
"category": {
|
|
99
|
+
"type": "string",
|
|
100
|
+
"enum": ["validation", "configuration", "parameter", "permission", "authentication", "scope_unresolved", "transport", "http", "protocol", "business_rejected", "not_found_in_scope", "data_unavailable", "upstream_query_failed"]
|
|
101
|
+
},
|
|
102
|
+
"stage": { "type": "string", "minLength": 1 },
|
|
103
|
+
"command": { "const": "fulfillment.waybill.get" },
|
|
104
|
+
"targetScope": {
|
|
105
|
+
"anyOf": [
|
|
106
|
+
{ "type": "object", "maxProperties": 0 },
|
|
107
|
+
{
|
|
108
|
+
"type": "object",
|
|
109
|
+
"required": ["kdtId"],
|
|
110
|
+
"additionalProperties": false,
|
|
111
|
+
"properties": {
|
|
112
|
+
"kdtId": { "$ref": "#/definitions/shopId" },
|
|
113
|
+
"carrierId": { "$ref": "#/definitions/carrierId" },
|
|
114
|
+
"waybillSuffix": { "type": "string", "minLength": 1, "maxLength": 4, "pattern": "^[^\\s]+$" }
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
]
|
|
118
|
+
},
|
|
119
|
+
"requestState": { "enum": ["not_sent", "sent", "unknown"] },
|
|
120
|
+
"nextStep": { "type": "string", "minLength": 1 },
|
|
121
|
+
"api": { "type": "string", "minLength": 1 },
|
|
122
|
+
"httpStatus": { "type": "integer", "minimum": 100, "maximum": 599 },
|
|
123
|
+
"businessCode": { "$ref": "#/definitions/code" },
|
|
124
|
+
"gatewayCode": { "$ref": "#/definitions/code" },
|
|
125
|
+
"trace_id": { "$ref": "#/definitions/trace" },
|
|
126
|
+
"request_id": { "$ref": "#/definitions/trace" }
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
"definitions": {
|
|
132
|
+
"shopId": { "type": "integer", "minimum": 1, "maximum": 9007199254740991 },
|
|
133
|
+
"carrierId": { "type": "integer", "minimum": 1, "maximum": 2147483647 },
|
|
134
|
+
"waybillNo": { "type": "string", "minLength": 1, "maxLength": 128, "pattern": "^[^\\s\\u0000-\\u001f\\u007f-\\u009f]+$" },
|
|
135
|
+
"text": { "type": "string", "minLength": 1, "pattern": "\\S" },
|
|
136
|
+
"event": {
|
|
137
|
+
"type": "object",
|
|
138
|
+
"required": ["description"],
|
|
139
|
+
"additionalProperties": false,
|
|
140
|
+
"properties": {
|
|
141
|
+
"description": { "type": "string" },
|
|
142
|
+
"statusText": { "type": "string" },
|
|
143
|
+
"timeText": { "type": "string" }
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
"waybill": {
|
|
147
|
+
"type": "object",
|
|
148
|
+
"required": ["waybillNo", "carrierId", "state", "events"],
|
|
149
|
+
"additionalProperties": false,
|
|
150
|
+
"properties": {
|
|
151
|
+
"waybillNo": { "$ref": "#/definitions/text" },
|
|
152
|
+
"carrierId": { "$ref": "#/definitions/carrierId" },
|
|
153
|
+
"state": {
|
|
154
|
+
"type": "integer",
|
|
155
|
+
"minimum": 0,
|
|
156
|
+
"maximum": 9007199254740991,
|
|
157
|
+
"$comment": "来源为 youzan.logistics.goodsexpress.get/3.0.0 的 data.state。",
|
|
158
|
+
"description": "运输状态,已知 JSON 数字值:0 收件、1 揽件、2 疑难、3 签收、4 退签、5 派送中、7 运输中、8 已取消。未知非负安全整数原样保留,不赋予业务含义,不作为封闭枚举校验。"
|
|
159
|
+
},
|
|
160
|
+
"carrierName": { "type": "string" },
|
|
161
|
+
"carrierCode": { "type": "string" },
|
|
162
|
+
"events": { "type": "array", "maxItems": 1000, "items": { "$ref": "#/definitions/event" } }
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
"code": {
|
|
166
|
+
"anyOf": [
|
|
167
|
+
{ "type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991 },
|
|
168
|
+
{ "type": "string", "pattern": "^-?[0-9]{1,12}$" }
|
|
169
|
+
]
|
|
170
|
+
},
|
|
171
|
+
"trace": { "type": "string", "pattern": "^[a-zA-Z0-9_-]{1,128}$" }
|
|
172
|
+
},
|
|
173
|
+
"modules": {
|
|
174
|
+
"waybill": {
|
|
175
|
+
"base": true,
|
|
176
|
+
"upstreamPath": "data",
|
|
177
|
+
"required": true,
|
|
178
|
+
"description": "按物流公司 ID 与运单号读取当前运输状态和固定轨迹有限视图。"
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
"api": { "method": "POST", "path": "youzan.logistics.goodsexpress.get/3.0.0" },
|
|
182
|
+
"success": { "description": "店铺核验和上游业务成功,运单锚点、状态和轨迹满足有限模型。" },
|
|
183
|
+
"errors": { "description": "失败 stdout 为空,stderr 返回安全错误 JSON;不输出上游自由消息或原始轨迹。" },
|
|
184
|
+
"notes": [
|
|
185
|
+
"轨迹固定返回,不提供 --include;不调用电子面单或外部快递接口。",
|
|
186
|
+
"carrierCode 是来源编码文本,不能替代 carrierId;waybillNo 保留大小写和前导零。",
|
|
187
|
+
"timeText 保留承运商原文,不猜测时区、格式或精度。",
|
|
188
|
+
"查询命中不证明订单、配送单或售后归属。"
|
|
189
|
+
]
|
|
190
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 3,
|
|
3
|
+
"domain": "interaction",
|
|
4
|
+
"businessCommands": [
|
|
5
|
+
{
|
|
6
|
+
"path": "interaction.lottery.get",
|
|
7
|
+
"kind": "atomic",
|
|
8
|
+
"risk": "read",
|
|
9
|
+
"availability": "available",
|
|
10
|
+
"at": "all",
|
|
11
|
+
"module": "interaction/lottery/get/command.js",
|
|
12
|
+
"fingerprint": "3db3d36bc577a110d917ee52ea9b9c2a6ba6eb39c306b2e4328dcc4d2417d1cf"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"path": "interaction.lottery.list",
|
|
16
|
+
"kind": "atomic",
|
|
17
|
+
"risk": "read",
|
|
18
|
+
"availability": "available",
|
|
19
|
+
"at": "all",
|
|
20
|
+
"module": "interaction/lottery/list/command.js",
|
|
21
|
+
"fingerprint": "18ba912db0600f674f6e9d0cf30f62487f292b0ff515a5bf54d8f342a80bc7cf"
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { withTargetShopDefault } = require('../../../../../execution/target-shop-default');
|
|
4
|
+
|
|
5
|
+
const { Option } = require('commander');
|
|
6
|
+
const { DiagnosticCommand } = require('../../../../../cli/diagnostic-command');
|
|
7
|
+
const { parseIntegerOption } = require('../../../../../execution/error-details');
|
|
8
|
+
const { resolveTargetShop } = require('../../../../../execution/target-shop');
|
|
9
|
+
const { validateCommandValue } = require('../../../../../execution/command-schema');
|
|
10
|
+
const { bindingPath, failure } = require('../../../../../execution/shop-query');
|
|
11
|
+
const { executeLottery } = require('./query');
|
|
12
|
+
const schema = require('./schema.json');
|
|
13
|
+
|
|
14
|
+
const command = 'interaction.lottery.get';
|
|
15
|
+
|
|
16
|
+
function createCommand({ context } = {}) {
|
|
17
|
+
return new DiagnosticCommand('get', { path: command, schema, parameterCategory: 'parameter' })
|
|
18
|
+
.description('按活动 ID 读取同店抽奖活动的参与、奖项、转盘及页面配置')
|
|
19
|
+
.allowExcessArguments(false)
|
|
20
|
+
.requiredOption('--activity-id <id>', 'integer,必填。抽奖活动 ID,须为正安全整数,不接受别名或奖项 ID。')
|
|
21
|
+
.option('--kdt-id <id>', 'integer,可选,默认 context.shopId。目标店铺 ID,须为正安全整数。')
|
|
22
|
+
.addOption(new Option('--format <format>', 'string,可选,默认 json。输出格式:json 紧凑,pretty 缩进。')
|
|
23
|
+
.choices(['json', 'pretty']).default('json'))
|
|
24
|
+
.option('--dry-run', 'boolean,可选,默认 false。仅预览查询计划,不读凭证、不联网。')
|
|
25
|
+
.addHelpText('after', `
|
|
26
|
+
输出 data.lottery;活动、奖项定义和转盘槽位不是客户参与、中奖或到账记录。
|
|
27
|
+
配置默认投影,未返回的可选字段省略;不提供 include、fields 或 kind 参数。
|
|
28
|
+
活动概率为万分比,奖项概率为百分比;槽位概率单位未证,不输出。
|
|
29
|
+
保留槽位顺序及重复奖项引用;不计算当前状态、客户资格或实际中奖概率。
|
|
30
|
+
仅支持已核实的微商城单店;at: all 不证明产品、员工或对象授权。
|
|
31
|
+
先以同一凭证核验店铺,再按活动 ID 单次读取,不扫描列表,不重试、换店或换身份。
|
|
32
|
+
店铺核验响应限 512 KiB,主响应限 8 MiB,超限整体失败,不裁剪或输出部分结果。
|
|
33
|
+
真实执行需有效四字段上下文和同店授权凭证;失败 stdout 为空,stderr 为一份脱敏错误 JSON。
|
|
34
|
+
契约:zan-saas schema interaction.lottery.get
|
|
35
|
+
示例:zan-saas interaction lottery get --activity-id 1001 --kdt-id 63077 --dry-run
|
|
36
|
+
`)
|
|
37
|
+
.action(async options => {
|
|
38
|
+
const scope = resolveTargetShop(options, context, command);
|
|
39
|
+
let input;
|
|
40
|
+
try {
|
|
41
|
+
input = Object.freeze({ ...scope, activityId: parseIntegerOption(options.activityId, schema, '/activityId') });
|
|
42
|
+
validateCommandValue(schema, 'input', input);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
error.inputScope = scope;
|
|
45
|
+
error.cliDetails = failure(command, 'validation', 'input', scope).cliDetails;
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
const preview = {
|
|
49
|
+
scope,
|
|
50
|
+
prerequisites: ['context', 'token-shop-binding'],
|
|
51
|
+
requests: [{ method: 'POST', api: bindingPath, body: {} },
|
|
52
|
+
{ method: 'POST', api: schema.api.path, body: { activity_id: input.activityId } }],
|
|
53
|
+
limits: { maxBusinessRequests: 2, bindingResponseBytes: 524288, queryResponseBytes: 8388608 }
|
|
54
|
+
};
|
|
55
|
+
validateCommandValue(schema, 'preview', preview);
|
|
56
|
+
const output = options.dryRun ? preview : await executeLottery(input);
|
|
57
|
+
process.stdout.write(`${JSON.stringify(output, null, options.format === 'pretty' ? 2 : 0)}\n`);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
module.exports = { kind: 'atomic', risk: 'read', at: 'all', createCommand: withTargetShopDefault(createCommand) };
|