@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,169 @@
|
|
|
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, withInputScope, 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 { parseDateTime } = require('../../../../../execution/datetime');
|
|
14
|
+
const { parseDateTimeRange } = require('../../../../../execution/range');
|
|
15
|
+
const { resolveTargetShop } = require('../../../../../execution/target-shop');
|
|
16
|
+
const schema = require('./schema.json');
|
|
17
|
+
|
|
18
|
+
const command = 'coupon.activity.list';
|
|
19
|
+
const reject = (category, stage, scope, state, facts) =>
|
|
20
|
+
failure(command, category, stage, scope, state, facts);
|
|
21
|
+
|
|
22
|
+
function buildInput(options, scope) {
|
|
23
|
+
const input = { ...scope, form: options.form };
|
|
24
|
+
for (const field of ['stage', 'pageNo', 'pageSize', 'displayType']) {
|
|
25
|
+
if (options[field] === undefined) continue;
|
|
26
|
+
input[field] = parseIntegerOption(options[field], schema, `/${field}`);
|
|
27
|
+
}
|
|
28
|
+
if (options.keyword !== undefined) {
|
|
29
|
+
if (/[\u0000-\u001f\u007f-\u009f]/u.test(options.keyword)) throw inputIssue('/keyword', 'invalid_format', constraints(modelAt(schema, 'input', '/keyword')));
|
|
30
|
+
input.keyword = options.keyword.trim();
|
|
31
|
+
}
|
|
32
|
+
if (options.createdAt !== undefined) {
|
|
33
|
+
try {
|
|
34
|
+
input.createdAt = parseDateTimeRange(options.createdAt, { precision: 'milliseconds', strictOrder: true });
|
|
35
|
+
} catch {
|
|
36
|
+
throw inputIssue('/createdAt', 'invalid_format', {
|
|
37
|
+
format: '北京时间 YYYY-MM-DD HH:mm:ss[.SSS]..YYYY-MM-DD HH:mm:ss[.SSS],可省略一端;开始须早于结束'
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
validateCommandValue(schema, 'input', input);
|
|
42
|
+
return input;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function requestBody(input) {
|
|
46
|
+
const body = { activity_type_group: input.form === 'card' ? 1 : 2,
|
|
47
|
+
time_line_status: input.stage, page_no: input.pageNo, page_size: input.pageSize };
|
|
48
|
+
for (const [field, upstream] of [['keyword', 'title_keyword'], ['displayType', 'activity_display_type']]) {
|
|
49
|
+
if (Object.hasOwn(input, field)) body[upstream] = input[field];
|
|
50
|
+
}
|
|
51
|
+
for (const [field, upstream] of [['start', 'create_begin_time'], ['end', 'create_end_time']]) {
|
|
52
|
+
if (input.createdAt?.[field] !== undefined) body[upstream] = parseDateTime(input.createdAt[field]);
|
|
53
|
+
}
|
|
54
|
+
return body;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function project(envelope, input, scope, facts) {
|
|
58
|
+
if (!Array.isArray(envelope.data)) throw new Error('Invalid activities');
|
|
59
|
+
const activities = envelope.data.map(row => {
|
|
60
|
+
if (!object(row) || !object(row.activity)) throw new Error('Invalid activity');
|
|
61
|
+
const activity = row.activity;
|
|
62
|
+
if (Number.isSafeInteger(activity.kdt_id) && activity.kdt_id > 0 && activity.kdt_id !== scope.kdtId) {
|
|
63
|
+
throw reject('scope_unresolved', 'response', scope, 'sent', facts);
|
|
64
|
+
}
|
|
65
|
+
const result = { activityId: activity.activity_id, ownerKdtId: activity.kdt_id,
|
|
66
|
+
title: activity.title, activityType: activity.activity_type, status: activity.status };
|
|
67
|
+
for (const [field, upstream] of [['alias', 'alias'], ['isDeleted', 'is_deleted']]) {
|
|
68
|
+
if (Object.hasOwn(activity, upstream)) result[field] = activity[upstream];
|
|
69
|
+
}
|
|
70
|
+
if (Object.hasOwn(row, 'preferential_copywriting')) result.offerText = row.preferential_copywriting;
|
|
71
|
+
if (Object.hasOwn(row, 'activity_budget')) {
|
|
72
|
+
if (!object(row.activity_budget)) throw new Error('Invalid budget');
|
|
73
|
+
result.budget = {};
|
|
74
|
+
for (const [field, upstream] of [
|
|
75
|
+
['takenQty', 'taken_qty'], ['usedQty', 'used_qty'],
|
|
76
|
+
['sendTotalQty', 'budget_send_total_qty'], ['useTotalQty', 'budget_use_total_qty'],
|
|
77
|
+
['sendStockQty', 'send_stock_qty'], ['useStockQty', 'use_stock_qty']
|
|
78
|
+
]) {
|
|
79
|
+
if (Object.hasOwn(row.activity_budget, upstream)) result.budget[field] = row.activity_budget[upstream];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
});
|
|
84
|
+
const reportedPage = Object.hasOwn(envelope, 'page_no') ? envelope.page_no : envelope.page_num;
|
|
85
|
+
if (Object.hasOwn(envelope, 'page_num') && envelope.page_num !== reportedPage) {
|
|
86
|
+
throw new Error('Conflicting page numbers');
|
|
87
|
+
}
|
|
88
|
+
const emptySentinel = activities.length === 0 && envelope.total === 0 &&
|
|
89
|
+
reportedPage === 0 && envelope.page_size === 0;
|
|
90
|
+
const pageNo = emptySentinel ? input.pageNo : reportedPage;
|
|
91
|
+
const total = readTotal(envelope, 'total');
|
|
92
|
+
const pagination = { pageNo, pageSize: emptySentinel ? input.pageSize : envelope.page_size,
|
|
93
|
+
...(total === null ? {} : { total }), returnedCount: activities.length, hasMore: null, nextPageNo: null };
|
|
94
|
+
const output = { data: { activities, pagination } };
|
|
95
|
+
validateCommandValue(schema, 'output', output);
|
|
96
|
+
const offset = (input.pageNo - 1) * input.pageSize;
|
|
97
|
+
if (pageNo !== input.pageNo || pagination.pageSize !== input.pageSize ||
|
|
98
|
+
activities.length > input.pageSize ||
|
|
99
|
+
(total !== null && ((activities.length > 0 && offset + activities.length > total) ||
|
|
100
|
+
(activities.length === 0 && offset < total)))) throw new Error('Invalid pagination');
|
|
101
|
+
pagination.hasMore = total === null ? null : input.pageNo * input.pageSize < total;
|
|
102
|
+
pagination.nextPageNo = pagination.hasMore === true && input.pageNo < 500 ? input.pageNo + 1 : null;
|
|
103
|
+
return output;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function createCommand({ context } = {}) {
|
|
107
|
+
return new DiagnosticCommand('list', { path: command, schema, parameterCategory: 'parameter' })
|
|
108
|
+
.description('查询同店一页券发行活动摘要及已返回的预算计数')
|
|
109
|
+
.allowExcessArguments(false)
|
|
110
|
+
.addOption(new Option('--form <form>', '必填:card 优惠卡券;code 优惠码,分别分页')
|
|
111
|
+
.choices(['card', 'code']).makeOptionMandatory())
|
|
112
|
+
.option('--kdt-id <id>', '目标店铺正安全整数;省略取有效上下文 shopId')
|
|
113
|
+
.option('--keyword <text>', '活动名称关键词,去除首尾空白后非空且无控制字符')
|
|
114
|
+
.option('--stage <n>', '0 全部;1 未开始;2 进行中;3 已结束;4 未结束', '0')
|
|
115
|
+
.option('--display-type <n>', '1 满减;2 折扣;3 随机金额;4 兑换;5 社区团购;6 通用码;7 一卡一码')
|
|
116
|
+
.option('--created-at <range>', '创建时间 START..END,可省略一端;北京时间 YYYY-MM-DD HH:mm:ss[.SSS],两端齐备时开始早于结束')
|
|
117
|
+
.option('--page-no <n>', '页码,十进制整数 1..500;只读取指定单页', '1')
|
|
118
|
+
.option('--page-size <n>', '单页容量,十进制整数 1..20', '10')
|
|
119
|
+
.addOption(new Option('--format <format>', 'json 或 pretty,仅改变缩进')
|
|
120
|
+
.choices(['json', 'pretty']).default('json'))
|
|
121
|
+
.option('--dry-run', '本地预览两个请求,不读取凭证、不联网')
|
|
122
|
+
.addHelpText('after', `
|
|
123
|
+
返回 data.activities 和 data.pagination;预算是固定摘要,可选源字段缺失保持省略。
|
|
124
|
+
创建区间必须包含 ..,省略边界不补值,不承诺端点包含性。
|
|
125
|
+
活动不是客户实际持有的券;活动 ID 不等于持券 ID,状态不证明领取资格或订单可用。
|
|
126
|
+
status:0 有效;1 已失效或审核失败,无法区分原因;2 审核中。未知整数保留,不当正常。
|
|
127
|
+
hasMore 只按 total 判断;第500页仍有后续时为 true,但 nextPageNo=null,不能请求501页。
|
|
128
|
+
保留店铺、分组和筛选继续下一页;收窄条件是新查询,不承诺无重无漏或跨页快照。
|
|
129
|
+
真实执行需有效四字段上下文与同店凭证,先核验凭证店铺,再查询同归属店铺活动。
|
|
130
|
+
每次最多2个请求,无自动重试、重定向、切店、翻页或详情补查;核验不证明员工 OAuth。
|
|
131
|
+
不提供 --include、--timeout、--retry 或旧 flag 别名。缺少上下文仅可显式店铺本地预览。
|
|
132
|
+
契约:zan-saas schema coupon.activity.list
|
|
133
|
+
示例:zan-saas coupon activity list --form card
|
|
134
|
+
示例:zan-saas coupon activity list --form code --kdt-id 63077 --page-no 2 --dry-run
|
|
135
|
+
`)
|
|
136
|
+
.action(async options => {
|
|
137
|
+
let scope;
|
|
138
|
+
try { scope = resolveTargetShop(options, context, command); }
|
|
139
|
+
catch (error) {
|
|
140
|
+
if (error.cliDetails) error.cliDetails.stage = error.cliDetails.category === 'configuration' ? 'configuration' : 'input';
|
|
141
|
+
throw error;
|
|
142
|
+
}
|
|
143
|
+
let input;
|
|
144
|
+
try { input = withInputScope(scope, () => buildInput(options, scope)); }
|
|
145
|
+
catch (error) {
|
|
146
|
+
error.cliDetails = reject('validation', 'input', scope).cliDetails;
|
|
147
|
+
throw error;
|
|
148
|
+
}
|
|
149
|
+
const body = requestBody(input);
|
|
150
|
+
const preview = { scope, prerequisites: ['context', 'token-shop-binding'], requests: [
|
|
151
|
+
{ method: 'POST', api: bindingPath, body: {} },
|
|
152
|
+
{ method: 'POST', api: schema.api.path, body }
|
|
153
|
+
] };
|
|
154
|
+
validateCommandValue(schema, 'preview', preview);
|
|
155
|
+
let output = preview;
|
|
156
|
+
if (!options.dryRun) {
|
|
157
|
+
const read = await createShopQuery(scope, command);
|
|
158
|
+
const { envelope, facts } = await read(schema.api.path, body, 'query');
|
|
159
|
+
try { output = project(envelope, input, scope, facts); }
|
|
160
|
+
catch (error) {
|
|
161
|
+
if (error.cliDetails) throw error;
|
|
162
|
+
throw reject('protocol', 'response', scope, 'sent', facts);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
process.stdout.write(`${JSON.stringify(output, null, options.format === 'pretty' ? 2 : 0)}\n`);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
module.exports = { kind: 'atomic', risk: 'read', at: 'all', createCommand: withTargetShopDefault(createCommand) };
|