@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,176 @@
|
|
|
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 { resolveTargetShop } = require('../../../../../execution/target-shop');
|
|
11
|
+
const { validateCommandValue } = require('../../../../../execution/command-schema');
|
|
12
|
+
const { createShopQuery, failure, bindingPath } = require('../../../../../execution/shop-query');
|
|
13
|
+
const { object } = require('../../../../../execution/query-api');
|
|
14
|
+
const { formatDateTime } = require('../../../../../execution/datetime');
|
|
15
|
+
const schema = require('./schema.json');
|
|
16
|
+
|
|
17
|
+
const command = 'interaction.lottery.list';
|
|
18
|
+
const bindingResponseBytes = 512 * 1024;
|
|
19
|
+
const queryResponseBytes = 8 * 1024 * 1024;
|
|
20
|
+
|
|
21
|
+
function reject(category, stage, scope = {}, requestState = 'not_sent', facts = {}) {
|
|
22
|
+
const error = failure(command, category, stage, scope, requestState, facts);
|
|
23
|
+
error.cliDetails.nextStep = stage === 'shop-binding' ?
|
|
24
|
+
'主查询未发送。核对原凭证绑定店铺及目标,不自动切换店铺、身份或重试。' :
|
|
25
|
+
'核对原店铺、玩法、筛选、页码和服务端授权;结果不完整时停止,不自动重放、换店或补查详情。';
|
|
26
|
+
return error;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function buildInput(options, context) {
|
|
30
|
+
let scope;
|
|
31
|
+
try { scope = resolveTargetShop(options, context, command); }
|
|
32
|
+
catch (error) {
|
|
33
|
+
if (['scope', 'validation'].includes(error.cliDetails?.stage)) error.cliDetails.stage = 'input';
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
try { return withInputScope(scope, () => {
|
|
37
|
+
const input = { kind: options.kind, ...scope, state: parseIntegerOption(options.state, schema, '/state'),
|
|
38
|
+
pageNo: parseIntegerOption(options.pageNo, schema, '/pageNo'),
|
|
39
|
+
pageSize: parseIntegerOption(options.pageSize, schema, '/pageSize') };
|
|
40
|
+
if (options.keyword !== undefined) {
|
|
41
|
+
if (typeof options.keyword !== 'string' || /[\u0000-\u001f\u007f-\u009f]/.test(options.keyword)) {
|
|
42
|
+
throw inputIssue('/keyword', 'invalid_format', constraints(modelAt(schema, 'input', '/keyword')));
|
|
43
|
+
}
|
|
44
|
+
input.keyword = options.keyword.trim();
|
|
45
|
+
}
|
|
46
|
+
validateCommandValue(schema, 'input', input);
|
|
47
|
+
return input;
|
|
48
|
+
}); } catch (error) {
|
|
49
|
+
error.cliDetails = reject('validation', 'input', scope).cliDetails;
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function previewFor(input) {
|
|
55
|
+
const condition = { state: input.state, app_name: input.kind,
|
|
56
|
+
page_no: input.pageNo, page_size: input.pageSize };
|
|
57
|
+
if (Object.hasOwn(input, 'keyword')) condition.keyword = input.keyword;
|
|
58
|
+
return {
|
|
59
|
+
scope: { kdtId: input.kdtId },
|
|
60
|
+
prerequisites: ['context', 'token-shop-binding'],
|
|
61
|
+
requests: [
|
|
62
|
+
{ method: 'POST', api: bindingPath, body: {} },
|
|
63
|
+
{ method: 'POST', api: schema.api.path, body: { search_condition_d_t_o: condition } }
|
|
64
|
+
],
|
|
65
|
+
limits: { maxBusinessRequests: 2, bindingResponseBytes, queryResponseBytes }
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function selected(source, fields) {
|
|
70
|
+
return Object.fromEntries(Object.entries(fields).filter(([key]) => Object.hasOwn(source, key))
|
|
71
|
+
.map(([key, name]) => [name, source[key]]));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function projectItem(item, kind) {
|
|
75
|
+
if (!object(item) || item.app_name !== kind) throw new Error('Invalid lottery');
|
|
76
|
+
const result = { activityId: item.id, title: item.title, kind: item.app_name, status: item.activity_status,
|
|
77
|
+
...selected(item, { alias: 'alias' }) };
|
|
78
|
+
for (const [source, target] of [['start_date', 'startsAt'], ['end_date', 'endsAt']]) {
|
|
79
|
+
if (Object.hasOwn(item, source)) result[target] = formatDateTime(item[source]);
|
|
80
|
+
}
|
|
81
|
+
const limits = selected(item, { limit_times_type: 'type', limit_times_value: 'count' });
|
|
82
|
+
if (Object.keys(limits).length) result.limits = limits;
|
|
83
|
+
if (Object.hasOwn(item, 'awards')) {
|
|
84
|
+
if (!Array.isArray(item.awards)) throw new Error('Invalid awards');
|
|
85
|
+
result.awards = item.awards.map(award => {
|
|
86
|
+
if (!object(award)) throw new Error('Invalid award');
|
|
87
|
+
return { awardId: award.id, ...selected(award, { award_name: 'name' }) };
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
const statistics = selected(item, { total_people_num: 'participantCount',
|
|
91
|
+
total_join_times: 'participationCount', total_winning_times: 'winningCount',
|
|
92
|
+
total_winning_num: 'winnerCount', total_un_winning_num: 'nonWinnerCount' });
|
|
93
|
+
if (Object.keys(statistics).length) result.statistics = statistics;
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function project(envelope, input) {
|
|
98
|
+
if (!Array.isArray(envelope.items) || !object(envelope.paginator)) throw new Error('Invalid page');
|
|
99
|
+
const paginator = envelope.paginator;
|
|
100
|
+
const total = readTotal(paginator, 'total_count');
|
|
101
|
+
const offset = (input.pageNo - 1) * input.pageSize;
|
|
102
|
+
if (paginator.page !== input.pageNo || paginator.page_size !== input.pageSize ||
|
|
103
|
+
envelope.items.length > input.pageSize || (total !== null && (total < envelope.items.length ||
|
|
104
|
+
(envelope.items.length === 0 && offset < total)))) throw new Error('Inconsistent page');
|
|
105
|
+
const hasMore = total === null ? null : input.pageNo * input.pageSize < total;
|
|
106
|
+
const output = { data: {
|
|
107
|
+
lotteries: envelope.items.map(item => projectItem(item, input.kind)),
|
|
108
|
+
pagination: { pageNo: paginator.page, pageSize: paginator.page_size, ...(total === null ? {} : { total }),
|
|
109
|
+
hasMore, nextPageNo: hasMore === true && input.pageNo < 1000 ? input.pageNo + 1 : null,
|
|
110
|
+
windowLimitReached: hasMore !== false && input.pageNo === 1000 }
|
|
111
|
+
} };
|
|
112
|
+
validateCommandValue(schema, 'output', output);
|
|
113
|
+
return output;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function createCommand({ context } = {}) {
|
|
117
|
+
return new DiagnosticCommand('list', { path: command, schema, parameterCategory: 'parameter' })
|
|
118
|
+
.description('按明确玩法查询一页抽奖活动、参与限制、奖项摘要及已返回统计')
|
|
119
|
+
.allowExcessArguments(false)
|
|
120
|
+
.addOption(new Option('--kind <kind>', 'string,必填。抽奖玩法:cards刮刮卡、wheel幸运大抽奖、zodiac生肖翻翻看、crazyguess疯狂猜猜猜、shake有赞摇一摇。')
|
|
121
|
+
.choices(['cards', 'wheel', 'zodiac', 'crazyguess', 'shake']).makeOptionMandatory())
|
|
122
|
+
.option('--kdt-id <id>', 'integer,可选。目标店铺ID,默认context.shopId;须为正安全整数,非总部不可跨店。')
|
|
123
|
+
.option('--state <state>', 'integer,可选。活动筛选:0全部、1未开始、2活动中、3已结束,默认0;不是返回status码。', '0')
|
|
124
|
+
.option('--keyword <text>', 'string,可选。活动名称关键字,服务端模糊查询;trim后非空,拒绝控制字符。')
|
|
125
|
+
.option('--page-no <number>', 'integer,可选。页码,范围1..1000,默认1。', '1')
|
|
126
|
+
.option('--page-size <number>', 'integer,可选。每页条数上限,范围1..200,默认20。', '20')
|
|
127
|
+
.addOption(new Option('--format <format>', 'string,可选。输出格式:json紧凑、pretty缩进,默认json。')
|
|
128
|
+
.choices(['json', 'pretty']).default('json'))
|
|
129
|
+
.option('--dry-run', 'boolean,可选。本地预览,默认false;零认证、零网络。')
|
|
130
|
+
.addHelpText('after', `
|
|
131
|
+
total 只描述本次筛选的接口总数,不保证跨页快照;按 nextPageNo 继续并保留店铺、筛选和容量。
|
|
132
|
+
nextPageNo=null 不能单独解释为结束;windowLimitReached=true 表示达到页码上限,仍有后续。
|
|
133
|
+
返回 data.lotteries 和 data.pagination:pageNo、pageSize、total、hasMore、nextPageNo、windowLimitReached。
|
|
134
|
+
返回 status:1未开始、2进行中、3暂停中、4已结束;未知安全整数保留,不按时钟重算。
|
|
135
|
+
limits.type:1一天N次、2一人N次,N为count;未知整数保留,不解释为无限次。
|
|
136
|
+
奖项仅含awardId及可选name,不代表客户中奖或实际资产到账;可选字段缺失省略。
|
|
137
|
+
空页只表示本次玩法及筛选范围,不证明活动全局不存在。第1000页仍可能hasMore,不能请求1001页。
|
|
138
|
+
核验响应最多512 KiB,主响应最多8 MiB;超限整体失败,不截断、不补查详情或伪造归属。
|
|
139
|
+
真实执行需有效上下文及同店授权。支持微商城单店、教育多校区总部,at不证明产品或员工授权。
|
|
140
|
+
不自动重试、换token或换店。预览不证明对象存在或授权有效。
|
|
141
|
+
契约:zan-saas schema interaction.lottery.list
|
|
142
|
+
示例:zan-saas interaction lottery list --kind wheel
|
|
143
|
+
示例:zan-saas interaction lottery list --kind cards --kdt-id 63077 --dry-run
|
|
144
|
+
`)
|
|
145
|
+
.action(async options => {
|
|
146
|
+
const input = buildInput(options, context);
|
|
147
|
+
const preview = previewFor(input);
|
|
148
|
+
validateCommandValue(schema, 'preview', preview);
|
|
149
|
+
let output = preview;
|
|
150
|
+
if (!options.dryRun) {
|
|
151
|
+
let binding = true;
|
|
152
|
+
let response;
|
|
153
|
+
try {
|
|
154
|
+
const read = await createShopQuery(preview.scope, command, {
|
|
155
|
+
transportOptions: { maxResponseBytes: () => binding ? bindingResponseBytes : queryResponseBytes }
|
|
156
|
+
});
|
|
157
|
+
binding = false;
|
|
158
|
+
response = await read(schema.api.path, preview.requests[1].body, 'query');
|
|
159
|
+
} catch (error) {
|
|
160
|
+
if (error.cliDetails) {
|
|
161
|
+
const details = error.cliDetails;
|
|
162
|
+
const stage = details.category === 'limit' && !binding ? 'response' : details.stage;
|
|
163
|
+
throw reject(details.category, stage, preview.scope, details.requestState,
|
|
164
|
+
Object.fromEntries(['api', 'httpStatus', 'businessCode', 'gatewayCode', 'trace_id', 'request_id']
|
|
165
|
+
.filter(key => Object.hasOwn(details, key)).map(key => [key, details[key]])));
|
|
166
|
+
}
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
try { output = project(response.envelope, input); }
|
|
170
|
+
catch { throw reject('protocol', 'response', preview.scope, 'sent', response.facts); }
|
|
171
|
+
}
|
|
172
|
+
process.stdout.write(`${JSON.stringify(output, null, options.format === 'pretty' ? 2 : 0)}\n`);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
module.exports = { kind: 'atomic', risk: 'read', at: 'all', createCommand: withTargetShopDefault(createCommand) };
|